Advertisement

!!!Very Advanced!!! Z-Buffer manipulation.

Started by December 07, 2000 07:35 PM
2 comments, last by Blue*Omega 23 years, 11 months ago
Is there any way to DIRECTLY manipulate the Z-Buffer in openGL? I want to do somthing to the effect of... ZBuffer[x+(y*width)]=z; Any way to do it? ----------------------------- Blue*Omega (Insert Witty Quote Here)
// Tojiart
well, if you''re not worried about a speed hit, you can use this. it''s sort of a hack (and if anyone has a better way, please share, i''d love to know ::not being sarcastic there, lol: anyways, here goes.

you can use if you wanted to set the pixel at say x,y (mesaured as the center being 0,0)to a depth of z, I *think* you could do the following (haven''t tried this out).

  unsigned char nada = 0;float z = MY_DEPTH_VALUE; // depth (translated by MV matrix)int x = MY_X, y = MY_Y;glLoadIdentity();glRasterPos3f(0,0,z); // set it to center at depth zglBitmap(0,0,0,0,x,y,NULL); // offset by x, y pixelsglColorMask(0,0,0,0); // turn off writing colorglDrawPixels(1,1,GL_RED,GL_UNSIGNED_BYTE, &nada); // write nothing// OR if you want to write the actual z value...// (see openGL man pages listing for glDrawPixels)float d = MY_DEPTH;int x = MY_X, y = MY_Y;glLoadIdentity();glRasterPos2f(0,0); // set it to centerglBitmap(0,0,0,0,x,y,NULL); // offset by x, y pixelsglColorMask(0,0,0,0); // turn off writing color (may not need this here)glDrawPixels(1,1,GL_DEPTH_COMPONENT,GL_FLOAT, &d); // write nothing  


hope that helps...and works, lol ;-)




Brought to you by: O.G.A.P.O.
+----------------------------------------+
| Surgeon General''s Warning - |
| OGAPO can cause serious mental damage |
| if taken in large doses. |
+----------------------------------------+
/* Never underestimate the power of stupid people in large groups */
Brought to you by: [email=ogapo@ithink.net]O.G.A.P.O.[/email] +----------------------------------------+| Surgeon General's Warning - || OGAPO can cause serious mental damage || if taken in large doses. |+----------------------------------------+/* Never underestimate the power of stupid people in large groups */
Advertisement
Hmmm... I''ll have to try that out. One concern though:
If your in perspective mode and set a pixle at say (8,2) with a z value of -20 wont it move the pixle twards the center of the screen (to simulate depth). Could you use the same method in glOrtho() and still have it work?

Thx!

-----------------------------

Blue*Omega

(Insert Witty Quote Here)
// Tojiart
I assume you''re refering to the first method. It shouldn''t move the pixel anywhere, because, since we loaded the ID matrix, setting the raster to 0,0,anything will place you on the middle pixel of the screen, then passing null to glBitmap offsets the raster position by x and y *pixels* (regardless of depth) and modifies the raster x and y accordingly (so you land on the pixel you want). With the second method, i''m not sure whether setting the depth value would move the pixel or not, but my guess would be no, because you''ve already specified exactly which pixel to write to and for GL to adjust that would be seem counter-intuitive.

Hope this helps, :-)

Brought to you by: O.G.A.P.O.
+----------------------------------------+
| Surgeon General''s Warning - |
| OGAPO can cause serious mental damage |
| if taken in large doses. |
+----------------------------------------+
/* Never underestimate the power of stupid people in large groups */
Brought to you by: [email=ogapo@ithink.net]O.G.A.P.O.[/email] +----------------------------------------+| Surgeon General's Warning - || OGAPO can cause serious mental damage || if taken in large doses. |+----------------------------------------+/* Never underestimate the power of stupid people in large groups */

This topic is closed to new replies.

Advertisement