Login  Register

Re: Seeking Help with OpenGL Depth Buffer Issue

Posted by xghost on Sep 27, 2014; 9:57pm
URL: https://forum.jogamp.org/Seeking-Help-with-OpenGL-Depth-Buffer-Issue-tp4033219p4033226.html

Hi jmaasing,

This is the vertex definition that gets sent to the VBO for one of the objects. The other object simply has values for a different shape, but still x, y, z and no w, which is left to the shader as a default value.

 
       final float[] vertices = new float[] {
            // x, y, z
            -0.25f,  0.25f, -0.25f,
            -0.25f, -0.25f, -0.25f,
             0.25f, -0.25f, -0.25f,

             0.25f, -0.25f, -0.25f,
             0.25f,  0.25f, -0.25f,
            -0.25f,  0.25f, -0.25f,

             0.25f, -0.25f, -0.25f,
             0.25f, -0.25f,  0.25f,
             0.25f,  0.25f, -0.25f,

             0.25f, -0.25f,  0.25f,
             0.25f,  0.25f,  0.25f,
             0.25f,  0.25f, -0.25f,

             0.25f, -0.25f,  0.25f,
            -0.25f, -0.25f,  0.25f,
             0.25f,  0.25f,  0.25f,

            -0.25f, -0.25f,  0.25f,
            -0.25f,  0.25f,  0.25f,
             0.25f,  0.25f,  0.25f,

            -0.25f, -0.25f,  0.25f,
            -0.25f, -0.25f, -0.25f,
            -0.25f,  0.25f,  0.25f,

            -0.25f, -0.25f, -0.25f,
            -0.25f,  0.25f, -0.25f,
            -0.25f,  0.25f,  0.25f,

            -0.25f, -0.25f,  0.25f,
             0.25f, -0.25f,  0.25f,
             0.25f, -0.25f, -0.25f,

             0.25f, -0.25f, -0.25f,
            -0.25f, -0.25f, -0.25f,
            -0.25f, -0.25f,  0.25f,

            -0.25f,  0.25f, -0.25f,
             0.25f,  0.25f, -0.25f,
             0.25f,  0.25f,  0.25f,

             0.25f,  0.25f,  0.25f,
            -0.25f,  0.25f,  0.25f,
            -0.25f,  0.25f, -0.25f
        };



The vertex shader code is below. Note that although I have in vec4 position; the documentation states that missing components (e.g. w) get set to 1.0 by default. This behaves the same as using a in vec3 position; and then vec4(position, 1.0) for the calculations instead. I had already tried both alternatives, just in case:

   
    #version 440 core

    layout (location = 0) in vec4 position;

    out VS_OUT
    {
        vec4 color;
    } vs;

    uniform mat4 model_matrix;
    uniform mat4 view_matrix;
    uniform mat4 proj_matrix;   // holds perspective projection

    void main()
    {
        gl_Position = proj_matrix * view_matrix * model_matrix * position;
        vs.color    = position * 2.0 + vec4(0.5, 0.5, 0.5, 0.0);
    }


The fragment shader code is the following:

   
    #version 440 core

    out vec4 color;

    in VS_OUT
    {
        vec4 color;
    } fs;

    void main()
    {
        color = fs.color;
    }


Perhaps you'll see something I've been missing for a while. Thanks again for the help.

PS: How do you reply to a thread via email? I just tried it and it ended up posting a new thread (which I deleted).