1/* 2 * glClear + glScissor + Undefined content of framebuffer 3 */ 4 5#include <stdio.h> 6#include <string.h> 7#include <stdlib.h> 8#include "glut_wrap.h" 9 10 11GLenum doubleBuffer; 12GLint Width = 200, Height = 150; 13 14static void Init(void) 15{ 16 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 17 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 18 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 19 fprintf(stderr, "Top right corner should be red\n"); 20 fflush(stderr); 21} 22 23static void Reshape(int width, int height) 24{ 25 Width = width; 26 Height = height; 27 28 glViewport(0, 0, (GLint)width, (GLint)height); 29 30 glMatrixMode(GL_PROJECTION); 31 glLoadIdentity(); 32 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 33 glMatrixMode(GL_MODELVIEW); 34} 35 36static void Key(unsigned char key, int x, int y) 37{ 38 switch (key) { 39 case 27: 40 exit(1); 41 default: 42 glutPostRedisplay(); 43 return; 44 } 45 46} 47 48static void Draw(void) 49{ 50 glColor4f(1.0, 0.0, 0.0, 1.0); 51 glBegin(GL_QUADS); 52 glVertex2d(0.0, 0.0); 53 glVertex2d(0.0, 1.0); 54 glVertex2d(1.0, 1.0); 55 glVertex2d(1.0, 0.0); 56 glEnd(); 57 58 glBegin(GL_QUADS); 59 glVertex2d(0.0, 0.0); 60 glVertex2d(0.0, -1.0); 61 glVertex2d(1.0, -1.0); 62 glVertex2d(1.0, 0.0); 63 glEnd(); 64 65 glEnable(GL_SCISSOR_TEST); 66 glClearColor(1, 1, 0, 0); 67 glScissor(Width / 2, 0, Width - Width / 2, Height / 2); 68 glClear(GL_COLOR_BUFFER_BIT); 69 70 glClearColor(0, 0, 1, 0); 71 glScissor(0, Height / 2, Width / 2, Height - Height / 2); 72 glClear(GL_COLOR_BUFFER_BIT); 73 glDisable(GL_SCISSOR_TEST); 74 75 glColor4f(0.0, 1.0, 0.0, 1.0); 76 glBegin(GL_QUADS); 77 glVertex2d( 0.0, 0.0); 78 glVertex2d( 0.0, -1.0); 79 glVertex2d(-1.0, -1.0); 80 glVertex2d(-1.0, 0.0); 81 glEnd(); 82 83 glFlush(); 84 85 if (doubleBuffer) { 86 glutSwapBuffers(); 87 } 88} 89 90static GLenum Args(int argc, char **argv) 91{ 92 GLint i; 93 94 doubleBuffer = GL_TRUE; 95 96 for (i = 1; i < argc; i++) { 97 if (strcmp(argv[i], "-sb") == 0) { 98 doubleBuffer = GL_FALSE; 99 } else if (strcmp(argv[i], "-db") == 0) { 100 doubleBuffer = GL_TRUE; 101 } else { 102 fprintf(stderr, "%s (Bad option).\n", argv[i]); 103 return GL_FALSE; 104 } 105 } 106 return GL_TRUE; 107} 108 109int main(int argc, char **argv) 110{ 111 GLenum type; 112 113 glutInit(&argc, argv); 114 115 if (Args(argc, argv) == GL_FALSE) { 116 exit(1); 117 } 118 119 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height ); 120 121 122 type = GLUT_RGB | GLUT_ALPHA; 123 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 124 glutInitDisplayMode(type); 125 126 if (glutCreateWindow(argv[0]) == GL_FALSE) { 127 exit(1); 128 } 129 130 Init(); 131 Reshape(Width, Height); 132 133 glutReshapeFunc(Reshape); 134 glutKeyboardFunc(Key); 135 glutDisplayFunc(Draw); 136 glutMainLoop(); 137 return 0; 138} 139