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

Author Topic: Render to a sub rectangle?  (Read 4490 times)

0 Members and 2 Guests are viewing this topic.

Pfhreak

  • Newbie
  • *
  • Posts: 11
    • View Profile
Render to a sub rectangle?
« on: February 06, 2009, 06:14:08 pm »
I'm building a top down, real time space game. I'd like to have a minimap available, and I'm somewhat stuck on how to do this.

I currently have a graphics manager, who maintains a list of graphics tokens (a wrapped sprite, basically). I also have an sf::View set up to properly show everything at the right scale. Because we needed to conform to box2d's standards, we scale all our images way down, then zoom the camera in.

My draw method currently iterates over my graphcis tokens and draws them, and everything is wonderful. Now, however, I'd like to redraw everything in that list, only to a 100x100 area in the corner of the screen.

Now, let's say my View shows 80x60 world units, and I want my minimap to show 500x500 world units. Now, my brain tells me that this is what sf::View was born to do. Seems like my graphics manager should be able to maintain a 'game view' and a 'map view' and just swap them out.

Only, there seems to be no way to render to anything but the framebuffer. I'd like to render everything to an image, for example, then draw that image in the upper right hand corner. Or tell my view to only draw on a sub section of the renderwindow. Is there a way to do this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Render to a sub rectangle?
« Reply #1 on: February 06, 2009, 08:13:12 pm »
You'll be able to draw to an image as soon as the RenderImage class is written ;)
Laurent Gomila - SFML developer

Pfhreak

  • Newbie
  • *
  • Posts: 11
    • View Profile
Render to a sub rectangle?
« Reply #2 on: February 06, 2009, 10:08:55 pm »
Awesome, I saw that in the header files for 1.4, but couldn't actually instantiate one, so I figured it was under construction.

Edit: How is this going to perform, compared to rendering to a renderwindow?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Render to a sub rectangle?
« Reply #3 on: February 06, 2009, 10:39:35 pm »
Quote
I saw that in the header files for 1.4

Really? What did you see?

Quote
How is this going to perform, compared to rendering to a renderwindow?

It will depend on the underlying implementation, which will depend on what your driver supports.
But it will be very fast.
Laurent Gomila - SFML developer

Pfhreak

  • Newbie
  • *
  • Posts: 11
    • View Profile
Render to a sub rectangle?
« Reply #4 on: February 06, 2009, 11:33:40 pm »
Quote from: "Laurent"
Quote
I saw that in the header files for 1.4

Really? What did you see?


Actually, I think I only saw the forward declaration in Image.hpp.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Render to a sub rectangle?
« Reply #5 on: February 07, 2009, 03:27:22 am »
Hmm, but do you need the minimap graphics look like the main screen? Because usually, minimaps use abstract symbols. Like this, you can for example easily distinguish enemy and allied units by different colors...

Otherwise, might the sf::RenderWindow::Capture() memberfunction be an option? Zooming out, capturing screenshot, saving to an image, zooming back again, loading a sprite from that image? That's probably not fast at all, but yes... ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Render to a sub rectangle?
« Reply #6 on: February 07, 2009, 09:04:57 am »
Quote
Otherwise, might the sf::RenderWindow::Capture() memberfunction be an option? Zooming out, capturing screenshot, saving to an image, zooming back again, loading a sprite from that image? That's probably not fast at all, but yes...

Yeah, it's like rendering to an image but using the window's buffer. It won't be as fast as direct rendering to an image, but it should be ok for now.
Using sf::Image::CopyScreen will even be faster than sf::RenderWindow::Capture.
Laurent Gomila - SFML developer

 

anything