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

Author Topic: [SOLVED] Render to part of window  (Read 2742 times)

0 Members and 1 Guest are viewing this topic.

Anrock

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[SOLVED] Render to part of window
« on: March 25, 2014, 10:12:33 am »
Hello. I'm making hacker roguelike simulator, kinda like uplink + cataclysm-dda. Majority of time player spends in in-game OS hacking something.
Gui of this os consists of several "windows" like terminal, proxies list, resource consumption monitor and so on.
Contents of each window is drawed by in-game processes which are runned and managed by OS class instance.
Problem is, i don't know how to restrict process drawing to specified rectangle of game window.

Right now i have OperatingSystem::Draw(sf::RenderWindow&) method, which draws background and then calls draw-method of every active process with sf::RenderWindow and sf::Rect which is used by process instance to know where to draw it's contents. I don't like that process could potentially draw anywhere it wants, because whole window is passed in and i must manually take care of this. That's error-prone.

So, what options i know of at the moment:
1) sf::View & viewports looks like something related to my problem. Though in tutorials it looked like it just renders same content, but scaled or resized or something. Didn't investigate it further, though.
2) Maybe make os pass only rect to process's draw method, make process's draw method render to texture with size of passed rect and return this texture to OS and make OS take care of rendering the texture to game window in correct position. Possible drawback: rendering to texture, then rendering to window would decrease perfomance. Or not?

I think second approach is the most elegant one. It also abstracts process of window arrangement in OS.
What would you advise?

p.s. english isn't my native language, sorry about mistakes and if you didn't understand something please tell - i'll try to explain better


 
« Last Edit: March 25, 2014, 10:58:51 am by Anrock »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Render to part of window
« Reply #1 on: March 25, 2014, 10:32:11 am »
I guess there are other ways to do it, but using a view is probably the most elegant one. Thus before anything is drawn to an in-game window, you'd be creating a view based on the dimensions of the in-game window and set the viewport limited to the window's position, thus everything that is drawn, is guaranteed to be drawn onto that window. The advantage with this method is, that stuff gets cut-off when it would go outside of the window.

The render texture has also its advantage and can be easier to apply than the whole view/viewport logic, but it will require more resources if you use one render texture per window.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anrock

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Render to part of window
« Reply #2 on: March 25, 2014, 10:40:16 am »
@eXpl0it3r, so in draw method of OS i would construct view for each process, assign it to renderwindow and pass it to process, then reset renderwindow view and repeat for next process, right? Process will see passed window as usual renderwindow just with smaller size?
« Last Edit: March 25, 2014, 10:43:55 am by Anrock »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Render to part of window
« Reply #3 on: March 25, 2014, 10:49:19 am »
Well I'm not sure how your current draw process is, but yes you draw the window, set the view, draw the process' stuff, reset the view, repeat. If windows don't move often you could also save the views.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anrock

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Render to part of window
« Reply #4 on: March 25, 2014, 10:58:37 am »
Good. Thank you.