00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00049 glTexCoord2d(x_begin, y_end);
00050 glVertex3d(0.5, 0.5, 0.0);
00051
00052 glTexCoord2d(x_begin, y_begin);
00053 glVertex3d(0.5, -0.5, 0.0);
00054
00055 glTexCoord2d(x_end, y_begin);
00056 glVertex3d(-0.5, -0.5, 0.0);
00057
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
00065 glTexCoord2d(x_begin, y_end);
00066 glVertex3d(0.5, 0.5, 0.0);
00067
00068 glTexCoord2d(x_begin, y_begin);
00069 glVertex3d(0.5, -0.5, 0.0);
00070
00071 glTexCoord2d(x_end, y_begin);
00072 glVertex3d(-0.5, -0.5, 0.0);
00073
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
00094 int j=0,i;
00095 for (i=0; i < (td->infoheader.biWidth) * (td->infoheader.biHeight); i++)
00096 {
00097
00098 if ((td->l_texture[j+0] == 255) && (td->l_texture[j+1] == 0) && (td->l_texture[j+2] == 0))
00099 {
00100
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;
00112 }
00113 handlerTexture = bind(td);
00114
00115 free(td->l_texture);
00116
00117
00118
00119
00120 td = loadBMP(p_filename);
00121
00122 j=0;
00123 for (i=0; i < (td->infoheader.biWidth) * (td->infoheader.biHeight); i++)
00124 {
00125
00126 if ((td->l_texture[j+0] == 255) && (td->l_texture[j+1] == 0) && (td->l_texture[j+2] == 0))
00127 {
00128
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
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;
00141 }
00142 handlerMask = bind(td);
00143 ratio = td->infoheader.biWidth / td->infoheader.biHeight;
00144
00145 free(td->l_texture);
00146
00147 return ret;
00148 }