🔒 Locked
depth func - GL_ZERO?
Advertisement
Original Post
No, that’s not what I meant.
Say I have 2 1.0f x 1.0f squares drawn facing the camera
The first one is red centered at (0, 0, -6)
The second one is blue centered at (0.5, 0.5, -5)
Now I want to draw a square that is 1.1fx1.1f and green at (0.5, 0.5, -6). I don''t want this green square to draw over any of the blue square and I don''t want it to draw over any of the red square. I only want it to draw in the small upper right section where it would protrude from behind the blue square, where the z value is still 0.
Say I have 2 1.0f x 1.0f squares drawn facing the camera
The first one is red centered at (0, 0, -6)
The second one is blue centered at (0.5, 0.5, -5)
Now I want to draw a square that is 1.1fx1.1f and green at (0.5, 0.5, -6). I don''t want this green square to draw over any of the blue square and I don''t want it to draw over any of the red square. I only want it to draw in the small upper right section where it would protrude from behind the blue square, where the z value is still 0.
You have the direction of the zbuffer backwards. 0 is for the objects closest to the camera.
What you''re doing should do what you want to, in theory, since the green square is being drawn last, so it shouldn''t occlude the red one at all. However, in practice, due to the inherent imprecision of floats, you''re probably experiencing zfighting, where pieces of the green show through the red. There are many ways to get around this, including glPolygonOffset, the stencil buffer, or simply offsetting your z-values slightly. Which you use depends on what you''re trying to do, which isn''t clear from your post.
What you''re doing should do what you want to, in theory, since the green square is being drawn last, so it shouldn''t occlude the red one at all. However, in practice, due to the inherent imprecision of floats, you''re probably experiencing zfighting, where pieces of the green show through the red. There are many ways to get around this, including glPolygonOffset, the stencil buffer, or simply offsetting your z-values slightly. Which you use depends on what you''re trying to do, which isn''t clear from your post.
The effect I am trying to produce is an outline but I don’t want each object outlined. I want all objects outlined from the background. So when the squares overlap, there is no line between them but only where they touch the background color. I can do this without alpha blending by disabling depth testing and rendering the outlines, and then enabling it again and drawing the objects, but with alpha blending this effect is ruined. Does anybody have an idea of how to do this a different way?
I don''t know if there''s a way to check if the z-buffer is 1, but you could use the stencil buffer.
1. Before you draw the scene, clear the stencil along with the Z-buffer.
2. Draw the first two quads, writing 1''s to the stencil.
3. Draw the green outline, checking the stencil buffer and only drawing if it''s zero.
Google or read manuals for glStencilOp, glStencilFunc, glStencilMask ...
1. Before you draw the scene, clear the stencil along with the Z-buffer.
2. Draw the first two quads, writing 1''s to the stencil.
3. Draw the green outline, checking the stencil buffer and only drawing if it''s zero.
Google or read manuals for glStencilOp, glStencilFunc, glStencilMask ...
if you want to do it by using the depth buffer only, it is quite easy, BUT can be quite slow.
all you need is glReadPixels, glDrawPixels, and alot of code and a secondary buffer.
Bascially,
backup old buffer and make a copy.
edit the copy to only include the range you want, send the others to 1.0f.
send the copy back.
use a test to let it only write to the colour and depth buffer if it isn''t equal to one.
grab the buffer back
merge it with the original buffer
send the merged buffer back to the depth buffer.
note: it isn''t very fast for really big displays.
1024x768 with single precision floating point in 32bit gets to be a bit laggy 
It works though if you are only using it for image/data manipulation, as time doesn''t matter, and its faster to use opengl in most situations than any other data manipulation method as its bit optimised for you already.
all you need is glReadPixels, glDrawPixels, and alot of code and a secondary buffer.
Bascially,
backup old buffer and make a copy.
edit the copy to only include the range you want, send the others to 1.0f.
send the copy back.
use a test to let it only write to the colour and depth buffer if it isn''t equal to one.
grab the buffer back
merge it with the original buffer
send the merged buffer back to the depth buffer.
note: it isn''t very fast for really big displays.
It works though if you are only using it for image/data manipulation, as time doesn''t matter, and its faster to use opengl in most situations than any other data manipulation method as its bit optimised for you already.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement