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:


// 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;
}


// 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 :frowning:

Kind regards,
decimad

Does it change anythin if you replace this line in the vertex shader:


    gl_Position = modelview * vec4(vertex, 1.0);

with this:


    gl_Position = projection * modelview * vec4(vertex, 1.0);

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

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:


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