Skip to main content
gamedev.net
🔒 Locked

Problem with MD2

Started by Chrysaor Jul 13, 2004 at 9:53 PM 9 replies 2k views
Original Post
Chrysaor
Chrysaor
hey, Trying to get the md2 model working. Its my first attempt at working with models. Anyhoo, like many, i use OpenGL Game Programming as my starting guide. Anyways, i basically copied their code so i can make sure it works before i modify it to my liking. But here is the problem. I load the file, and then i just draw a frame. I didnt add texturing yet cause i wanna make sure things work so far. So basically, i should just get a white silhouette of the model (i set the color to white). Anyhooo, when i compile and run, nothing. Just a black screen. There is alot of code involved in loading it and just rendering a frame so i wont post it those functions unless i have to(dunno how to post source code in that little white box so my post would be very long). Anyone who has that book can look it up (chapter 18). But, i believe my problem is in the loading function. I found a for loop that doesnt make any sense. Here is the code from the book: triIndex = new mesh_t [numTriangles]; // point to triangle indexes in buffer bufIndexPtr = (mesh_t*)&buffer[modelHeader->offsetTris]; // create a mesh (triangle) list for (j = 0; j < numFrames; j++) { // for all triangles in each frame for(i = 0; i < numTriangles; i++) { triIndex.meshIndex[0] = bufIndexPtr.meshIndex[0]; triIndex.meshIndex[1] = bufIndexPtr.meshIndex[1]; triIndex.meshIndex[2] = bufIndexPtr.meshIndex[2]; triIndex.stIndex[0] = bufIndexPtr.stIndex[0]; triIndex.stIndex[1] = bufIndexPtr.stIndex[1]; triIndex.stIndex[2] = bufIndexPtr.stIndex[2]; } } Is it just me, or is that for wrong. I mean, the j is never used. So every loop of the j for loop will erase any data written the previous loop. However, if you look at the mem alloc, they only alloc enough mem for the tris in one frame.
kburkhart84
kburkhart84
I too have the OpenGL Game Programming Book. If you want, I'll send you a set of classes that I use with OpenGL to make it all easier, including loading and animating of MD2 models. It includes a kbgl class that is basicly everthing basic to OpenGL itself and the window(creating and destroying the window, drawing everything, etc...). Post here or e-mail me at "kburkhart84@sbcglobal.net" and I'll send it all to you.
Also, I just finished a terrain editor and terrain class for use with the rest of the stuff.


Myopic Rhino
Myopic Rhino
The outer loop shouldn't even be there. It's not what's causing your problem, though, it's just inefficient. There is only one set of tris for the whole model (they're just indicies into the vertex lists which *are* per frame).

The loading code in the book should work, though. The thing is, there are many things that can result in a black screen, so it's kind of hard to say what the problem might be. Most often, it's because the camera is set up incorrectly.

btw, you can use the [source][/source] tags to get the white code boxes. It's covered in the FAQ.
Chrysaor
Chrysaor
thanks for the info on the source tags.

anyways, this is how I set up the camera:

// Position View Up-Vector
gluLookAt(0,0,6, 0,0,0, 0,1,0);


I've tried multpiple positions, still nothing.
Tera_Dragon
Tera_Dragon
I've just gone through that code and set it up, and I found that the model is HUGE. I have to translate about -60 n the z axis. So the camera might be inside the model and looking at the back faces of some of the polys, and if backface culling is enabled then you won't see anything.
Hope this helps
Tera_Draon
____________________________________________________________Programmers Resource Central
kburkhart84
kburkhart84
Quote:
Original post by Tera_Dragon
I've just gone through that code and set it up, and I found that the model is HUGE. I have to translate about -60 n the z axis. So the camera might be inside the model and looking at the back faces of some of the polys, and if backface culling is enabled then you won't see anything.
Hope this helps
Tera_Draon


I forgot about that. You have to scale them like 1/10th or something. Model editors make the vertices this huge. I sent you my code with the class, but you still have to scale it down to size before you draw it. Good point.


Tera_Dragon
Tera_Dragon
Yes, you can either use the large coordinates for everything in your world, or scale the model down. I used glScalef(0.0f, 0.05f, 0.05f); I think to scale it down to a nice size.
____________________________________________________________Programmers Resource Central
kburkhart84
kburkhart84
Quote:
Original post by Tera_Dragon
Yes, you can either use the large coordinates for everything in your world, or scale the model down. I used glScalef(0.0f, 0.05f, 0.05f); I think to scale it down to a nice size.


I don't think that would work too well, the model would still be the same width, but the height and depth (Y and Z), would be 1/20th the original size. You used glScalef(0.0f, 0.05f, 0.05f); You forgot to make the first paramter 0.05f as well. Not only that, but I don't think it is necessary to put the ".0f" anyway. The GLfloat is the same thing as a normal float except that I think the GLfloat does some kind of error checking or bounds checking. I never have ran into any problem using normal floats and without putting the .0f after an int.


Chrysaor
Chrysaor
Thank you soooo much kburkhart84 and tera_dragon, for the files and the help. Ya.. it was a scaling problem. Scaled by 0.05 on all axis and its all good. Thanks again.
Tera_Dragon
Tera_Dragon
Quote:
Original post by kburkhart84
Quote:
Original post by Tera_Dragon
Yes, you can either use the large coordinates for everything in your world, or scale the model down. I used glScalef(0.0f, 0.05f, 0.05f); I think to scale it down to a nice size.


I don't think that would work too well, the model would still be the same width, but the height and depth (Y and Z), would be 1/20th the original size. You used glScalef(0.0f, 0.05f, 0.05f); You forgot to make the first paramter 0.05f as well. Not only that, but I don't think it is necessary to put the ".0f" anyway. The GLfloat is the same thing as a normal float except that I think the GLfloat does some kind of error checking or bounds checking. I never have ran into any problem using normal floats and without putting the .0f after an int.


I accidently missed the 5 of there...

As for the f on the end of a float, if you don't put it there the compiler will think that you are using a double, so I just do that to be safe (you somethimes get errors, if u return a double and not float etc.)

And GLfloat doesn't have bounds checking, but another type does (forgotten what it's called...), and it's from 0.0f ot 1.0f
Tera_Dragon
____________________________________________________________Programmers Resource Central

Topic Locked

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

Sign in to reply to this topic.