GLUT 經過下面幾個函數執行初始化一個窗口,並渲染。編程
gluInit (int *argc, char **argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
glutInitDisplayMode(usigned int mode)
glutInitWindowSize(int width, int size) glutInitWindowPosition(int x, int y)
glutInitContextVersion(int mojorVersion, int minorVersion)
glutInitContextFlags(int flags)
glutCreateWindow(char *string)
glutDisplayFunc(void (*func)(void))
#include <GL/freeglut.h> #include <GL/gl.h> void renderFunction() { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glVertex3f(0.25, 0.75, 0.0); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow("OpenGL - First window demo"); glutDisplayFunc(renderFunction); glutMainLoop(); return 0; } //編譯命令: // gcc gl_test_0.c -o gl_test_0 -lGL -lGLU -lglut