有人可以告诉我这里有什么错误。它显示显示窗口,但不幸的是没有绘制三角形。
#include<glut.h>
GLint vertices[] ={ /*vertex array */
0.25, 0.25,
-0.9, 0.8,
0.5, -0.5
-0.2, -0.8
};
GLfloat colors[]={ /*color array*/
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 1.0, 0.0
};
void display(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_COLOR_ARRAY); /* enabling color array*/
glEnableClientState(GL_VERTEX_ARRAY); /*enableing vertex array */
glColorPointer(3, GL_FLOAT, 0, colors);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glBegin(GL_TRIANGLES); /* dereferencing */
glArrayElement(0);
glArrayElement(1);
glArrayElement(2);
glEnd();
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glFlush();
}
void main() {
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowPosition(200, 200);
glutInitWindowSize(300,300);
glutCreateWindow("My application");
glutDisplayFunc(display);
glutMainLoop();
}