K3dOpenGL.cpp

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00032  ***************************************************************************/
00033 
00034 #include "K3dOpenGL.h"
00035 
00039 K3dOpenGL::K3dOpenGL(K3dGameData *_pGameData)
00040 {
00041         m_pGameData = _pGameData;
00042         // Set this pointer to the game data
00043         m_pGameData->SetOpenGL(this);
00044 }
00045 
00046 K3dOpenGL::~K3dOpenGL()
00047 {
00048 }
00049 
00051 void K3dOpenGL::Set2DProjection()
00052 {
00053         glMatrixMode(GL_PROJECTION);
00054         glLoadIdentity();
00055         glOrtho(0,m_pGameData->GetGraphicOption()->iWidth,0,m_pGameData->GetGraphicOption()->iHeight,-1,1);
00056         glMatrixMode(GL_MODELVIEW);
00057         glLoadIdentity(); 
00058 }
00059 
00061 void K3dOpenGL::Set3DProjection()
00062 {
00063         glMatrixMode(GL_PROJECTION);
00064         glLoadIdentity();
00065 
00066         gluPerspective((GLdouble)m_pGameData->GetGraphicOption()->iFovy, (GLdouble)m_pGameData->GetGraphicOption()->iWidth/(GLdouble)m_pGameData->GetGraphicOption()->iHeight,
00067                 (GLdouble)m_pGameData->GetGraphicOption()->iNearPlane, (GLdouble)m_pGameData->GetGraphicOption()->iFarPlane);
00068 
00069         glMatrixMode(GL_MODELVIEW);
00070         glLoadIdentity();
00071 }
00072 
00076 void K3dOpenGL::ResizeGL(const int _iWidth, int _iHeight)
00077 {
00078         if(_iHeight == 0)
00079                 _iHeight = 1;
00080 
00081         glViewport(0, 0, _iWidth, _iHeight);
00082 
00083         // Set screen width height to the graphics option
00084         TGraphicOption *ptGraphics = m_pGameData->GetGraphicOption();
00085         ptGraphics->iWidth = _iWidth;
00086         ptGraphics->iHeight = _iHeight;
00087 
00088         Set3DProjection();
00089         //Set2DProjection();
00090 }
00091 

Generated on Thu Aug 16 23:53:26 2007 for K3dEngine by  doxygen 1.5.0