Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using the Alpha Value embedded in an image file  (Read 1904 times)

0 Members and 1 Guest are viewing this topic.

pogrady

  • Newbie
  • *
  • Posts: 21
    • View Profile
Using the Alpha Value embedded in an image file
« on: January 22, 2013, 06:00:46 pm »
Hello,
How do I render an image that has RGBA values?  I would like to utilize the transparency i created in my paint program, but i am unsure how to use OpenGL. I know that there is a blend mode, and that utilization of OpenGL is simple in SFML since OpenGL is the backend, but i'm not sure which blend mode, or which function i should use.

I added this code after the ceation of my window:
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "SFML works!");

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_COLOR);
        window.pushGLStates();
 


If somebody has a link to a tutorial that would be awesome as I don't even know what this is called.  :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Using the Alpha Value embedded in an image file
« Reply #1 on: January 22, 2013, 06:37:41 pm »
Why not just use SFML instead of OpenGL?

sf::Texture tex;
tex.loadFromFile("image.png");
sf::Sprite sprite(tex);
// ...
window.draw(sprite);
// ...

The PNG format supports transparency and so thus SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

pogrady

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Using the Alpha Value embedded in an image file
« Reply #2 on: January 22, 2013, 06:54:56 pm »
Thanks. I was looking through the documentation about SOIL, but it didn't mention that PNG supports RGBA, only TGA, so i was trying to use TGA.

Just a question, but do i need to enable blending, or can i remove that?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Using the Alpha Value embedded in an image file
« Reply #3 on: January 22, 2013, 06:57:24 pm »
SFML is built on top of RGBA you don't need to do anything, just load the PNG. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

pogrady

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Using the Alpha Value embedded in an image file
« Reply #4 on: January 23, 2013, 12:09:56 am »
Thanks for your help.