PDA

View Full Version : Why do the objects get blended together?



mobilevisuals
07-08-2011, 12:33 AM
My problem is that the objects get blended together, even if one opaque object is in front of a transparent one. This picture shows how it looks like:

http://www.mobile-visuals.com/transCP.png

The sphere on the picture is behind the morphing object, so they shouldn't be blended together. I don't know why this happens, because I have enabled DEPTH_TEST with

gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);

Does anyone know what I can try to get this to work?
This is the other method calls, which could have an effect on the transparency:

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY );
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,39000.0f);
gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0); glSurfaceView.getHolder().setFormat(PixelFormat.RG BA_8888);

mobeen
07-08-2011, 01:57 AM
Try this blend state


gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

mobilevisuals
07-08-2011, 05:24 AM
I tried it now, but it didn't change anything. The objects are still blended together. Maybe there is something wrong with my DepthFunc setup? I used the three lines of code above to set it up.

ZbuffeR
07-08-2011, 05:28 AM
Do you ask for and get a depth buffer at all ?

Try with a narrower depth rang, like this:
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 1f,3900.0f);

Maybe you get only 16 bits instead of 24 bits depth, much much less precise ?

Any depth mask ?

mobilevisuals
07-09-2011, 01:51 AM
Thanks, I changed gluPerspective and it seemed to improve the situation, but it still don't work like it should. I use

gl.glClearDepthf(1.0f);

Isn't this a call for a depth buffer? How can I check if I get only 16 bits instead of 24 bits depth?

I haven't used any depth mask yet. Do you mean that I should
use
glDepthMask(GL_TRUE);
and mask off the color buffer with
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) ?

ZbuffeR
07-09-2011, 02:28 AM
Do not use commands you do not understand :)
Instead of glClearDepthf(1.0f) better use glClear(GL_DEPTH_BUFFER_BIT), and for depth mask, defaults should be ok, so don't mess with it unless you really understand what it does.


it seemed to improve the situation, but it still don't work like it should.
Uh, it is hard to help when you are not specific...

How is your GL context created ?

mobilevisuals
07-11-2011, 06:19 AM
I use

glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0); glSurfaceView.getHolder().setFormat(PixelFormat.RG BA_8888);

to set up the GL context. What is that you meant with "How is your GL context created"?

I changed to glClear(GL_DEPTH_BUFFER_BIT). It is acting very strange, so it is hard to explain what the problem is. The morphing object is inside 2 spherical objects. The morphing object doesn't get drawn when the 2 spherical objects are drawn, even if the viewpoint is inside the spherical objects.

But the morphing object is drawn when the 2 spherical objects are not drawn.

mobilevisuals
07-16-2011, 08:07 AM
This problem was caused by the depth buffer. I fixed it after studying more about this in the OpenGL docs and books.
These lines of code caused the problem, so I removed them:

glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0); glSurfaceView.getHolder().setFormat(PixelFormat.RG BA_8888);