Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
gl.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 18898 $ *
38  * $Author: ebke $ *
39  * $Date: 2014-06-26 13:00:55 +0200 (Thu, 26 Jun 2014) $ *
40  * *
41 \*===========================================================================*/
42 
43 
44 //=============================================================================
45 // overload some GL functions
46 //=============================================================================
47 
48 
49 #ifndef ACG_GLTEXT_HH
50 #define ACG_GLTEXT_HH
51 
52 
53 //== INCLUDES =================================================================
54 
55 #include <cstdlib>
56 #include <sstream>
57 
58 
59 #if defined(ARCH_DARWIN)
60 
61  #include <glut.h>
62  #include <OpenGL/gl.h>
63  #include <OpenGL/glu.h>
64 
65 #elif defined(WIN32)
66 
67  #include <windows.h>
68  // Dont do this anymore! Use dll version. No problems with plugins and dll
69  // but a lot with static linking
70  // # define GLEW_STATIC 1
71  #include <gl/glew.h>
72  #include <gl/glut.h>
73 
74 #else
75 
76  #include <GL/glut.h>
77  #include <GL/gl.h>
78  #include <GL/glu.h>
79 
80 #endif
81 
82 #include "../Math/VectorT.hh"
83 
84 
85 //=============================================================================
86 namespace ACG {
87 //=============================================================================
88 
89 
90 //-------------------------------------------------------------------- glVertex
91 
93 inline void glVertex(const Vec2i& _v) { glVertex2i(_v[0], _v[1]); }
95 inline void glVertex(const Vec2f& _v) { glVertex2fv(_v.data()); }
97 inline void glVertex(const Vec2d& _v) { glVertex2dv(_v.data()); }
98 
100 inline void glVertex(const Vec3f& _v) { glVertex3fv(_v.data()); }
102 inline void glVertex(const Vec3d& _v) { glVertex3dv(_v.data()); }
103 
105 inline void glVertex(const Vec4f& _v) { glVertex4fv(_v.data()); }
107 inline void glVertex(const Vec4d& _v) { glVertex4dv(_v.data()); }
108 
109 
110 
111 //------------------------------------------------------------------- glTexCoord
112 
114 inline void glTexCoord(const Vec2f& _t) { glTexCoord2fv(_t.data()); }
116 inline void glTexCoord(const Vec2d& _t) { glTexCoord2dv(_t.data()); }
117 
119 inline void glTexCoord(const Vec3f& _t) { glTexCoord3fv(_t.data()); }
121 inline void glTexCoord(const Vec3d& _t) { glTexCoord3dv(_t.data()); }
122 
124 inline void glTexCoord(const Vec4f& _t) { glTexCoord4fv(_t.data()); }
126 inline void glTexCoord(const Vec4d& _t) { glTexCoord4dv(_t.data()); }
127 
128 
129 
130 //--------------------------------------------------------------------- glNormal
131 
133 inline void glNormal(const Vec3f& _n) { glNormal3fv(_n.data()); }
135 inline void glNormal(const Vec3d& _n) { glNormal3dv(_n.data()); }
136 
137 
138 
139 //---------------------------------------------------------------------- glColor
140 
142 inline void glColor(const Vec3f& _v) { glColor3fv(_v.data()); }
144 inline void glColor(const Vec3uc& _v) { glColor3ubv(_v.data()); }
145 
147 inline void glColor(const Vec4f& _v) { glColor4fv(_v.data()); }
149 inline void glColor(const Vec4uc& _v) { glColor4ubv(_v.data()); }
150 
151 
152 
153 //-------------------------------------------------------------- ACG::GLState::vertexPointer
154 /*
156 inline void glVertexPointer(const Vec2f* _p)
157 { ::ACG::GLState::vertexPointer(2, GL_FLOAT, 0, _p); }
159 inline void ACG::GLState::vertexPointer(const Vec2d* _p)
160 { ::ACG::GLState::vertexPointer(2, GL_DOUBLE, 0, _p); }
161 
163 inline void ACG::GLState::vertexPointer(const Vec3f* _p)
164 { ::ACG::GLState::vertexPointer(3, GL_FLOAT, 0, _p); }
166 inline void ACG::GLState::vertexPointer(const Vec3d* _p)
167 { ::ACG::GLState::vertexPointer(3, GL_DOUBLE, 0, _p); }
168 
170 inline void ACG::GLState::vertexPointer(const Vec4f* _p)
171 { ::ACG::GLState::vertexPointer(4, GL_FLOAT, 0, _p); }
173 inline void ACG::GLState::vertexPointer(const Vec4d* _p)
174 { ::ACG::GLState::vertexPointer(4, GL_DOUBLE, 0, _p); }
175 
177 inline void ACG::GLState::vertexPointer(GLint n, GLenum t, GLsizei s, const GLvoid *p)
178 { ::ACG::GLState::vertexPointer(n, t, s, p); }
179 
180 
181 
182 //-------------------------------------------------------------- ACG::GLState::normalPointer
183 
185 inline void ACG::GLState::normalPointer(const Vec3f* _p)
186 { ::ACG::GLState::normalPointer(GL_FLOAT, 0, _p); }
188 inline void ACG::GLState::normalPointer(const Vec3d* _p)
189 { ::ACG::GLState::normalPointer(GL_DOUBLE, 0, _p); }
190 
192 inline void ACG::GLState::normalPointer(GLenum t, GLsizei s, const GLvoid *p)
193 { ::ACG::GLState::normalPointer(t, s, p); }
194 
195 
196 
197 //--------------------------------------------------------------- ACG::GLState::colorPointer
198 
200 inline void ACG::GLState::colorPointer(const Vec3uc* _p)
201 { ::ACG::GLState::colorPointer(3, GL_UNSIGNED_BYTE, 0, _p); }
203 inline void ACG::GLState::colorPointer(const Vec3f* _p)
204 { ::ACG::GLState::colorPointer(3, GL_FLOAT, 0, _p); }
205 
207 inline void ACG::GLState::colorPointer(const Vec4uc* _p)
208 { ::ACG::GLState::colorPointer(4, GL_UNSIGNED_BYTE, 0, _p); }
210 inline void ACG::GLState::colorPointer(const Vec4f* _p)
211 { ::ACG::GLState::colorPointer(4, GL_FLOAT, 0, _p); }
212 
214 inline void ACG::GLState::colorPointer(GLint n, GLenum t, GLsizei s, const GLvoid *p)
215 { ::ACG::GLState::colorPointer(n, t, s, p); }
216 
217 
218 
219 //------------------------------------------------------------ ACG::GLState::texcoordPointer
220 
222 inline void ACG::GLState::texcoordPointer(const float* _p)
223 { ::ACG::GLState::texcoordPointer(1, GL_FLOAT, 0, _p); }
225 inline void ACG::GLState::texcoordPointer(const double* _p)
226 { ::ACG::GLState::texcoordPointer(1, GL_DOUBLE, 0, _p); }
227 
229 inline void ACG::GLState::texcoordPointer(const Vec2f* _p)
230 { ::ACG::GLState::texcoordPointer(2, GL_FLOAT, 0, _p); }
232 inline void ACG::GLState::texcoordPointer(const Vec2d* _p)
233 { ::ACG::GLState::texcoordPointer(2, GL_DOUBLE, 0, _p); }
234 
236 inline void ACG::GLState::texcoordPointer(const Vec3f* _p)
237 { ::ACG::GLState::texcoordPointer(3, GL_FLOAT, 0, _p); }
239 inline void ACG::GLState::texcoordPointer(const Vec3d* _p)
240 { ::ACG::GLState::texcoordPointer(3, GL_DOUBLE, 0, _p); }
241 
243 inline void ACG::GLState::texcoordPointer(const Vec4f* _p)
244 { ::ACG::GLState::texcoordPointer(4, GL_FLOAT, 0, _p); }
246 inline void ACG::GLState::texcoordPointer(const Vec4d* _p)
247 { ::ACG::GLState::texcoordPointer(4, GL_DOUBLE, 0, _p); }
248 
250 inline void ACG::GLState::texcoordPointer(GLint n, GLenum t, GLsizei s, const GLvoid *p)
251 { ::ACG::GLState::texcoordPointer(n, t, s, p); }
252 */
253 
254 
255 //-----------------------------------------------------------------------------
256 
259 inline bool checkExtensionSupported( std::string _extension ) {
260  std::string supported((const char*)glGetString(GL_EXTENSIONS));
261 
262  return (supported.find(_extension) != std::string::npos);
263 }
264 
267 inline bool openGLVersion( const int _major, const int _minor ) {
268 
269  // Read OpenGL Version string
270  std::string glVersionString = (const char*)glGetString(GL_VERSION);
271 
272  // Use string stream to parse
273  std::istringstream stream;
274  stream.str(glVersionString);
275 
276  // Buffer for the dot between major and minor
277  char dot;
278 
279  // Read Major version number
280  int major ;
281  stream >> major;
282  stream >> dot;
283 
284  // Read minor version number
285  int minor;
286  stream >> minor;
287 
288  if ( (_major > major) || ( (_major == major) && (_minor > minor)) ) {
289  std::cerr << "OpenGL Version check failed. Required : " << _major << "." << _minor << std::endl;
290  std::cerr << "OpenGL Version check failed. Available : " << major << "." << minor << std::endl;
291  return false;
292  }
293 
294  return true;
295 }
296 
297 
298 //=============================================================================
299 } // namespace ACG
300 //=============================================================================
301 #endif // ACG_GLTEXT_HH defined
302 //=============================================================================
bool openGLVersion(const int _major, const int _minor)
Definition: gl.hh:267
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
Definition: gl.hh:142
VectorT< float, 2 > Vec2f
Definition: VectorT.hh:101
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:118
VectorT< double, 2 > Vec2d
Definition: VectorT.hh:103
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
Definition: gl.hh:133
VectorT< signed int, 2 > Vec2i
Definition: VectorT.hh:97
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
Definition: gl.hh:93
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:120
VectorT< unsigned char, 4 > Vec4uc
Definition: VectorT.hh:127
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:10
VectorT< double, 4 > Vec4d
Definition: VectorT.hh:139
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:137
void glTexCoord(const Vec2f &_t)
Wrapper: glTexCoord for Vec2f.
Definition: gl.hh:114
bool checkExtensionSupported(std::string _extension)
Definition: gl.hh:259
VectorT< unsigned char, 3 > Vec3uc
Definition: VectorT.hh:108