如何在 OpenGL 中使用 alpha 透明度? [英] How to use alpha transparency in OpenGL?
本文介绍了如何在 OpenGL 中使用 alpha 透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
void display(void);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
glutInitWindowSize(600,600);
glutInitWindowPosition(200,50);
glutCreateWindow("glut test");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(8);
glBegin(GL_POINTS);
glColor4f(.23,.78,.32,1.0);
glVertex2f(0,0);
glColor4f(.23,.78,.32,0.1);
glVertex2f(0.1,0);
glEnd();
glFlush();
}
问题是这两个点看起来相同(即使我将 alpha 设置为 0).启用 alpha 透明度时我遗漏了什么吗?
The problem is that these two points appear identical (even when I set the alpha to 0). Is there something I missed to enable alpha transparency?
推荐答案
只是一个猜测,但会不会是你没有背景色?那么,当您渲染具有 alpha 0.1 的第二个顶点时,没有背景来计算正确的颜色?只是一个猜测,自从我使用 opengl 已经很多年了.
Just a guess, but could it be that you dont have a background color ? So, when your rendering the second vertex which has alpha 0.1, there is no background to compute the proper color ? Just a guess, been years since i used opengl.
这篇关于如何在 OpenGL 中使用 alpha 透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文