简体   繁体   English

如何绘制在OpenGL中显示alpha纹理背后的线框?

[英]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. 我有一个带alpha通道的纹理立方体,并希望在立方体周围绘制一个线框框。 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: 我的Init中的混合函数使用:

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. 我在绘制纹理之前尝试了不同的glColor4f alpha值,但它并没有什么区别。

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. 我的第一个猜测是,既然你已经绘制了纹理立方体(并且可能被写入深度缓冲区),那么在同一个Z之后立即绘制线框立方体的尝试将无法进行深度测试并且不会被渲染。

Try disabling it, or changing the order in which you render the cube and then the wireframe. 尝试禁用它,或更改渲染多维数据集的顺序,然后更改线框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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