简体   繁体   中英

How do I draw a wireframe that shows behind an alpha texture in OpenGL?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM