132001f49Smrg/* 232001f49Smrg * glClear + glScissor + Undefined content of framebuffer 332001f49Smrg */ 432001f49Smrg 532001f49Smrg#include <stdio.h> 632001f49Smrg#include <string.h> 732001f49Smrg#include <stdlib.h> 832001f49Smrg#include "glut_wrap.h" 932001f49Smrg 1032001f49Smrg 1132001f49SmrgGLenum doubleBuffer; 1232001f49SmrgGLint Width = 200, Height = 150; 1332001f49Smrg 1432001f49Smrgstatic void Init(void) 1532001f49Smrg{ 1632001f49Smrg fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 1732001f49Smrg fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 1832001f49Smrg fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 1932001f49Smrg fprintf(stderr, "Top right corner should be red\n"); 2032001f49Smrg fflush(stderr); 2132001f49Smrg} 2232001f49Smrg 2332001f49Smrgstatic void Reshape(int width, int height) 2432001f49Smrg{ 2532001f49Smrg Width = width; 2632001f49Smrg Height = height; 2732001f49Smrg 2832001f49Smrg glViewport(0, 0, (GLint)width, (GLint)height); 2932001f49Smrg 3032001f49Smrg glMatrixMode(GL_PROJECTION); 3132001f49Smrg glLoadIdentity(); 3232001f49Smrg glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 3332001f49Smrg glMatrixMode(GL_MODELVIEW); 3432001f49Smrg} 3532001f49Smrg 3632001f49Smrgstatic void Key(unsigned char key, int x, int y) 3732001f49Smrg{ 3832001f49Smrg switch (key) { 3932001f49Smrg case 27: 4032001f49Smrg exit(1); 4132001f49Smrg default: 4232001f49Smrg glutPostRedisplay(); 4332001f49Smrg return; 4432001f49Smrg } 4532001f49Smrg 4632001f49Smrg} 4732001f49Smrg 4832001f49Smrgstatic void Draw(void) 4932001f49Smrg{ 5032001f49Smrg glColor4f(1.0, 0.0, 0.0, 1.0); 5132001f49Smrg glBegin(GL_QUADS); 5232001f49Smrg glVertex2d(0.0, 0.0); 5332001f49Smrg glVertex2d(0.0, 1.0); 5432001f49Smrg glVertex2d(1.0, 1.0); 5532001f49Smrg glVertex2d(1.0, 0.0); 5632001f49Smrg glEnd(); 5732001f49Smrg 5832001f49Smrg glBegin(GL_QUADS); 5932001f49Smrg glVertex2d(0.0, 0.0); 6032001f49Smrg glVertex2d(0.0, -1.0); 6132001f49Smrg glVertex2d(1.0, -1.0); 6232001f49Smrg glVertex2d(1.0, 0.0); 6332001f49Smrg glEnd(); 6432001f49Smrg 6532001f49Smrg glEnable(GL_SCISSOR_TEST); 6632001f49Smrg glClearColor(1, 1, 0, 0); 6732001f49Smrg glScissor(Width / 2, 0, Width - Width / 2, Height / 2); 6832001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 6932001f49Smrg 7032001f49Smrg glClearColor(0, 0, 1, 0); 7132001f49Smrg glScissor(0, Height / 2, Width / 2, Height - Height / 2); 7232001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 7332001f49Smrg glDisable(GL_SCISSOR_TEST); 7432001f49Smrg 7532001f49Smrg glColor4f(0.0, 1.0, 0.0, 1.0); 7632001f49Smrg glBegin(GL_QUADS); 7732001f49Smrg glVertex2d( 0.0, 0.0); 7832001f49Smrg glVertex2d( 0.0, -1.0); 7932001f49Smrg glVertex2d(-1.0, -1.0); 8032001f49Smrg glVertex2d(-1.0, 0.0); 8132001f49Smrg glEnd(); 8232001f49Smrg 8332001f49Smrg glFlush(); 8432001f49Smrg 8532001f49Smrg if (doubleBuffer) { 8632001f49Smrg glutSwapBuffers(); 8732001f49Smrg } 8832001f49Smrg} 8932001f49Smrg 9032001f49Smrgstatic GLenum Args(int argc, char **argv) 9132001f49Smrg{ 9232001f49Smrg GLint i; 9332001f49Smrg 9432001f49Smrg doubleBuffer = GL_TRUE; 9532001f49Smrg 9632001f49Smrg for (i = 1; i < argc; i++) { 9732001f49Smrg if (strcmp(argv[i], "-sb") == 0) { 9832001f49Smrg doubleBuffer = GL_FALSE; 9932001f49Smrg } else if (strcmp(argv[i], "-db") == 0) { 10032001f49Smrg doubleBuffer = GL_TRUE; 10132001f49Smrg } else { 10232001f49Smrg fprintf(stderr, "%s (Bad option).\n", argv[i]); 10332001f49Smrg return GL_FALSE; 10432001f49Smrg } 10532001f49Smrg } 10632001f49Smrg return GL_TRUE; 10732001f49Smrg} 10832001f49Smrg 10932001f49Smrgint main(int argc, char **argv) 11032001f49Smrg{ 11132001f49Smrg GLenum type; 11232001f49Smrg 11332001f49Smrg glutInit(&argc, argv); 11432001f49Smrg 11532001f49Smrg if (Args(argc, argv) == GL_FALSE) { 11632001f49Smrg exit(1); 11732001f49Smrg } 11832001f49Smrg 11932001f49Smrg glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height ); 12032001f49Smrg 12132001f49Smrg 12232001f49Smrg type = GLUT_RGB | GLUT_ALPHA; 12332001f49Smrg type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 12432001f49Smrg glutInitDisplayMode(type); 12532001f49Smrg 12632001f49Smrg if (glutCreateWindow(argv[0]) == GL_FALSE) { 12732001f49Smrg exit(1); 12832001f49Smrg } 12932001f49Smrg 13032001f49Smrg Init(); 13132001f49Smrg Reshape(Width, Height); 13232001f49Smrg 13332001f49Smrg glutReshapeFunc(Reshape); 13432001f49Smrg glutKeyboardFunc(Key); 13532001f49Smrg glutDisplayFunc(Draw); 13632001f49Smrg glutMainLoop(); 13732001f49Smrg return 0; 13832001f49Smrg} 139