132001f49Smrg/* 232001f49Smrg * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. 332001f49Smrg * Copyright (c) 2009 VMware, Inc. 432001f49Smrg * 532001f49Smrg * Permission to use, copy, modify, distribute, and sell this software and 632001f49Smrg * its documentation for any purpose is hereby granted without fee, provided 732001f49Smrg * that (i) the above copyright notices and this permission notice appear in 832001f49Smrg * all copies of the software and related documentation, and (ii) the name of 932001f49Smrg * Silicon Graphics may not be used in any advertising or 1032001f49Smrg * publicity relating to the software without the specific, prior written 1132001f49Smrg * permission of Silicon Graphics. 1232001f49Smrg * 1332001f49Smrg * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF 1432001f49Smrg * ANY KIND, 1532001f49Smrg * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 1632001f49Smrg * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 1732001f49Smrg * 1832001f49Smrg * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR 1932001f49Smrg * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 2032001f49Smrg * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 2132001f49Smrg * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 2232001f49Smrg * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 2332001f49Smrg * OF THIS SOFTWARE. 2432001f49Smrg */ 2532001f49Smrg 2632001f49Smrg#include <stdio.h> 2732001f49Smrg#include <string.h> 2832001f49Smrg#include <stdlib.h> 2932001f49Smrg#include "glut_wrap.h" 3032001f49Smrg 3132001f49Smrgstruct program 3232001f49Smrg{ 3332001f49Smrg unsigned width; 3432001f49Smrg unsigned height; 3532001f49Smrg int i; 3632001f49Smrg}; 3732001f49Smrg 3832001f49Smrgstruct program prog; 3932001f49Smrg 4032001f49Smrgstatic void init(void) 4132001f49Smrg{ 4232001f49Smrg fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 4332001f49Smrg fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 4432001f49Smrg fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 4532001f49Smrg fflush(stderr); 4632001f49Smrg 4732001f49Smrg prog.i = 0; 4832001f49Smrg} 4932001f49Smrg 5032001f49Smrgstatic void reshape(int width, int height) 5132001f49Smrg{ 5232001f49Smrg glViewport(0, 0, 100, 100); 5332001f49Smrg 5432001f49Smrg prog.width = width; 5532001f49Smrg prog.height = height; 5632001f49Smrg 5732001f49Smrg glMatrixMode(GL_PROJECTION); 5832001f49Smrg glLoadIdentity(); 5932001f49Smrg glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 6032001f49Smrg glMatrixMode(GL_MODELVIEW); 6132001f49Smrg} 6232001f49Smrg 6332001f49Smrgstatic void key(unsigned char key, int x, int y) 6432001f49Smrg{ 6532001f49Smrg 6632001f49Smrg switch (key) { 6732001f49Smrg case 27: 6832001f49Smrg exit(1); 6932001f49Smrg default: 7032001f49Smrg glutPostRedisplay(); 7132001f49Smrg return; 7232001f49Smrg } 7332001f49Smrg} 7432001f49Smrg 7532001f49Smrgstatic void drawQuad(void) 7632001f49Smrg{ 7732001f49Smrg glBegin(GL_QUADS); 7832001f49Smrg glVertex2d(-1.0, -1.0); 7932001f49Smrg glVertex2d( 1.0, -1.0); 8032001f49Smrg glVertex2d( 1.0, 1.0); 8132001f49Smrg glVertex2d(-1.0, 1.0); 8232001f49Smrg glEnd(); 8332001f49Smrg} 8432001f49Smrg 8532001f49Smrgstatic void draw(void) 8632001f49Smrg{ 8732001f49Smrg int i; 8832001f49Smrg 8932001f49Smrg glClearColor(0.0, 0.0, 1.0, 0.0); 9032001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 9132001f49Smrg 9232001f49Smrg i = prog.i++; 9332001f49Smrg if (prog.i >= 3) 9432001f49Smrg prog.i = 0; 9532001f49Smrg 9632001f49Smrg glEnable(GL_SCISSOR_TEST); 9732001f49Smrg 9832001f49Smrg { 9932001f49Smrg glColor4d(1.0, 0.0, 0.0, 1.0); 10032001f49Smrg 10132001f49Smrg glScissor(i, i, 10 - 2*i, 10 - 2*i); 10232001f49Smrg drawQuad(); 10332001f49Smrg } 10432001f49Smrg 10532001f49Smrg glDisable(GL_SCISSOR_TEST); 10632001f49Smrg 10732001f49Smrg /* glutSwapBuffers(); */ 10832001f49Smrg glFlush(); 10932001f49Smrg} 11032001f49Smrg 11132001f49Smrgint main(int argc, char **argv) 11232001f49Smrg{ 11332001f49Smrg GLenum type; 11432001f49Smrg 11532001f49Smrg glutInit(&argc, argv); 11632001f49Smrg 11732001f49Smrg prog.width = 200; 11832001f49Smrg prog.height = 200; 11932001f49Smrg 12032001f49Smrg glutInitWindowPosition(100, 0); 12132001f49Smrg glutInitWindowSize(prog.width, prog.height); 12232001f49Smrg 12332001f49Smrg /* type = GLUT_RGB | GLUT_DOUBLE; */ 12432001f49Smrg type = GLUT_RGB | GLUT_SINGLE; 12532001f49Smrg glutInitDisplayMode(type); 12632001f49Smrg 12732001f49Smrg if (glutCreateWindow(*argv) == GL_FALSE) { 12832001f49Smrg exit(1); 12932001f49Smrg } 13032001f49Smrg 13132001f49Smrg init(); 13232001f49Smrg 13332001f49Smrg glutReshapeFunc(reshape); 13432001f49Smrg glutKeyboardFunc(key); 13532001f49Smrg glutDisplayFunc(draw); 13632001f49Smrg glutMainLoop(); 13732001f49Smrg return 0; 13832001f49Smrg} 139