1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| CTexture::CTexture(const CText* text)
{
text->saveBMP("OriginalText.bmp");
unsigned int
w = (int)floor(pow(2, ceil(log(text->getWidth()) / log(2)))),
h = (int)floor(pow(2, ceil(log(text->getHeight()) / log(2))));
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32
RMask = 0xff000000,
GMask = 0x00ff0000,
BMask = 0x0000ff00,
AMask = 0x000000ff;
#else
Uint32
RMask = 0x000000ff,
GMask = 0x0000ff00,
BMask = 0x00ff0000,
AMask = 0xff000000;
#endif
SDL_Surface *temp = SDL_CreateRGBSurface
(
SDL_SWSURFACE,
w,
h,
32,
text->getRMask(),
text->getGMask(),
text->getBMask(),
text->getAMask()
);
if (!temp)
{
SDL_FreeSurface(temp);
cerr << "Fatal error : unable to create texture from SDL surface : " << SDL_GetError() << endl;
bool error;
throw error;
}
//SDL_Rect position;
//position.x = 0; position.y = h - text->getHeight();
SDL_SetAlpha(temp, 0, 0);
CSurface temp2(temp);
temp2.saveBMP("temp2.bmp");
text->blit(0, &temp2, 0);
temp2.saveBMP("temp2blit.bmp");
//temp2.setColorKey(SDL_SRCCOLORKEY, color);
//temp2.displayFormatAlpha();
glGenTextures(1, &texture);
this->bind();
//gluBuild2DMipmaps(GL_TEXTURE_2D, 4, temp2.getWidth(), temp2.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, temp2.getPixels());
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, temp2.getWidth(), temp2.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, temp2.getPixels());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
CTexture::CTexture(const CText* text)
{
text->saveBMP("OriginalText.bmp");
unsigned int
w = (int)floor(pow(2, ceil(log(text->getWidth()) / log(2)))),
h = (int)floor(pow(2, ceil(log(text->getHeight()) / log(2))));
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32
RMask = 0xff000000,
GMask = 0x00ff0000,
BMask = 0x0000ff00,
AMask = 0x000000ff;
#else
Uint32
RMask = 0x000000ff,
GMask = 0x0000ff00,
BMask = 0x00ff0000,
AMask = 0xff000000;
#endif
SDL_Surface *temp = SDL_CreateRGBSurface
(
SDL_SWSURFACE,
w,
h,
32,
text->getRMask(),
text->getGMask(),
text->getBMask(),
text->getAMask()
);
if (!temp)
{
SDL_FreeSurface(temp);
cerr << "Fatal error : unable to create texture from SDL surface : " << SDL_GetError() << endl;
bool error;
throw error;
}
//SDL_Rect position;
//position.x = 0; position.y = h - text->getHeight();
SDL_SetAlpha(temp, 0, 0);
CSurface temp2(temp);
temp2.saveBMP("temp2.bmp");
text->blit(0, &temp2, 0);
temp2.saveBMP("temp2blit.bmp");
//temp2.setColorKey(SDL_SRCCOLORKEY, color);
//temp2.displayFormatAlpha();
glGenTextures(1, &texture);
this->bind();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
} |
Partager