K2dImageWork.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #include "K2dImageWork.h"
00034 
00038 K2dImageWork::K2dImageWork(K3dGameData *_pGameData)
00039 {
00040         m_pGameData = _pGameData;
00041         // Set this pointer to the game data
00042         m_pGameData->SetImageWork(this);
00043 }
00044 
00045 K2dImageWork::~K2dImageWork(void)
00046 {
00047 }
00048 
00050 void K2dImageWork::DrawImages()
00051 {
00052         for(int i=0; i<m_pGameData->Get2dImageObjSP().GetNum(); i++)
00053         {
00054                 // Get 2d image from game data
00055                 K2dImageObj *pkImage = m_pGameData->Get2dImageObjSP().Get(i);
00056 
00057                 bool bIsBlend = pkImage->GetBlend();
00058                 if(bIsBlend)
00059                 {
00060                         glEnable(GL_BLEND);
00061                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
00062                 }
00063 
00064                 int iTextureId = pkImage->GetTextureId();
00065                 glBindTexture(GL_TEXTURE_2D, iTextureId );
00066                 // Alpha determine blending
00067                 glColor4f(1.0f,1.0f,1.0f,1.0f);
00068 
00069                 SDL_Rect tRect = pkImage->GetRectangle();
00070                 float x1 = tRect.x;
00071                 float y1 = tRect.y;
00072                 float x2 = tRect.w;
00073                 float y2 = tRect.h;
00074 
00075                 glBegin(GL_QUADS);
00076                 glTexCoord2f(0.0f, 0.0f); glVertex2f(x1,y1);
00077                 glTexCoord2f(1.0f, 0.0f); glVertex2f(x2,y1);
00078                 glTexCoord2f(1.0f, 1.0f); glVertex2f(x2,y2);
00079                 glTexCoord2f(0.0f, 1.0f); glVertex2f(x1,y2);
00080                 glEnd(); 
00081 
00082                 if(bIsBlend)
00083                 {
00084                         glDisable(GL_BLEND);
00085                 }
00086         }
00087 }
00088 

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