1 | #ifndef MXGL_INCLUDED // -*- C++ -*-
|
---|
2 | #define MXGL_INCLUDED
|
---|
3 | #if !defined(__GNUC__)
|
---|
4 | # pragma once
|
---|
5 | #endif
|
---|
6 |
|
---|
7 | /************************************************************************
|
---|
8 |
|
---|
9 | MxGL
|
---|
10 |
|
---|
11 | Copyright (C) 1998 Michael Garland. See "COPYING.txt" for details.
|
---|
12 |
|
---|
13 | $Id: MxGL.h,v 1.1 2002/09/24 16:53:54 wimmer Exp $
|
---|
14 |
|
---|
15 | ************************************************************************/
|
---|
16 |
|
---|
17 | #ifdef WIN32
|
---|
18 | #include <windows.h>
|
---|
19 | #else
|
---|
20 | #include <GL/glx.h>
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #include <GL/gl.h>
|
---|
24 | #include <GL/glu.h>
|
---|
25 |
|
---|
26 | /*************************************************************************
|
---|
27 | *
|
---|
28 | * Yes, here it is. A bunch of nice overloaded routines to make it
|
---|
29 | * easier on the fingers to write OpenGL drawing code.
|
---|
30 | *
|
---|
31 | * The general stuff provided here is:
|
---|
32 | *
|
---|
33 | * - glV
|
---|
34 | * - glN
|
---|
35 | * - glC
|
---|
36 | *
|
---|
37 | *************************************************************************/
|
---|
38 |
|
---|
39 | inline void glV(short x, short y) { glVertex2s(x,y); }
|
---|
40 | inline void glV(int x, int y) { glVertex2i(x,y); }
|
---|
41 | inline void glV(float x, float y) { glVertex2f(x,y); }
|
---|
42 | inline void glV(double x, double y) { glVertex2d(x,y); }
|
---|
43 |
|
---|
44 | inline void glV(short x, short y, short z) { glVertex3s(x,y,z); }
|
---|
45 | inline void glV(int x, int y, int z) { glVertex3i(x,y,z); }
|
---|
46 | inline void glV(float x, float y, float z) { glVertex3f(x,y,z); }
|
---|
47 | inline void glV(double x, double y, double z) { glVertex3d(x,y,z); }
|
---|
48 |
|
---|
49 | inline void glV(short x, short y, short z, short w ) { glVertex4s(x,y,z,w); }
|
---|
50 | inline void glV(int x, int y, int z, int w) { glVertex4i(x,y,z,w); }
|
---|
51 | inline void glV(float x, float y, float z, float w) { glVertex4f(x,y,z,w); }
|
---|
52 | inline void glV(double x,double y,double z,double w) { glVertex4d(x,y,z,w); }
|
---|
53 |
|
---|
54 | inline void glV2(const short *v) { glVertex2sv(v); }
|
---|
55 | inline void glV2(const int *v) { glVertex2iv(v); }
|
---|
56 | inline void glV2(const float *v) { glVertex2fv(v); }
|
---|
57 | inline void glV2(const double *v) { glVertex2dv(v); }
|
---|
58 |
|
---|
59 | inline void glV3(const short *v) { glVertex3sv(v); }
|
---|
60 | inline void glV3(const int *v) { glVertex3iv(v); }
|
---|
61 | inline void glV3(const float *v) { glVertex3fv(v); }
|
---|
62 | inline void glV3(const double *v) { glVertex3dv(v); }
|
---|
63 |
|
---|
64 | inline void glV4(const short *v) { glVertex4sv(v); }
|
---|
65 | inline void glV4(const int *v) { glVertex4iv(v); }
|
---|
66 | inline void glV4(const float *v) { glVertex4fv(v); }
|
---|
67 | inline void glV4(const double *v) { glVertex4dv(v); }
|
---|
68 |
|
---|
69 | ////////////////////////////////////
|
---|
70 |
|
---|
71 | inline void glN(short x, short y, short z) { glNormal3s(x,y,z); }
|
---|
72 | inline void glN(int x, int y, int z) { glNormal3i(x,y,z); }
|
---|
73 | inline void glN(float x, float y, float z) { glNormal3f(x,y,z); }
|
---|
74 | inline void glN(double x, double y, double z) { glNormal3d(x,y,z); }
|
---|
75 |
|
---|
76 | inline void glN(const short *v) { glNormal3sv(v); }
|
---|
77 | inline void glN(const int *v) { glNormal3iv(v); }
|
---|
78 | inline void glN(const float *v) { glNormal3fv(v); }
|
---|
79 | inline void glN(const double *v) { glNormal3dv(v); }
|
---|
80 |
|
---|
81 | ////////////////////////////////////
|
---|
82 |
|
---|
83 | inline void glC(short x, short y, short z) { glColor3s(x,y,z); }
|
---|
84 | inline void glC(int x, int y, int z) { glColor3i(x,y,z); }
|
---|
85 | inline void glC(float x, float y, float z) { glColor3f(x,y,z); }
|
---|
86 | inline void glC(double x, double y, double z) { glColor3d(x,y,z); }
|
---|
87 |
|
---|
88 | inline void glC(short x,short y,short z,short w) {glColor4s(x,y,z,w);}
|
---|
89 | inline void glC(int x, int y, int z, int w) {glColor4i(x,y,z,w);}
|
---|
90 | inline void glC(float x,float y,float z,float w) {glColor4f(x,y,z,w);}
|
---|
91 | inline void glC(double x,double y,double z,double w) {glColor4d(x,y,z,w);}
|
---|
92 |
|
---|
93 | ////////////////////////////////////
|
---|
94 |
|
---|
95 | inline void glLoadMatrix(const double *m) { glLoadMatrixd(m); }
|
---|
96 | inline void glLoadMatrix(const float *m) { glLoadMatrixf(m); }
|
---|
97 |
|
---|
98 | inline void glGetMatrix(double *m, GLenum src=GL_PROJECTION_MATRIX)
|
---|
99 | { glGetDoublev(src, m); }
|
---|
100 | inline void glGetMatrix(float *m, GLenum src=GL_PROJECTION_MATRIX)
|
---|
101 | { glGetFloatv(src, m); }
|
---|
102 |
|
---|
103 | /*************************************************************************
|
---|
104 | *
|
---|
105 | * Here's some more useful stuff.
|
---|
106 | *
|
---|
107 | *************************************************************************/
|
---|
108 |
|
---|
109 | inline void glOffsetForMesh(float factor=1.0, float bias=1e-6)
|
---|
110 | {
|
---|
111 | #if defined(MIX_HAVE_POLYOFFSET) || defined(WIN32)
|
---|
112 | glEnable(GL_POLYGON_OFFSET_FILL);
|
---|
113 | glPolygonOffset(factor, bias);
|
---|
114 | #elif defined(MIX_HAVE_POLYOFFSET_EXT)
|
---|
115 | glEnable(GL_POLYGON_OFFSET_EXT);
|
---|
116 | glPolygonOffsetEXT(factor, bias);
|
---|
117 | #endif
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | inline void glNoOffset()
|
---|
122 | {
|
---|
123 | #if defined(MIX_HAVE_POLYOFFSET) || defined(WIN32)
|
---|
124 | glDisable(GL_POLYGON_OFFSET_FILL);
|
---|
125 | #elif defined(MIX_HAVE_POLYOFFSET_EXT)
|
---|
126 | glDisable(GL_POLYGON_OFFSET_EXT);
|
---|
127 | #endif
|
---|
128 | }
|
---|
129 |
|
---|
130 | inline void glGetViewport(int *x, int *y, int *w, int *h)
|
---|
131 | {
|
---|
132 | GLint viewport[4];
|
---|
133 | glGetIntegerv(GL_VIEWPORT, viewport);
|
---|
134 |
|
---|
135 | if( x ) *x = viewport[0];
|
---|
136 | if( y ) *y = viewport[1];
|
---|
137 | if( w ) *w = viewport[2];
|
---|
138 | if( h ) *h = viewport[3];
|
---|
139 | }
|
---|
140 |
|
---|
141 | inline void glUnproject(int win_x, int win_y, int win_z,
|
---|
142 | double *x, double *y, double *z)
|
---|
143 | {
|
---|
144 | GLdouble modelMatrix[16];
|
---|
145 | GLdouble projMatrix[16];
|
---|
146 | GLint viewport[4];
|
---|
147 |
|
---|
148 | glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
|
---|
149 | glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
|
---|
150 | glGetIntegerv(GL_VIEWPORT, viewport);
|
---|
151 |
|
---|
152 | gluUnProject(win_x,win_y,win_z,
|
---|
153 | modelMatrix, projMatrix, viewport,
|
---|
154 | x, y, z);
|
---|
155 | }
|
---|
156 |
|
---|
157 | inline int glGetRenderMode()
|
---|
158 | {
|
---|
159 | int mode; glGetIntegerv(GL_RENDER_MODE, &mode); return mode;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*************************************************************************
|
---|
163 | *
|
---|
164 | * Debugging and diagnostic tools
|
---|
165 | *
|
---|
166 | *************************************************************************/
|
---|
167 |
|
---|
168 | extern void mxgl_report_stack_depth();
|
---|
169 | extern void mxgl_check_errors(const char *msg=NULL);
|
---|
170 |
|
---|
171 | // MXGL_INCLUDED
|
---|
172 | #endif
|
---|