PDA

View Full Version : Order of 2d objects in OpenGL

03-19-2003, 06:21 AM
I need to use two different kinds of 2d objects in my program. One of them must appear always behind (like a wall paper). The other one, always in first order (always visble).

Can I do that using the Depht Buffer?

All is programed in 3D, but using the third coordenate equal to zero.

nexusone
03-19-2003, 07:08 AM
The depth buffer is used to determin what object drawing order is based on Z axis level.

With depth off your drawing order is based on first draw object are drawn over by next object, so you have to draw far objects first the near last.

but you can just draw your 2D using the Z axis as a level value.
Z = -1 = far level (backgound)
Z = 0 = middle level.( object area )
Z = 1 = near level ( forground )

I hope this gives you the idea.

Originally posted by nusuto:
I need to use two different kinds of 2d objects in my program. One of them must appear always behind (like a wall paper). The other one, always in first order (always visble).

Can I do that using the Depht Buffer?

All is programed in 3D, but using the third coordenate equal to zero.

jleffelm
03-19-2003, 07:11 AM
You do something like:
glDisable( GL_DEPTH_TEST );
DrawWallPaper();
DrawOther2DObject();
glEnable( GL_DEPTH_TEST );

I am pretty sure this should work.

-Drew

cbwan
03-19-2003, 07:11 AM
I guess drawing the back object first, then other objects, and at the very end the front object is too easy, do you have a limitation that prevents you from doing this?

> Can I do that using the Depht Buffer?

yes, assign z values <0 for back objects,
0 for other objects and >0 for front objects

>All is programed in 3D, but using the third coordenate equal to zero.

well change z http://www.opengl.org/discussion_boards/ubb/wink.gif
or sort the drawing of your object according to their group.

have fun!
cb

03-19-2003, 08:35 AM
Thank you all.

I can't separate both kinds of objects (It's my problem). But all your explanations lead me to think that using the z coordenate and Enable(GL_DEPTH_TEST), I can do that. I'll try.

Thanks again.