Jump to content
  • Advertisement
Sign in to follow this  
General_Lee

lib3ds help

This topic is 2847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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();
}

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!