如何在 OpenGL 中使用 alpha 透明度?

发布于 2024-08-08 23:54:12 字数 722 浏览 1 评论 0原文

这是我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南城追梦 2024-08-15 23:54:12

你启用了 alpha 混合吗?您设置了混合参数吗?您不能只设置 alpha,您还需要在 OpenGL 中设置各种其他参数。

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

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.

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
百合的盛世恋 2024-08-15 23:54:12

只是猜测,但可能是您没有背景颜色吗?那么,当渲染 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文