如何使用OpenGL使背景色透明?

时间:2019-01-31 20:21:14

标签: c opengl glfw

我正在尝试使背景色透明,但是我在网络上看不到任何教程。在Windows API中,有一个函数可以将背景设置为分层并使所有层透明,但是我还没有看到与OpenGL相关的任何信息。

当我调用函数glClearColor(0.0, 0.0, 0.0, 0.0); 将BG颜色更改为黑色,如果将不透明度设置为1.0(第4个参数),则会使背景变为白色。


int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    glfwWindowHint(GLFW_DECORATED, 0);
    glfwWindowHint(GLFW_FLOATING, 1);
    glfwWindowHint(GLFW_REFRESH_RATE, GLFW_DONT_CARE);
    window = glfwCreateWindow(1000, 700, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);


    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {


        /* Render here */
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0, 0);
        glVertex2f(1.0f, 0.5f);
        glColor3f(0.0, 1.f, 0);
        glVertex2f(0.0f, 0.5f);
        glColor3f(0.0, 0.0, 1.0f);
        glVertex2f(0.5f, -0.5f);
        glEnd();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

当我尝试glClearColor时,背景并没有像我预期的那样被清除。

0 个答案:

没有答案