OpenGL - Drawing a square with glDrawArrays()
19,779
I believe you want:
glVertexPointer(3, GL_FLOAT, 0, quadVertices);
as you are only using 3 floats per vertex, not 4.
Author by
Iceman
Updated on July 20, 2022Comments
-
Iceman almost 2 years
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.
-
Iceman about 12 yearsYup, got it. I was mistaking this 3 for the number of vertices. Thanks a lot!