Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 614
Iceman Avatar asked Apr 14 '12 03:04

Iceman


1 Answers

I believe you want:

glVertexPointer(3, GL_FLOAT, 0, quadVertices);

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

like image 100
ccjuju Avatar answered Sep 19 '22 14:09

ccjuju