Archived

This topic is now archived and is closed to further replies.

TDragon

SDL transparent blitting prob

Recommended Posts

TDragon    679
I''m using the Simple DirectMedia Layer to make a platform game. Right now I''m having a problem with transparent blitting -- although I can set the transparent color fine, and everything runs fine without any errors, the blits still aren''t transparent. Here''s the code: SDL_Surface *screen; SDL_Surface *sprites; Uint32 val; screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); sprites = SDL_ConvertSurface(screen, fmt, SDL_HWSURFACE | SDL_SRCCOLORKEY); sprites = SDL_LoadBMP("sprites.ckl"); val = SDL_MapRGB(fmt, 0, 0, 0); if(SDL_SetColorKey(sprites, SDL_SRCCOLORKEY | SDL_RLEACCEL, val) != 0) { (display an error message) return FALSE; } SDL_BlitSurface(sprites, &keenrect, screen, &kscreenpos); This is a highly simplified version; I''ve left out everything that doesn''t seem important. Does anyone who uses SDL see anything wrong with my code? FYI, sprites.ckl is a 256-color RGB-stored bitmap, with the transparent areas set to 0, 0, 0 (black, obviously, although I originally tried it with white), and loads fine without returning any errors (and so do several others). Any other parameters not declared here are declared somewhere else, and didn''t seem relevant. If you need to know more, just ask. Twilight Dragon Win32 API Expert www.freewebz.com/j-world

Share this post


Link to post
Share on other sites
Kylotan    10008
Piece of advice - read through all the SDL documentation rather than using it as a reference. It''s not very comprehensively cross-referenced so you miss important information if you just dip into it.

Firstly, you want SDL_DisplayFormat, not SDL_ConvertSurface. Essentially they''re the same thing but SDL_DisplayFormat is semantically closer to what you really want in this example.

Secondly, from the docs for SDL_DisplayFormat: "If you want to take advantage of hardware colorkey or alpha blit acceleration, you should set the colorkey and alpha value before calling this function." So, do the colourkey stuff first, then call SDL_DisplayFormat (or SDL_ConvertSurface, on the occasions when you need that).

Let us know if that works.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Share this post


Link to post
Share on other sites
randomZ    163
I have a little question on how these SDL functions work.

SDL_LoadBMP() creates a new surface, right? So how does it matter whether you used SDL_DisplayFormat() before? Nevertheless, it works.

Also, what exactly does SDL_DisplayFormat() do? It creates a new surface based on the passed surface''s format. But what happens with pixel data, size etc.? What values do these have then?


My Wonderful Web Site (C++ SDL OpenGL Game Programming)

I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites