E:/Eigene Dateien/Eigene Projekte/c0re/TextureMasked.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 "TextureMasked.h"
00022 
00023 #include "system.h"
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 
00027 TextureMasked::TextureMasked()
00028 {
00029         handlerMask = handlerTexture = -1;
00030 }
00031 
00032 TextureMasked::~TextureMasked()
00033 {
00034 
00035 }
00036 
00037 
00038 int TextureMasked::render(double x_begin, double x_end, double y_begin, double y_end)
00039 {
00040         int ret = 0;
00041 
00042         if ((handlerMask != -1) && (handlerTexture != -1))
00043         {       
00044                 glEnable(GL_BLEND);
00045                 glBlendFunc(GL_DST_COLOR, GL_ZERO);
00046                 glBindTexture(GL_TEXTURE_2D, handlerMask);
00047                 glBegin(GL_QUADS);
00048                         // top left vertex
00049                         glTexCoord2d(x_begin, y_end);
00050                         glVertex3d(0.5, 0.5, 0.0);
00051                         // bottom left vertex
00052                         glTexCoord2d(x_begin, y_begin);
00053                         glVertex3d(0.5, -0.5, 0.0);
00054                         // bottom right vertex
00055                         glTexCoord2d(x_end, y_begin);
00056                         glVertex3d(-0.5, -0.5, 0.0);
00057                         // top right vertex
00058                         glTexCoord2d(x_end, y_end);
00059                         glVertex3d(-0.5, 0.5, 0.0);
00060                 glEnd();
00061                 glBlendFunc(GL_ONE, GL_ONE);
00062                 glBindTexture(GL_TEXTURE_2D, handlerTexture);
00063                 glBegin(GL_QUADS);
00064                         // top left vertex
00065                         glTexCoord2d(x_begin, y_end);
00066                         glVertex3d(0.5, 0.5, 0.0);
00067                         // bottom left vertex
00068                         glTexCoord2d(x_begin, y_begin);
00069                         glVertex3d(0.5, -0.5, 0.0);
00070                         // bottom right vertex
00071                         glTexCoord2d(x_end, y_begin);
00072                         glVertex3d(-0.5, -0.5, 0.0);
00073                         // top right vertex
00074                         glTexCoord2d(x_end, y_end);
00075                         glVertex3d(-0.5, 0.5, 0.0);
00076                 glEnd();
00077 
00078                 glDisable(GL_BLEND);
00079                 glBindTexture(GL_TEXTURE_2D, 0);
00080         }
00081 
00082         return ret;
00083 }
00084 
00085 
00086 
00087 int TextureMasked::loadAndBind(std::string p_filename, eTextureModification p_modifikationflag)
00088 {
00089         int ret = 0;
00090         p_modifikationflag = TM_Masked_Normal;
00091 
00092         TextureData* td = loadBMP(p_filename);
00093         //postprozess td -> change RED to BLACK
00094         int j=0,i;
00095         for (i=0; i < (td->infoheader.biWidth) * (td->infoheader.biHeight); i++)
00096         {            
00097                 //if red
00098                 if ((td->l_texture[j+0] == 255) && (td->l_texture[j+1] == 0) && (td->l_texture[j+2] == 0))
00099                 {       
00100                         //adjust to black
00101                         td->l_texture[j+0] = 0;
00102                 }
00103                 else if (p_modifikationflag == TM_Masked_Blue_To_Red)
00104                 {
00105                         unsigned char temp = td->l_texture[j+0];
00106                         unsigned char t = 255 - td->l_texture[j+2];
00107                         t /= 2;
00108                         td->l_texture[j+0] = 255 - t;
00109                         td->l_texture[j+2] = temp;
00110                 }
00111                 j += 4; // Go to the next position
00112         }
00113         handlerTexture = bind(td);
00114         //dump the rawdata
00115         free(td->l_texture);
00116         
00117         /*
00118                 now the mask
00119         */
00120         td = loadBMP(p_filename);
00121         //postprozess td -> change RED to White all else to black
00122         j=0;
00123         for (i=0; i < (td->infoheader.biWidth) * (td->infoheader.biHeight); i++)
00124         {            
00125                 //if red
00126                 if ((td->l_texture[j+0] == 255) && (td->l_texture[j+1] == 0) && (td->l_texture[j+2] == 0))
00127                 {       
00128                         //adjust to white
00129                         td->l_texture[j+0] = 255;
00130                         td->l_texture[j+1] = 255;
00131                         td->l_texture[j+2] = 255;
00132                 }
00133                 else
00134                 {
00135                         //adjust to black
00136                         td->l_texture[j+0] = 0;
00137                         td->l_texture[j+1] = 0;
00138                         td->l_texture[j+2] = 0;
00139                 }
00140                         j += 4; // Go to the next position
00141         }
00142         handlerMask = bind(td);
00143         ratio = td->infoheader.biWidth / td->infoheader.biHeight;
00144         //dump the rawdata
00145         free(td->l_texture);
00146 
00147         return ret;
00148 }

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