PDA

View Full Version : draw order

MOlOX
12-22-2009, 12:41 PM
Hi i have another newbie question :)

This is the case,

I calculate vertexes of a 3d object , than draw it using GL_GUADS.

After this drawing everything seems ok.

You can think of 3d object like plastic glass (or a cylinder with one side is open). But glass is drawn as not standing but lying on side, so there is opening on the right side.

than i draw polygon at opening of glass with different color.

so now it look like cylinder with one opening part different color.

Than i start to rotate this all 3d cylinder on y-axis.

i suppose to see a cylinder rotating on y axis, and when the polygon with different color (opening part of glass) is drawn at the back,
i should not see it , because other side of glass should be in front of it.

at drawing method, first i draw 3d object , after that i draw polygon.

So as far as i get, regardless of coordinates of shapes, openGL draws shapes with the order that you draw in your code. (i first code to draw 3d object than polygon with different color, so according to code, openGL draws 3d object , and last polygon, so polygon can always be seen , regardless of coordinates)

There is certainly a way to accomplish this, but i dont know it.

So, how can i draw multiple shapes and see that in the way that , they are drawn by their coordinates, not in the order of drawing code.

Thank you very much...

blofeld9999
12-22-2009, 03:45 PM
I think you want to use a depth buffer here.

MOlOX
12-22-2009, 04:04 PM
yes, when i used dept buffer, somethings changed but not as i wanted. things got weirder.
I will send screenshots but first i want to ask another question.

my set up scene function is like this

glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glPointSize(4.0f);
glMatrixMode(GL_PROJECTION);
gluLookAt( 1/32.0f, 1/32.0f, 1/32.0f,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glOrtho(-100,100,-100,100,100,-100);
glMatrixMode(GL_MODELVIEW);

i could not exactly understand
gluLookAt( 1/32.0f, 1/32.0f, 1/32.0f,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);

first 3 parameters are position of camera.

So what is camera position so near to 0,0,0 (1/32,1/32,1/32)

i found code snipplet where i was looking for isometric projection with glOrtho.

when i change this function to

gluLookAt(100,100,100,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);

i get black screen,

What am i doing wrong ?

Dark Photon
12-22-2009, 05:28 PM
So, how can i draw multiple shapes and see that in the way that , they are drawn by their coordinates, not in the order of drawing code.
If the geometry you're drawing is opaque, then blofeld9999 has your solution. Make sure you allocate a depth buffer for your framebuffer, and enable its use via glEnable( GL_DEPTH_TEST ) and glDepthMask( GL_TRUE ).

If some of the geometry you're drawing is "not" opaque (i.e. translucent), then do the above for opaque objects, then do a pass for the translucent objects, blending them in from back-to-front (relative to the eye's point of view). Don't forget to glEnable( GL_BLEND ) on these.