1

I'm trying to draw a transparent object inside an opaque cage, but what ever I seem to try I can't get it right.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 

glDisable(GL_BLEND);

glEnable(GL_DEPTH_TEST);

glEnable(GL_CULL_FACE); 
glCullFace(GL_BACK);

glColor4f(1.0, 1.0, 1.0, 1.0);
drawCage();

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glColor4f(0.0, 0.0, 0.0, 0.5);
drawObject();   

glPopAttrib();

This makes the transparent object within appear in front of the, despite it being inside it.

What am I doing wrong, could it be something to do with the shaders I am using

henryprescott
  • 483
  • 4
  • 19

2 Answers2

1

A few things.

  1. Check the depth function in your initialisation and that your pixel format has a depth buffer.
  2. Try it with the standard gouraud shader first.
  3. Triple check that all the vertices of the transparent object are inside the cage.
  4. Use some sort of camera rotation each frame so that you can see the rendered scene from all angles. (That way you can check if you accidentally rendered the object inside-out [Often happens to me when I go back to 3D after being away for a while])

Hope that helps

  • I was doing some off screen rendering that I did not allude to in my original question and because I didn't attach a depth buffer to this FBO It was causing problems. I've given the answer to you because your debugging tips seem a good idea. – henryprescott Feb 23 '12 at 23:15
0

Then you don't have a problem with your transparency. If you've got a depth test enabled, and your object appears in front of the other one, you've got a problem either in your geometry, or in your drawing routine. Could be a million things, try disabling culling first since and see what happens.

On the other hand, you're trying to render a transparent object with a constant colour that has 1.0f alpha. This means fully opaque. Are you sure about that?

El Marcel
  • 1,767
  • 1
  • 10
  • 11
  • Sorry, I should have left the colouring out as it is being changed within those methods anyway. There is definitely isn't a problem with the geometry and disabling back face culling seems to have no effect. – henryprescott Jul 04 '11 at 14:08
  • What do your shaders look like? Perhaps you can post a screenshot? – El Marcel Jul 04 '11 at 14:15