如何在 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 透明度的某些功能?
Here's my code:
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();
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你启用了 alpha 混合吗?您设置了混合参数吗?您不能只设置 alpha,您还需要在 OpenGL 中设置各种其他参数。
have you glEnable'd alpha blending? And have you set up your blend parameters? You can't just set the alpha you need to setup various other parameters in OpenGL.
只是猜测,但可能是您没有背景颜色吗?那么,当渲染 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.