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

gl.cpp

00001 //FILE:         gl.cpp
00002 //AUTHOR:       Nathan Cournia <nathan@cournia.com>
00003 
00004 #include "gl.h"
00005 
00007 void
00008 gl::init( unsigned int width, unsigned int height )
00009 {
00010         //clear color is blah
00011         glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
00012 
00013         //nive perspective correction
00014         glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
00015 
00016         //set viewport
00017         glViewport( 0, 0, width, height );
00018 
00019         //set frustrum
00020         glMatrixMode( GL_PROJECTION );
00021         glLoadIdentity( );
00022         gluPerspective( 45.0f, (float)width / (float)height , 0.1f, 100.0f );
00023 
00024         //switch to modelview matrix
00025         glMatrixMode( GL_MODELVIEW );
00026         glLoadIdentity( );
00027 }
00028 
00030 //0,0 at lower left
00031 //current matrix is set to modelview
00032 void
00033 gl::enable_2d( GLsizei w, GLsizei h )
00034 {
00035         //save enable bits
00036         glPushAttrib( GL_ENABLE_BIT );
00037 
00038         //set the viewport
00039         glViewport(0, 0, w, h);
00040 
00041         //save the projection matrix and reset it
00042         glMatrixMode( GL_PROJECTION );
00043         glPushMatrix( );
00044         glLoadIdentity( );
00045 
00046         //go into orthogonal mode (0,0 in lower left)
00047         glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0);
00048 
00049         //save modelview matrix and reset
00050         glMatrixMode(GL_MODELVIEW);
00051         glPushMatrix( );
00052         glLoadIdentity( );
00053 
00054         glDisable(GL_DEPTH_TEST);
00055         glDisable(GL_CULL_FACE);
00056 }
00057 
00059 void
00060 gl::disable_2d( void )
00061 {
00062         //get old modelview matrix
00063         glMatrixMode(GL_MODELVIEW);
00064         glPopMatrix( );
00065 
00066         //get old projection matrix
00067         glMatrixMode(GL_PROJECTION);
00068         glPopMatrix( );
00069 
00070         //get old enable bits
00071         glPopAttrib( );
00072 }
00073 
00075 void
00076 gl::render_image( const rectf& rect, const gl::texture& tex )
00077 {
00078         tex.bind( );
00079         glBegin( GL_TRIANGLE_STRIP );
00080                 //upper left
00081                 glTexCoord2d( 0.0, 1.0 );
00082                 glVertex2f( rect.x, rect.y + rect.h );
00083                                 
00084                 //lower left
00085                 glTexCoord2d( 0.0, 0.0 );
00086                 glVertex2f( rect.x, rect.y );
00087 
00088                 //upper right
00089                 glTexCoord2d( 1.0, 1.0 );
00090                 glVertex2f( rect.x + rect.w, rect.y + rect.h );
00091 
00092                 //lower right
00093                 glTexCoord2d( 1.0, 0.0 );
00094                 glVertex2f( rect.x + rect.w, rect.y );
00095         glEnd( );
00096 }

Generated on Tue Feb 11 18:49:41 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002