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 * pointp.c 4532001f49Smrg * This program demonstrates point parameters and their effect 4632001f49Smrg * on point primitives. 4732001f49Smrg * 250 points are randomly generated within a 10 by 10 by 40 4832001f49Smrg * region, centered at the origin. In some modes (including the 4932001f49Smrg * default), points that are closer to the viewer will appear larger. 5032001f49Smrg * 5132001f49Smrg * Pressing the 'l', 'q', and 'c' keys switch the point 5232001f49Smrg * parameters attenuation mode to linear, quadratic, or constant, 5332001f49Smrg * respectively. 5432001f49Smrg * Pressing the 'f' and 'b' keys move the viewer forward 5532001f49Smrg * and backwards. In either linear or quadratic attenuation 5632001f49Smrg * mode, the distance from the viewer to the point will change 5732001f49Smrg * the size of the point primitive. 5832001f49Smrg * Pressing the '+' and '-' keys will change the current point 5932001f49Smrg * size. In this program, the point size is bounded, so it 6032001f49Smrg * will not get less than 2.0, nor greater than GL_POINT_SIZE_MAX. 6132001f49Smrg */ 6232001f49Smrg 6332001f49Smrg#include <GL/glew.h> 6432001f49Smrg#include "glut_wrap.h" 6532001f49Smrg#include <stdlib.h> 6632001f49Smrg#include <stdio.h> 6732001f49Smrg 6832001f49Smrgstatic GLfloat psize = 7.0; 6932001f49Smrgstatic GLfloat pmax[1]; 7032001f49Smrgstatic GLfloat constant[3] = {1.0, 0.0, 0.0}; 7132001f49Smrgstatic GLfloat linear[3] = {0.0, 0.12, 0.0}; 7232001f49Smrgstatic GLfloat quadratic[3] = {0.0, 0.0, 0.01}; 7332001f49Smrg 7432001f49Smrgstatic void init(void) 7532001f49Smrg{ 7632001f49Smrg int i; 7732001f49Smrg 7832001f49Smrg srand (12345); 7932001f49Smrg 8032001f49Smrg glNewList(1, GL_COMPILE); 8132001f49Smrg glBegin (GL_POINTS); 8232001f49Smrg for (i = 0; i < 250; i++) { 8332001f49Smrg glColor3f (1.0, ((rand()/(float) RAND_MAX) * 0.5) + 0.5, 8432001f49Smrg rand()/(float) RAND_MAX); 8532001f49Smrg/* randomly generated vertices: 8632001f49Smrg -5 < x < 5; -5 < y < 5; -5 < z < -45 */ 8732001f49Smrg glVertex3f ( ((rand()/(float)RAND_MAX) * 10.0) - 5.0, 8832001f49Smrg ((rand()/(float)RAND_MAX) * 10.0) - 5.0, 8932001f49Smrg ((rand()/(float)RAND_MAX) * 40.0) - 45.0); 9032001f49Smrg } 9132001f49Smrg glEnd(); 9232001f49Smrg glEndList(); 9332001f49Smrg 9432001f49Smrg glEnable(GL_DEPTH_TEST); 9532001f49Smrg glEnable(GL_POINT_SMOOTH); 9632001f49Smrg glEnable(GL_BLEND); 9732001f49Smrg glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 9832001f49Smrg glPointSize(psize); 9932001f49Smrg glGetFloatv(GL_POINT_SIZE_MAX_EXT, pmax); 10032001f49Smrg 10132001f49Smrg glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, linear); 10232001f49Smrg glPointParameterfEXT (GL_POINT_FADE_THRESHOLD_SIZE_EXT, 2.0); 10332001f49Smrg} 10432001f49Smrg 10532001f49Smrgstatic void display(void) 10632001f49Smrg{ 10732001f49Smrg glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 10832001f49Smrg glCallList (1); 10932001f49Smrg glutSwapBuffers (); 11032001f49Smrg} 11132001f49Smrg 11232001f49Smrgstatic void reshape (int w, int h) 11332001f49Smrg{ 11432001f49Smrg glViewport (0, 0, (GLsizei) w, (GLsizei) h); 11532001f49Smrg glMatrixMode (GL_PROJECTION); 11632001f49Smrg glLoadIdentity (); 11732001f49Smrg gluPerspective (35.0, 1.0, 0.25, 200.0); 11832001f49Smrg glMatrixMode (GL_MODELVIEW); 11932001f49Smrg glTranslatef (0.0, 0.0, -10.0); 12032001f49Smrg} 12132001f49Smrg 12232001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 12332001f49Smrg{ 12432001f49Smrg switch (key) { 12532001f49Smrg case 'b': 12632001f49Smrg glMatrixMode (GL_MODELVIEW); 12732001f49Smrg glTranslatef (0.0, 0.0, -0.5); 12832001f49Smrg glutPostRedisplay(); 12932001f49Smrg break; 13032001f49Smrg case 'c': 13132001f49Smrg glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, constant); 13232001f49Smrg glutPostRedisplay(); 13332001f49Smrg break; 13432001f49Smrg case 'f': 13532001f49Smrg glMatrixMode (GL_MODELVIEW); 13632001f49Smrg glTranslatef (0.0, 0.0, 0.5); 13732001f49Smrg glutPostRedisplay(); 13832001f49Smrg break; 13932001f49Smrg case 'l': 14032001f49Smrg glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, linear); 14132001f49Smrg glutPostRedisplay(); 14232001f49Smrg break; 14332001f49Smrg case 'q': 14432001f49Smrg glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, quadratic); 14532001f49Smrg glutPostRedisplay(); 14632001f49Smrg break; 14732001f49Smrg case '+': 14832001f49Smrg if (psize < (pmax[0] + 1.0)) 14932001f49Smrg psize = psize + 1.0; 15032001f49Smrg glPointSize (psize); 15132001f49Smrg glutPostRedisplay(); 15232001f49Smrg break; 15332001f49Smrg case '-': 15432001f49Smrg if (psize >= 2.0) 15532001f49Smrg psize = psize - 1.0; 15632001f49Smrg glPointSize (psize); 15732001f49Smrg glutPostRedisplay(); 15832001f49Smrg break; 15932001f49Smrg case 27: 16032001f49Smrg exit(0); 16132001f49Smrg break; 16232001f49Smrg } 16332001f49Smrg} 16432001f49Smrg 16532001f49Smrgint main(int argc, char** argv) 16632001f49Smrg{ 16732001f49Smrg glutInit(&argc, argv); 16832001f49Smrg glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); 16932001f49Smrg glutInitWindowSize (500, 500); 17032001f49Smrg glutInitWindowPosition (100, 100); 17132001f49Smrg glutCreateWindow (argv[0]); 17232001f49Smrg glewInit(); 17332001f49Smrg init (); 17432001f49Smrg glutDisplayFunc (display); 17532001f49Smrg glutReshapeFunc (reshape); 17632001f49Smrg glutKeyboardFunc (keyboard); 17732001f49Smrg glutMainLoop(); 17832001f49Smrg return 0; 17932001f49Smrg} 180