Reputation: 6756
I tried render simple triangle using glVertexPointer, glColorPointer and glDrawArrays, but it still doesn't work. There is also version with glBegin and it works, so there isn't fault in vertices.
void GlWindow::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0,-0.5,-1.0);
GLfloat object[] = {
-length/5, 0.0, 0.0,
length/5, 0.0, 0.0,
0.0, 1.0, 0.0
};
GLfloat colors[] = {
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, object);
glColorPointer(3, GL_FLOAT, 0, colors);
glDrawArrays(GL_TRIANGLES, 0, 1);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
/*
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex3f(-length/5, 0.0, 0.0);
glVertex3f(length/5, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
*/
glFlush();
}
Upvotes: 1
Views: 2131
Reputation: 7131
The last argument to glDrawArrays is the number of vertices. So in this case you should specify 3, not 1.
Upvotes: 6