Stuck with building a game engine

I'm trying to build a (simple) game engine using C ++, SDL and OpenGL, but I can't figure out the next step. This is what I have so far ...

The engine object that controls the main game loop

A scene renderer that will render the scene

Stack of game states that can be pushed and pushed

Every state has a collection of actors, and every actor has a collection of triangles. Scene renderer successfully sets view projection matrix

I'm not sure if the problem is related to how to keep the position of the actors or how to create the render queue.

I have read that it is efficient to create a render queue that will draw opaque polygons from front to back and then draw transparent polygons from front to back. Because of this, my actors make a call to the "queueTriangle" method of the scene render object. The scene renderer then stores a pointer to each of the actors' triangles, then sorts them by their position, and then displays them.

The problem I'm running into is that the triangle needs to know its position in world coordinates for this, but if I use glTranslatef and glRotatef I don't know those coordinates!

Can someone please please suggest me a solution or maybe follow me with a (simple) guide on how to fix this issue.

Thankyou!

+2


source to share


2 answers


I got a call from "queueTriangle" which is very inefficient. Modern motors often run many thousands of triangles at a time, so you usually hardly ever work with anything at the level of one triangle. And if you change textures a lot to fulfill this order, it's even worse.



I would recommend a simpler approach - draw your opaque polygons in a much less strict order, sorting the positions of the actor in world space rather than the positions of the individual triangles, and make the actors front to back, actor at a time, your transparent / translucent polygons still need to be approached. " back to front "(assuming you're not using pre-multiplied alpha), but everything else should be simpler and faster.

+1


source


If you write a camera class and use its functions to move / rotate in the world, you can use the matrix you get from the inner quaternion to transform the vertices, giving you a position in camera space so you can sort the triangles from back to front.



+2


source







All Articles