Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Coming back to OpenGL (1.2 to 3.3)

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    6

    Coming back to OpenGL (1.2 to 3.3)

    Hello,
    after a rather long absence, I'm coming back to OpenGL coding and much has happened.
    I'm trying to get started rendering a shaded triangle with the VAO/VBO and shaders, however I'm facing some difficulties that you might be able to help me with.

    I'm playing with the following VS/FS combination:
    Code :
    // VERTEX SHADER
    #version 330
    layout(location = 0) in vec3 vertex;
    layout(location = 1) in vec4 vertex_color;
     
    smooth out vec4 ColorVar;
    uniform mat4 modelview;
    uniform mat4 projection;
     
    void main() {
        gl_Position = modelview * vec4(vertex, 1.0);
     
        ColorVar    = vec4(1.0,1.0,1.0,1.0);
    //    ColorVar    = vertex_color;
    }
    Code :
    // FRAGMENT SHADER
    #version 330
     
    smooth in vec4 ColorVar;
    out vec4 out_color;
     
    void main() {
        out_color = ColorVar;
    //  out_color = vec4(1.0f,1.0f,1.0f,1.0f);
    }

    The fragment shader always procudes black output whenever I have that ColorVar data channel between VS and FS declared (smooth or not). It doesn't matter if the FS actually uses its value or not, whenever ColorVar is not removed from the shaders, all I get is the darkest black (even if I set the FS's output to the hardcoded value).
    Can you spot the mistake I'm making? The Shader and Program logs are empty, glGetError is not reporting anything, transformation is working, but I can't get colors from VS to FS

    Kind regards,
    decimad

  2. #2
    Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    281
    Does it change anythin if you replace this line in the vertex shader:
    Code :
        gl_Position = modelview * vec4(vertex, 1.0);

    with this:
    Code :
        gl_Position = projection * modelview * vec4(vertex, 1.0);

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    6
    Hello,

    thanks for your response.
    Sorry I didn't clarify that, I had that in there in the beginning, but the screen was all black so I thought the transformations were off, so I removed them alltogether, before I tried changing the Clear-Color from black to white, when I saw that the triangle was rendered in glory black. Vertices are in Clip-Space currently, so that is not a problem (Actually I'm looking at a spinning black triangle currently ).

    With Kind Regards,
    decimad

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    6
    Gosh, I'm so completely ashamed of the error I made and on the other hand I wonder why the shader compiler did not complain.

    The mistake was along these lines:
    Code :
    const char* program = 
    " blah "
    " blah "
    " smooth in vec4 ColorVar";
    " blah "
    " blah ";
    Basically, I didn't pass in the complete shader source when I uncommented the ColorVar-variable. However I wonder why the compiler did not complain about a missing main() function, that could have saved me from myself...

    Sorry for the noise!
    decimad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •