Jump to content
  • Advertisement
Sign in to follow this  
insanepotato

How can I clear data from SDL_Surface

This topic is 3710 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

Hello everybody. I am currently working on a map editor for my MMORPG(like everybody else xD) and ran into a little problem concerned the SDL_Surface. My Map contains 6 Layers of Tiles. Each of the layers maintain their own pre drawn SDL_Surface, to avoid blitting heaps of little tiles each frame. Normaly there is no problem, but in the map editor, I need to be able to clear off each layer's surface cache every time a tile is changed. I'm looking for a way to clear a surface. By clear, I mean the equivalent of freeing a surface and recreating it. So its completely empty. I tried to used SDL_FillRect with SDL_MapRGBA without much success. I have googled around a bit but didn't find much. Sorry if the question has already been answered. Thank you in advance. p.s While I'm at it, I'd like to say that gamedev seems to have a really nice, I'm not sure why I never joined until recently XD

Share this post


Link to post
Share on other sites
Advertisement
That would require me to free the old surface and then make a new one. Is there a way to achieve the same result without freeing and deleting surfaces? If not then I will use SDL_CreateRGBSurface. I'm just a little reluctant to do so if there's another way, because freeing and recreating the surface so frequently seems a little prone to error.

Thank you for your swift reply

Share this post


Link to post
Share on other sites
Surfaces have no notion of being clear. They have pixels and you set them to whatever colour you want. If SDL_FillRect didn't work, you're probably using it wrongly.

Share this post


Link to post
Share on other sites
With that said, I shall look around at my other code. I probably done something stupid somewhere that's unrelated to the SDL_FillRect call. lol


Thanks for the help.

Share this post


Link to post
Share on other sites
If you post your code we can take a look at it, often times a fresh pair of eyes can spot things in your code very quickly that you wouldn't otherwise notice. It has saved me more than a few times.

Share this post


Link to post
Share on other sites
Why use SDL_MapRGBA to get the color? If you are clearing it, do you really need a special color, or can it just be black?
If you must, try using SDL_MapRGB instead of SDL_MapRGBA, seeing as how SDL_FillRect doesn't draw transparently (Although, it really shouldn't matter).

SDL_FillRect(mySurface, NULL, 0x000000); //Fills 'mySurface' black.
SDL_FillRect(mySurface, NULL, 0xFFFFFF); //Fills 'mySurface' white.

SDL_FillRect(mySurface, NULL, 0xFF0000); //Fills 'mySurface' red.
SDL_FillRect(mySurface, NULL, 0x00FF00); //Fills 'mySurface' green.
SDL_FillRect(mySurface, NULL, 0x0000FF); //Fills 'mySurface' blue.

SDL_FillRect(mySurface, NULL, 0xFF00FF); //Fills 'mySurface' that obnoxious bright pink.
SDL_FillRect(mySurface, NULL, 0x00FFFF); //Fills 'mySurface' with cyan (light-blue).
SDL_FillRect(mySurface, NULL, 0xFFFF00); //Fills 'mySurface' with yellow.



Ofcourse, if you use different operating systems, the colors will change, but if you use just black or white, they'll stay constant between operating systems.

Share this post


Link to post
Share on other sites
Well, you use SDL_MapRGBA because it handles the format of the surface/endianness of the system for you. Those hex values are not going to give you the colors you say they will with a 16 bit surface on a PowerPC processor.

Share this post


Link to post
Share on other sites
Hello everybody, I would like to apologise for kicking such a fuss; and thank you all so much for your help.

I found the problem, and it was because I was filling to the wrong surface =_=. I guess I just over looked it every time I checked. SDL_FillRect did indeed work with SDL_MapRGBA to fulfil my needs. It fill the whole surface with transparency, which was what I was attempting to achieve.


Sorry for wasting your time, and thank you very much for your advice and help nonetheless.

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!