📄 example.cpp
字号:
// basic primitives.
#include <stdlib.h>
#include <GL/glut.h>
void OnReshape(int w, int h)
{
// set the drawable region of the window to the maximum available window size
glViewport(0,0,w,h);
// set up the projection matrix
glMatrixMode(GL_PROJECTION);
// clear any previous transform and set to the identity matrix
glLoadIdentity();
// just use an orthographic projection
glOrtho(0,12,12,0,-1,1);
// go back to modelview matrix so we can move the objects about
glMatrixMode(GL_MODELVIEW);
}
void OnDraw() {
glClearColor ( 1 , 1 , 1, 1 );
// clear the screen & depth buffer
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
// clear the previous transform
glLoadIdentity();
// GL_POINTS
// GL_LINES
// GL_LINE_LOOP
// GL_LINE_STRIP
// GL_TRIANGLES
// GL_TRIANGLE_STRIP
// GL_TRIANGLE_FAN
// GL_QUADS
// GL_QUAD_STRIP
// GL_POLYGON
glBegin(GL_LINES);
glColor3f(0,1,0);
glVertex3f(3,3,0);
glColor3f(1,0,0);
glVertex3f(2,10,0);
glVertex3f(7,12,0);
glColor3f(0,1,0);
glVertex3f(5,9,0);
glColor3f(0,0,1);
glVertex3f(8,7,0);
glVertex3f(6,12,0);
glEnd();
// currently we've been drawing to the back buffer, we need
// to swap the back buffer with the front one to make the image visible
glutSwapBuffers();
}
int main(int argc,char** argv) {
// initialise glut
glutInit(&argc,argv);
// request a depth buffer, RGBA display mode, and we want double buffering
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE);
// set the initial window size
glutInitWindowSize(640,480);
// create the window
glutCreateWindow("A basic primitive example");
// set the function to use to draw our scene
glutDisplayFunc(OnDraw);
// set the function to handle changes in screen size
glutReshapeFunc(OnReshape);
// run our custom initialisation
glEnable(GL_DEPTH_TEST);
// this function runs a while loop to keep the program running.
glutMainLoop();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -