Jump to content
  • Advertisement
Sign in to follow this  
Ptival

[SDL] VRAM, RAM & transparency

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ! I'm french so excuse my faults please :) Surfacetemp is a Software SDL_Surface* (RAM) Vramtemp is a Hardware SDL_Surface* (VRAM), filled in black (0,0,0) I've got a SDL_LoadBMP() who loades a bitmap in Surfacetemp. I want to copy this bitmap in Vramtemp and set it the Color Key (0,255,0)[GREEN] In the first time, I tried to blit Surfacetemp on Vramtemp, then set the color key of Vramtemp :
SDL_BlitSurface(Surfacetemp,NULL,Vramtemp,&Recttemp);
SDL_SetColorKey(Vramtemp, SDL_SRCCOLORKEY, SDL_MapRGB(Vramtemp->format, 0, 255, 0));

The bitmap is well blitted on Vramtemp, but the colorkey is not transparent in game ! Then I tried to set the colorkey green on Surfacetemp, to blit Surfacetemp on Vramtemp, then to set the colorkey black on Vramtemp :
SDL_SetColorKey(Surfacetemp, SDL_SRCCOLORKEY, SDL_MapRGB(Surfacetemp->format, 0, 255, 0));
SDL_BlitSurface(Surfacetemp,NULL,Vramtemp,&Recttemp);
SDL_SetColorKey(Vramtemp, SDL_SRCCOLORKEY, SDL_MapRGB(Vramtemp->format, 0, 0, 0));

This second method works, but I wonder why the first didn't work...This method doesn't satisfy me much :Is there a way to do it like I wanted to ? (I hope my english is understandable -___-) Thank you ! :)

Share this post


Link to post
Share on other sites
Advertisement
I'm thinking the problem is because the image loaded and the destination are not of the same format, so try something like this:

// Load the BMP
SDL_Surface* Surfacetemp = SDL_LoadBMP("YourBMP");
// Convert to the Vramtemp surface format
SDL_Surface* temp2 = SDL_ConvertSurface(Surfacetemp,Vramtemp->format,Vramtemp->flags );
// Blit this onto the Vramtemp surface
SDL_BlitSurface(Surfacetemp,NULL,Vramtemp,&Recttemp);
// Now set the color key
SDL_SetColorKey(Vramtemp, SDL_SRCCOLORKEY, SDL_MapRGB(Vramtemp->format, 0, 255, 0));



Here is the doc page for SDL_ConvertSurface. I'm not sure if the Vramtemp->flags is correct, so you may have to mess around with that.

Another option is to make sure that the Vramtemp is of the same display format as the main screen, then convert the BMP into the main screens format, then blit, and set transparency.


Vramtemp = SDL_DisplayFormat( SDL_GetVideoSurface() );
// Load the BMP
SDL_Surface* Surfacetemp = SDL_LoadBMP("YourBMP");
// Convert to the Vramtemp surface format
SDL_Surface* temp2 = SDL_DisplayFormat(SDL_GetVideoSurface());
// Blit this onto the Vramtemp surface
SDL_BlitSurface(Surfacetemp,NULL,Vramtemp,&Recttemp);
// Now set the color key
SDL_SetColorKey(Vramtemp, SDL_SRCCOLORKEY, SDL_MapRGB(Vramtemp->format, 0, 255, 0));



Here's the main doc function listing for reference for other functions. Good luck!

Share this post


Link to post
Share on other sites
I think I found a best solution using :


SDL_Surface*Vramtemp = SDL_AllocSurface(SDL_HWSURFACE|SDL_SRCCOLORKEY, Ramtemp->w, Ramtemp->h, 24, 0, 255, 0, 255);



Thanks for your help ;)

Share this post


Link to post
Share on other sites
Unless I'm misstaken, you use 24 bits, which is slow (not sure how slow, but just about everyone will warn you about it).. Make sure all surfaces are the same format..

Share this post


Link to post
Share on other sites
I've been down this road before. Your original surface is colorkeyed, so when you blit it onto the second surface it only blits the non-colorkeyed pixels. The colorkeyed pixels will be black or randomized on your destination surface. You have to turn off colorkeying when copying surfaces.

psuedo code

function CopySurface(origSurface, destSurface)
{
origColorKey = origSurface->colorkey;
turnOffColorkey(origSurface);

blitSurface(origSurface, destSurface)

// set colorkey
origSurface->colorKey = origColorKey;
destSurface->colorKey = origColorKey;
}



Share this post


Link to post
Share on other sites
Finally I didn't succeed...

Has anyone ever load an image in VideoRAM and Colorkey-d it ?

Share this post


Link to post
Share on other sites
Any reason why you don't just use SDL_DisplayFormat on the loaded graphics and forget about trying to explicitly handle video memory?

Share this post


Link to post
Share on other sites
Well, I tried this :

http://www.rafb.net/paste/results/Hv551q50.html

But the colorkey does'nt work :(Although if I force the loading in RAM, the color key is well put)



€dit -> Finally it works !

I've just deleted the second ColorKey :)

Thanks to evetyone ;)

[Edited by - Ptival on June 15, 2005 11:36:09 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!