Jump to content

  • Log In with Google      Sign In   
  • Create Account


sfml, when loading images/textures ignore background color!?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 BaneTrapper   Members   -  Reputation: 1159

Like
0Likes
Like

Posted 22 October 2012 - 02:28 PM

Hello.
What i am trying to do is draw "Hero.png" 50x50 image to screen.
Problem is that i don't know how to ignore one color, so it does not draw a square of pink(color i use for background on "Hero.png" around my character. Therefore make the (255,0,255) color transparent on my sprite.

I cant find a function to do this in sfml.

in SDL the function is something like
//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
//SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );

//int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key); This is definition

SDL_SetColorKey(MyImage,
SDL_SRCCOLORKEY,
SDL_MapRGB(Screen->format, 255, 0, 255);


Edited by BaneTrapper, 22 October 2012 - 02:37 PM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


Sponsor:

#2 superman3275   Crossbones+   -  Reputation: 2011

Like
1Likes
Like

Posted 22 October 2012 - 02:37 PM

Why not open up your favorite photo editing program (paint.net is free and will do this), go to the magic wand tool (or use an eraser if you can't get paint.net) and select the pink, delete it. Unless your using MS Paint, it should be transparent when you save it. Why you'd use pink I don't know. If you don't have a magic wand here's how:

Use an eraser and delete all the pink. In SFML, you really can't do this without writing your own special and pointless line of code. However, I highly reccomend paint.net, because it makes doing this extremely easy.
EDIT:
The magic wand is a photo editing tool, google it.

Edited by superman3275, 22 October 2012 - 02:38 PM.

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#3 BaneTrapper   Members   -  Reputation: 1159

Like
0Likes
Like

Posted 22 October 2012 - 02:39 PM

Why not open up your favorite photo editing program (paint.net is free and will do this), go to the magic wand tool (or use an eraser if you can't get paint.net) and select the pink, delete it. Unless your using MS Paint, it should be transparent when you save it. Why you'd use pink I don't know. If you don't have a magic wand here's how:

Use an eraser and delete all the pink. In SFML, you really can't do this without writing your own special and pointless line of code. However, I highly reccomend paint.net, because it makes doing this extremely easy.
EDIT:
The magic wand is a photo editing tool, google it.


Well if that is the case ok then. And thank you!
Already edit all my images. Did it with gimp...
Again thanks you very much on fast reply.

Edited by BaneTrapper, 22 October 2012 - 02:42 PM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#4 Serapth   Crossbones+   -  Reputation: 5309

Like
1Likes
Like

Posted 22 October 2012 - 04:19 PM

If you already have images keyed to a certain color, you can set that color to be transparent using createMaskFromColor()

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS