2

I have a textured cube with alpha channels and wish to draw a wireframe box around the cube. The problem I'm running into is that the wireframe does not show through transparent part of the textured cube. How can I show the wireframe in the back?

Here is the code that I'm using to draw both cubes:

glLoadIdentity();

glTranslatef(0.0f, 0.0f, z);

glRotatef(xRotation, 1.0f, 0.0f, 0.0f);
glRotatef(yRotation, 0.0f, 1.0f, 0.0f);
glRotatef(zRotation, 0.0f, 0.0f, 1.0f);

// Draw Textured    
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glBindTexture(GL_TEXTURE_2D, _images[_filter]);

glBegin(GL_QUADS);
    DrawTexturedCube();
glEnd();

// Draw Wireframe
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);

glColor3f(1.0f, 0.0f, 0.0f);

glBegin(GL_QUADS);
    DrawWireframeCube();
glEnd();

xRotation += xSpeed;
yRotation += ySpeed;
zRotation += zSpeed;

The blend function in my Init is using:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I've tried different alpha values for glColor4f before drawing the textures, but it didn't make a difference.

DoryuX
  • 179
  • 4
  • 11
  • 1
    Do you want the wireframe to always be visible on top of the cube or want to show the wireframe though "holes" in the alpha texture? – Ani Jun 07 '12 at 18:55
  • I would like the wireframe to only show through the "holes", sorry if this was unclear. – DoryuX Jun 07 '12 at 19:09

1 Answers1

3

Do you have depth testing enabled? My first guess would be that since you've already drawn the textured cube (and presumably written to the depth buffer) an attempt to draw the wireframe cube immediately afterward at the same Z fails the depth test and is not rendered.

Try disabling it, or changing the order in which you render the cube and then the wireframe.

ravuya
  • 8,586
  • 4
  • 30
  • 33
  • 1
    I don't believe the OP wants to draw the wireframe on top of the entire cube - but wants it to show through "holes" in the alpha texture. Correct me if I'm wrong. – Ani Jun 07 '12 at 18:54