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.
11 *
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.
24 *
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.
34 *
35 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36 */
37
38 /*
39 * lines.c
40 * This program demonstrates geometric primitives and
41 * their attributes.
42 */
43 #include "glut_wrap.h"
44 #include <stdlib.h>
45
46 #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
47 glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
48
init(void)49 static void init(void)
50 {
51 glClearColor (0.0, 0.0, 0.0, 0.0);
52 glShadeModel (GL_FLAT);
53 }
54
display(void)55 static void display(void)
56 {
57 int i;
58
59 glClear (GL_COLOR_BUFFER_BIT);
60
61 /* select white for all lines */
62 glColor3f (1.0, 1.0, 1.0);
63
64 /* in 1st row, 3 lines, each with a different stipple */
65 glEnable (GL_LINE_STIPPLE);
66
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);
73
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);
83
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 ();
91
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);
96 }
97
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);
102
103 glDisable (GL_LINE_STIPPLE);
104 glFlush ();
105 }
106
reshape(int w,int h)107 static void reshape (int w, int h)
108 {
109 glViewport (0, 0, (GLsizei) w, (GLsizei) h);
110 glMatrixMode (GL_PROJECTION);
111 glLoadIdentity ();
112 gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
113 }
114
115 /* ARGSUSED1 */
keyboard(unsigned char key,int x,int y)116 static void keyboard(unsigned char key, int x, int y)
117 {
118 switch (key) {
119 case 27:
120 exit(0);
121 break;
122 }
123 }
124
main(int argc,char ** argv)125 int main(int argc, char** argv)
126 {
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;
138 }
139