Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gfxGL.cpp

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #include <freecloth/gfx/gfxGL.h>
00020 #include <freecloth/geom/gePoint.h>
00021 #include <freecloth/geom/geVector.h>
00022 #include <freecloth/geom/geMatrix4.h>
00023 #include <freecloth/colour/colColourRGB.h>
00024 
00025 ////////////////////////////////////////////////////////////////////////////////
00026 // LOCAL DECLARATIONS
00027 
00028 ////////////////////////////////////////////////////////////////////////////////
00029 // CLASS GfxGL
00030 
00031 //------------------------------------------------------------------------------
00032 
00033 void GL::colour( const ColColourRGB& c )
00034 {
00035     if ( sizeof(Float) == sizeof(GLfloat) ) {
00036         ::glColor3fv( reinterpret_cast<const GLfloat*>( &c._r ) );
00037     }
00038     else {
00039         ::glColor3dv( reinterpret_cast<const GLdouble*>( &c._r ) );
00040     }
00041 }
00042 
00043 //------------------------------------------------------------------------------
00044 
00045 void GL::colour( const ColColourRGB& c, Float alpha )
00046 {
00047     ::glColor4f( c._r, c._g, c._b, alpha );
00048 }
00049 
00050 //------------------------------------------------------------------------------
00051 
00052 void GL::fog( const ColColourRGB& c, Float alpha )
00053 {
00054     GLfloat f[ 4 ] = { c._r, c._g, c._b, alpha };
00055     ::glFogfv( GL_FOG_COLOR, f );
00056 }
00057 
00058 //------------------------------------------------------------------------------
00059 
00060 void GL::lightPosition( GLenum light, const GeVector& dir )
00061 {
00062     const GLfloat data[] = { dir._x, dir._y, dir._z, 0 };
00063     ::glLightfv( light, GL_POSITION, data );
00064 }
00065 
00066 //------------------------------------------------------------------------------
00067 
00068 void GL::light( GLenum light, GLenum pname, const ColColourRGB& c, Float alpha )
00069 {
00070     DGFX_ASSERT(
00071         pname == GL_AMBIENT || pname == GL_DIFFUSE || pname == GL_SPECULAR
00072     );
00073     const Float data[] = { c._r, c._g, c._b, alpha };
00074     ::glLightfv( light, pname, data );
00075 }
00076 
00077 //------------------------------------------------------------------------------
00078 
00079 void GL::material(
00080     GLenum face,
00081     GLenum pname,
00082     const ColColourRGB& c,
00083     Float alpha
00084 ) {
00085     DGFX_ASSERT(
00086         pname == GL_AMBIENT || pname == GL_DIFFUSE || pname == GL_SPECULAR ||
00087         pname == GL_EMISSION || pname == GL_SHININESS ||
00088         pname == GL_AMBIENT_AND_DIFFUSE
00089     );
00090     const Float data[] = { c._r, c._g, c._b, alpha };
00091     ::glMaterialfv( face, pname, data );
00092 }
00093 
00094 //------------------------------------------------------------------------------
00095 
00096 void GL::multMatrix( const GeMatrix4& m )
00097 {
00098     if ( sizeof(Float) == sizeof(GLfloat) ) {
00099         ::glMultMatrixf( reinterpret_cast<const GLfloat*>( m.asColMajor() ) );
00100     }
00101     else {
00102         ::glMultMatrixd( reinterpret_cast<const GLdouble*>( m.asColMajor() ) );
00103     }
00104 }
00105 
00106 //------------------------------------------------------------------------------
00107 
00108 void GL::normal( const GeVector& v )
00109 {
00110     if ( sizeof(Float) == sizeof(GLfloat) ) {
00111         ::glNormal3fv( reinterpret_cast<const GLfloat*>( &v._x ) );
00112     }
00113     else {
00114         ::glNormal3dv( reinterpret_cast<const GLdouble*>( &v._x ) );
00115     }
00116 }
00117 
00118 //------------------------------------------------------------------------------
00119 
00120 void GL::texCoord2( const GePoint& p )
00121 {
00122     ::glTexCoord2f( p._x, p._y );
00123 }
00124 
00125 //------------------------------------------------------------------------------
00126 
00127 void GL::translate( const GePoint& p )
00128 {
00129     ::glTranslatef( p._x, p._y, p._z );
00130 }
00131 
00132 //------------------------------------------------------------------------------
00133 
00134 void GL::translate( const GeVector& v )
00135 {
00136     ::glTranslatef( v._x, v._y, v._z );
00137 }
00138 
00139 //------------------------------------------------------------------------------
00140 
00141 void GL::vertex( const GePoint& p )
00142 {
00143     if ( sizeof(Float) == sizeof(GLfloat) ) {
00144         ::glVertex3fv( reinterpret_cast<const GLfloat*>( &p._x ) );
00145     }
00146     else {
00147         ::glVertex3dv( reinterpret_cast<const GLdouble*>( &p._x ) );
00148     }
00149 }
00150 

Generated on Fri May 2 16:51:12 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002