1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ///////////////////////////////////////////////////////////////////////////
36 #ifndef INCLUDED_IMATHGL_H
37 #define INCLUDED_IMATHGL_H
42 #include "ImathMatrix.h"
43 #include "IexMathExc.h"
46 inline void glVertex ( const Imath::V3f &v ) { glVertex3f(v.x,v.y,v.z); }
47 inline void glVertex ( const Imath::V2f &v ) { glVertex2f(v.x,v.y); }
48 inline void glNormal ( const Imath::V3f &n ) { glNormal3f(n.x,n.y,n.z); }
49 inline void glColor ( const Imath::V3f &c ) { glColor3f(c.x,c.y,c.z); }
50 inline void glTranslate ( const Imath::V3f &t ) { glTranslatef(t.x,t.y,t.z); }
52 inline void glTexCoord( const Imath::V2f &t )
54 glTexCoord2f(t.x,t.y);
57 inline void glDisableTexture()
59 glActiveTexture(GL_TEXTURE1);
60 glBindTexture(GL_TEXTURE_2D, 0);
61 glDisable(GL_TEXTURE_2D);
63 glActiveTexture(GL_TEXTURE0);
68 const float GL_FLOAT_MAX = 1.8e+19; // sqrt (FLT_MAX)
73 return !Imath::finitef (f) || f < - GL_FLOAT_MAX || f > GL_FLOAT_MAX;
79 throwBadMatrix (const Imath::M44f& m)
81 if (badFloat (m[0][0]) ||
97 throw Iex::OverflowExc ("GL matrix overflow");
101 glMultMatrix( const Imath::M44f& m )
104 glMultMatrixf( (GLfloat*)m[0] );
108 glMultMatrix( const Imath::M44f* m )
111 glMultMatrixf( (GLfloat*)(*m)[0] );
115 glLoadMatrix( const Imath::M44f& m )
118 glLoadMatrixf( (GLfloat*)m[0] );
122 glLoadMatrix( const Imath::M44f* m )
125 glLoadMatrixf( (GLfloat*)(*m)[0] );
132 // Class objects that push/pop the GL state. These objects assist with
133 // proper cleanup of the state when exceptions are thrown.
139 GLPushMatrix () { glPushMatrix(); }
140 ~GLPushMatrix() { glPopMatrix(); }
146 GLPushAttrib (GLbitfield mask) { glPushAttrib (mask); }
147 ~GLPushAttrib() { glPopAttrib(); }
153 GLBegin (GLenum mode) { glBegin (mode); }
154 ~GLBegin() { glEnd(); }