1
I’m learning now Vbos and Vaos, and I can’t draw objects of different colors, they are rendered with the same color. I tried to use Uniform but I couldn’t make it work, how can I do it?
Fragment Shader:
#version 130
out vec4 color;
void main(){
  color = vec4(1,0,0,1);
}
Initialization of Shader:
// Set "clearing" or background color
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black and opaque
    // Create and compile our GLSL program from the shaders
    GLint vertexShaderId = this->loadAndCompileShader("shader/hello.vp",
                                                      GL_VERTEX_SHADER);
    GLint fragmentShaderId = this->loadAndCompileShader("shader/hello.fp",
                                                        GL_FRAGMENT_SHADER);
    this->programId = this->linkShaderProgram(vertexShaderId, fragmentShaderId);
    // Set up vertex data (and buffer(s)) and attribute pointers
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
And then I want to draw each object a different color:
// Clear the colorbuffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //load everthing back
    glUseProgram(this->programId);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vbo1[0]);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vboC[0].data());
    glDrawArrays(GL_TRIANGLE_FAN, 0, 360);