lib3ds help

Started by
2 comments, last by General_Lee 13 years, 4 months ago
Hello, I'm trying to render my 3ds model with lib3ds and this function:

void render(const char * p)
{
Lib3dsFile * model = lib3ds_file_open(p);
if(!model)
{
cout<<"Failed"<<endl;

}
else
{
Lib3dsMesh * mesh;
index=glGenLists(1);
glNewList(index,GL_COMPILE);
for(int i =0;i<=model->meshes_size;++i)
{
mesh=model->meshes;

for(int j =0;j<=mesh->nfaces;++j)
{
glBegin(GL_TRIANGLES);
for(int z=0;z<3;++z)
{
glVertex3fv(mesh->vertices[mesh->faces[j].index[z]]);
}
glEnd();

}
}

glEndList();
}

}

After successful reading of the file(program doesn't write "Failed") it crashes.

What may be the problem.
Any help is greatly appreciated.
Advertisement
Quote:Original post by General_Lee
After successful reading of the file(program doesn't write "Failed") it crashes.
Where? With what error? What does your Debugger say is wrong?
it crashes here:

glVertex3fv(mesh->vertices[mesh->faces[j].index[z]]);

glslDevil says that my program have called glVertex3fv 37 times,glBegin 13 times,glEnd 12 times,glGenLists and glNewList only one time.

Ahh... I've found the problem.

void render(const char * p){  system("pause");  Lib3dsFile * model = lib3ds_file_open(p);  if(!model)  {	  cout<<"Failed"<<endl;	  cout<<p<<endl;	    }  else  {	  cout<<p<<endl;  index=glGenLists(1);  glNewList(index,GL_COMPILE);    for(int i =0;i<sizeof(model->meshes)/sizeof(int);++i)  {	  float (*normalL)[3] = (float(*)[3])malloc(3 * 3 * sizeof(float) * model->meshes->nfaces);	  lib3ds_mesh_calculate_vertex_normals(model->meshes, normalL);	  for(int j =0;j<model->meshes->nfaces;++j)	  {		  glBegin(GL_TRIANGLES);		  for(int z=0;z<3;++z)		  {			  cout<<"Mesh:";			  cout<<i<<endl;			  cout<<"Face:";			  cout<<j<<endl;			  cout<<"Vertex:";			  cout<<z<<endl;			  			  glNormal3fv(normalL[3*j+z]);		      glVertex3fv(model->meshes->vertices[model->meshes->faces[j].index[z]]);		  		      		  }		  glEnd();		  	  }  }    glEndList();  }	}

This topic is closed to new replies.

Advertisement