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.
lib3ds help
Quote:Original post by General_LeeWhere? With what error? What does your Debugger say is wrong?
After successful reading of the file(program doesn't write "Failed") it crashes.
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.
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
Popular Topics
Advertisement