132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-2003, Silicon Graphics, Inc. 332001f49Smrg * All Rights Reserved 432001f49Smrg * 532001f49Smrg * Permission to use, copy, modify, and distribute this software for any 632001f49Smrg * purpose and without fee is hereby granted, provided that the above 732001f49Smrg * copyright notice appear in all copies and that both the copyright 832001f49Smrg * notice and this permission notice appear in supporting documentation, 932001f49Smrg * and that the name of Silicon Graphics, Inc. not be used in 1032001f49Smrg * advertising or publicity pertaining to distribution of the software 1132001f49Smrg * without specific, written prior permission. 1232001f49Smrg * 1332001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND 1432001f49Smrg * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1532001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1632001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1732001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1832001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 1932001f49Smrg * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF 2032001f49Smrg * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD 2132001f49Smrg * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF 2232001f49Smrg * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF 2332001f49Smrg * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE 2432001f49Smrg * OR PERFORMANCE OF THIS SOFTWARE. 2532001f49Smrg * 2632001f49Smrg * US Government Users Restricted Rights 2732001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2832001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2932001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 3032001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor clauses 3132001f49Smrg * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights 3232001f49Smrg * reserved under the copyright laws of the United States. 3332001f49Smrg * 3432001f49Smrg * Contractor/manufacturer is: 3532001f49Smrg * Silicon Graphics, Inc. 3632001f49Smrg * 1500 Crittenden Lane 3732001f49Smrg * Mountain View, CA 94043 3832001f49Smrg * United State of America 3932001f49Smrg * 4032001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 4132001f49Smrg */ 4232001f49Smrg 4332001f49Smrg/* 4432001f49Smrg * multisamp.c 4532001f49Smrg * This program draws shows how to use multisampling to 4632001f49Smrg * draw anti-aliased geometric primitives. The same 4732001f49Smrg * display list, a pinwheel of triangles and lines of 4832001f49Smrg * varying widths, is rendered twice. Multisampling is 4932001f49Smrg * enabled when the left side is drawn. Multisampling is 5032001f49Smrg * disabled when the right side is drawn. 5132001f49Smrg * 5232001f49Smrg * Pressing the 'b' key toggles drawing of the checkerboard 5332001f49Smrg * background. Antialiasing is sometimes easier to see 5432001f49Smrg * when objects are rendered over a contrasting background. 5532001f49Smrg */ 5632001f49Smrg#include <GL/glew.h> 5732001f49Smrg#include "glut_wrap.h" 5832001f49Smrg#include <stdlib.h> 5932001f49Smrg#include <stdio.h> 6032001f49Smrg 6132001f49Smrgstatic int bgtoggle = 1; 6232001f49Smrg 6332001f49Smrg/* 6432001f49Smrg * Print out state values related to multisampling. 6532001f49Smrg * Create display list with "pinwheel" of lines and 6632001f49Smrg * triangles. 6732001f49Smrg */ 6832001f49Smrgstatic void init(void) 6932001f49Smrg{ 7032001f49Smrg static GLint buf[1], sbuf[1]; 7132001f49Smrg int i, j; 7232001f49Smrg 7332001f49Smrg glClearColor(0.0, 0.0, 0.0, 0.0); 7432001f49Smrg glGetIntegerv (GL_SAMPLE_BUFFERS_ARB, buf); 7532001f49Smrg printf ("number of sample buffers is %d\n", buf[0]); 7632001f49Smrg glGetIntegerv (GL_SAMPLES_ARB, sbuf); 7732001f49Smrg printf ("number of samples is %d\n", sbuf[0]); 7832001f49Smrg 7932001f49Smrg glNewList (1, GL_COMPILE); 8032001f49Smrg for (i = 0; i < 19; i++) { 8132001f49Smrg glPushMatrix(); 8232001f49Smrg glRotatef(360.0*(float)i/19.0, 0.0, 0.0, 1.0); 8332001f49Smrg glColor3f (1.0, 1.0, 1.0); 8432001f49Smrg glLineWidth((i%3)+1.0); 8532001f49Smrg glBegin (GL_LINES); 8632001f49Smrg glVertex2f (0.25, 0.05); 8732001f49Smrg glVertex2f (0.9, 0.2); 8832001f49Smrg glEnd (); 8932001f49Smrg glColor3f (0.0, 1.0, 1.0); 9032001f49Smrg glBegin (GL_TRIANGLES); 9132001f49Smrg glVertex2f (0.25, 0.0); 9232001f49Smrg glVertex2f (0.9, 0.0); 9332001f49Smrg glVertex2f (0.875, 0.10); 9432001f49Smrg glEnd (); 9532001f49Smrg glPopMatrix(); 9632001f49Smrg } 9732001f49Smrg glEndList (); 9832001f49Smrg 9932001f49Smrg glNewList (2, GL_COMPILE); 10032001f49Smrg glColor3f (1.0, 0.5, 0.0); 10132001f49Smrg glBegin (GL_QUADS); 10232001f49Smrg for (i = 0; i < 16; i++) { 10332001f49Smrg for (j = 0; j < 16; j++) { 10432001f49Smrg if (((i + j) % 2) == 0) { 10532001f49Smrg glVertex2f (-2.0 + (i * 0.25), -2.0 + (j * 0.25)); 10632001f49Smrg glVertex2f (-2.0 + (i * 0.25), -1.75 + (j * 0.25)); 10732001f49Smrg glVertex2f (-1.75 + (i * 0.25), -1.75 + (j * 0.25)); 10832001f49Smrg glVertex2f (-1.75 + (i * 0.25), -2.0 + (j * 0.25)); 10932001f49Smrg } 11032001f49Smrg } 11132001f49Smrg } 11232001f49Smrg glEnd (); 11332001f49Smrg glEndList (); 11432001f49Smrg} 11532001f49Smrg 11632001f49Smrg/* Draw two sets of primitives, so that you can 11732001f49Smrg * compare the user of multisampling against its absence. 11832001f49Smrg * 11932001f49Smrg * This code enables antialiasing and draws one display list 12032001f49Smrg * and disables and draws the other display list 12132001f49Smrg */ 12232001f49Smrgstatic void display(void) 12332001f49Smrg{ 12432001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 12532001f49Smrg 12632001f49Smrg if (bgtoggle) 12732001f49Smrg glCallList (2); 12832001f49Smrg 12932001f49Smrg glEnable (GL_MULTISAMPLE_ARB); 13032001f49Smrg glPushMatrix(); 13132001f49Smrg glTranslatef (-1.0, 0.0, 0.0); 13232001f49Smrg glCallList (1); 13332001f49Smrg glPopMatrix(); 13432001f49Smrg 13532001f49Smrg glDisable (GL_MULTISAMPLE_ARB); 13632001f49Smrg glPushMatrix(); 13732001f49Smrg glTranslatef (1.0, 0.0, 0.0); 13832001f49Smrg glCallList (1); 13932001f49Smrg glPopMatrix(); 14032001f49Smrg glutSwapBuffers(); 14132001f49Smrg} 14232001f49Smrg 14332001f49Smrgstatic void reshape(int w, int h) 14432001f49Smrg{ 14532001f49Smrg glViewport(0, 0, w, h); 14632001f49Smrg glMatrixMode(GL_PROJECTION); 14732001f49Smrg glLoadIdentity(); 14832001f49Smrg if (w <= (2 * h)) 14932001f49Smrg gluOrtho2D (-2.0, 2.0, 15032001f49Smrg -2.0*(GLfloat)h/(GLfloat)w, 2.0*(GLfloat)h/(GLfloat)w); 15132001f49Smrg else 15232001f49Smrg gluOrtho2D (-2.0*(GLfloat)w/(GLfloat)h, 15332001f49Smrg 2.0*(GLfloat)w/(GLfloat)h, -2.0, 2.0); 15432001f49Smrg glMatrixMode(GL_MODELVIEW); 15532001f49Smrg glLoadIdentity(); 15632001f49Smrg} 15732001f49Smrg 15832001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 15932001f49Smrg{ 16032001f49Smrg switch (key) { 16132001f49Smrg case 'b': 16232001f49Smrg case 'B': 16332001f49Smrg bgtoggle = !bgtoggle; 16432001f49Smrg glutPostRedisplay(); 16532001f49Smrg break; 16632001f49Smrg case 27: /* Escape Key */ 16732001f49Smrg exit(0); 16832001f49Smrg default: 16932001f49Smrg break; 17032001f49Smrg } 17132001f49Smrg} 17232001f49Smrg 17332001f49Smrg/* Main Loop 17432001f49Smrg * Open window with initial window size, title bar, 17532001f49Smrg * RGBA display mode, and handle input events. 17632001f49Smrg */ 17732001f49Smrgint main(int argc, char** argv) 17832001f49Smrg{ 17932001f49Smrg glutInit(&argc, argv); 18032001f49Smrg glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_MULTISAMPLE); 18132001f49Smrg glutInitWindowSize (600, 300); 18232001f49Smrg glutCreateWindow (argv[0]); 18332001f49Smrg init(); 18432001f49Smrg glutReshapeFunc (reshape); 18532001f49Smrg glutKeyboardFunc (keyboard); 18632001f49Smrg glutDisplayFunc (display); 18732001f49Smrg glutMainLoop(); 18832001f49Smrg return 0; 18932001f49Smrg} 190