GL_LINEAR
This commit is contained in:
parent
0f145bd83b
commit
c4d03fc582
45
src/external/SDLGL_Util.cpp
vendored
45
src/external/SDLGL_Util.cpp
vendored
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#if (GFX_BACKEND == ZE_OGL)
|
#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 power_of_two(int input)
|
||||||
{
|
{
|
||||||
int value = 1;
|
int value = 1;
|
||||||
@ -20,12 +20,12 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
|
|||||||
{
|
{
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_Surface *image;
|
SDL_Surface *temp;
|
||||||
SDL_Rect area;
|
SDL_Rect area;
|
||||||
Uint32 saved_flags;
|
Uint32 saved_flags;
|
||||||
Uint8 saved_alpha;
|
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);
|
w = power_of_two(surface->w);
|
||||||
h = power_of_two(surface->h);
|
h = power_of_two(surface->h);
|
||||||
texcoord[0] = 0.0f; //min X
|
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[2] = (GLfloat)surface->w / w; //max X
|
||||||
texcoord[3] = (GLfloat)surface->h / h; //max Y
|
texcoord[3] = (GLfloat)surface->h / h; //max Y
|
||||||
|
|
||||||
image = SDL_CreateRGBSurface(
|
temp = SDL_CreateRGBSurface(
|
||||||
SDL_SWSURFACE,
|
SDL_SWSURFACE,
|
||||||
w, h,
|
w, h,
|
||||||
32,
|
32,
|
||||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN //endian specific color masks
|
||||||
0x000000FF,
|
0x000000FF,
|
||||||
0x0000FF00,
|
0x0000FF00,
|
||||||
0x00FF0000,
|
0x00FF0000,
|
||||||
@ -49,43 +49,34 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
|
|||||||
0x000000FF
|
0x000000FF
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if ( image == NULL ) {
|
if(!temp) //failure in CreateRGBSurface
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Save the alpha blending attributes */
|
//save alpha
|
||||||
saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
|
saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
|
||||||
saved_alpha = surface->format->alpha;
|
saved_alpha = surface->format->alpha;
|
||||||
if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
|
if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
|
||||||
SDL_SetAlpha(surface, 0, 0);
|
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.x = 0;
|
||||||
area.y = 0;
|
area.y = 0;
|
||||||
area.w = static_cast<Sint16>(surface->w);
|
area.w = static_cast<Sint16>(surface->w);
|
||||||
area.h = static_cast<Sint16>(surface->h);
|
area.h = static_cast<Sint16>(surface->h);
|
||||||
SDL_BlitSurface(surface, &area, image, &area);
|
SDL_BlitSurface(surface, &area, temp, &area);
|
||||||
|
|
||||||
/* Restore the alpha blending attributes */
|
//restore saved alpha
|
||||||
if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
|
if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
|
||||||
SDL_SetAlpha(surface, saved_flags, saved_alpha);
|
SDL_SetAlpha(surface, saved_flags, saved_alpha);
|
||||||
}
|
|
||||||
|
|
||||||
/* Create an OpenGL texture for the image */
|
//create the OpenGL texture
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
|
//setup texture parmaters
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels);
|
||||||
0,
|
SDL_FreeSurface(temp); //temp surface no longer needed
|
||||||
GL_RGBA16,
|
|
||||||
w, h,
|
|
||||||
0,
|
|
||||||
GL_RGBA,
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
image->pixels);
|
|
||||||
SDL_FreeSurface(image); /* No longer needed */
|
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user