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

Author Topic: [Solved] Image not drawn on render window  (Read 3430 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
[Solved] Image not drawn on render window
« on: August 31, 2012, 11:46:56 pm »
This is my code:

int main()
{ ///Test to learn how to draw individual bullets
   sf::RenderWindow window(sf::VideoMode(800, 600), "Bullet Testing"); ///Es necesario usar RenderWindow para dibujar algo.
   sf::Event event;
   sf::Texture Img;
   Img.loadFromFile("S_Circle.psd");
   sf::Sprite Sprite;
   Sprite.setTexture(Img, true);
   Sprite.setColor(sf::Color(255, 255, 255, 200));
   Sprite.setScale(2.f, 2.f);
   Sprite.setPosition(100, 25);

    while (window.isOpen())
    {  
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(Sprite);
        window.display();
    }
 return 0;
}
 

What I am trying to do is to call a 16x16 pixels photoshop file, the depth is 8 bits, therefore supported by SFML, but nothing is visible, the screen remains black as if I hadn't used the draw method. I've added more sets and even put them within the loop in the hope that it would change anything, but so far nothing has happened.

As there have been some changes between how you do things in 1.6 and 2.0rc, the 1.6 tutorial hasn't been much help in other than giving the base structure for the code and there aren't any graphics tutorials yet for 2.0rc, I've read the documentation over and over only to see if it was that I was omitting something, but haven't found anything noticeable so far.

I have drawn and made shapes visible, but this is my first time trying with a sprite and an external file. I use Code::Blocks. The image loads correctly, getting no compatibility problem message and the return is 0.

I'm not even trying to make the image move or anything for now, just make the image visible in the render window. But having read most of documentation of the classes I am using I still don't know what's wrong.

Thanks in advance for the help I may get. 
« Last Edit: September 01, 2012, 12:44:50 am by masskiller »
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Image not drawn on render window
« Reply #1 on: August 31, 2012, 11:57:10 pm »
What does the console output say?
Have you tried another image format? I mean it says that psd files are supported but that doesn't exclude that some specialisations of them may not be supported (e.g. PNG is supported but 8bit PNG aren't). ;)

The code seems okay, but to really test it if it's your machine or similar you need to also provide the image itself. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Image not drawn on render window
« Reply #2 on: September 01, 2012, 12:18:40 am »
The output was a successful run. I used an 8-bit psd (which is the supported type of psd), I also tried with a png to have nothing change.

I'll attach both images in this post.

Edit: The forum apparently doesn't allow me to upload the psd, so I just uploaded the png I used to test wether it was the file type or something other than that.

Re-edit: Earlier I tried the png file and nothing happened. I just tried and it did appear the way it should have. I'll try saving the psd into another type and try again.

It did appear after I saved the psd as a jpg. I think I remember now why it didn't work at first. When I wrote it I didn't write the window.display(), I feel stupid now, but at least it's working. If I hadn't made this post I propably wouldn't have rechecked. Thanks and sorry for the inconvenience.

I know this post looks bad with so many edits, but I have another noob question that I think doesn't deserve a thread: How do I cut the extra background pixels from the image? What I want is a clean circle/bullet and the white background behind it is annoying. Would doing it with SFML be better than doing it with another software?

[attachment deleted by admin]
« Last Edit: September 01, 2012, 12:43:39 am by masskiller »
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Image not drawn on render window
« Reply #3 on: September 01, 2012, 08:31:54 am »
I know this post looks bad with so many edits, but I have another noob question that I think doesn't deserve a thread: How do I cut the extra background pixels from the image? What I want is a clean circle/bullet and the white background behind it is annoying. Would doing it with SFML be better than doing it with another software?
Replace it with a transparent color in your favourite image editor, save it as PNG and load it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Marukyu

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Image not drawn on render window
« Reply #4 on: September 01, 2012, 02:16:41 pm »
How do I cut the extra background pixels from the image? What I want is a clean circle/bullet and the white background behind it is annoying. Would doing it with SFML be better than doing it with another software?

It is possible to do this in SFML by loading to an sf::Image first, applying createMaskFromColor() with the specific background color that you want removed, and then creating an sf::Texture from the image.
If you're working with white-transparent-looking images that have a black background, then they're likely supposed to be additively blended by the application. You can do this by setting the "blendMode" parameter of the sf::RenderStates you're using to "sf::BlendAdd".

Also, yay for Touhou! n_n
« Last Edit: September 01, 2012, 02:18:28 pm by def8x »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: [Solved] Image not drawn on render window
« Reply #5 on: September 01, 2012, 04:26:09 pm »
Ok thanks, btw nice Iku avatar def8x.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

 

anything