jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | |
| 2 | /* Copyright (c) Mark J. Kilgard, 1994. */ |
| 3 | |
| 4 | /* |
| 5 | * (c) Copyright 1993, Silicon Graphics, Inc. |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 6 | * ALL RIGHTS RESERVED |
| 7 | * Permission to use, copy, modify, and distribute this software for |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | * any purpose and without fee is hereby granted, provided that the above |
| 9 | * copyright notice appear in all copies and that both the copyright notice |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 10 | * and this permission notice appear in supporting documentation, and that |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 11 | * the name of Silicon Graphics, Inc. not be used in advertising |
| 12 | * or publicity pertaining to distribution of the software without specific, |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 13 | * written prior permission. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 14 | * |
| 15 | * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" |
| 16 | * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, |
| 17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON |
| 19 | * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, |
| 20 | * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY |
| 21 | * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, |
| 22 | * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF |
| 23 | * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN |
| 24 | * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON |
| 25 | * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE |
| 26 | * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 27 | * |
| 28 | * US Government Users Restricted Rights |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 29 | * Use, duplication, or disclosure by the Government is subject to |
| 30 | * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph |
| 31 | * (c)(1)(ii) of the Rights in Technical Data and Computer Software |
| 32 | * clause at DFARS 252.227-7013 and/or in similar or successor |
| 33 | * clauses in the FAR or the DOD or NASA FAR Supplement. |
| 34 | * Unpublished-- rights reserved under the copyright laws of the |
| 35 | * United States. Contractor/manufacturer is Silicon Graphics, |
| 36 | * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. |
| 37 | * |
| 38 | * OpenGL(TM) is a trademark of Silicon Graphics, Inc. |
| 39 | */ |
| 40 | /* |
| 41 | * anti.c |
| 42 | * This program draws antialiased lines in RGBA mode. |
| 43 | */ |
| 44 | #include <stdlib.h> |
| 45 | #include <stdio.h> |
| 46 | #include <GL/glut.h> |
| 47 | |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 48 | /* Initialize antialiasing for RGBA mode, including alpha |
| 49 | * blending, hint, and line width. Print out implementation |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 50 | * specific info on line width granularity and width. |
| 51 | */ |
| 52 | void myinit(void) |
| 53 | { |
| 54 | GLfloat values[2]; |
| 55 | glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values); |
| 56 | printf ("GL_LINE_WIDTH_GRANULARITY value is %3.1f\n", values[0]); |
| 57 | |
| 58 | glGetFloatv (GL_LINE_WIDTH_RANGE, values); |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 59 | printf ("GL_LINE_WIDTH_RANGE values are %3.1f %3.1f\n", |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 60 | values[0], values[1]); |
| 61 | |
| 62 | glEnable (GL_LINE_SMOOTH); |
| 63 | glEnable (GL_BLEND); |
| 64 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 65 | glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); |
| 66 | glLineWidth (1.5); |
| 67 | |
| 68 | glShadeModel(GL_FLAT); |
| 69 | glClearColor(0.0, 0.0, 0.0, 0.0); |
| 70 | glDepthFunc(GL_LESS); |
| 71 | glEnable(GL_DEPTH_TEST); |
| 72 | } |
| 73 | |
| 74 | /* display() draws an icosahedron with a large alpha value, 1.0. |
| 75 | */ |
| 76 | void display(void) |
| 77 | { |
| 78 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 79 | glColor4f (1.0, 1.0, 1.0, 1.0); |
| 80 | glutWireIcosahedron(); |
| 81 | glFlush(); |
| 82 | } |
| 83 | |
| 84 | void myReshape(int w, int h) |
| 85 | { |
| 86 | glViewport(0, 0, w, h); |
| 87 | glMatrixMode(GL_PROJECTION); |
| 88 | glLoadIdentity(); |
| 89 | gluPerspective (45.0, (GLfloat) w/(GLfloat) h, 3.0, 5.0); |
| 90 | |
| 91 | glMatrixMode(GL_MODELVIEW); |
| 92 | glLoadIdentity (); |
| 93 | glTranslatef (0.0, 0.0, -4.0); /* move object into view */ |
| 94 | } |
| 95 | |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 96 | static void |
| 97 | key(unsigned char k, int x, int y) |
| 98 | { |
| 99 | switch (k) { |
| 100 | case 27: /* Escape */ |
| 101 | exit(0); |
| 102 | break; |
| 103 | default: |
| 104 | return; |
| 105 | } |
| 106 | glutPostRedisplay(); |
| 107 | } |
| 108 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | /* Main Loop |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 110 | * Open window with initial window size, title bar, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 111 | * RGBA display mode, and handle input events. |
| 112 | */ |
| 113 | int main(int argc, char** argv) |
| 114 | { |
| 115 | glutInit(&argc, argv); |
| 116 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); |
| 117 | glutCreateWindow (argv[0]); |
| 118 | myinit(); |
| 119 | glutReshapeFunc (myReshape); |
| 120 | glutDisplayFunc(display); |
Ted Jump | 83c02ef | 1999-09-17 02:40:51 +0000 | [diff] [blame^] | 121 | glutKeyboardFunc(key); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 122 | glutMainLoop(); |
| 123 | return 0; /* ANSI C requires main to return int. */ |
| 124 | } |