#include <GL/gl.h>
#include <GL/glut.h>
void display();
void init();
int main(int argc, char* argv[])
{
init();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(320, 240);
glutCreateWindow("Main Window");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void init()
{
glDisable(GL_DEPTH_TEST);
}
void display()
{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3i(255,255,255);
glVertex2f(10, 10);
glVertex2f(100, 10);
glVertex2f(100, 100);
glVertex2f(10, 100);
glEnd();
glutSwapBuffers();
}
理论上,这段代码应该绘制一个白色矩形。但我看到的只是一个黑色的空屏幕。怎么了?