Sign in to follow this  
General_Lee

lib3ds help

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[i];

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
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[i]->nfaces);

lib3ds_mesh_calculate_vertex_normals(model->meshes[i], normalL);
for(int j =0;j<model->meshes[i]->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[i]->vertices[model->meshes[i]->faces[j].index[z]]);

}
glEnd();


}
}

glEndList();
}

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this