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?
问题是这两个点看起来是相同的(即使我将alpha设置为0)。有没有我错过了启用alpha透明度的东西?
2 个解决方案
#1
18
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.
只是一个猜测,但可能是你没有背景颜色?那么,当你渲染第二个具有alpha 0.1的顶点时,没有背景来计算正确的颜色?只是猜测,自从我使用opengl以来已经有好几年了。
#2
56
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.
你有glEnable'd alpha混合吗?你有没有设置你的混合参数?您不能只设置在OpenGL中设置各种其他参数所需的alpha。
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
#1
18
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.
只是一个猜测,但可能是你没有背景颜色?那么,当你渲染第二个具有alpha 0.1的顶点时,没有背景来计算正确的颜色?只是猜测,自从我使用opengl以来已经有好几年了。
#2
56
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.
你有glEnable'd alpha混合吗?你有没有设置你的混合参数?您不能只设置在OpenGL中设置各种其他参数所需的alpha。
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );