1 
2 /*
3  * main for exhibiting differnt join styles
4  *
5  * FUNCTION:
6  * This demo demonstrates the various join styles,
7  * and how they get applied.
8  *
9  * HISTORY:
10  * Linas Vepstas March 1995
11  * Copyright (c) 1995 Linas Vepstas <linas@linas.org>
12  */
13 
14 
15 /* required include files */
16 #include <stdlib.h>
17 
18 #include <GL/gl.h>
19 #include <GL/glut.h>
20 #include <GL/gle.h>
21 #include "main.h"
22 
23 float lastx=0;
24 float lasty=0;
25 
26 /* get notified of mouse motions */
27 static void
MouseMotion(int x,int y)28 MouseMotion (int x, int y)
29 {
30    lastx = x;
31    lasty = y;
32    glutPostRedisplay ();
33 }
34 
35 static void
JoinStyle(int msg)36 JoinStyle (int msg)
37 {
38    int style;
39    /* get the current joint style */
40    style = gleGetJoinStyle ();
41 
42    /* there are four different join styles,
43     * and two different normal vector styles */
44    switch (msg) {
45       case 0:
46          style &= ~TUBE_JN_MASK;
47          style |= TUBE_JN_RAW;
48          break;
49       case 1:
50          style &= ~TUBE_JN_MASK;
51          style |= TUBE_JN_ANGLE;
52          break;
53       case 2:
54          style &= ~TUBE_JN_MASK;
55          style |= TUBE_JN_CUT;
56          break;
57       case 3:
58          style &= ~TUBE_JN_MASK;
59          style |= TUBE_JN_ROUND;
60          break;
61 
62       case 20:
63          style &= ~TUBE_NORM_MASK;
64          style |= TUBE_NORM_FACET;
65          break;
66       case 21:
67          style &= ~TUBE_NORM_MASK;
68          style |= TUBE_NORM_EDGE;
69          break;
70 
71       case 99:
72          exit (0);
73 
74       default:
75          break;
76    }
77    gleSetJoinStyle (style);
78    glutPostRedisplay ();
79 }
80 
81 /* set up a light */
82 GLfloat lightOnePosition[] = {40.0, 40, 100.0, 0.0};
83 GLfloat lightOneColor[] = {0.99, 0.99, 0.99, 1.0};
84 
85 GLfloat lightTwoPosition[] = {-40.0, 40, 100.0, 0.0};
86 GLfloat lightTwoColor[] = {0.99, 0.99, 0.99, 1.0};
87 
88 int
main(int argc,char * argv[])89 main (int argc, char * argv[])
90 {
91    /* initialize glut */
92    glutInit (&argc, argv);
93    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
94    glutCreateWindow ("join styles");
95    glutDisplayFunc (DrawStuff);
96    glutMotionFunc (MouseMotion);
97 
98    /* create popup menu */
99    glutCreateMenu (JoinStyle);
100    glutAddMenuEntry ("Raw Join Style", 0);
101    glutAddMenuEntry ("Angle Join Style", 1);
102    glutAddMenuEntry ("Cut Join Style", 2);
103    glutAddMenuEntry ("Round Join Style", 3);
104    glutAddMenuEntry ("------------------", 9999);
105    glutAddMenuEntry ("Facet Normal Vectors", 20);
106    glutAddMenuEntry ("Edge Normal Vectors", 21);
107    glutAddMenuEntry ("------------------", 9999);
108    glutAddMenuEntry ("Exit", 99);
109    glutAttachMenu (GLUT_MIDDLE_BUTTON);
110 
111    /* initialize GL */
112    glClearDepth (1.0);
113    glEnable (GL_DEPTH_TEST);
114    glClearColor (0.0, 0.0, 0.0, 0.0);
115    glShadeModel (GL_SMOOTH);
116 
117    glMatrixMode (GL_PROJECTION);
118    /* roughly, measured in centimeters */
119    glFrustum (-9.0, 9.0, -9.0, 9.0, 50.0, 150.0);
120    glMatrixMode(GL_MODELVIEW);
121 
122    /* initialize lighting */
123    glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition);
124    glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor);
125    glEnable (GL_LIGHT0);
126    glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition);
127    glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor);
128    glEnable (GL_LIGHT1);
129    glEnable (GL_LIGHTING);
130    glEnable (GL_NORMALIZE);
131    glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
132    glEnable (GL_COLOR_MATERIAL);
133 
134    InitStuff ();
135 
136    glutMainLoop ();
137    return 0;             /* ANSI C requires main to return int. */
138 }
139 /* ------------------ end of file -------------------- */
140