Sign in to follow this  
General_Lee

lib3ds normals help

Recommended Posts

Hello, I'm using this algorithm to load my model


void render(const char * p)
{

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

}
else
{
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)
{
float colorBlue[] = { 0.0f, 0.0f, 1.0f, 1.0f };
glBegin(GL_TRIANGLES);
for(int z=0;z<3;++z)
{


glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorBlue);
colorBlue[z]+=1.0f;
glNormal3fv(normalL[3*j+z]);
glVertex3fv(model->meshes[i]->vertices[model->meshes[i]->faces[j].index[z]]);


}
glEnd();


}
}

glEndList();
}

}



But It seems completely wrong.

http://www.glowfoto.com/static_image/10-022629L/2124/jpg/12/2010/img5/glowfoto
http://www.glowfoto.com/static_image/10-022725L/6905/jpg/12/2010/img5/glowfoto
http://www.glowfoto.com/static_image/10-022755L/3608/jpg/12/2010/img5/glowfoto


As far as I can see the problem isn't connected with color changing.

Am I using the wrong algorithm?

[Edited by - General_Lee on December 10, 2010 5:22:41 AM]

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