Iceman
Iceman

Reputation: 4362

OpenGL - Drawing a square with glDrawArrays()

I am drawing a square with glDrawArrays() as follows:

glTranslatef(0.0f,0.0f,-6.0f);  
const GLfloat quadVertices[] = { -1.0f, 1.0f, 0.0f, 
        1.0f, 1.0f, 0.0f, 
        1.0f,-1.0f, 0.0f,
        -1.0f,-1.0f, 0.0f
    }; 

    glVertexPointer(4, GL_FLOAT, 0, quadVertices);
    glDrawArrays(GL_QUADS, 0, 4);

The output is not as expected.

Upvotes: 10

Views: 22148

Answers (1)

ccjuju
ccjuju

Reputation: 507

I believe you want:

glVertexPointer(3, GL_FLOAT, 0, quadVertices);

as you are only using 3 floats per vertex, not 4.

Upvotes: 7

Related Questions