fixed dithering

This commit is contained in:
James Turk 2003-01-24 10:23:39 +00:00
parent 60a6417662
commit 510ba33aff

View File

@ -6,84 +6,84 @@
int power_of_two(int input) int power_of_two(int input)
{ {
int value = 1; int value = 1;
while ( value < input ) { while ( value < input ) {
value <<= 1; value <<= 1;
} }
return value; return value;
} }
GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
{ {
GLuint texture; GLuint texture;
int w, h; int w, h;
SDL_Surface *image; SDL_Surface *image;
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 */ /* Use the surface width and height expanded to 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
texcoord[1] = 0.0f; //min Y texcoord[1] = 0.0f; //min Y
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( image = 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 /* OpenGL RGBA masks */
0x000000FF, 0x000000FF,
0x0000FF00, 0x0000FF00,
0x00FF0000, 0x00FF0000,
0xFF000000 0xFF000000
#else #else
0xFF000000, 0xFF000000,
0x00FF0000, 0x00FF0000,
0x0000FF00, 0x0000FF00,
0x000000FF 0x000000FF
#endif #endif
); );
if ( image == NULL ) { if ( image == NULL ) {
return 0; return 0;
} }
/* Save the alpha blending attributes */ /* Save the alpha blending attributes */
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 the surface into the GL texture image */
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, image, &area);
/* Restore the alpha blending attributes */ /* Restore the alpha blending attributes */
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 an OpenGL texture for the image */
glGenTextures(1, &texture); glGenTextures(1, &texture);
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RGBA, GL_RGBA16,
w, h, w, h,
0, 0,
GL_RGBA, GL_RGBA,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
image->pixels); image->pixels);
SDL_FreeSurface(image); /* No longer needed */ SDL_FreeSurface(image); /* No longer needed */
return texture; return texture;
} }