Jump to content
  • Advertisement
Sign in to follow this  
BkoChan

Stuck building a game engine...

This topic is 3172 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

I'm trying to build a (simple) game engine using c++, SDL and OpenGL but I can't seem to figure out the next step. This is what I have so far... An engine object which controls the main game loop A scene renderer which will render the scene A stack of game states that can be pushed and popped Each state has a collection of actors and each actor has a collection of triangles. The scene renderer successfully sets up the view projection matrix I'm not sure if the problem I am having relates to how to store an actors position or how to create a rendering queue. I have read that it is efficient to create a rendering queue that will draw opaque polygons front to back and then draw transparent polygons from back to front. Because of this my actors make calls to the "queueTriangle" method of the scene renderer object. The scene renderer object then stores a pointer to each of the actors triangles, then sorts them based on their position and then renders them. The problem I am facing is that for this to happen the triangle needs to know its position in world coordinates, but if I'm using glTranslatef and glRoatetef I don't know these coordinates! Could someone please, please, please offer me a solution or perhaps link me to a (simple) guide on how to solve this. Thankyou!

Share this post


Link to post
Share on other sites
Advertisement
AFAIK you draw transparent polygons in back to front order to get correct alpha blending, I've never heard of any reason why you'd want to also sort the opaque polygons, generally this is handled by the Z-buffer. Maybe that wasn't what you meant.

I don't know about you, but having the actors call the scene renderer seems a little bit backwards to me. Wouldn't the renderer be able to fetch the polygons on it's own?

Why do the triangles have have to know their world-coordinates? Don't the renderer have this information already? After all it's the renderer that does the drawing of the polygons.

Edit: I guess I didn't read your post enough times. :)
What you want to do is apply the same transformation to the polygons as OpenGL does with the glTranslatef and glRoatetef routines.
You can accomplish this through matrix math or doing vector addition/rotation directly. Google is your friend. :)

Edit2: Read up on why you'd want to sort the opaque objects as well. Appears to be an optimization indeed.

[Edited by - Redien on October 11, 2009 3:50:24 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Redien
AFAIK you draw transparent polygons in back to front order to get correct alpha blending, I've never heard of any reason why you'd want to also sort the opaque polygons, generally this is handled by the Z-buffer. Maybe that wasn't what you meant.


By drawing opaque polygons that are closer to the camera first, occluded pixels are very unlikely to be drawn before the pixels occluding them and so writes to the buffer are minimized.

Share this post


Link to post
Share on other sites
Quote:
Original post by WavyVirus

By drawing opaque polygons that are closer to the camera first, occluded pixels are very unlikely to be drawn before the pixels occluding them and so writes to the buffer are minimized.


Yes that appears to be the case. Thanks!
I guess you learn something new every day. :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!