Archived

This topic is now archived and is closed to further replies.

Mage2k

Do models need lighting?

Recommended Posts

Here''s why I ask: I am writing my first model loader (md2) and want to render the model without the skin (wireframe). I am just trying to view the first frame and have glPolygonMode set as such: glPolygonMode(GL_FRONT, GL_LINE). I have all of the vertices loaded into a display list (i''ve verified that I have valid vertices in my vertex array that I use to generate the display list) and use the same color for all when rendering but I am not seeing anything. Do I need lighting or is it something else? peace and (trance) out Mage

Share this post


Link to post
Share on other sites
Well, no, I know that I''ve loaded all of the vertex and command data correctly (as I have outputted the arrays to a text file after loading). The problem must be where I''m building the display lists for the frames or how I''ve set up the camera and/or perspective transforms... I''ll post again if I can''t get it figured out. Thanx.

peace and (trance) out

Mage

Share this post


Link to post
Share on other sites
Are you sure you are rendering the model inside the viewing frustum?

You may have something like this:

gluPerspective( 45, width/height/ 10.0, 100.0 );

but you have done

glTranslatef( 0.0, 0.0, -2.0 );

Look, it is before the near plane! Did you get what I mean?

Check those vertex coodinates, mate!

Share this post


Link to post
Share on other sites
Just another little something... turn off glCullFace... when loading model formats (such as md3), it''s very easy to end up with HUGE models, and it''s quite possible that your camera is inside it!

Just turn off culling to test... that way even if you are inside it, you''ll see something (the inside of it).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You should read the Red Book 1.1 or a good book on OpenGL.

You CAN''T use vertex arrays in a display list, becouse of the client-server model of the OpenGL. (Yes, that''s why it''s called glEnableClientState()).

You have to decide between using a display list or an array. As far as I''ve seen, the vertex array is slightly faster than the display list, and if you use a boostin'' aproach (like using vertex pools instead of simple vertex arrays), you can get an 40-70% speed boost when rendering big amounts of data. But that''s up to you.

Share this post


Link to post
Share on other sites
OK: I am working all this weekend so I really don''t have time to work on this (although I do have time to browse the gamedev forums...:->) but, I am already reading the redbook and I am not using vertex arrays for rendering, I am using arrays to store the vertexes and then using the indices from the glcommands in the md2 file to build the display list in a loop... anywayz, thanks for all of the suggestions guyz...

peace and (trance) out

Mage

Share this post


Link to post
Share on other sites
Just use this function


  
void Wire()
{
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_TEXTURE_2D);
glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);
}

Share this post


Link to post
Share on other sites
Ok, I'm stumped. The problem must be somewhere in how I'm building/using the display lists as I've checked out my camera and projection stuff by drawing some basic objects and I can see them just fine. So, here's the code where I build the display lists:


      
//read in the glcommands

int *commands = new int[header.num_glcmds];
file.seekg(header.ofs_glcmds, ios::beg);
file.read((char*) commands, header.num_glcmds * sizeof(int));


//build the display lists

numFrames = header.num_frames;
firstFrame = glGenLists(numFrames);
int *temp2, count;
for(i = 0; i < numFrames; ++i){
temp2 = commands;
count = 4; //need to set to 3 for first iteration of inner for loop


glNewList(firstFrame + i, GL_COMPILE);
while(count < header.num_glcmds){
int j = *(temp2++);
if(j < 0){
glBegin(GL_TRIANGLE_FAN);
j = -j;
}
else
glBegin(GL_TRIANGLE_STRIP);

for(; j > 0; --j, temp2 += 3, count +=3){
glVertex3fv(&verts[temp2[2] + i*header.num_xyz]);
}
++count;
glEnd();
}
glEndList();
}
verts is an array of 3*numFrames*header.num_xyz floats and as I noted earlier I have verified that I am loading them and the commands from the .md2 file correctly and successfully. However, when I call glCallList(firstFrame) I am not seeing anything... See any problems?

peace and (trance) out

Mage

[edited by - Mage2k on May 5, 2003 4:10:36 PM]

[edited by - Mage2k on May 5, 2003 4:11:18 PM]

Share this post


Link to post
Share on other sites
Wow, 306 views and nobody has an answer... Is everybody checking the thread looking to see if anyone''s posted an answer or another suggestion, or have 306 different people actually looked at it... Seems unlikely looking at the avg number of times most of the other threads in this forum have been viewed...

Share this post


Link to post
Share on other sites
Heh... it''s always something really stupid... first, and most important for why nothing was being drawn: I was loading the model before I had initialized OpenGL. Second, when I was indexing into the verts array to draw the vertices, I wasn''t moving forward by a factor of 3 for each vertex (3 floats in the array for each vertex) so when I was first seeing something it was garbage, but that was an easy one to find as the location of that bug was a little more obvious. And, once again, thanx for all of the suggestions...

Share this post


Link to post
Share on other sites
quote:
Original post by Mage2k
Wow, 306 views and nobody has an answer...

When I saw the post, I was hoping it was a discussion about using OpenGL lighting versus using other methods... I think the title might have caused more people to look in than a title like, "MD2 model renderer not showing anything" would have.

- sighuh?

[edited by - redragon on May 7, 2003 1:38:25 PM]

Share this post


Link to post
Share on other sites