2 * Copyright (c) 1993-2003, Silicon Graphics, Inc.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose and without fee is hereby granted, provided that the above
7 * copyright notice appear in all copies and that both the copyright
8 * notice and this permission notice appear in supporting documentation,
9 * and that the name of Silicon Graphics, Inc. not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission.
13 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
14 * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
16 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
17 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
18 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF
20 * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD
21 * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF
22 * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE
24 * OR PERFORMANCE OF THIS SOFTWARE.
26 * US Government Users Restricted Rights
27 * Use, duplication, or disclosure by the Government is subject to
28 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
29 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
30 * clause at DFARS 252.227-7013 and/or in similar or successor clauses
31 * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights
32 * reserved under the copyright laws of the United States.
34 * Contractor/manufacturer is:
35 * Silicon Graphics, Inc.
36 * 1500 Crittenden Lane
37 * Mountain View, CA 94043
38 * United State of America
40 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
45 * This program demonstrates point parameters and their effect
46 * on point primitives.
47 * 250 points are randomly generated within a 10 by 10 by 40
48 * region, centered at the origin. In some modes (including the
49 * default), points that are closer to the viewer will appear larger.
51 * Pressing the 'l', 'q', and 'c' keys switch the point
52 * parameters attenuation mode to linear, quadratic, or constant,
54 * Pressing the 'f' and 'b' keys move the viewer forward
55 * and backwards. In either linear or quadratic attenuation
56 * mode, the distance from the viewer to the point will change
57 * the size of the point primitive.
58 * Pressing the '+' and '-' keys will change the current point
59 * size. In this program, the point size is bounded, so it
60 * will not get less than 2.0, nor greater than GL_POINT_SIZE_MAX.
63 #define GL_GLEXT_PROTOTYPES
69 static GLfloat psize
= 7.0;
70 static GLfloat pmax
[1];
71 static GLfloat constant
[3] = {1.0, 0.0, 0.0};
72 static GLfloat linear
[3] = {0.0, 0.12, 0.0};
73 static GLfloat quadratic
[3] = {0.0, 0.0, 0.01};
75 static void init(void)
81 glNewList(1, GL_COMPILE
);
83 for (i
= 0; i
< 250; i
++) {
84 glColor3f (1.0, ((rand()/(float) RAND_MAX
) * 0.5) + 0.5,
85 rand()/(float) RAND_MAX
);
86 /* randomly generated vertices:
87 -5 < x < 5; -5 < y < 5; -5 < z < -45 */
88 glVertex3f ( ((rand()/(float)RAND_MAX
) * 10.0) - 5.0,
89 ((rand()/(float)RAND_MAX
) * 10.0) - 5.0,
90 ((rand()/(float)RAND_MAX
) * 40.0) - 45.0);
95 glEnable(GL_DEPTH_TEST
);
96 glEnable(GL_POINT_SMOOTH
);
98 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
100 glGetFloatv(GL_POINT_SIZE_MAX_EXT
, pmax
);
102 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, linear
);
103 glPointParameterfEXT (GL_POINT_FADE_THRESHOLD_SIZE_EXT
, 2.0);
106 static void display(void)
108 glClear (GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
113 static void reshape (int w
, int h
)
115 glViewport (0, 0, (GLsizei
) w
, (GLsizei
) h
);
116 glMatrixMode (GL_PROJECTION
);
118 gluPerspective (35.0, 1.0, 0.25, 200.0);
119 glMatrixMode (GL_MODELVIEW
);
120 glTranslatef (0.0, 0.0, -10.0);
123 static void keyboard(unsigned char key
, int x
, int y
)
127 glMatrixMode (GL_MODELVIEW
);
128 glTranslatef (0.0, 0.0, -0.5);
132 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, constant
);
136 glMatrixMode (GL_MODELVIEW
);
137 glTranslatef (0.0, 0.0, 0.5);
141 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, linear
);
145 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, quadratic
);
149 if (psize
< (pmax
[0] + 1.0))
166 int main(int argc
, char** argv
)
168 glutInit(&argc
, argv
);
169 glutInitDisplayMode (GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
| GLUT_MULTISAMPLE
);
170 glutInitWindowSize (500, 500);
171 glutInitWindowPosition (100, 100);
172 glutCreateWindow (argv
[0]);
174 glutDisplayFunc (display
);
175 glutReshapeFunc (reshape
);
176 glutKeyboardFunc (keyboard
);