如何在OpenGL中设置顶点的不透明度? [英] How do I set the opacity of a vertex in OpenGL?
本文介绍了如何在OpenGL中设置顶点的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下片段绘制了一个灰色方形。
The following snippet draws a gray square.
glColor3b(50, 50, 50);
glBegin(GL_QUADS);
glVertex3f(-1.0, +1.0, 0.0); // top left
glVertex3f(-1.0, -1.0, 0.0); // bottom left
glVertex3f(+1.0, -1.0, 0.0); // bottom right
glVertex3f(+1.0, +1.0, 0.0); // top right
glEnd();
在我的应用程序中,单个正方形后面是一个彩色立方体。
In my application, behind this single square exists a colored cube.
我应该使用什么函数来使正方形(并且只有这个正方形)不透明?
What function should I use to make square (and only this square) opaque?
推荐答案
init函数,使用这两行:
In the init function, use these two lines:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
在您的render函数中,确保 glColor4f
代替 glColor3f
,并将第四个参数设置为所需的不透明度。
And in your render function, ensure that glColor4f
is used instead of glColor3f
, and set the 4th argument to the level of opacity required.
glColor4f(1.0, 1.0, 1.0, 0.5);
glBegin(GL_QUADS);
glVertex3f(-1.0, +1.0, 0.0); // top left
glVertex3f(-1.0, -1.0, 0.0); // bottom left
glVertex3f(+1.0, -1.0, 0.0); // bottom right
glVertex3f(+1.0, +1.0, 0.0); // top right
glEnd();
这篇关于如何在OpenGL中设置顶点的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文