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

Author Topic: Porting from CImg - Vertcal axis now inverted  (Read 2002 times)

0 Members and 1 Guest are viewing this topic.

SuperVGA

  • Newbie
  • *
  • Posts: 3
    • View Profile
Porting from CImg - Vertcal axis now inverted
« on: October 08, 2018, 05:36:19 pm »
Hi Everyone,

I picked up SFML in the weekend hoping to replace my existing graphics library with SFML.
CImg is good for direct graphics manipulations, better actually, but it's not fast and it does graphics only.
I'm hoping to use the abstractions for networking and audio too, and switch from -std=gnu11 to c++11,
so I can finally use STL threads. That's the backstory.

Anyways, while porting my drawing procedures, I do a switch from Image, over Texture and Sprite, then RenderTexture.
An awful lot of conversions - I realise that, I thought Image would be something I could write to, but after discovering RenderTexture, I'll probably remove the first conversions.

To dump the image, I convert back from over Texture to Image. The image is crisp and exactly like the original, except that the Y-axis is inverted entirely. This even goes for the bits of text I've drawn (and on the RenderTexture mind you, so unless a transform matrix was copied from the prior types. I think the culprit is to be found in the last conversions).

At first, after making an Image with the right background colour:

sf::Texture texture;
texture.loadFromImage(image);
sf::Sprite sprite(texture);
sf::RenderTexture renderTexture;
renderTexture.create(image.getSize().x, image.getSize().y);
renderTexture.draw(sprite);

I do my drawing using a classic origo-in-top-left-corner approach, then save the image to a file like so:

image = renderTexture.getTexture().copyToImage();
image.saveToFile(filename.c_str());

Thank you for your help, and thanks SFML devs for making this broad library for me to use.

SuperVGA

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Porting from CImg - Vertcal axis now inverted
« Reply #1 on: October 08, 2018, 08:54:57 pm »
Just to update this one; I found out why. It's a bug. An old one: ;D
https://github.com/SFML/SFML/issues/1319

I'm using 2.4.2 since I went with the regular GCC version coming with the regular MinGW installer.
I guess this has since been fixed.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Porting from CImg - Vertcal axis now inverted
« Reply #2 on: October 08, 2018, 10:38:19 pm »
It's not a bug (and the bug you linked to only happened after copying a texture and is already fixed in 2.4.2). You have to call "renderTexture.display();" after drawing to the render texture (https://www.sfml-dev.org/documentation/2.5.0/classsf_1_1RenderTexture.php#af92886d5faef3916caff9fa9ab32c555).
TGUI: C++ SFML GUI

SuperVGA

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Porting from CImg - Vertcal axis now inverted
« Reply #3 on: October 09, 2018, 06:42:50 pm »
It's not a bug (and the bug you linked to only happened after copying a texture and is already fixed in 2.4.2). You have to call "renderTexture.display();" after drawing to the render texture (https://www.sfml-dev.org/documentation/2.5.0/classsf_1_1RenderTexture.php#af92886d5faef3916caff9fa9ab32c555).

Many thanks for this, texus - it works nicely now, and I no longer feel like I'm misusing SFML.
It felt silly to perform the same sequence of copies again to flip back. :)

As well as similar items to the bug I linked to, it added to my confusion that I saw m_pixelsFlipped in RenderTexture.cpp. I'm sure there are valid reasons to handle something like this internally, though.

It's very satisfying to see things come together - my drawing wrapper now produces the same output as with CImg - now onward to the per-pixel operations. ;)

Thanks again - and have a great day/night.

 

anything