The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_BlitScaled not working on palletized surfaces
manskirtbrew


Joined: 05 Feb 2014
Posts: 12
I'm trying to blit from an 8-bit palletized surface to a 32-bit RGB one. A normal SDL_BlitSurface() works fine, but SDL_BlitScaled() doesn't display anything.

SDL_BlitScaled() does work correctly when blitting from RGB to RGB.

I've done a lot of searching, and found reports that SDL_BlitScaled() wasn't copying the alpha channel, and I should set SDL_BLENDMODE_NONE for both surfaces. I tried this, and it still doesn't work.

I'm using SDL2-2.0.1 on Window 7, MSVC 2008. Return codes from all functions are tested, but error checking removed below for clarity.

Code:

// Setup
m_pMainWnd = SDL_CreateWindow("Hello World!", 200, 100, 728, 480, SDL_WINDOW_SHOWN);
m_pWndSurf = SDL_GetWindowSurface(m_pMainWnd);
m_pBuffSurf = SDL_CreateRGBSurface(0, 182, 240, m_pWndSurf->format->BitsPerPixel, 0, 0, 0, 0); // BPP == 32
SDL_SetSurfaceBlendMode(m_pBuffSurf, SDL_BLENDMODE_NONE); // Tried both with and without this call
SDL_FillRect(m_pBuffSurf, NULL, SDL_MapRGBA(m_pBuffSurf->format, 0, 0, 0, 0xFF));

m_pSpriteSurf = SDL_CreateRGBSurface(0, 18, 32, 8, 0, 0, 0, 0);
SDL_SetPaletteColors(m_pSpriteSurf->format->palette, m_spriteCols, 0, 9);
SDL_SetSurfaceBlendMode(m_pSpriteSurf, SDL_BLENDMODE_NONE); // Tried both with and without this call
SDL_SetColorKey(m_pSpriteSurf, SDL_TRUE, 8); // Tried both with and without color key

// Drawing
SDL_Rect src, dst;
src.x = 0;
src.y = 0;
src.w = 9;
src.h = 16;
dst.x = x;
dst.y = y;
dst.w = 9;
dst.h = 16;

//SDL_BlitScaled(m_pSpriteSurf, &src, m_pBuffSurf, &dst); // Succeeds, but displays nothing
//SDL_BlitScaled(m_pSpriteSurf, NULL, m_pBuffSurf, &dst); // Succeeds, but displays nothing
SDL_BlitSurface(m_pSpriteSurf, &src, m_pBuffSurf, &dst); // Succeeds, correctly displays sprite

SDL_BlitScaled(m_pBuffSurf, NULL, m_pWndSurf, NULL); // Correctly stretches the buffer surface onto the main window surface
SDL_UpdateWindowSurface(m_pMainWnd);



Any suggestions are very welcome. Thanks!
SDL_BlitScaled not working on palletized surfaces
Jonas Kulla
Guest

2014-02-07 20:56 GMT+01:00 manskirtbrew:
Quote:
I'm trying to blit from an 8-bit palletized surface to a 32-bit RGB one. A normal SDL_BlitSurface() works fine, but SDL_BlitScaled() doesn't display anything.

SDL_BlitScaled() does work correctly when blitting from RGB to RGB.

I've done a lot of searching, and found reports that SDL_BlitScaled() wasn't copying the alpha channel, and I should set SDL_BLENDMODE_NONE for both surfaces. I tried this, and it still doesn't work.

I'm using SDL2-2.0.1 on Window 7, MSVC 2008. Return codes from all functions are tested, but error checking removed below for clarity.




Code:


// Setup
m_pMainWnd = SDL_CreateWindow("Hello World!", 200, 100, 728, 480, SDL_WINDOW_SHOWN);
m_pWndSurf = SDL_GetWindowSurface(m_pMainWnd);
m_pBuffSurf = SDL_CreateRGBSurface(0, 182, 240, m_pWndSurf->format->BitsPerPixel, 0, 0, 0, 0); // BPP == 32
SDL_SetSurfaceBlendMode(m_pBuffSurf, SDL_BLENDMODE_NONE); // Tried both with and without this call
SDL_FillRect(m_pBuffSurf, NULL, SDL_MapRGBA(m_pBuffSurf->format, 0, 0, 0, 0xFF));

m_pSpriteSurf = SDL_CreateRGBSurface(0, 18, 32, 8, 0, 0, 0, 0);
SDL_SetPaletteColors(m_pSpriteSurf->format->palette, m_spriteCols, 0, 9);
SDL_SetSurfaceBlendMode(m_pSpriteSurf, SDL_BLENDMODE_NONE); // Tried both with and without this call
SDL_SetColorKey(m_pSpriteSurf, SDL_TRUE, Cool; // Tried both with and without color key

// Drawing
SDL_Rect src, dst;
src.x = 0;
src.y = 0;
src.w = 9;
src.h = 16;
dst.x = x;
dst.y = y;
dst.w = 9;
dst.h = 16;

//SDL_BlitScaled(m_pSpriteSurf, &src, m_pBuffSurf, &dst); // Succeeds, but displays nothing
//SDL_BlitScaled(m_pSpriteSurf, NULL, m_pBuffSurf, &dst); // Succeeds, but displays nothing
SDL_BlitSurface(m_pSpriteSurf, &src, m_pBuffSurf, &dst); // Succeeds, correctly displays sprite

SDL_BlitScaled(m_pBuffSurf, NULL, m_pWndSurf, NULL); // Correctly stretches the buffer surface onto the main window surface
SDL_UpdateWindowSurface(m_pMainWnd);






Any suggestions are very welcome. Thanks!




Hi, not sure if related, but I had a similar problem where a surface
with alpha channel would become completely unusable after a
stretched blit: http://lists.libsdl.org/pipermail/sdl-libsdl.org/2013-September/090664.html