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
|
if (surface->flags & SDL_OPENGL)
{
ManageTexture();
glBegin(GL_QUADS);
glColor4f(1.0, 1.0, 1.0, 1.0);
glTexCoord2d(0, 0);
glVertex2i(x, y);
glTexCoord2d(0, hTexHeight);
glVertex2i(x, y + hSurface->h);
glTexCoord2d(hTexWidth, hTexHeight);
glVertex2i(x + hSurface->w, y + hSurface->h);
glTexCoord2d(hTexWidth, 0);
glVertex2i(x + hSurface->w, y);
glEnd();
}
.....
void SDLgfx::ManageTexture()
{
if (!hTextureIndex)
{
glGenTextures(1, &hTextureIndex);
hTextureStatus = TEX_TO_RELOAD;
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, hTextureIndex);
if (hTextureStatus & TEX_TO_RELOAD)
{
#ifdef DEBUGGFX
std::cout << "Loading texture " << hTextureIndex << std::endl;
#endif
int w, h;
SDL_Surface *image;
Uint32 saved_flags;
Uint8 saved_alpha;
/* Use the surface width and height expanded to powers of 2 */
w = power_of_two(hSurface->w);
h = power_of_two(hSurface->h);
hTexWidth = GLdouble(hSurface->w) / w; /* Max X */
hTexHeight = GLdouble(hSurface->h) / h; /* Max Y */
image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
0x000000FF,
0x0000FF00,
0x00FF0000,
0xFF000000
#else
0xFF000000,
0x00FF0000,
0x0000FF00,
0x000000FF
#endif
);
if ( image == NULL )
return;
/* Save the alpha blending attributes */
saved_flags = hSurface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
saved_alpha = hSurface->format->alpha;
if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
SDL_SetAlpha(hSurface, 0, 0);
/* Copy the surface into the GL texture image */
SDL_BlitSurface(hSurface, NULL, image, NULL);
/* Restore the alpha blending attributes */
if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
SDL_SetAlpha(hSurface, saved_flags, saved_alpha);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, image->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
SDL_FreeSurface(image); /* No longer needed */
hTextureStatus = TEX_NONE;
}
} |
Partager