GL_LINEAR

This commit is contained in:
James Turk 2003-10-13 20:43:07 +00:00
parent 0f145bd83b
commit c4d03fc582

View File

@ -6,7 +6,7 @@
#if (GFX_BACKEND == ZE_OGL)
//finds nearest power of two (going up), needed for surfaces
//finds next largest power of two, needed for GL textures
int power_of_two(int input)
{
int value = 1;
@ -20,12 +20,12 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
{
GLuint texture;
int w, h;
SDL_Surface *image;
SDL_Surface *temp;
SDL_Rect area;
Uint32 saved_flags;
Uint8 saved_alpha;
/* Use the surface width and height expanded to powers of 2 */
//expand width and height to nearest powers of 2
w = power_of_two(surface->w);
h = power_of_two(surface->h);
texcoord[0] = 0.0f; //min X
@ -33,11 +33,11 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
texcoord[2] = (GLfloat)surface->w / w; //max X
texcoord[3] = (GLfloat)surface->h / h; //max Y
image = SDL_CreateRGBSurface(
temp = SDL_CreateRGBSurface(
SDL_SWSURFACE,
w, h,
32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
#if SDL_BYTEORDER == SDL_LIL_ENDIAN //endian specific color masks
0x000000FF,
0x0000FF00,
0x00FF0000,
@ -49,43 +49,34 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
0x000000FF
#endif
);
if ( image == NULL ) {
if(!temp) //failure in CreateRGBSurface
return 0;
}
/* Save the alpha blending attributes */
//save alpha
saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
saved_alpha = surface->format->alpha;
if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
SDL_SetAlpha(surface, 0, 0);
}
/* Copy the surface into the GL texture image */
//copy surface (do not alter passed surface to allow this function to be used in special situations)
area.x = 0;
area.y = 0;
area.w = static_cast<Sint16>(surface->w);
area.h = static_cast<Sint16>(surface->h);
SDL_BlitSurface(surface, &area, image, &area);
SDL_BlitSurface(surface, &area, temp, &area);
/* Restore the alpha blending attributes */
if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
//restore saved alpha
if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
SDL_SetAlpha(surface, saved_flags, saved_alpha);
}
/* Create an OpenGL texture for the image */
//create the OpenGL texture
glGenTextures(1, &texture);
//setup texture parmaters
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA16,
w, h,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
image->pixels);
SDL_FreeSurface(image); /* No longer needed */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels);
SDL_FreeSurface(temp); //temp surface no longer needed
return texture;
}