I cut out the code and the effect repeats here, check this code:
Code:
#include "GL/glew.h"
#include <iostream>
#include "fstream"
#include "math.h"
#include <stdio.h>
#include <string.h>
const int sgNumberOfObjects=200;
const int sgNumberOfPolygons=9000;
const int sgNumberOfBones=45;
const int sgNumberOfTextures=8;
const int sgNumberOfTexturesAnimation=15;
const int sgNumberOfAnimations=100;
const int sgNumberOfFrames=10;
const int sgNumberOfDataTextures=7;
char sgFileName[sgNumberOfObjects][99];
char sgTexName[(sgNumberOfObjects*sgNumberOfTextures*sgNumberOfTexturesAnimation)+
sgNumberOfDataTextures][99];
static float sgRv[sgNumberOfPolygons*9*2];// VERTICES.
static float sgRc[sgNumberOfPolygons*12*2];// COLOR.
static float sgRt[sgNumberOfPolygons*6*2];// TEXTURE COORDINATES.
class sgObject{
public:
int animation_number_of_animations;
int animation_number_of_frames[sgNumberOfAnimations];
int animate;
int animation_select;
int animation_completed;// IS SET TO 1 IF AN ANIMATION SEQUENCE HAS PLAYED THROUGH.
float animation_time;
float animation_lenght[sgNumberOfAnimations];
float animation_frametime[sgNumberOfAnimations][sgNumberOfFrames];
float animation_angle[sgNumberOfAnimations][sgNumberOfFrames][sgNumberOfBones][3];
float animation_speed;// 1.0 = NORMAL TIME, <1.0 = SLOWMOTION, >1.0 FASTFORWARD.
float animation_offset[sgNumberOfAnimations][sgNumberOfFrames][3];
int skeleton_number_of_bones;
int skeleton_selected_bone;
int skeleton_parent[sgNumberOfBones];
int skeleton_parent_heritage[sgNumberOfBones][sgNumberOfBones];
int skeleton_curve[sgNumberOfBones];
float skeleton_angle_in[sgNumberOfBones][3];// INPUT ANGLES (USE THIS FOR DYNAMIC ANIMATION).
float skeleton_angle[sgNumberOfBones][3];
float skeleton_angle_pose[sgNumberOfBones][3];
float skeleton_reference[sgNumberOfBones][3];
float skeleton_pose[sgNumberOfBones][3];
float skeleton_pose_c[3][sgNumberOfBones][3];
float skeleton_offset[3];
int vertice_number_of_polygons;
int vertice_link[sgNumberOfPolygons*3];
int vertice_child[sgNumberOfPolygons*3];
int vertice_sorted_chunk[sgNumberOfBones+2];
float vertice_weight[sgNumberOfPolygons*3];
float vertice_reference[sgNumberOfPolygons*3][3];
float vertice_pose[sgNumberOfPolygons*3][3];
float vertice_pose_c[3][sgNumberOfPolygons*3][3];
float *vertice_sorted[sgNumberOfPolygons*3];
int texture_number_of_textures;
int texture_number_of_frames[sgNumberOfTextures];
int texture_link[sgNumberOfTextures];
int texture_select[sgNumberOfTextures];
int texture_framerate[sgNumberOfTextures];
float texture_time[sgNumberOfTextures];
float texture_lenght[sgNumberOfTextures];
float texture_coordinate[sgNumberOfPolygons*3][2];
GLuint texture[sgNumberOfTextures][sgNumberOfTexturesAnimation];
GLuint tex_s[sgNumberOfTextures][sgNumberOfTexturesAnimation];
GLuint tex_e[sgNumberOfTextures][sgNumberOfTexturesAnimation];
GLuint tex_n[sgNumberOfTextures][sgNumberOfTexturesAnimation];
int attach;
int attach_object;// ATTACH TO THIS OBJECT (NUMBER IN ARRAY).
int attached;
int attach_bone;// ATTACH TO THIS BONE IN THE HOSTING OBJECT.
float attach_offset_position[3];
float attach_offset_angle[3];
sgObject *attach_adress;
int render;
int render_surface;
int render_mesh;// 0 = NO, 1 = YES (WITH DEPTHTEST), 2 = YES (WITHOUT DEPTHTEST).
int render_skeleton;
float position[3];
float position_old[3];
float color[4];
float angle[3];
float last_position[3];
float last_angle[3];
};
sgObject object[sgNumberOfObjects];int sgSo=0;
#define o object
int offset=0;
void sgLOAD_OBJ(int object_id,int data_id){
int c=0,d=0,e=0,f=0,g=0,t=0,tex_val=-1,r=0;char lr[200];FILE * file;
float rv[sgNumberOfPolygons*9];
float rtc[sgNumberOfPolygons*6];
int rf[sgNumberOfPolygons*3];
int rt[sgNumberOfPolygons*3];
int rtv[sgNumberOfPolygons+1];
file=fopen(sgFileName[data_id],"r");while(1){r=fscanf(file,"%s",lr);if(r==EOF)break;
if(strcmp(lr,"usemtl")==0){tex_val+=1;}
if(strcmp(lr,"v")==0){fscanf(file,"%f %f %f\n",&rv[d+0],&rv[d+1],&rv[d+2]);d+=3;
if(d>=sgNumberOfPolygons*3){d=0;}}
if(strcmp(lr,"vt")==0){fscanf(file,"%f %f\n",&rtc[e+0],&rtc[e+1]);e+=2;
if(e>=sgNumberOfPolygons*2){e=0;}}
if(strcmp(lr,"f")==0){fscanf(file,"%d/%d %d/%d %d/%d\n",
&rf[f+0],&rt[f+0],&rf[f+1],&rt[f+1],&rf[f+2],&rt[f+2]);rtv[c]=tex_val;
c+=1;f+=3;if(c>=sgNumberOfPolygons){c=0;f=0;}g+=1;}}rtv[g]=tex_val+1;c=0;d=0;e=0;f=0;fclose(file);
//std::cout<<sgFileName[data_id]<<std::endl;
//std::cout<<g<<std::endl;
if(g<sgNumberOfPolygons){
o[object_id].animation_number_of_animations=0;
o[object_id].animate=1;
o[object_id].animation_select=0;
o[object_id].animation_completed=0;
o[object_id].animation_time=0.0f;
for(int i=0;i<sgNumberOfAnimations;i++){
o[object_id].animation_number_of_frames[I]=0;
o[object_id].animation_lenght[I]=0.0f;
for(int j=0;j<sgNumberOfFrames;j++){
o[object_id].animation_offset[I][j][0]=0.0f;
o[object_id].animation_offset[I][j][1]=0.0f;
o[object_id].animation_offset[I][j][2]=0.0f;
o[object_id].animation_frametime[I][j]=0.0f;
for(int k=0;k<sgNumberOfBones;k++){
o[object_id].animation_angle[I][j][k][0]=0.0f;
o[object_id].animation_angle[I][j][k][1]=0.0f;
o[object_id].animation_angle[I][j][k][2]=0.0f;}}}
o[object_id].animation_speed=1.0f;
o[object_id].skeleton_number_of_bones=0;
o[object_id].skeleton_selected_bone=0;
o[object_id].skeleton_offset[0]=0.0f;
o[object_id].skeleton_offset[1]=0.0f;
o[object_id].skeleton_offset[2]=0.0f;
for(int i=0;i<sgNumberOfBones;i++){
o[object_id].skeleton_parent[I]=0;
o[object_id].skeleton_angle[I][0]=0.0f;
o[object_id].skeleton_angle[I][1]=0.0f;
o[object_id].skeleton_angle[I][2]=0.0f;
o[object_id].skeleton_angle_pose[I][0]=0.0f;
o[object_id].skeleton_angle_pose[I][1]=0.0f;
o[object_id].skeleton_angle_pose[I][2]=0.0f;
o[object_id].skeleton_reference[I][0]=0.0f;
o[object_id].skeleton_reference[I][1]=0.0f;
o[object_id].skeleton_reference[I][2]=0.0f;
o[object_id].skeleton_pose[I][0]=0.0f;
o[object_id].skeleton_pose[i][1]=0.0f;
o[object_id].skeleton_pose[i][2]=0.0f;
o[object_id].skeleton_pose_c[0][i][0]=0.0f;
o[object_id].skeleton_pose_c[0][i][1]=0.0f;
o[object_id].skeleton_pose_c[0][i][2]=0.0f;
o[object_id].skeleton_pose_c[1][i][0]=0.0f;
o[object_id].skeleton_pose_c[1][i][1]=0.0f;
o[object_id].skeleton_pose_c[1][i][2]=0.0f;
o[object_id].skeleton_pose_c[2][i][0]=0.0f;
o[object_id].skeleton_pose_c[2][i][1]=0.0f;
o[object_id].skeleton_pose_c[2][i][2]=0.0f;
o[object_id].skeleton_curve[i]=0;
o[object_id].skeleton_angle_in[i][0]=0.0f;
o[object_id].skeleton_angle_in[i][1]=0.0f;
o[object_id].skeleton_angle_in[i][2]=0.0f;
for(int j=0;j<sgNumberOfBones;j++){
o[object_id].skeleton_parent_heritage[i][j]=0;}}
o[object_id].vertice_number_of_polygons=g;
for(int i=0;i<sgNumberOfBones+2;i++){
o[object_id].vertice_sorted_chunk[i]=0;}
for(int i=0;i<sgNumberOfPolygons*3;i++){
o[object_id].vertice_link[i]=0;
o[object_id].vertice_child[i]=0;
o[object_id].vertice_weight[i]=0.0f;
o[object_id].vertice_reference[i][0]=0.0f;
o[object_id].vertice_reference[i][1]=0.0f;
o[object_id].vertice_reference[i][2]=0.0f;
o[object_id].vertice_pose_c[0][i][0]=0.0f;
o[object_id].vertice_pose_c[0][i][1]=0.0f;
o[object_id].vertice_pose_c[0][i][2]=0.0f;
o[object_id].vertice_pose_c[1][i][0]=0.0f;
o[object_id].vertice_pose_c[1][i][1]=0.0f;
o[object_id].vertice_pose_c[1][i][2]=0.0f;
o[object_id].vertice_pose_c[2][i][0]=0.0f;
o[object_id].vertice_pose_c[2][i][1]=0.0f;
o[object_id].vertice_pose_c[2][i][2]=0.0f;
o[object_id].vertice_pose[i][0]=0.0f;
o[object_id].vertice_pose[i][1]=0.0f;
o[object_id].vertice_pose[i][2]=0.0f;}
o[object_id].attach=0;
o[object_id].attach_object=0;
o[object_id].attached=0;
o[object_id].attach_bone=0;
o[object_id].attach_offset_position[0]=0.0f;
o[object_id].attach_offset_position[1]=0.0f;
o[object_id].attach_offset_position[2]=0.0f;
o[object_id].attach_offset_angle[0]=0.0f;
o[object_id].attach_offset_angle[1]=0.0f;
o[object_id].attach_offset_angle[2]=0.0f;
o[object_id].attach_adress=NULL;
o[object_id].render=1;
o[object_id].render_surface=1;
o[object_id].render_mesh=1;
o[object_id].render_skeleton=0;
o[object_id].position[0]=0.0f;
o[object_id].position[1]=0.0f;
o[object_id].position[2]=0.0f;
o[object_id].color[0]=1.0f;
o[object_id].color[1]=1.0f;
o[object_id].color[2]=1.0f;
o[object_id].color[3]=1.0f;
o[object_id].angle[0]=0.0f;
o[object_id].angle[1]=0.0f;
o[object_id].angle[2]=0.0f;
o[object_id].texture_link[0]=0;
while(c<o[object_id].vertice_number_of_polygons){
o[object_id].vertice_reference[d+0][0]=rv[(rf[d+0]*3)-3];
o[object_id].vertice_reference[d+0][1]=rv[(rf[d+0]*3)-2];
o[object_id].vertice_reference[d+0][2]=rv[(rf[d+0]*3)-1];
o[object_id].vertice_reference[d+1][0]=rv[(rf[d+1]*3)-3];
o[object_id].vertice_reference[d+1][1]=rv[(rf[d+1]*3)-2];
o[object_id].vertice_reference[d+1][2]=rv[(rf[d+1]*3)-1];
o[object_id].vertice_reference[d+2][0]=rv[(rf[d+2]*3)-3];
o[object_id].vertice_reference[d+2][1]=rv[(rf[d+2]*3)-2];
o[object_id].vertice_reference[d+2][2]=rv[(rf[d+2]*3)-1];
o[object_id].texture_coordinate[d+0+30][0]=rtc[(rt[d+0]*2)-2];
o[object_id].texture_coordinate[d+0+30][1]=rtc[(rt[d+0]*2)-1]*-1.0f;
o[object_id].texture_coordinate[d+1+30][0]=rtc[(rt[d+1]*2)-2];
o[object_id].texture_coordinate[d+1+30][1]=rtc[(rt[d+1]*2)-1]*-1.0f;
o[object_id].texture_coordinate[d+2+30][0]=rtc[(rt[d+2]*2)-2];
o[object_id].texture_coordinate[d+2+30][1]=rtc[(rt[d+2]*2)-1]*-1.0f;
o[object_id].texture_link[rtv[c]+1]=c+1;
o[object_id].texture_number_of_textures=rtv[c]+1;
o[object_id].texture_framerate[c]=10;
/*std::cout<<c<<" "<<o[object_id].texture_coordinate[d+0+offset][0]<<" "<<
o[object_id].texture_coordinate[d+0+offset][1]<<std::endl;
std::cout<<c<<" "<<o[object_id].texture_coordinate[d+1+offset][0]<<" "<<
o[object_id].texture_coordinate[d+1+offset][1]<<std::endl;
std::cout<<c<<" "<<o[object_id].texture_coordinate[d+2+offset][0]<<" "<<
o[object_id].texture_coordinate[d+2+offset][1]<<std::endl;*/
c+=1;d+=3;}
c=0;d=0;while(c<o[object_id].vertice_number_of_polygons){
std::cout<<c<<" "<<o[object_id].texture_coordinate[d+0+offset][0]<<" "<<
o[object_id].texture_coordinate[d+0+offset][1]<<std::endl;
std::cout<<c<<" "<<o[object_id].texture_coordinate[d+1+offset][0]<<" "<<
o[object_id].texture_coordinate[d+1+offset][1]<<std::endl;
std::cout<<c<<" "<<o[object_id].texture_coordinate[d+2+offset][0]<<" "<<
o[object_id].texture_coordinate[d+2+offset][1]<<std::endl;
c+=1;d+=3;}
for(int i=0;i<o[object_id].texture_number_of_textures;i++){
o[object_id].texture_lenght[i]=
o[object_id].texture_number_of_frames[i]*
(1.0f/(float)o[object_id].texture_framerate[i]);
}
}else{
}
}
int main(int argc,char **argv){
strncpy(sgFileName[0],"./temp/testf.obj",50);
sgLOAD_OBJ(0,0);
return 0;}
and here is the file I use uploaded, testf.obj, you need GLEW lib and create the temp directory or edit the sgFileName to were you put the file if you want to compile and test it.[/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/I][/code]
[doublepost=1472751569,1472751418][/doublepost]THESE are the lines were the evil happens?
while(c<o[object_id].vertice_number_of_polygons){
o[object_id].vertice_reference[d+0][0]=rv[(rf[d+0]*3)-3];
o[object_id].vertice_reference[d+0][1]=rv[(rf[d+0]*3)-2];
o[object_id].vertice_reference[d+0][2]=rv[(rf[d+0]*3)-1];
o[object_id].vertice_reference[d+1][0]=rv[(rf[d+1]*3)-3];
o[object_id].vertice_reference[d+1][1]=rv[(rf[d+1]*3)-2];
o[object_id].vertice_reference[d+1][2]=rv[(rf[d+1]*3)-1];
o[object_id].vertice_reference[d+2][0]=rv[(rf[d+2]*3)-3];
o[object_id].vertice_reference[d+2][1]=rv[(rf[d+2]*3)-2];
o[object_id].vertice_reference[d+2][2]=rv[(rf[d+2]*3)-1];
o[object_id].texture_coordinate[d+0+30][0]=rtc[(rt[d+0]*2)-2];
o[object_id].texture_coordinate[d+0+30][1]=rtc[(rt[d+0]*2)-1]*-1.0f;
o[object_id].texture_coordinate[d+1+30][0]=rtc[(rt[d+1]*2)-2];
o[object_id].texture_coordinate[d+1+30][1]=rtc[(rt[d+1]*2)-1]*-1.0f;
o[object_id].texture_coordinate[d+2+30][0]=rtc[(rt[d+2]*2)-2];
o[object_id].texture_coordinate[d+2+30][1]=rtc[(rt[d+2]*2)-1]*-1.0f;
[doublepost=1472751729][/doublepost]Actually you dont need GLEW just normal GL I think, just for the GLuint variables if that would matter in the grand scheme of things...
[doublepost=1472752294][/doublepost]Oh wow, I forgot to change from my old manual offset in the loop, instead of texture_coordinate[d+0+30] change to [d+0+offset], and then you can sett the offset manually more easily, but it reveals one thing, the 1.4013e-044 value is set in the first couple of elements before already if I dont write to them, but why would they report my real value when I print out inside the loop, but then revert back again as ssoon as loop iis done? That makes no sense to me.