Created
July 1, 2017 14:46
-
-
Save insaneyilin/9320e8263b29e3c172c4f5963b8db693 to your computer and use it in GitHub Desktop.
OpenGL multiple viewports example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <GL/gl.h> | |
#include <GL/glu.h> | |
#include <GL/glut.h> | |
static int width; | |
static int height; | |
static void display(void) { | |
glClear(GL_COLOR_BUFFER_BIT); | |
glViewport(0, 0, width/2, height/2); | |
glLoadIdentity(); | |
gluLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
glColor3f(1.0f, 0.0f, 0.0f); | |
glutWireTeapot(1); | |
glViewport(width/2, 0, width/2, height/2); | |
glLoadIdentity(); | |
gluLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
glColor3f(1.0f, 1.0f, 0.0f); | |
glutWireTeapot(1); | |
glViewport(0, height/2, width/2, height/2); | |
glLoadIdentity(); | |
gluLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
glColor3f(1.0f, 0.0f, 1.0f); | |
glutWireTeapot(1); | |
glViewport(width/2, height/2, width/2, height/2); | |
glLoadIdentity(); | |
gluLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
glColor3f(0.0f, 0.0f, 1.0f); | |
glutWireTeapot(1); | |
glFlush(); | |
} | |
static void reshape(int w, int h) { | |
width = w; | |
height = h; | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); | |
glMatrixMode(GL_MODELVIEW); | |
} | |
int main(int argc, char** argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow(argv[0]); | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
glShadeModel(GL_FLAT); | |
glutDisplayFunc(display); | |
glutReshapeFunc(reshape); | |
glutMainLoop(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment