<p>Your inputs and outputs still don't line up.</p>
<pre><code>#version 440 core  

// Comment out the line below
// in vec4 vs_pos;    &lt;----- No corresponding output in the vertex shader
in vec3 vs_color; 

out vec4 fs_color;


void main()
{
    fs_color=vec4(vs_color, 1.f);
}
</code></pre>
<p>The gl_Position output is consumed and does not need a specific input in the fragment shader. Only variable declared as &quot;out&quot; in the vertex shader need a corresponding &quot;in&quot;.</p>
<p>The next issue is the vertices need to have colors in them. The way it is setup now all the components are consumed before even a single triangle is drawn.</p>
<p>The vertex buffer needs to be setup:
vertex,color, vertex,color, vertex,color</p>
<p>where each vertex and color has 3 floating point values.</p>
<pre><code>GLfloat vertices[] = {

//    vertex           color
-0.5f, -0.5f, 0.0f,  1.0f,0.0f,0.0f
 0.5f, -0.5f, 0.0f,  0.0f,1.0f,0.0f
 0.0f,  0.5f, 0.0f,  0.0f,0.0f,1.0f 
};
</code></pre>
<p>Something like the above. Is what you need for the vertices.</p>

CC BY-SA 4.0
2021-03-30T14:28:17.677Z
I comment it but still not working. maybe this information will help: I use a Intel HD Graphics 5500 and I updated it with the latest driver from HP
Gamer
CC BY-SA 4.0
2021-03-30T15:51:00.137Z
@gamer updated the answer
pmw1234
CC BY-SA 4.0
2021-03-30T13:32:41.910Z
2021-03-30T15:49:05.843Z
2021-03-30T15:49:05.843Z
pmw1234
<p>I wrote a program to render a simple triangle with colors, the triangle is there but there's no color.</p>
<pre><code>GLfloat vertices[] = {
        0.6f,0.4f , 0.3f,0.5f, 0.1f,0.3f, 0.8f,0.2f, 0.1f,-0.4f, 0.9f,0.3f
    };


    unsigned int program;
    if (!loadShader(program))
        return -1;

    unsigned int VAO;
    glGenVertexArrays(1, &amp;VAO);
    
    unsigned int buffer;
    /* GENERATE THE BUFFER (1 BUUFER) */
    glGenBuffers(1, &amp;buffer);
    glBindVertexArray(VAO);
    /* SELECT THAT BUFFER TO WORK WITH */
    glBindBuffer(GL_ARRAY_BUFFER, buffer);

    //glBufferData(GL_ARRAY_BUFFER, RealPositions.size()*sizeof(float), RealPositions.data(), GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

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

   

    glBindVertexArray(0);
    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        
        glUseProgram(program);

    
        glBindVertexArray(VAO);
        glDrawArrays(GL_TRIANGLES, 0, 3);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
}

</code></pre>
<p>and this the vertex shader:</p>
<pre><code>#version 440


layout (location = 0) in vec3 vertices;
layout (location = 1) in vec3 vertex_color;
out vec3 vs_color;
void main()
{
    gl_Position=vec4(vertices, 1.f);
    vs_color=vertex_color;
}
</code></pre>
<p>and this is the fragment shader:</p>
<pre><code>#version 440 core  


in vec4 vs_pos;
in vec3 vs_color;
out vec4 fs_color;


void main()
{
    fs_color=vec4(vs_color, 1.f);
}
</code></pre>
<p>what am i doing wrong?</p>

CC BY-SA 4.0
2021-03-30T04:08:26.133Z
The out variable "vs_colour" in your vertex shader does not match any 'in' variable in your fragment shader, i see "vertex_color" as the fragment shaders input, you should match the VS's "out vec3 vs_color;" with a "in vec3 vs_color" in the FS. You will need a different output variable in your fragment shader to output the fragment colour.
PaulHK
CC BY-SA 4.0
2021-03-30T09:10:04.463Z
sorry, I edited the post, I posted the vertex shader twice
Gamer
<opengl>
rendering a triangle has no color
Gamer
# rendering a triangle has no color

(Asked by: username_0 on 2021-03-29)

I wrote a program to render a simple triangle with colors, the triangle is there but there's no color.

```
GLfloat vertices[] = {
        0.6f,0.4f , 0.3f,0.5f, 0.1f,0.3f, 0.8f,0.2f, 0.1f,-0.4f, 0.9f,0.3f
    };

    unsigned int program;
    if (!loadShader(program))
        return -1;

    unsigned int VAO;
    glGenVertexArrays(1, &VAO);
    
    unsigned int buffer;
    /* GENERATE THE BUFFER (1 BUUFER) */
    glGenBuffers(1, &buffer);
    glBindVertexArray(VAO);
    /* SELECT THAT BUFFER TO WORK WITH */
    glBindBuffer(GL_ARRAY_BUFFER, buffer);

    //glBufferData(GL_ARRAY_BUFFER, RealPositions.size()*sizeof(float), RealPositions.data(), GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

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

   

    glBindVertexArray(0);
    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        
        glUseProgram(program);

    
        glBindVertexArray(VAO);
        glDrawArrays(GL_TRIANGLES, 0, 3);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
}

```

and this the vertex shader:

```
#version 440

layout (location = 0) in vec3 vertices;
layout (location = 1) in vec3 vertex_color;
out vec3 vs_color;
void main()
{
    gl_Position=vec4(vertices, 1.f);
    vs_color=vertex_color;
}

```

and this is the fragment shader:

```
#version 440 core  

in vec4 vs_pos;
in vec3 vs_color;
out vec4 fs_color;

void main()
{
    fs_color=vec4(vs_color, 1.f);
}

```

what am i doing wrong?

**Tags:** opengl

> **Comments:**
> **username_1**: The out variable "vs_colour" in your vertex shader does not match any 'in' variable in your fragment shader, i see "vertex_color" as the fragment shaders input, you should match the VS's "out vec3 vs_color;" with a "in vec3 vs_color" in the FS. You will need a different output variable in your fragment shader to output the fragment colour.  
> **username_0**: sorry, I edited the post, I posted the vertex shader twice  

---

## 1 answers

### Answer by username_2 on 2021-03-30. Score: 1

Your inputs and outputs still don't line up.

```
#version 440 core  

// Comment out the line below
// in vec4 vs_pos;    <----- No corresponding output in the vertex shader
in vec3 vs_color; 

out vec4 fs_color;

void main()
{
    fs_color=vec4(vs_color, 1.f);
}

```

The gl\_Position output is consumed and does not need a specific input in the fragment shader. Only variable declared as "out" in the vertex shader need a corresponding "in".

The next issue is the vertices need to have colors in them. The way it is setup now all the components are consumed before even a single triangle is drawn.

The vertex buffer needs to be setup:
vertex,color, vertex,color, vertex,color

where each vertex and color has 3 floating point values.

```
GLfloat vertices[] = {

//    vertex           color
-0.5f, -0.5f, 0.0f,  1.0f,0.0f,0.0f
 0.5f, -0.5f, 0.0f,  0.0f,1.0f,0.0f
 0.0f,  0.5f, 0.0f,  0.0f,0.0f,1.0f 
};

```

Something like the above. Is what you need for the vertices.

> **Comments:**
> **username_0**: I comment it but still not working. maybe this information will help: I use a Intel HD Graphics 5500 and I updated it with the latest driver from HP  
> **username_2**: @username_0 updated the answer  

---

