Skip to main content
gamedev.net
🔒 Locked

Lighting/Normals problem

Started by samsamm777 Apr 14, 2006 at 9:20 AM 2 replies 400+ views
Original Post
samsamm777
samsamm777
Im making a little program to display a 3dsmax(vrml) model. its my head :) im having massive problems with lighting. my normals outputted by max are indexed so i think thats whats causing the problems. my verts etc are just hardcoded in an array :) any ideas how i can use the indexs for the normals? void drawHead() { #define NUM_OF_TRIANGLES 295 glRotatef(-90,1,0,0); glTranslatef(0,70,0); glShadeModel(GL_SMOOTH); // Enable vertes array, normal array, texture coord array glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); //glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Set vertex pointer, normal pointer, tex coord pointer glVertexPointer(3, GL_FLOAT, 0, meshCords); glNormalPointer(GL_FLOAT, 0, meshNormals); //glTexCoordPointer(2, GL_FLOAT, 0, textCords); float material_diffuse[4] = { 0.5f, 0.5f, 0.5f, 0.3f }; float material_specular[4] = { 0.3f, 0.4f, 0.451f, 0.6f }; float material_shininess[1] = { 30.0f }; glMaterialfv(GL_FRONT, GL_DIFFUSE, material_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, material_specular); glMaterialfv(GL_FRONT, GL_SHININESS, material_shininess); //DRAW THE HEAD! :) glDrawElements(GL_TRIANGLES, NUM_OF_TRIANGLES*3, GL_UNSIGNED_INT, meshIndices); } http://www.sosickclothing.com/stuff/lightingprobs.jpg screenshot of the problem! [Edited by - samsamm777 on April 14, 2006 11:23:00 AM]
nefthy
nefthy
If they are indexed reorder them to match you verticles. Or you could load the index, verticles and normals from the MAX file and use glIndexPointer().
samsamm777
samsamm777
any chance you can expand on that please?
MARS_999
MARS_999
I think you may want to look into glInterleavedArrays() instead.

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/interleavedarrays.html

You can use this if max has output the vertex data as a single chunk of data. If not you could load them each individually like so
struct Vertex{float vx, vy, vz;float nx, ny, nz;float s, t;};Vertex *vertexdata = new Vertex[numberofVerticesInModel];unsigned int vertexStride = sizeof(Vertex);glVertexPointer(3, GL_FLOAT, vertexStride, vertexdata.vx);glEnableClientState(GL_VERTEX_ARRAY);glNormalPointer(GL_FLOAT, vertexStride, vertexdata.nx);glEnableClientState(GL_NORMAL_ARRAY);	glActiveTextureARB(GL_TEXTURE0_ARB);glBindTexture(GL_TEXTURE_2D, textureObject);glClientActiveTextureARB(GL_TEXTURE0_ARB);glTexCoordPointer(2, GL_FLOAT, vertexStride, vertexdata.s);glEnableClientState(GL_TEXTURE_COORD_ARRAY);


I am not sure if that is what you are looking for but sounds like your data is packed but I have never looked at .max files...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.