OpenGL褪色方块

时间:2015-03-05 19:21:54

标签: opengl

我试图获得淡入淡出效果,其中正方形的角有不同的alpha。我这样做:

glBegin(GL_QUADS);

glColor4d(r, g, b, alphaTopLeft);
glVertex2d(x, y);
glColor4d(r, g, b, alphaTopRight);
glVertex2d(x + width, y);
glColor4d(r, g, b, alphaBottomRight);
glVertex2d(x + width, y + height);
glColor4d(r, g, b, alphaBottomLeft);
glVertex2d(x, y + height);

glEnd();

值alphaTopLeft = 0,alphaTopRight = 0,alphaBottomRight = 1,alphaBottomLeft = 1,但它会产生一个实心形状(所有角落alpha 1),为什么?

1 个答案:

答案 0 :(得分:3)

您是否启用了GL_BLEND?在渲染之前尝试添加它:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
glEnable( GL_BLEND );