E:/Eigene Dateien/Eigene Projekte/c0re/Texture.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 "Texture.h"
00022 
00023 #include "system.h"
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 #include <iostream>
00027 #include <stdlib.h>
00028 #include <conio.h>
00029 #include <io.h>
00030 #include <math.h>
00031 
00032 #include "TextureMasked.h"
00033 #include "TextureAlpha.h"
00034 
00035 std::map<std::string, TextureInterface*> Texture::cachedTextures;
00036 std::map<int, Texture*> Texture::allItems;
00037 
00038 int Texture::idCounter = 1;
00039 
00040 Texture::Texture()
00041 {
00042         id = idCounter++;
00043         allItems[id] = this;
00044 }
00045 
00046 Texture::~Texture()
00047 {
00048         allItems.erase(allItems.find(id));
00049 }
00050 
00051 Texture* Texture::get(int p_id)
00052 {
00053         Texture* ret = 0;
00054         std::map<int, Texture*>::iterator it = allItems.find(p_id);
00055         if (it != allItems.end())
00056                 ret = it->second;
00057         return ret;
00058 }
00059 
00060 int Texture::loadAndBind(std::string p_filename, eTextureModification p_modifikationflag)
00061 {
00062         int ret = 0;
00063 
00064         if (cachedTextures.find(p_filename) == cachedTextures.end()) //Not cached yet
00065         {
00066                 TextureInterface *ti = new TextureAlpha();
00067                 ti->loadAndBind(p_filename, p_modifikationflag);
00068                 cachedTextures[p_filename] = ti;
00069         }
00070         
00071         myTexture = cachedTextures[p_filename];
00072         ratio = myTexture->ratio;
00073         sequence = 0;
00074         sequenceCount = 1;
00075         return ret;
00076 }
00077 
00078 int Texture::render()
00079 {
00080         int ret = 0;
00081 
00082         glPushMatrix();
00083         glScaled(1.0, 1.0 / ratio, 1.0);
00084 
00085         double frame_width = 1.0 / (double)sequenceCount;
00086         double x_anfang = ((sequence % sequenceCount) * frame_width);
00087         double x_ende = x_anfang + frame_width;
00088         double y_anfang = 1 - frame_width - (sequence / sequenceCount) * frame_width;
00089         double y_ende = y_anfang + frame_width;
00090 
00091         double width = 1.0, height = 1.0;
00092         glLoadName(id);
00093                 
00094         myTexture->render(x_anfang, x_ende, y_anfang, y_ende);
00095 
00096         glPopMatrix();
00097 
00098         return ret;
00099 }
00100 
00101 
00102 Field* Texture::getField()
00103 {
00104         return 0;
00105 }
00106 
00107 Button* Texture::getButton()
00108 {
00109         return 0;
00110 }

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