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

CToxiGLRenderer.cpp

Go to the documentation of this file.
00001 
00009 /* 
00010         ---- Copyright (C) 2002  Jose Eduardo R. Mourão (eduardo_rdm@hotmail.com) ----
00011           
00012         This file is part of ToxiTea.
00013 
00014     ToxiTea is free software; you can redistribute it and/or modify
00015     it under the terms of the GNU General Public License as published by
00016     the Free Software Foundation; either version 2 of the License, or
00017     (at your option) any later version.
00018 
00019     ToxiTea is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022     GNU General Public License for more details.
00023 
00024     You should have received a copy of the GNU General Public License
00025     along with ToxiTea; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 
00028         For more information and updates visit: 
00029         http://toxitea.sourceforge.net
00030         or mail to: eduardo_rdm@hotmail.com
00031 
00032         COMPILING AND/OR USING YOU ARE ACCEPTING ALL TERMS ABOVE.
00033         THIS LICENSE CAN BE CHANGED ANY TIME FOR ANY REASON WITHOUT NO COMMUNICATION.
00034 */
00035 
00040 #include "CToxiGLRenderer.h"
00041 
00042 #ifdef TOXITEA_GL
00043 
00044 CToxiGLRenderer::CToxiGLRenderer()
00045 {
00046 }
00047 
00048 CToxiGLRenderer::~CToxiGLRenderer()
00049 {
00050 }
00051 
00053 void CToxiGLRenderer::sampleDrawScene()
00054 {
00055         glPushMatrix();
00056                 glBegin(GL_TRIANGLES);
00057                         glColor3f(1.0f,0.0f,0.0f);
00058                         glVertex3f( 0.0f, 1.0f, 0.0f);
00059                         glColor3f(0.0f,1.0f,0.0f);
00060                         glVertex3f(-1.0f,-1.0f, 0.0f);
00061                         glColor3f(0.0f,0.0f,1.0f);
00062                         glVertex3f( 1.0f,-1.0f, 0.0f);
00063                 glEnd();
00064         glPopMatrix();
00065 }
00066 
00068 void CToxiGLRenderer::sampleInitScene()
00069 {
00070 
00071 }
00072 
00074 void CToxiGLRenderer::sampleResizeContext()
00075 {       
00076         if(windowHeight==0) windowHeight=1;                                                                             
00077         glViewport(0,0,windowWidth,windowHeight);                                               
00078         glMatrixMode(GL_PROJECTION);                                    
00079         glLoadIdentity();                                                               
00080         gluPerspective(viewportAngle,(GLfloat)windowWidth/(GLfloat)windowHeight,viewportClose,viewportFar);
00081         glMatrixMode(GL_MODELVIEW);                                                     
00082         glLoadIdentity();
00083 }
00084 
00086 void CToxiGLRenderer::setupRenderer(int _width,int _height,int _bits)
00087 {
00088         this->windowWidth       = _width;
00089         this->windowHeight      = _height;
00090         this->windowBits        = _bits;
00091 }
00092 
00094 bool CToxiGLRenderer::createContext()
00095 {
00096         GLuint PixelFormat;
00097 
00098         static  PIXELFORMATDESCRIPTOR pfd=                              
00099         {
00100                 sizeof(PIXELFORMATDESCRIPTOR),                          
00101                 1,                                                                                      
00102                 PFD_DRAW_TO_WINDOW |                                            
00103                 PFD_SUPPORT_OPENGL |                                            
00104                 PFD_DOUBLEBUFFER,                                                       
00105                 PFD_TYPE_RGBA,                                                          
00106                 windowBits,                                                                             
00107                 0, 0, 0, 0, 0, 0,                                                       
00108                 0,                                                                                      
00109                 0,                                                                                      
00110                 0,                                                                                      
00111                 0, 0, 0, 0,                                                                     
00112                 16,                                                                                     
00113                 0,                                                                                      
00114                 0,                                                                                      
00115                 PFD_MAIN_PLANE,                                                         
00116                 0,                                                                                      
00117                 0, 0, 0                                                                         
00118         };
00119         
00120         if(!(hDC=GetDC(hWnd))) {                                                        
00121                 MessageBox(NULL,REGISTER_DC,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00122                 return false;                                                           
00123         }
00124 
00125         if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))  {                                                               
00126                 MessageBox(NULL,REGISTER_PFD,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00127                 return false;                                                           
00128         }
00129 
00130         if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {;                                                    
00131                 MessageBox(NULL,REGISTER_SET_PFD,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00132                 return false;                                                   
00133         }
00134 
00135         if(!(hRC=wglCreateContext(hDC))) {;                                                     
00136                 MessageBox(NULL,REGISTER_RC,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00137                 return false;                                                   
00138         }
00139 
00140         if(!wglMakeCurrent(hDC,hRC)) {                                                  
00141                 MessageBox(NULL,REGISTER_SET_RC,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00142                 return false;                                                   
00143         }
00144 
00145         ShowWindow(hWnd,SW_SHOW);                                       
00146         SetForegroundWindow(hWnd);                                      
00147         SetFocus(hWnd);                                                         
00148         resizeContext();                                
00149         return true;                                                            
00150 }
00151 
00152 
00154 bool CToxiGLRenderer::killContext()
00155 {
00156         if(hRC) {
00157                 if (!wglMakeCurrent(NULL,NULL)) {                       
00158                         MessageBox(NULL,RELEASE_DC_RC,ERROR_SHOT_TITLE,MB_OK | MB_ICONINFORMATION);
00159                         hRC=NULL;
00160                         return false;
00161                 }
00162 
00163                 if (!wglDeleteContext(hRC)) {                                           
00164                         MessageBox(NULL,RELEASE_RC,ERROR_SHOT_TITLE,MB_OK | MB_ICONINFORMATION);
00165                         hRC=NULL;
00166                         return false;
00167                 }
00168                 return true;
00169         }
00170         return false;
00171 }
00172 
00173 
00174 void CToxiGLRenderer::swapBuffers()
00175 {
00176         SwapBuffers(hDC);       
00177 }
00178 
00180 int CToxiGLRenderer::getRendererType()
00181 {       
00182         return this->rendererType;                                                              
00183 }
00184 
00185 #endif

Generated on Mon Sep 23 23:07:01 2002 for ToxiTea by doxygen1.2.18