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

Author Topic: Resolution-Independent Rendering?  (Read 3317 times)

0 Members and 1 Guest are viewing this topic.

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Resolution-Independent Rendering?
« on: November 23, 2013, 04:35:14 pm »
Hi,
I'm new to smfl and I was wondering how I can scale my content to fit into the window without having a global scale variable which has to be used in every frame. I tried a simple approach with RenderTextures, but calling the GetTexture() method every frame seems to be VERY slow. Any ideas?

Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #1 on: November 23, 2013, 04:55:44 pm »
Did you try Views?

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #2 on: November 23, 2013, 05:00:11 pm »
No, but i found a tutorial doing EXACTLY what I'm doing, which is weird, since this method reduces the performance of my program to about 5 frames per second:

window.clear();
                renderTarget.clear();
        RenderFrame();
                renderTarget.display();
                contentTexture = renderTarget.getTexture();
                auto spr = sf::Sprite(contentTexture);
                window.draw(spr);
        window.display();

edit: I will use views now, I'm still interested why this does kill the performance.
« Last Edit: November 23, 2013, 05:03:28 pm by pixartist »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Resolution-Independent Rendering?
« Reply #3 on: November 23, 2013, 05:17:41 pm »
window.clear();
        renderTarget.clear();
        RenderFrame();
        renderTarget.display();
        //contentTexture = renderTarget.getTexture(); // NO-NO
        auto spr = sf::Sprite(renderTarget.getTexture());//Yes!
        window.draw(spr);//could be window.draw(sf::Sprite(renderTarget.getTexture()));
        window.display();
You're making a roundtrip to CPU and then back to GPU every frame now, which is terrible really and takes a long time.
https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Texture.cpp#L82
Back to C++ gamedev with SFML in May 2023

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #4 on: November 23, 2013, 05:21:07 pm »
There is no way to render to a texture on the GPU ?

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Resolution-Independent Rendering?
« Reply #5 on: November 23, 2013, 05:23:57 pm »
Your question makes no sense, everything is rendered on GPU but what you are doing is copying texture every frame(instead of using the render texture's texture directly) which takes a long time because it goes from GPU to CPU then back to GPU, you should do that instead:
window.clear();
        renderTarget.clear();
        RenderFrame();
        renderTarget.display();
        auto spr = sf::Sprite(renderTarget.getTexture());
        window.draw(spr);
        window.display();
Back to C++ gamedev with SFML in May 2023

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #6 on: November 23, 2013, 05:42:35 pm »
I did that first, it makes absolutely no difference. GetTexture does not return a pointer, so the texture will be copied anyway, won't it?

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Resolution-Independent Rendering?
« Reply #7 on: November 23, 2013, 05:46:55 pm »
It returns a const reference and Sprite takes a const reference so there is no copy then.
« Last Edit: November 23, 2013, 05:49:43 pm by FRex »
Back to C++ gamedev with SFML in May 2023

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #8 on: November 23, 2013, 05:57:00 pm »
okay thanks.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: Resolution-Independent Rendering?
« Reply #9 on: November 23, 2013, 05:57:25 pm »
The roudtrip via RenderTexture isn't really needed either (unless I didn't understand what you're trying to do), because as Ghosa pointed out, you can simply use an sf::View to make the content fit your window. The official tutorials explain views quite well, you should read it! :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #10 on: November 23, 2013, 06:37:32 pm »
Yeah but views can't be nested right ?

pixartist

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Resolution-Independent Rendering?
« Reply #11 on: November 23, 2013, 07:51:54 pm »
Also how do I draw a sprite with a fixed size? My sprite is always rendered fullscreen? I looked into the tutorials, they all describe relative scaling, but none shows how to draw s sprite with an absolute size.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
AW: Resolution-Independent Rendering?
« Reply #12 on: November 23, 2013, 10:34:01 pm »
Not sure what you mean with nested, but you can use multiple views.

There's no absolute scaling. A sprite simple represents a texture' axis aligned bounding box. If you want it absolute scaled you need to calculate the scaling yourself. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything