E:/Eigene Dateien/Eigene Projekte/c0re/TextureAlpha.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of c0re.
00003 
00004         c0re is a multiplayer RTS on a hexagonal map with an evolving unit concept.
00005     Copyright (C) 2007 Stephan Hofmann
00006 
00007     c0re is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     This program 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
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "TextureAlpha.h"
00022 
00023 #include "system.h"
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 
00027 TextureAlpha::TextureAlpha()
00028 {
00029         handlerTexture = -1;
00030 }
00031 
00032 TextureAlpha::~TextureAlpha()
00033 {
00034 
00035 }
00036 
00037 
00038 int TextureAlpha::render(double x_begin, double x_end, double y_begin, double y_end)
00039 {
00040         int ret = 0;
00041 
00042         if (handlerTexture != -1)
00043         {       
00044                 glEnable(GL_BLEND);
00045                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00046                 glBindTexture(GL_TEXTURE_2D, handlerTexture);
00047                 glBegin(GL_QUADS);
00048                         // top left vertex
00049                         glTexCoord2d(x_begin, y_begin);
00050                         glVertex3d(0.5, 0.5, 0.0);
00051                         // bottom left vertex
00052                         glTexCoord2d(x_begin, y_end);
00053                         glVertex3d(0.5, -0.5, 0.0);
00054                         // bottom right vertex
00055                         glTexCoord2d(x_end, y_end);
00056                         glVertex3d(-0.5, -0.5, 0.0);
00057                         // top right vertex
00058                         glTexCoord2d(x_end, y_begin);
00059                         glVertex3d(-0.5, 0.5, 0.0);
00060                 glEnd();
00061 
00062                 glDisable(GL_BLEND);
00063                 glBindTexture(GL_TEXTURE_2D, 0);
00064         }
00065 
00066         return ret;
00067 }
00068 
00069 int TextureAlpha::loadAndBind(std::string p_filename, eTextureModification p_modifikationflag)
00070 {
00071         int ret = 0;
00072         p_modifikationflag = TM_Masked_Normal;
00073         TextureData* td = 0;
00074 
00075         td = loadPNG(p_filename);
00076 
00077         //postprozess td -> change RED to Black with Alpha = 0.0
00078         int j=0,i;
00079         for (i=0; i < (td->infoheader.biWidth) * (td->infoheader.biHeight); i++)
00080         {            
00081                 //if red
00082                 if ((td->l_texture[j+0] == 255) && (td->l_texture[j+1] == 0) && (td->l_texture[j+2] == 0))
00083                 {       
00084                         //adjust to black with alpha = 0
00085                         td->l_texture[j+0] = 0;
00086                         td->l_texture[j+3] = 0;
00087                 }
00088                 j += 4; // Go to the next position
00089         }
00090         handlerTexture = bind(td);
00091         ratio = td->infoheader.biWidth / td->infoheader.biHeight;
00092         //dump the rawdata
00093         free(td->l_texture);
00094 
00095         return ret;
00096 }

Generated on Tue Jul 17 22:02:22 2007 for C0re by  doxygen 1.5.2