Strange basic opengl problem

i have a simple test:

    float vertices[] = {
        2.f,  0.5f, 0.0f, // top right
        2.f, -0.5f, 0.0f, // bottom right
        1.f, -0.5f, 0.0f, // bottom left
        1.f,  0.5f, 0.0f  // top left 

// Different color at each vertex
    float vcolors[] = {
        1.f, 0.f, 0.f, // Red
        0.f, 1.f, 0.f, // Green
        0.f, 0.f, 1.f, // Blue
        1.f, 1.f, 0.f  // Yellow

    unsigned int indices[] = {
        0, 1, 3,  // first Triangle
        1, 2, 3   // second Triangle

i create VBO’s:

        unsigned int vbo[2],ibo;
        glGenBuffers(2, vbo);
        glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vcolors), vcolors, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0); 

        glGenBuffers(1, &ibo);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 

then if i use these VBO’s such as:

        glVertexPointer(3, GL_FLOAT, 0, (void*) 0);

        glColorPointer(3, GL_FLOAT, 0, (void*) 0);


        // unbind VBOs
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);


the first time drawing the two triangles shows the correct vertex color and interpolated interior colors however, all subsequent draws only show as one solid color (yellow) because that is the last color in the vcolors array.

if i use shaders with these same VBO’s it works perfectly.

any ideas why this may be incorrect because i can’t see anything wrong.

thanks for any help.

sorry here are a couple of images showing the problem: the first is the initial draw and the second shows all subsequent draws:


Are you switching glShadeModel to GL_FLAT after the first draw?

great find. thanks that fixed the problem. sometimes the most obvious things are missed.