Fixed SDL 1.3 GL state messed up due to the on-screen keyboard, that also fixes issues with Alien Blaster

This commit is contained in:
pelya
2012-01-03 17:54:20 +02:00
parent 32c68280bf
commit 66c66a59d9
2 changed files with 12 additions and 41 deletions
@@ -33,39 +33,15 @@ static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface(
ret->w = surface->w;
ret->h = surface->h;
ret->format = new SDL_PixelFormat();
*(ret->format) = *(surface->format);
memcpy(ret->format, surface->format, sizeof(SDL_PixelFormat));
format = SDL_PIXELFORMAT_RGB565;
SDL_Surface * surface2 = surface;
if( surface->flags & SDL_SRCCOLORKEY )
{
format = SDL_PIXELFORMAT_RGBA4444;
//surface2 = SDL_ConvertSurfaceFormat(surface, format, 0); // Does not copy alpha
int bpp;
Uint32 r,g,b,a;
SDL_PixelFormatEnumToMasks(format, &bpp, &r, &g, &b, &a);
surface2 = SDL_CreateRGBSurface(0, surface->w, surface->h, bpp, r, g, b, a);
SDL_FillRect(surface2, NULL, 0);
SDL_BlitSurface(surface, NULL, surface2, NULL);
// Fix the alpha channel, using ugly pixel access
SDL_LockSurface(surface2);
SDL_LockSurface(surface);
for(int y = 0; y < surface->h; y++)
for(int x = 0; x < surface->w; x++)
{
// Assume 24-bit or 32-bit surface
Uint8 * pixel = ((Uint8 *) surface->pixels) + y*surface->pitch + x*surface->format->BytesPerPixel;
if( pixel[0] == 255 && pixel[1] == 0 && pixel[2] == 255 )
*(Uint16 *)(((Uint8 *) surface2->pixels) + y*surface2->pitch + x*surface2->format->BytesPerPixel) = 0;
}
SDL_UnlockSurface(surface);
SDL_UnlockSurface(surface2);
}
ret->t = SDL_CreateTextureFromSurface(SDL_global_renderer, surface2);
if(surface != surface2)
SDL_FreeSurface(surface2);
ret->t = SDL_CreateTextureFromSurface(SDL_global_renderer, surface);
if( ! ret->t )
{
@@ -123,11 +99,8 @@ static inline void SdlCompat_ReloadSurfaceToVideoMemory(SdlCompat_AcceleratedSur
{
// Allocate accelerated surface even if that means loss of color quality
Uint32 format;
format = SDL_PIXELFORMAT_RGB565;
if( src->flags & SDL_SRCCOLORKEY )
format = SDL_PIXELFORMAT_RGBA5551;
//surface->t = SDL_CreateTextureFromSurface(format, src);
int access, w, h;
SDL_QueryTexture(surface->t, &format, &access, &w, &h);
int bpp;
Uint32 r,g,b,a;
@@ -137,14 +110,6 @@ static inline void SdlCompat_ReloadSurfaceToVideoMemory(SdlCompat_AcceleratedSur
SDL_LockSurface(converted);
// debug
/*
for( int x=0; x<converted->w; x++ )
for( int y=0; y<converted->h; y++ )
*(Sint16 *) ( ((Uint8 *)converted->pixels) + y*converted->pitch + x*2 ) = y*4;
*/
// end debug
SDL_UpdateTexture( surface->t, NULL, converted->pixels, converted->pitch );
SDL_UnlockSurface(converted);
@@ -210,8 +210,14 @@ void ANDROID_GL_SwapBuffers(_THIS, SDL_Window * window)
if( SDL_ANDROID_InsideVideoThread() )
SDL_ANDROID_CallJavaSwapBuffers();
// SDL: 1.3 does not clear framebuffer before drawing
//glClearColor(0, 0, 0, 1);
//glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
// Restore blend mode messed up by screen keyboard
glColor4f(1, 1, 1, 1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
};
SDL_GLContext ANDROID_GL_CreateContext(_THIS, SDL_Window * window)