00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00049 glTexCoord2d(x_begin, y_begin);
00050 glVertex3d(0.5, 0.5, 0.0);
00051
00052 glTexCoord2d(x_begin, y_end);
00053 glVertex3d(0.5, -0.5, 0.0);
00054
00055 glTexCoord2d(x_end, y_end);
00056 glVertex3d(-0.5, -0.5, 0.0);
00057
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
00078 int j=0,i;
00079 for (i=0; i < (td->infoheader.biWidth) * (td->infoheader.biHeight); i++)
00080 {
00081
00082 if ((td->l_texture[j+0] == 255) && (td->l_texture[j+1] == 0) && (td->l_texture[j+2] == 0))
00083 {
00084
00085 td->l_texture[j+0] = 0;
00086 td->l_texture[j+3] = 0;
00087 }
00088 j += 4;
00089 }
00090 handlerTexture = bind(td);
00091 ratio = td->infoheader.biWidth / td->infoheader.biHeight;
00092
00093 free(td->l_texture);
00094
00095 return ret;
00096 }