OpenGL Utility Toolkit
http://www.lighthouse3d.com/opengl/glut/ 에서 가져와서 정리한 것.
#include <glut.h> #pragma comment(lib, "glut32.lib") float angle=0.0f; void OnIdle(void) { // notice that we're now clearing the depth buffer // as well this is required, otherwise the depth buffer // gets filled and nothing gets rendered. // Try it out, remove the depth buffer part. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // save the previous settings, in this case save // we're refering to the camera settings. glPushMatrix(); // Perform a rotation around the y axis (0,1,0) // by the amount of degrees defined in the variable angle glRotatef(angle,0.0,1.0,0.0); glBegin(GL_TRIANGLES); glVertex3f(-0.5,-0.5,0.0); glVertex3f(0.5,0.0,0.0); glVertex3f(0.0,0.5,0.0); glEnd(); // discard the modelling transformations // after this the matrix will have only the camera settings. glPopMatrix(); // swapping the buffers causes the rendering above to be // shown glutSwapBuffers(); // finally increase the angle for the next frame angle += 1.0f; } void OnResize(int w, int h) { // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if(h == 0) h = 1; float ratio = 1.0* w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); // Set the correct perspective. gluPerspective(45, ratio, 1, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100, 100); glutInitWindowSize(320, 320); glutCreateWindow("3D Tech- GLUT Tutorial"); glutIdleFunc(OnIdle); glutDisplayFunc(OnIdle); glutReshapeFunc(OnResize); glEnable(GL_DEPTH_TEST); glutMainLoop(); return 0; }