source: GTP/trunk/Lib/Vis/Preprocessing/src/mixkit/MxGL.h @ 1097

Revision 1097, 5.7 KB checked in by mattausch, 18 years ago (diff)
Line 
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
39inline void glV(short x, short y)   { glVertex2s(x,y); }
40inline void glV(int x, int y)       { glVertex2i(x,y); }
41inline void glV(float x, float y)   { glVertex2f(x,y); }
42inline void glV(double x, double y) { glVertex2d(x,y); }
43
44inline void glV(short x, short y, short z)    { glVertex3s(x,y,z); }
45inline void glV(int x, int y, int z)          { glVertex3i(x,y,z); }
46inline void glV(float x, float y, float z)    { glVertex3f(x,y,z); }
47inline void glV(double x, double y, double z) { glVertex3d(x,y,z); }
48
49inline void glV(short x, short y, short z, short w ) { glVertex4s(x,y,z,w); }
50inline void glV(int x, int y, int z, int w)          { glVertex4i(x,y,z,w); }
51inline void glV(float x, float y, float z, float w)  { glVertex4f(x,y,z,w); }
52inline void glV(double x,double y,double z,double w) { glVertex4d(x,y,z,w); }
53
54inline void glV2(const short *v)  { glVertex2sv(v); }
55inline void glV2(const int *v)    { glVertex2iv(v); }
56inline void glV2(const float *v)  { glVertex2fv(v); }
57inline void glV2(const double *v) { glVertex2dv(v); }
58
59inline void glV3(const short *v)  { glVertex3sv(v); }
60inline void glV3(const int *v)    { glVertex3iv(v); }
61inline void glV3(const float *v)  { glVertex3fv(v); }
62inline void glV3(const double *v) { glVertex3dv(v); }
63
64inline void glV4(const short *v)  { glVertex4sv(v); }
65inline void glV4(const int *v)    { glVertex4iv(v); }
66inline void glV4(const float *v)  { glVertex4fv(v); }
67inline void glV4(const double *v) { glVertex4dv(v); }
68
69////////////////////////////////////
70
71inline void glN(short x, short y, short z)    { glNormal3s(x,y,z); }
72inline void glN(int x, int y, int z)          { glNormal3i(x,y,z); }
73inline void glN(float x, float y, float z)    { glNormal3f(x,y,z); }
74inline void glN(double x, double y, double z) { glNormal3d(x,y,z); }
75
76inline void glN(const short *v)  { glNormal3sv(v); }
77inline void glN(const int *v)    { glNormal3iv(v); }
78inline void glN(const float *v)  { glNormal3fv(v); }
79inline void glN(const double *v) { glNormal3dv(v); }
80
81////////////////////////////////////
82
83inline void glC(short x, short y, short z)    { glColor3s(x,y,z); }
84inline void glC(int x, int y, int z)          { glColor3i(x,y,z); }
85inline void glC(float x, float y, float z)    { glColor3f(x,y,z); }
86inline void glC(double x, double y, double z) { glColor3d(x,y,z); }
87
88inline void glC(short x,short y,short z,short w)     {glColor4s(x,y,z,w);}
89inline void glC(int x, int y, int z, int w)          {glColor4i(x,y,z,w);}
90inline void glC(float x,float y,float z,float w)     {glColor4f(x,y,z,w);}
91inline void glC(double x,double y,double z,double w) {glColor4d(x,y,z,w);}
92
93////////////////////////////////////
94
95inline void glLoadMatrix(const double *m) { glLoadMatrixd(m); }
96inline void glLoadMatrix(const float *m)  { glLoadMatrixf(m); }
97
98inline void glGetMatrix(double *m, GLenum src=GL_PROJECTION_MATRIX)
99{ glGetDoublev(src, m); }
100inline 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
109inline 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
121inline 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
130inline 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
141inline 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
157inline 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
168extern void mxgl_report_stack_depth();
169extern void mxgl_check_errors(const char *msg=NULL);
170
171// MXGL_INCLUDED
172#endif
Note: See TracBrowser for help on using the repository browser.