#include <gl/glew.h> #include <gl/freeglut.h> #include <iostream> int window_width = 1024; int window_height = 800; float rtri = 0.0; float rquad = 0.0; void init(); void display(); void resize(int w, int h); int main(int argc, char ** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(1024, 800); glutCreateWindow("OpenGL"); GLenum res = glewInit(); if (res != GLEW_OK) { std::cout << glewGetErrorString(res) << std::endl; } init(); glutDisplayFunc(display); glutReshapeFunc(resize); glutMainLoop(); return EXIT_SUCCESS; } void init() { glClearColor(0.0, 0.0, 0.0, 1.0); } void display() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); for (int loop = 0; loop < 4; ++loop) { if (0 == loop) { glViewport(0, 0, window_width/2, window_height/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-20, 20, -20, 20); } if (1 == loop) { glViewport(window_width/2, 0, window_width, window_height/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-20, 20, -20, 20); } if (2 == loop) { glViewport(0, window_height/2, window_width/2, window_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-20, 20, -20, 20); } if (3 == loop) { glViewport(window_width/2, window_height/2, window_width, window_height) ; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-20, 20, -20, 20); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_DEPTH_BUFFER_BIT); if (0 == loop) { glBegin(GL_QUADS); glVertex2f(-10, -10); glVertex2f(10, -10); glVertex2f(10, 10); glVertex2f(-10, 10); glEnd(); } if (1 == loop) { glBegin(GL_QUADS); glVertex2f(-10, -10); glVertex2f(10, -10); glVertex2f(10, 10); glVertex2f(-10, 10); glEnd(); } if (2 == loop) { glBegin(GL_QUADS); glVertex2f(-10, -10); glVertex2f(10, -10); glVertex2f(10, 10); glVertex2f(-10, 10); glEnd(); } if (3 == loop) { glBegin(GL_QUADS); glVertex2f(-10, -10); glVertex2f(10, -10); glVertex2f(10, 10); glVertex2f(-10, 10); glEnd(); } } glutSwapBuffers(); } void resize(int w, int h) { window_height = h; window_width = w; }
转载于:https://www.cnblogs.com/nmgxbc/p/3505744.html