Sign in to follow this  
JeffreyChen

Is depth buffer not working ?

Recommended Posts

How do I solve this problem ... all objects are texture mapped cubes ... I have enabled the depth test but I cant figure out whats wrong ... is order of drawing important ?

I have labeled the order of my drawing ...
plz let me know what is wrong and how to fix it

And does the depth buffer only work with z value ?

my + z axis is up
+x axis right and
+y axis down
much like the space that appears in 3d software with +Z axis going top

Share this post


Link to post
Share on other sites
if you turn off depth writing, then when you draw an object, it doesn't write its depth values to the depth buffer.

quick question, what do you mean all objects are texture mapped cubes? can you post a pic of just the "house" object?

Share this post


Link to post
Share on other sites
[quote name='Switchblade_77' timestamp='1310420555' post='4833999']
how do I enable depth writing ?
[/quote]

See [url="http://www.khronos.org/opengles/sdk/1.1/docs/man/glDepthMask.xml"]http://www.khronos.org/opengles/sdk/1.1/docs/man/glDepthMask.xml[/url]

Share this post


Link to post
Share on other sites
You say your objects are texture mapped cubes?

What I see is that your cubes are overlapping each other and for that reason hiding objects drawn after them.

I don't exactly understand the shape of your objects and what kind of texture each object has.

For me it seems that your z-buffer is working correctly.

Seems that you could solve the problem by drawing your objects back to front order.
However, that is probably you want to avoid since you are using z-buffer.

Can you elaborate a bit your objects (like show them closer or from different angles and show the real geometry in wireframe) ?

Cheers!

Share this post


Link to post
Share on other sites
Alpha channel and alpha testing is what you are looking for-


Ok, seems that you have alpha channel for your textures. Check that you use alpha testing to clip transparent pixels.

Cheers!

Share this post


Link to post
Share on other sites
by default its enabled ... so to check it I enabled it and still having the same results..
[code]
public void render() {
glDepthMask(true);
glEnable(GL_TEXTURE_2D);
loadView();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Color.white.bind();

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
loadIsometricView();
setViewQuadrant(quadrant);
glTranslatef(movementInX, movementInY, 0);
drawTerrain();

glPushMatrix();
glTranslatef(-movementInX, -movementInY, 0);
c3.mapTexture(cottage, 1, GL_MODULATE);
c3.draw();
glPopMatrix();

glPushMatrix();

glTranslatef(100, 400, 0);
c2.mapTexture(tree3, 1, GL_MODULATE);
c2.draw();
glTranslatef(50, 0, 0);
c2.draw();
glTranslatef(200, -100, 0);
c2.draw();
glTranslatef(-200, +50, 0);
c3.mapTexture(cottage, 1, GL_MODULATE);
c3.draw();
glPopMatrix();

unloadIsometricView();
}
[/code]

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1310420856' post='4834002']
You say your objects are texture mapped cubes?

What I see is that your cubes are overlapping each other and for that reason hiding objects drawn after them.

I don't exactly understand the shape of your objects and what kind of texture each object has.

For me it seems that your z-buffer is working correctly.

Seems that you could solve the problem by drawing your objects back to front order.
However, that is probably you want to avoid since you are using z-buffer.

Can you elaborate a bit your objects (like show them closer or from different angles and show the real geometry in wireframe) ?

Cheers!
[/quote]

My objects are cubes but with textures drawn in isometric view and then mapped to it like a paper over the cube in 2d space.

So is the drawing order important ... I thought the z buffer should take care of the drawing order
When I turn my view the image is distorted ... I can fix that by drawing textures for each quadrant ... and applying the texture to respective vertices..

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1310420940' post='4834007']
Alpha channel and alpha testing is what you are looking for-


Ok, seems that you have alpha channel for your textures. Check that you use alpha testing to clip transparent pixels.

Cheers!
[/quote]

How do I clip transparent pixels ? u mean clip the geometry ?

Share this post


Link to post
Share on other sites
The z-buffer will do the work, but you must not draw the transparent parts of the cubes.

You'll need to use alpha testing (or what ever it is called under opengl). This way your z-buffer will remain untouched for fragments with zero alpha and thus will make your drawing order independant.

Cheers!


Edit:

[url="http://www.opengl.org/sdk/docs/man/xhtml/glAlphaFunc.xml"]Alphafunc[/url]


Clip pixels, not geometry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this