chmod a-x **/glslnoise.c
[mesa-demos.git] / src / redbook / lines.c
blobb34d4c418c698baa7a58685879a945de55bc7dc0
1 /*
2 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 * Permission to use, copy, modify, and distribute this software for
5 * any purpose and without fee is hereby granted, provided that the above
6 * copyright notice appear in all copies and that both the copyright notice
7 * and this permission notice appear in supporting documentation, and that
8 * the name of Silicon Graphics, Inc. not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission.
12 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
25 * US Government Users Restricted Rights
26 * Use, duplication, or disclosure by the Government is subject to
27 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29 * clause at DFARS 252.227-7013 and/or in similar or successor
30 * clauses in the FAR or the DOD or NASA FAR Supplement.
31 * Unpublished-- rights reserved under the copyright laws of the
32 * United States. Contractor/manufacturer is Silicon Graphics,
33 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
35 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
39 * lines.c
40 * This program demonstrates geometric primitives and
41 * their attributes.
43 #include <GL/glut.h>
44 #include <stdlib.h>
46 #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
47 glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
49 void init(void)
51 glClearColor (0.0, 0.0, 0.0, 0.0);
52 glShadeModel (GL_FLAT);
55 void display(void)
57 int i;
59 glClear (GL_COLOR_BUFFER_BIT);
61 /* select white for all lines */
62 glColor3f (1.0, 1.0, 1.0);
64 /* in 1st row, 3 lines, each with a different stipple */
65 glEnable (GL_LINE_STIPPLE);
67 glLineStipple (1, 0x0101); /* dotted */
68 drawOneLine (50.0, 125.0, 150.0, 125.0);
69 glLineStipple (1, 0x00FF); /* dashed */
70 drawOneLine (150.0, 125.0, 250.0, 125.0);
71 glLineStipple (1, 0x1C47); /* dash/dot/dash */
72 drawOneLine (250.0, 125.0, 350.0, 125.0);
74 /* in 2nd row, 3 wide lines, each with different stipple */
75 glLineWidth (5.0);
76 glLineStipple (1, 0x0101); /* dotted */
77 drawOneLine (50.0, 100.0, 150.0, 100.0);
78 glLineStipple (1, 0x00FF); /* dashed */
79 drawOneLine (150.0, 100.0, 250.0, 100.0);
80 glLineStipple (1, 0x1C47); /* dash/dot/dash */
81 drawOneLine (250.0, 100.0, 350.0, 100.0);
82 glLineWidth (1.0);
84 /* in 3rd row, 6 lines, with dash/dot/dash stipple */
85 /* as part of a single connected line strip */
86 glLineStipple (1, 0x1C47); /* dash/dot/dash */
87 glBegin (GL_LINE_STRIP);
88 for (i = 0; i < 7; i++)
89 glVertex2f (50.0 + ((GLfloat) i * 50.0), 75.0);
90 glEnd ();
92 /* in 4th row, 6 independent lines with same stipple */
93 for (i = 0; i < 6; i++) {
94 drawOneLine (50.0 + ((GLfloat) i * 50.0), 50.0,
95 50.0 + ((GLfloat)(i+1) * 50.0), 50.0);
98 /* in 5th row, 1 line, with dash/dot/dash stipple */
99 /* and a stipple repeat factor of 5 */
100 glLineStipple (5, 0x1C47); /* dash/dot/dash */
101 drawOneLine (50.0, 25.0, 350.0, 25.0);
103 glDisable (GL_LINE_STIPPLE);
104 glFlush ();
107 void reshape (int w, int h)
109 glViewport (0, 0, (GLsizei) w, (GLsizei) h);
110 glMatrixMode (GL_PROJECTION);
111 glLoadIdentity ();
112 gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
115 /* ARGSUSED1 */
116 void keyboard(unsigned char key, int x, int y)
118 switch (key) {
119 case 27:
120 exit(0);
121 break;
125 int main(int argc, char** argv)
127 glutInit(&argc, argv);
128 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
129 glutInitWindowSize (400, 150);
130 glutInitWindowPosition (100, 100);
131 glutCreateWindow (argv[0]);
132 init ();
133 glutDisplayFunc(display);
134 glutReshapeFunc(reshape);
135 glutKeyboardFunc(keyboard);
136 glutMainLoop();
137 return 0;