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
| CTexture::CTexture(const CText* text)
{
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_HWSURFACE,
w,
h,
32,
RMask,
GMask,
BMask,
AMask
);
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();
CSurface temp2(temp);
SDL_Color color;
color.r = 0; color.g = 0; color.b = 0;
temp2.fill(color);
text->blit(&position, &temp2);
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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} |
Partager