Jump to content
  • Advertisement
Sign in to follow this  
deus krid

OpenGL engine's level render

This topic is 3808 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 everyone, i have some question the fact is that i am working on my own 3d-engine with using OpenGL. and now i have trouble with the organization object-passing in engine. now it has simple way ala "every object draws himself". i mean, there is a tree of objects. object's draw method look like a 1) glPushMatrix; 2) matrix transformations 3) directly drawing 4) calling draw for all children objects 5) glPopMatrix but its very stupid, i think, cause this way of passage cuts many kinds of optimization, such as requiring additional sorting for example. so i want to do it more centralized: all objects are directly drawing in RenderManagers. for each type of drawing object is a manager - for a GUI, for statics, for animated meshes etc. each manager has its object's list. before drawing, during tree-passage, Dobjects add themselfs to one kind of list. then each manager draws its objects and after it they clean their lists. and now main problem. with the first method, when each object draws himself, there was no problem with object's orientation in space while using matrix's stack. but with using managers, during drawing a tree-order of drawing will be lost. so how can i get out of this problem? maybe yo can advice me some better ways for realizing objects-passing p.s. sorry for my bad english)))

Share this post


Link to post
Share on other sites
Advertisement
You should introduce some kind of "scene graph", start with a basic approach for now. A linear list of models with a linear list of sub meshes each. Iterate over them constructing some kind of list called a queue. The queue should be sorted by materials (and other attributes). Then you iterate this one last time doing the actual drawing.


psuedo:

for each material in queue
apply material
for each submesh in material
push transform
draw submesh
pop transform
loop
loop

Share this post


Link to post
Share on other sites
with linear list all clear, but how about more difficult hierarchy (i mean tree's one)? for example, when children objects depends from their owner's local matrix transformations?

Share this post


Link to post
Share on other sites
For each child transformation, push a copy of the current matrix on the stack and pop it when you are done with the child.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sabonis
For each child transformation, push a copy of the current matrix on the stack and pop it when you are done with the child.

in my engine i'm doing exactly in that way, but how to be, with using sorting lists (remndermanagers)? for example, at first engine will sorts objects by active viewports, than by using materials etc. (as in bzroom's advice). and how can i use matrix stack while linear passage through list i get after sorting? the one way i see is to definite for all objects only global matrixes, and when owner is moving, change global matrixes for all child objects. but of course its lamas way, because when some object would move, for example, engine will change matrixes for all child objects, and it dosnt much, cause its slow.

so how to be? just dont use owner-child scheme with local matrixes?

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!