Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL 3.3 different colours with fragment shader

I'm trying to colour 3 circles but only 3 white circles are appearing. n is 3 in this example. Each vertice has 5 points, 2 for position and 3 for color

Here is where I think a problem may lie:

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glVertexAttribPointer(
        0,                  
        2,                 
        GL_FLOAT,           
        GL_FALSE,          
        5*sizeof(float), 
        (void*)0            
    );

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(
        1, 
        3,
        GL_FLOAT,
        GL_FALSE, 
        5*sizeof(float), 
        (void*)(2*sizeof(float))
    );

    glDrawElements(GL_TRIANGLES, 20 * 3 * n, GL_UNSIGNED_INT, 0);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

My shaders:

#version 330 core

in vec3 Color;

out vec4 outColor;

void main()
{
    outColor = vec4(Color, 1.0);
}


#version 330 core

layout(location = 0) in vec2 position;

layout(location = 1) in vec3 color
out vec3 Color

void main(){
    gl_Position = vec4(position, 0.0, 1.0);
    Color = color;
}

Thanks for taking a look Andy

EDIT:

layout(location = 1) in vec3 color
    out vec3 Color

layout(location = 1) in vec3 color;
    out vec3 Color;
like image 653
Andrew Seymour Avatar asked Nov 02 '13 16:11

Andrew Seymour


Video Answer


1 Answers

(Posting the solutions from the comments to mark this question answered.)

You are missing semicolons at the end of these two lines:

layout(location = 1) in vec3 color
out vec3 Color

In the future, use glGetShader with GL_COMPILE_STATUS after compiling your shader to check if compilation succeeded, and glGetShaderInfoLog to retrieve the exact errors and warnings. See Shader Compilation for further detail and code samples.

like image 120
Yakov Galka Avatar answered Oct 10 '22 01:10

Yakov Galka