1 
2 /*
3  * port.h
4  *
5  * FUNCTION:
6  * This file contains defines for porting the tubing toolkit
7  * from GL to OpenGL; it also allows one to define an interface
8  * to get at the low-level GL output of this package via callbacks.
9  *
10  * HISTORY:
11  * Created by Linas Vepstas --  February 1993
12  * Added auto texture coord generation hooks, Linas April 1994
13  */
14 
15 #ifndef __GLE_PORT_H__
16 #define __GLE_PORT_H__
17 
18 #include <stdio.h>
19 
20 /* most of the build-specific info should be in configure.in */
21 #include "../config.h"
22 
23 #ifndef TRUE
24 #define TRUE 1
25 #endif
26 
27 #ifndef FALSE
28 #define FALSE 0
29 #endif
30 
31 #ifndef M_PI
32 #define M_PI 3.14159265358979323846
33 #endif
34 
35 /* ====================================================== */
36 /* needed for Windows NT */
37 
38 #ifdef WIN32
39 #include <windows.h>
40 #endif
41 
42 /* ====================================================== */
43 /* Some compilers can't handle multiply-subscripted array's */
44 
45 #if FUNKY_C
46 typedef gleDouble gleVector;
47 #define AVAL(arr,n,i,j)  arr(6*n+3*i+j)
48 #define VVAL(arr,n,i)  arr(3*n+i)
49 
50 #else  /* FUNKY_C */
51 typedef double gleVector[3];
52 #define AVAL(arr,n,i,j)  arr[n][i][j]
53 #define VVAL(arr,n,i)  arr[n][i];
54 
55 #endif /* FUNKY_C */
56 
57 /* ====================================================== */
58 /* These are used to convey info about topography to the
59  * texture mapping routines */
60 
61 #define FRONT 		1
62 #define BACK 		2
63 #define FRONT_CAP 	3
64 #define BACK_CAP	4
65 #define FILLET		5
66 
67 /* ====================================================== */
68 
69 #ifdef __GLE_DOUBLE
70 /* #define gleDouble 		double */
71 #define MULTMATRIX(m)		MULTMATRIX_D(m)
72 #define LOADMATRIX(m)		LOADMATRIX_D(m)
73 #define V3F(x,j,id)		V3F_D(x,j,id)
74 #define N3F(x)			N3F_D(x)
75 #define T2F(x,y)		T2F_D(x,y)
76 #else
77 #define gleDouble 		float
78 #define MULTMATRIX(m)		MULTMATRIX_F(m)
79 #define LOADMATRIX(m)		LOADMATRIX_F(m)
80 #define V3F(x,j,id)		V3F_F(x,j,id)
81 #define N3F(x)			N3F_F(x)
82 #define T2F(x,y)		T2F_F(x,y)
83 #endif
84 
85 /* ====================================================== */
86 
87 #if DEBUG_OUTPUT
88 #undef GL_32
89 #undef OPENGL_10
90 
91 #define BGNTMESH(i,len)	printf ("bgntmesh() \n");
92 #define ENDTMESH()      printf ("endtmesh() \n");
93 #define BGNPOLYGON()	printf ("bgnpolygon() \n");
94 #define ENDPOLYGON()	printf ("endpolygon() \n");
95 #define V3F_F(x,j,id)	printf ("v3f(x)		%f %f %f \n", x[0], x[1], x[2]);
96 #define V3F_D(x,j,id)	printf ("v3d(x) 	%f %f %f \n", x[0], x[1], x[2]);
97 #define	N3F_F(x)	printf ("n3f(x) 	%f %f %f \n", x[0], x[1], x[2]);
98 #define	N3F_D(x)	printf ("n3d(x)		%f %f %f \n", x[0], x[1], x[2]);
99 #define	C3F(x)		printf ("c3f(x) 	%f %f %f \n", x[0], x[1], x[2]);
100 #define	T2F_F(x)	printf ("t2f(x) 	%f %f \n", x[0], x[1]);
101 #define	T2F_D(x)	printf ("t2d(x)		%f %f \n", x[0], x[1]);
102 
103 #define	POPMATRIX()	printf ("popmatrix () \n");
104 #define	PUSHMATRIX()	printf ("pushmatrix() \n");
105 #define	MULTMATRIX_F(x)	MULTMATRIX_D(x)
106 #define	LOADMATRIX_F(x)	LOADMATRIX_D(x)
107 
108 
109 #define LOADMATRIX_D(x) {				\
110    int i, j; 						\
111    printf ("loadmatrix (x) \n");			\
112    for (i=0; i<4; i++) {				\
113       for (j=0; j<4; j++) {				\
114          printf ( "%f ", (x)[i][j]);			\
115       }							\
116       printf (" \n");					\
117    }							\
118 }
119 
120 #define MULTMATRIX_D(x) {				\
121    int i, j; 						\
122    printf ("multmatrix (x) \n");			\
123    for (i=0; i<4; i++) {				\
124       for (j=0; j<4; j++) {				\
125          printf ( "%f ", (x)[i][j]);			\
126       }							\
127       printf (" \n");					\
128    }							\
129 }
130 
131 #define __IS_LIGHTING_ON  (1)
132 
133 #endif /* DEBUG_OUTPUT */
134 
135 /* ====================================================== */
136 
137 #if GL_32
138 
139 #include <gl/gl.h>
140 
141 #define BGNTMESH(i,len)	bgntmesh()
142 #define ENDTMESH()	endtmesh()
143 #define BGNPOLYGON()	bgnpolygon()
144 #define ENDPOLYGON()	endpolygon()
145 #define V3F_F(x,j,id)	v3f(x)
146 #define V3F_D(x,j,id)	v3d(x)
147 #define	N3F_F(x)	n3f(x)
148 #define	T2F_F(x,y)
149 #define	T2F_D(x,y)
150 #define	C3F(x)		c3f(x)
151 
152 #define	POPMATRIX()	popmatrix ()
153 #define	PUSHMATRIX()	pushmatrix()
154 #define	MULTMATRIX_F(x)	multmatrix (x)
155 #define	LOADMATRIX_F(x)	loadmatrix (x)
156 
157 #define	N3F_D(x) {					\
158    float nnn[3];					\
159    nnn[0] = (float) (x)[0]; 				\
160    nnn[1] = (float) (x)[1]; 				\
161    nnn[2] = (float) (x)[2]; 				\
162    n3f (nnn);						\
163 }
164 
165 #define LOADMATRIX_D(x) {				\
166    int i, j; 						\
167    float mmm[4][4];					\
168    for (i=0; i<4; i++) {				\
169       for (j=0; j<4; j++) {				\
170          mmm[i][j] = (float) (x)[i][j];			\
171       }							\
172    }							\
173    loadmatrix(mmm);					\
174 }
175 
176 #define MULTMATRIX_D(x) {				\
177    int i, j; 						\
178    float mmm[4][4];					\
179    for (i=0; i<4; i++) {				\
180       for (j=0; j<4; j++) {				\
181          mmm[i][j] = (float) (x)[i][j];			\
182       }							\
183    }							\
184    multmatrix(mmm);					\
185 }
186 
187 /* #define __IS_LIGHTING_ON  (MSINGLE == getmmode()) */
188 #define __IS_LIGHTING_ON  (extrusion_join_style & TUBE_LIGHTING_ON)
189 
190 #endif /* GL_32 */
191 
192 /* ====================================================== */
193 #if OPENGL_10
194 
195 #ifdef WIN32
196 #include <windows.h>
197 #endif
198 
199 #include <GL/gl.h>
200 #include <GL/glu.h>
201 
202 #if FLIP_NORMAL
203 #define	N3F_F(x) {					\
204    float nnn[3];					\
205    nnn[0] = - (float) (x)[0]; 				\
206    nnn[1] = - (float) (x)[1]; 				\
207    nnn[2] = - (float) (x)[2]; 				\
208    glNormal3fv (nnn);					\
209 }
210 #define	N3F_D(x) {					\
211    float nnn[3];					\
212    nnn[0] = - (float) (x)[0]; 				\
213    nnn[1] = - (float) (x)[1]; 				\
214    nnn[2] = - (float) (x)[2]; 				\
215    glNormal3fv (nnn);					\
216 }
217 #endif /* FLIP_NORMAL */
218 
219 #define	C3F(x)		glColor3fv(x)
220 #define	T2F_F(x,y)	glTexCoord2f(x,y)
221 #define	T2F_D(x,y)	glTexCoord2d(x,y)
222 
223 #define	POPMATRIX()	glPopMatrix()
224 #define	PUSHMATRIX()	glPushMatrix()
225 
226 #define	MULTMATRIX_F(x)	glMultMatrixf ((const GLfloat *)x)
227 #define	LOADMATRIX_F(x)	glLoadMatrixf ((const GLfloat *)x)
228 
229 #define	MULTMATRIX_D(x)	glMultMatrixd ((const GLdouble *)x)
230 #define	LOADMATRIX_D(x)	glLoadMatrixd ((const GLdouble *)x)
231 
232 #define __IS_LIGHTING_ON  (glIsEnabled(GL_LIGHTING))
233 
234 /* ====================================================== */
235 #ifdef AUTO_TEXTURE
236 
237 #define BGNTMESH(i,len) { 					\
238 	if(_gle_gc -> bgn_gen_texture) (*(_gle_gc -> bgn_gen_texture))(i,len);\
239 	glBegin (GL_TRIANGLE_STRIP); 			\
240 }
241 
242 #define BGNPOLYGON() { 					\
243 	if(_gle_gc -> bgn_gen_texture) (*(_gle_gc -> bgn_gen_texture))();\
244 	glBegin (GL_POLYGON);				\
245 }
246 
247 #define N3F_F(x) { 					\
248 	if(_gle_gc -> n3f_gen_texture) (*(_gle_gc -> n3f_gen_texture))(x); \
249 	glNormal3fv(x); 				\
250 }
251 
252 #define N3F_D(x) { 					\
253 	if(_gle_gc -> n3d_gen_texture) (*(_gle_gc -> n3d_gen_texture))(x); \
254 	glNormal3dv(x); 				\
255 }
256 
257 #define V3F_F(x,j,id) { 					\
258 	if(_gle_gc -> v3f_gen_texture) (*(_gle_gc -> v3f_gen_texture))(x,j,id);\
259 	glVertex3fv(x); 				\
260 }
261 
262 #define V3F_D(x,j,id) { 					\
263 	if(_gle_gc -> v3d_gen_texture) (*(_gle_gc -> v3d_gen_texture))(x,j,id); \
264 	glVertex3dv(x); 				\
265 }
266 
267 #define ENDTMESH() {					\
268 	if(_gle_gc -> end_gen_texture) (*(_gle_gc -> end_gen_texture))(); \
269 	glEnd ();					\
270 }
271 
272 #define ENDPOLYGON() {					\
273 	if(_gle_gc -> end_gen_texture) (*(_gle_gc -> end_gen_texture))(); \
274 	glEnd ();					\
275 }
276 
277 /* ====================================================== */
278 #else /* AUTO_TEXTURE */
279 
280 #define BGNTMESH(i,len)	glBegin (GL_TRIANGLE_STRIP);
281 #define BGNPOLYGON() 	glBegin (GL_POLYGON);
282 
283 #define	N3F_F(x)	glNormal3fv(x)
284 #define	N3F_D(x)	glNormal3dv(x)
285 #define V3F_F(x,j,id)	glVertex3fv(x);
286 #define V3F_D(x,j,id)	glVertex3dv(x);
287 
288 #define ENDTMESH()	glEnd ()
289 #define ENDPOLYGON()	glEnd()
290 
291 #endif /* AUTO_TEXTURE */
292 
293 #endif /* OPENGL_10 */
294 
295 #endif /* __GLE_PORT_H__ */
296 /* ================== END OF FILE ======================= */
297