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.
64 #include "glut_wrap.h"
68 static GLfloat psize
= 7.0;
69 static GLfloat pmax
[1];
70 static GLfloat constant
[3] = {1.0, 0.0, 0.0};
71 static GLfloat linear
[3] = {0.0, 0.12, 0.0};
72 static GLfloat quadratic
[3] = {0.0, 0.0, 0.01};
74 static void init(void)
80 glNewList(1, GL_COMPILE
);
82 for (i
= 0; i
< 250; i
++) {
83 glColor3f (1.0, ((rand()/(float) RAND_MAX
) * 0.5) + 0.5,
84 rand()/(float) RAND_MAX
);
85 /* randomly generated vertices:
86 -5 < x < 5; -5 < y < 5; -5 < z < -45 */
87 glVertex3f ( ((rand()/(float)RAND_MAX
) * 10.0) - 5.0,
88 ((rand()/(float)RAND_MAX
) * 10.0) - 5.0,
89 ((rand()/(float)RAND_MAX
) * 40.0) - 45.0);
94 glEnable(GL_DEPTH_TEST
);
95 glEnable(GL_POINT_SMOOTH
);
97 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
99 glGetFloatv(GL_POINT_SIZE_MAX_EXT
, pmax
);
101 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, linear
);
102 glPointParameterfEXT (GL_POINT_FADE_THRESHOLD_SIZE_EXT
, 2.0);
105 static void display(void)
107 glClear (GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
112 static void reshape (int w
, int h
)
114 glViewport (0, 0, (GLsizei
) w
, (GLsizei
) h
);
115 glMatrixMode (GL_PROJECTION
);
117 gluPerspective (35.0, 1.0, 0.25, 200.0);
118 glMatrixMode (GL_MODELVIEW
);
119 glTranslatef (0.0, 0.0, -10.0);
122 static void keyboard(unsigned char key
, int x
, int y
)
126 glMatrixMode (GL_MODELVIEW
);
127 glTranslatef (0.0, 0.0, -0.5);
131 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, constant
);
135 glMatrixMode (GL_MODELVIEW
);
136 glTranslatef (0.0, 0.0, 0.5);
140 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, linear
);
144 glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT
, quadratic
);
148 if (psize
< (pmax
[0] + 1.0))
165 int main(int argc
, char** argv
)
167 glutInit(&argc
, argv
);
168 glutInitDisplayMode (GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
| GLUT_MULTISAMPLE
);
169 glutInitWindowSize (500, 500);
170 glutInitWindowPosition (100, 100);
171 glutCreateWindow (argv
[0]);
174 glutDisplayFunc (display
);
175 glutReshapeFunc (reshape
);
176 glutKeyboardFunc (keyboard
);