OpenGL 褪色正方形
OpenGL faded square
我正在尝试实现淡入淡出效果,其中正方形的角具有不同的 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),为什么?
你启用GL_BLEND
了吗?在渲染之前尝试添加:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
我正在尝试实现淡入淡出效果,其中正方形的角具有不同的 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),为什么?
你启用GL_BLEND
了吗?在渲染之前尝试添加:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );