So, I’m working with SDL and OpenGL, and I know SDL makes textures upside-down, but what’s really strange is that for some reason I imported an MD2 model into my program, using some code from a tutorial that used Windows code (rather than SDL), and well… the thing is rendering sideways. @_@
Is it just something that SDL does? If so, then does anyone know how to fix the problem? And if not, then that clues me that it’s possibly something I did wrong…
Okay, now I’m just having weird problems with rendering them in the SDL/OpenGL combo.
So I’m working with an OpenGL tutorial (actually, a book, but whatever) that explains how to open MD2 files in OpenGL with Win32 code, but I’m converting the project to work with SDL since I prefer it to that Win32 stuff. So I successfully converted everything, and everything seemed to be working correctly up close…
But then, as the camera gets further from the models, things start to mess up… some of the surfaces start to disappear. I don’t know why, since the same OpenGL code works fine with win32 rather than SDL. So I’m wondering if there’s something special I have to do in order to keep this from happening.
Here, you can see part of their faces and legs have appeared to turned black at this distance:
And in this picture, their faces and front of their bodies have disappeared for no real reason:
I also noticed that at distances, there’s a weird problem with anti-aliasing and jagged lines at a distance… surely that’s not normal:
I had the same problem when rendering a landscape a while back, too… check out the jaggies here (this with OpenGL anti-aliasing turned on):
I just know there’s gotta be something I must not setting up correctly. All this stuff is really bizarre… remember, the Win32 version of the model program works correctly. So I don’t get why it has problems in SDL…
glFrustrum…? Actually, I’ve never used that before, but I have used gluPerspective though. That’s similar I suppose.
Wait, I just looked at the tutorial and I notice that for their gluPerspective() they have set up, they set the first parameter “fovy” as 54.0f… whereas I’m using 45.0f… so I put that number in and sure enough, it’s working better now.
Hmm… gosh, such a newbie at this. xP So anyway, would I need to change the fovy for a different window resolution then?
The last 2 parameters of gluPerspective will be of more interest to you in this case. If the models start disappearing when moving to close your near plane is probably too far away. If they start disappearing when zooming out, your far plane is probably too close. Best way would be too dynamically calculate the near and far plane values based on a bounding box of your scene.
Well, I changed the first parameter, fovy, to “54.0f” as I said… and that problem’s gone away. I don’t know why, though.
Should I be calculating the fovy value based on the resolution of the window/screen? Like, if someone were to change the resolution or switch to fullscreen mode, does it have to be given a new value to still render correctly?