Jump to content
  • Advertisement
Sign in to follow this  
ukdeveloper

Good practice or not? (OpenGL)

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm referring to my thread about there being a problem with an OpenGL rotating triangle I'd set up. I've managed to solve the problem, but not sure if the method I used was good practice or not. I want to get into good habits early. The reason the "wipe" effect occurred was because my triangle vertices were disappearing through the Z-boundary because the Z-boundary was too close to the front of the screen (if I'm making any sense). Here's my call for glOrtho()

glOrtho(0.0f,1024,768,0.0f,-100.0f,100.0f);

My question is, NeHe used gluPerspective, should I use that instead? My method seems like a bit of a hack, randomly shoving values into the Z-boundary until it was far enough away for the triangle to rotate normally. I tried gluPerspective myself, but I got a black screen instead of my nice triangle in the middle of said black screen. Like I say, I want to get into good habits early, considering how difficult OpenGL could potentially get. Thanks in advance, ukdeveloper.

Share this post


Link to post
Share on other sites
Advertisement
Use of glOrtho or glPerspective depends on what you are trying to achieve. glOrtho renders your polygons with an orthogonal projection: items that are far away are just as large as items that are close by.
With glPerspective, as the function name says, you really get perspective calculations (i.e. a real 3D feel).

Both methods have their merits. CAD/CAM or 3D-modelling applications use ortho, most games (but not all) use perspective.

Share this post


Link to post
Share on other sites
Randomly shoving values in is probably not good practice, no :D

The problem has to do with your near and far clip planes (the Z-boundaries you speak of). Your triangle has to be inbetween them to get drawn. In the ortho camera you describe there, the near-clip plane is 100 units behind the camera, giving your triangle plenty of room. But with a perspective camera the near-clip plane must be in front of your camera (must be a positive number).

The best thing to do is figure out how far your triangle will be from the camera, and use these to decide the clip planes.

Just to get things working, try a small number like 0.01 for the near-clip. Be aware, though, that having a such a small near-clip value will reduce the accuracy of your depth-buffer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!