Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ViewGL.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: ViewGL.cpp,v 1.5 2002/02/16 12:41:39 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/TeddyConfig.h"
00026 #include "Teddy/Graphics/Color.h"
00027 #include "Teddy/Graphics/Device.h"
00028 #include "Teddy/Graphics/Texture.h"
00029 #include "Teddy/Graphics/View.h"
00030 #include "Teddy/SysSupport/Messages.h"
00031 using namespace Teddy::Maths;
00032 using namespace Teddy::SysSupport;
00033 
00034 
00035 namespace Teddy    {
00036 namespace Graphics {
00037 
00038 
00039 void View::beginPoints(){
00040     if( current_element != -1 ){
00041         msg( M_GL, "current element" );
00042     }
00043     glBegin( GL_POINTS );
00044     current_element = GL_POINTS;
00045 }
00046 
00047 
00048 void View::beginLines(){
00049     if( current_element != -1 ){
00050         msg( M_GL, "current element" );
00051     }
00052     glBegin( GL_LINES );
00053     current_element = GL_LINES;
00054 }
00055 
00056 
00057 void View::beginLineStrip(){
00058     if( current_element != -1 ){
00059         msg( M_GL, "current element" );
00060     }
00061     glBegin( GL_LINE_STRIP );
00062     current_element = GL_LINE_STRIP;
00063 }
00064 
00065 
00066 void View::beginLineLoop(){
00067     if( current_element != -1 ){
00068         msg( M_GL, "current element" );
00069     }
00070     glBegin( GL_LINE_LOOP );
00071     current_element = GL_LINE_LOOP;
00072 }
00073 
00074 void View::beginTriangles(){
00075     if( current_element != -1 ){
00076         msg( M_GL, "current element" );
00077     }
00078     glBegin( GL_TRIANGLES );
00079     current_element = GL_TRIANGLES;
00080 }
00081 
00082 
00083 void View::beginTriangleStrip(){
00084     if( current_element != -1 ){
00085         msg( M_GL, "current element" );
00086     }
00087     glBegin( GL_TRIANGLE_STRIP );
00088     current_element = GL_TRIANGLE_STRIP;
00089 }
00090 
00091 
00092 void View::beginTriangleFan(){
00093     if( current_element != -1 ){
00094         msg( M_GL, "current element" );
00095     }
00096     glBegin( GL_TRIANGLE_FAN );
00097     current_element = GL_TRIANGLE_FAN;
00098 }
00099 
00100 
00101 void View::beginQuads(){
00102     if( current_element != -1 ){
00103         msg( M_GL, "current element" );
00104     }
00105     glBegin( GL_QUADS );
00106     current_element = GL_QUADS;
00107 }
00108 
00109 
00110 void View::beginQuadStrip(){
00111     if( current_element != -1 ){
00112         msg( M_GL, "current element" );
00113     }
00114     glBegin( GL_QUAD_STRIP );
00115     current_element = GL_QUAD_STRIP;
00116 }
00117 
00118 
00119 void View::beginPolygon(){
00120     if( current_element != -1 ){
00121         msg( M_GL, "current element" );
00122     }
00123     glBegin( GL_POLYGON );
00124     current_element = GL_POLYGON;
00125 }
00126 
00127 
00128 void View::end(){
00129     if( current_element == -1 ){
00130         msg( M_GL, "current element" );
00131     }
00132     glEnd();
00133     current_element = -1;
00134 }
00135 
00136 
00137 void View::setProjectionMatrix(){
00138     if( current_matrix_mode != GL_PROJECTION ){
00139         glMatrixMode( GL_PROJECTION );
00140         current_matrix_mode = GL_PROJECTION;
00141     }
00142     glLoadIdentity();
00143     //glLoadMatrixf( m );
00144     //glScalef(1.0f, 1.0f, -1.0f);
00145 }
00146 
00147 
00148 void View::setProjectionMatrix( const Matrix &m ){
00149     if( current_matrix_mode != GL_PROJECTION ){
00150         glMatrixMode( GL_PROJECTION );
00151         current_matrix_mode = GL_PROJECTION;
00152     }
00153     glLoadMatrixf( m );
00154     //glScalef(1.0f, 1.0f, -1.0f);
00155 }
00156 
00157 
00158 void View::setModelViewMatrix(){
00159     if( current_matrix_mode != GL_MODELVIEW ){
00160         glMatrixMode( GL_MODELVIEW );
00161         current_matrix_mode = GL_MODELVIEW;
00162     }
00163     glLoadIdentity();
00164     //glLoadMatrixf( m );
00165 }
00166 
00167 
00168 void View::setModelViewMatrix( const Matrix &m ){
00169     if( current_matrix_mode != GL_MODELVIEW ){
00170         glMatrixMode( GL_MODELVIEW );
00171         current_matrix_mode = GL_MODELVIEW;
00172     }
00173     glLoadMatrixf( m );
00174 }
00175 
00176 
00177 void View::setTextureMatrix( const Matrix &m ){
00178     if( current_matrix_mode != GL_TEXTURE ){
00179         glMatrixMode( GL_TEXTURE );
00180         current_matrix_mode = GL_TEXTURE;
00181     }
00182     glLoadMatrixf( m );
00183 }
00184 
00185 
00186 void View::color( float r, float g, float b, float a ) const {
00187     glColor4f( r, g, b, a );
00188 }
00189 
00190 
00191 void View::color( const Color &c ) const {
00192     glColor4fv( c.rgba );
00193 }
00194 
00195 
00196 void View::vertex( const float x, const float y ) const {
00197     glVertex2f( x, y );
00198 }
00199 
00200 
00201 void View::vertex( const TVector<int> &v ) const {
00202 #   if defined( USE_TINY_GL )
00203     glVertex3f( float(v[0]), float(v[1]), float(v[2]) );
00204 #   else
00205     glVertex3iv( v );
00206 #   endif
00207 }
00208 
00209 
00210 void View::vertex( const TVector<float> &v ) const {
00211 #   if defined( USE_TINY_GL )
00212     glVertex3f( float(v[0]), float(v[1]), float(v[2]) );
00213 #   else
00214     glVertex3fv( v );
00215 #   endif
00216 }
00217 
00218 
00219 void View::vertex( const TVector<double> &v ) const {
00220 #   if defined( USE_TINY_GL )
00221     glVertex3f( float(v[0]), float(v[1]), float(v[2]) );
00222 #   else
00223     glVertex3dv( v );
00224 #   endif
00225 }
00226 
00227 
00228 void View::vertex( const TVector2<int> &v ) const {
00229 #   if defined( USE_TINY_GL )
00230     glVertex2f( float(v[0]), float(v[1]) );
00231 #   else
00232     glVertex2i( v[0], v[1] );
00233     //glVertex2iv( v );
00234 #   endif
00235 }
00236 
00237 
00238 void View::vertex( const TVector2<float> &v ) const {
00239     glVertex2f( v[0], v[1] );
00240     //glVertex2fv( v );
00241 }
00242 
00243 
00244 void View::vertex( const TVector2<double> &v ) const {
00245 #   if defined( USE_TINY_GL )
00246     glVertex2f( float(v[0]), float(v[1]) );
00247 #   else
00248     glVertex2d( v[0], v[1] );
00249     //glVertex2dv( v );
00250 #   endif
00251 }
00252 
00253 
00254 void View::normal( const TVector<int> &n ) const {
00255 #   if defined( USE_TINY_GL )
00256     glNormal3f( float(n[0]), float(n[1]), float(n[2]) );
00257 #   else
00258     glNormal3iv( n );
00259 #   endif
00260 }
00261 
00262 
00263 void View::normal( const TVector<float> &n ) const {
00264 #   if defined( USE_TINY_GL )
00265     glNormal3f( float(n[0]), float(n[1]), float(n[2]) );
00266 #   else
00267     glNormal3fv( n );
00268 #   endif
00269 }
00270 
00271 
00272 void View::normal( const TVector<double> &n ) const {
00273 #   if defined( USE_TINY_GL )
00274     glNormal3f( float(n[0]), float(n[1]), float(n[2]) );
00275 #   else
00276     glNormal3dv( n );
00277 #   endif
00278 }
00279 
00280 
00281 void View::normal( const TVector2<int> &n ) const {
00282 #   if defined( USE_TINY_GL )
00283     glNormal3f( float(n[0]), float(n[1]), float(n[2]) );
00284 #   else
00285     //  glNormal2iv( n );
00286     glNormal3i( n[0], n[1], 1 );
00287 #   endif
00288 }
00289 
00290 
00291 void View::normal( const TVector2<float> &n ) const {
00292     //glNormal2fv( n );
00293     glNormal3f( n[0], n[1], 1 );
00294 }
00295 
00296 
00297 void View::normal( const TVector2<double> &n ) const {
00298 #   if defined( USE_TINY_GL )
00299     glNormal3f( float(n[0]), float(n[1]), 1.0f );
00300 #   else
00301     glNormal3d( n[0], n[1], 1 );
00302 #   endif
00303     //glNormal2dv( n );
00304 }
00305 
00306 
00307 void View::texture( const TVector<int> &t ) const {
00308 #   if defined( USE_TINY_GL )
00309     glTexCoord2f( float(t[0]), float(t[1]) );
00310 #   else
00311     glTexCoord3i( t[0], t[1], t[2] );
00312     //glTexCoord3iv( t );
00313 #   endif
00314 }
00315 
00316 
00317 void View::texture( const TVector<float> &t ) const {
00318 #   if defined( USE_TINY_GL )
00319     glTexCoord2f( float(t[0]), float(t[1]) );
00320 #   else
00321     glTexCoord3f( t[0], t[1], t[2] );
00322     //glTexCoord3fv( t );
00323 #   endif
00324 }
00325 
00326 
00327 void View::texture( const TVector<double> &t ) const {
00328 #   if defined( USE_TINY_GL )
00329     glTexCoord2f( float(t[0]), float(t[1]) );
00330 #   else
00331     glTexCoord3d( t[0], t[1], t[2] );
00332     //glTexCoord3dv( t );
00333 #   endif
00334 }
00335 
00336 
00337 void View::texture( const TVector2<int> &t ) const {
00338 #   if defined( USE_TINY_GL )
00339     glTexCoord2f( float(t[0]), float(t[1]) );
00340 #   else
00341     glTexCoord2i( t[0], t[1] );
00342     //glTexCoord2iv( t );
00343 #   endif
00344 }
00345 
00346 
00347 void View::texture( const TVector2<float> &t ) const {
00348 #   if defined( USE_TINY_GL )
00349     glTexCoord2f( float(t[0]), float(t[1]) );
00350 #   else
00351     glTexCoord2f( t[0], t[1] );
00352     //glTexCoord3f( t[0], t[1], 0.0f );
00353     //glTexCoord2fv( t );
00354 #endif
00355 }
00356 
00357 
00358 void View::texture( const TVector2<double> &t ) const {
00359 #   if defined( USE_TINY_GL )
00360     glTexCoord2f( float(t[0]), float(t[1]) );
00361 #   else
00362     glTexCoord2d( t[0], t[1] );
00363     //glTexCoord2dv( t );
00364 #   endif
00365 }
00366 
00367 
00368 
00369 char *View::getExtensions(){
00370 #   if defined( USE_OPEN_GL )
00371 //#error poo
00372         return (char *)glGetString( GL_EXTENSIONS );
00373 #   else
00374         return "";
00375 #   endif
00376 }
00377 
00378 
00379 char *View::getVendor(){
00380 #   if defined( USE_OPEN_GL )
00381         return (char *)glGetString( GL_VENDOR );
00382 #   else
00383         return "Inbuilt Software";
00384 #   endif
00385 }
00386 
00387 
00388 char *View::getRenderer(){
00389 #   if defined( USE_OPEN_GL )
00390     return (char *)glGetString( GL_RENDERER );
00391 #   endif
00392 #   if defined( USE_TINY_GL )
00393     return "TinyGL";
00394 #   endif
00395     return "";
00396 }
00397 
00398 
00399 char *View::getVersion(){
00400 #   if defined( USE_OPEN_GL )
00401     return (char *)glGetString( GL_VERSION );
00402 #   endif
00403 #   if defined( USE_TINY_GL )
00404     return "1.0";
00405 #   endif
00406     return "";
00407 }
00408 
00409 
00410 int View::getMaxTextureSize(){
00411     GLint max_texture_size = 0;
00412     glGetIntegerv( GL_MAX_TEXTURE_SIZE, &max_texture_size );
00413     return max_texture_size;
00414 }
00415 
00416 
00417 int View::getMaxLights(){
00418     GLint max_lights = 0;
00419     glGetIntegerv( GL_MAX_LIGHTS, &max_lights );
00420     return max_lights;
00421 }
00422 
00423 
00424 /*
00425 void View::getMaxViewportDims( int &width, int &height ){
00426     GLint dims[2] = { 0, 0 };
00427     glGetIntegerv( GL_MAX_VIEWPORT_DIMS, dims );
00428     width  = dims[0];
00429     height = dims[1];
00430 }*/
00431 
00432 
00433 void View::setTexture( Texture *t ){
00434     if( current_texture != t ){
00435         current_texture = t;
00436         t->apply();
00437     }
00438 }
00439 
00440 
00441 };  //  namespace Graphics
00442 };  //  namespace Teddy
00443