00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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())
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 }