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
|
if (surface->flags & SDL_OPENGL)
{
ManageTexture();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, hTexture->w, hTexture->h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, hTexture->pixels);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2d(x, y);
glTexCoord2f(0, hTexWidth);
glVertex2d(x + hSurface->w, y);
glTexCoord2f(hTexHeight, hTexWidth);
glVertex2d(x + hSurface->w, y + hSurface->h);
glTexCoord2f(hTexHeight, 0);
glVertex2d(x, y + hSurface->h);
glEnd();
return;
}
static int GetPowerSize(int value)
{
int result = 0, count = 0;
while (result < value)
{
result = int(pow (2, count));
count++;
}
return (result);
}
void SDLgfx::ManageTexture()
{
/* hTexture is of 2 power of n size so if hSurface is equal or smaller
than hTexture then there is no need to redefine it, only clean it and blit
hSurface into hTexture
hTexture is of RGBA (32 bits) format */
/* define the size of hTexture */
int texHeight = GetPowerSize(hSurface->h);
int texWidth = GetPowerSize(hSurface->w);
/* define hTexture if it isn't */
if (!hTexture)
{
hTexture = SDL_CreateRGBSurface(SDL_SWSURFACE, texWidth, texHeight, 32, 0, 0, 0, 0);
hTextureStatus = TEX_TO_RELOAD;
}
/* do we need to resize hTexture ? */
if (((hSurface->w) > (hTexture->w)) || ((hSurface->h) > (hTexture->h)))
{
SDL_FreeSurface(hTexture);
hTexture = SDL_CreateRGBSurface(SDL_SWSURFACE, texWidth, texHeight, 32, 0, 0, 0, 0);
hTextureStatus = TEX_TO_RELOAD;
}
if (hTextureStatus & TEX_TO_RELOAD)
{
SDL_FillRect(hTexture, NULL, 0);
SDL_BlitSurface(hSurface, NULL, hTexture, NULL);
}
/* ratio for the texture coords */
hTexWidth = GLdouble(hSurface->w) / hTexture->w;
hTexHeight = GLdouble(hSurface->h) / hTexture->h;
} |
Partager