Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 67 characters in body
Source Link
#version 440


layout (location =core 0)  


in vec3vec4 vertices;vs_pos;
layout (location = 1) in vec3 vertex_color;vs_color;
out vec3vec4 vs_color;fs_color;


void main()
{
    gl_Position=vec4fs_color=vec4(verticesvs_color, 1.f);
    vs_color=vertex_color;
}
#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;
}
#version 440 core   


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


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

rendering a triangle has no color

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


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

what am i doing wrong?