gl_FragDepth打破了颜色

时间:2015-09-21 14:13:10

标签: windows opengl glsl depth-buffer

似乎我不能在我的电脑上使用gl_FragDepth。我的程序运行良好,否则没有glsl错误,glGetError返回0,但是我无法从片段着色器中写入深度缓冲区。

此外,写入gl_FragDepth会更改像素颜色的红色分量。

我的程序有简化版。我修剪了所有无用的东西(我gess?),而且效果不是很好:

proc sql;
select cats("&libname..",memname)
   into :tables separated by ' '
   from dictionary.tables
   where libname=upcase("&libname.");
quit;

data counts;
set &tables. indsname=ds_name end=eof; 
retain count dataset_name;
if _n_=1 then count=0;
if ds_name ne lag(ds_name) and _n_ ne 1 then do;
   output;
   count=0;
end;
dataset_name=ds_name;
count = count+1;  
if eof then output;
keep count dataset_name;
run;

它应该绘制红色和绿色条纹,但我得到模糊的红线。如果我删除第二个drawcall,它是相同的。 在Windows上,即。我在OSX上测试它并按预期工作。

以下是glGetString的一些规范:

int        main(void)
{
//  These are custom structures for handling shader programs.
    t_glprog                prog;
    t_glprog                prog2;

    GLuint                  vbo;
    GLFWwindow              *window;
    static const GLfloat    vertab[] =
    {
        -1.0, -1.0, 1.0,
        1.0, -1.0, 1.0,
        1.0, 1.0, 1.0,
        -1.0, 1.0, 1.0
    };

    char const *vert =
        "attribute vec3 Coord;"
        "void main() {\
        gl_Position = vec4(Coord, 1.0);\
        }";

    char const *frag1 =
        "void main () {\
        gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\
        gl_FragDepth = sin(gl_FragCoord.x * 0.1);\
        }";

    char const *frag2 =
        "void main () {\
        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\
        gl_FragDepth = cos(gl_FragCoord.x * 0.1);\
        }";

    if (!glfwInit())
    {
        fprintf(stderr, "GLFW failed to init.\n");
        return (-1);
    }

    glfwWindowHint(GLFW_DEPTH_BITS, 64);
    window = glfwCreateWindow(640, 480, "TEST", NULL, NULL);
    if (window == NULL)
    {
        fprintf( stderr, "Failed to open GLFW window.\n" );
        glfwTerminate();
        return (-1);
    }
    glfwMakeContextCurrent(window);

//  For Windows.
    if (glewInit() != GLEW_OK)
    {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return (-1);
    }

    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glClearDepth(1.0);
    glViewport(0, 0, 640, 480);

    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertab), vertab, GL_STATIC_DRAW);

    create_shaders_prog(&prog, vert, frag1);
    create_shaders_prog(&prog2, vert, frag2);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glUseProgram(prog.prog);
    glDrawArrays(GL_QUADS, 0, 4);

    glUseProgram(prog2.prog);
    glDrawArrays(GL_QUADS, 0, 4);

    glFlush();
    glfwSwapBuffers(window);

    while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
            glfwWindowShouldClose(window) == 0)
    {
        glfwPollEvents();
    }
    return (0);
}

1 个答案:

答案 0 :(得分:1)

您的集成显卡驱动程序是否可能在这条线路上窒息?

Qty
对于深度缓冲区,64位是非常多的。 24位是更典型的值。如果不支持64位深度缓冲区,则上下文创建应该会失败,但是如果没有正确设置深度缓冲区,我会看到一些OpenGL驱动程序的奇怪行为。