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

Author Topic: Viewporting the Viewport?  (Read 5225 times)

0 Members and 2 Guests are viewing this topic.

KRS

  • Newbie
  • *
  • Posts: 19
  • The burning you feel?
    • View Profile
    • Email
Viewporting the Viewport?
« on: April 27, 2021, 06:14:05 pm »
Hello! I'm making a user interface for my game(I want to do it by myself so I get more programming expirience). It's going ok but I have a problem that I can not resolve for long time. So as you can see in the video, I made some kind of scrollable window(this particular window will show up information about choosed item), and those black squares(its buttons for testing ;D ) are smoothly disappearing on the edge of the window. For this effect ViewPort was used. Im drawing these buttons to the separate view, than setting viewport so that it matches position of window and its size. And then when wheel is scrolled, or bar is mooved this viewPorted view is mooving up and down like so
windowView.move(0, +- step);
My problem is that I want to put, let's say, such window inside other window. So that Im kind of want to draw viewPort to other view. But as I understand viewPorts are drawn on the only default view of a target window, so its not really possible to put one "inside" another. Can someone help me if Im missing something? Maybe its dumb idea to use ViewPort for such task, and maybe it is other ways to "crop" content like this? Or maybe I actually can draw one ViewPort to other views? I will be happy to hear any advice. Also sorry for my horrible english. :P


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Viewporting the Viewport?
« Reply #1 on: April 28, 2021, 07:57:53 am »
It's doable but also a bit hacky to get right. You have to think about views as cameras/windows into another world. So all the views have to be defined "globally", which requires quite a bit of math to get right.
So your view inside a view, is more like a view on top of another view that is limited by the size of the other view, etc.

Alternatively you can use scissor testing, by grabbing this branch, (rebasing) and building SFML yourself.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Viewporting the Viewport?
« Reply #2 on: April 28, 2021, 08:07:56 am »
Another way would be use a render texture of the desired size. You can scroll it around using a view, then render it onto the screen where the viewport was. You could then also render it into another render texture that is also scrolling, etc.
(Could also save a bit on rendering by only redrawing into the render textures if something changed)

KRS

  • Newbie
  • *
  • Posts: 19
  • The burning you feel?
    • View Profile
    • Email
Re: Viewporting the Viewport?
« Reply #3 on: April 28, 2021, 02:45:26 pm »
Alternatively you can use scissor testing, by grabbing this branch, (rebasing) and building SFML yourself.

Yeah, I readed whole "Added support for clipping masks (Implements #1)" merge request brunch, I hope you guys will add it in some time in future. But I'm pretty newbie, as I understand "rebasing" means mooving  master brunch on top of the branch with future, so that now build will now have that future. Is this right? Anyways I think Im not familiar enough to do that, and I checked sf::RenderTexture's API as kojack wrote

Another way would be use a render texture of the desired size. You can scroll it around using a view, then render it onto the screen where the viewport was. You could then also render it into another render texture that is also scrolling, etc.
(Could also save a bit on rendering by only redrawing into the render textures if something changed)

And I think that'll do. At least I will try to use RenderTexture and if It will work, ill post results here. Thank you very much for ideas guys, you are awesome. ;D
« Last Edit: April 28, 2021, 09:15:10 pm by KRS »

 

anything