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

Author Topic: Views in SFML 2  (Read 5218 times)

0 Members and 1 Guest are viewing this topic.

Lox

  • Newbie
  • *
  • Posts: 14
    • View Profile
Views in SFML 2
« on: August 01, 2011, 09:46:45 pm »
Hey, I have a slight problem.

I have this:

SFMLWin.GetView().Viewport = (new SFML.Graphics.FloatRect(0.0f, 0.0f, SFMLWin.Width, SFMLWin.Height));

in my OnResize event.  However, it seems like the view doesn't completely fill the screen, which causes the edges of my images to become rigid (I have smooth turned off).  This was something I ran into when converting to SFML 2 from the current version.

What's wrong?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Views in SFML 2
« Reply #1 on: August 01, 2011, 10:37:56 pm »
The viewport is in homogeneous coordinates (0 to 1), not in pixels. So that you don't have to change it when the window is resized.
Laurent Gomila - SFML developer

Lox

  • Newbie
  • *
  • Posts: 14
    • View Profile
Views in SFML 2
« Reply #2 on: August 02, 2011, 06:12:01 am »
I would like my view to grow as my window grows.  That's why I reset the viewport on resize.  

However, it seems that when I do, the edges are very rigid and uneven.  I think this is because the view happens to be bigger than the actual window.

When I call a method

setWindowSize(320, 320);

which calls RenderWindow.SetSize(320,320), there ends up being a border on the right and bottom side of extra empty space. Does this have anything to do with the window's border? Here's the full code:

Code: [Select]
setWindowSize(uint width,uint height){
renderWin.GetView().Viewport = (new SFML.Graphics.FloatRect(0.0f, 0.0f, width, height));
renderWin.SetSize(width, height);
}

Lox

  • Newbie
  • *
  • Posts: 14
    • View Profile
Views in SFML 2
« Reply #3 on: August 02, 2011, 06:41:21 am »
Update: Yes the margin is the same size as the window border (left and bottom).  When I change the size of the border in my windows settings, the margin shrinks too when I restart the application.

Is there a way get the thickness of the border?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Views in SFML 2
« Reply #4 on: August 02, 2011, 07:44:33 am »
Quote
I would like my view to grow as my window grows. That's why I reset the viewport on resize.

It's not the viewport that you must resize (like I said it is done implicitely), but the view itself (with the Reset function).

Quote
Yes the margin is the same size as the window border (left and bottom). When I change the size of the border in my windows settings, the margin shrinks too when I restart the application.

That's very strange. Could you write a complete and minimal code that reproduces this problem?
Laurent Gomila - SFML developer

Lox

  • Newbie
  • *
  • Posts: 14
    • View Profile
Views in SFML 2
« Reply #5 on: August 02, 2011, 08:27:05 am »
Yes. Laughably I've been using the viewport instead of the view. Sorry for wasting your time. :(

In terms of reproducing the problem, I only see the margin when I reset the viewport VS the view.  I will try to get something up soon.  I have also noticed that the opposite happens (the view is cut off based on the borders of the window) when I set the view.

One last thing, is there a way to set a view's dimensions? I have been unsuccessful in setting GetView().size.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Views in SFML 2
« Reply #6 on: August 02, 2011, 08:34:25 am »
Quote
Also, is there a way to set a view's dimensions? I have been unsuccessful in setting GetView().size.

Either Reset or Size should work. But there might be something wrong in SFML.Net, I need to check something.
Laurent Gomila - SFML developer

Lox

  • Newbie
  • *
  • Posts: 14
    • View Profile
Views in SFML 2
« Reply #7 on: August 02, 2011, 10:13:23 pm »
Does the view have a property that get's its bounds?

Something like a FloatRect that stores Left, Right, Top, and Bottom.  I don't think viewport is what I'm looking for.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Views in SFML 2
« Reply #8 on: August 03, 2011, 07:58:36 am »
You can easily recompose the view's rectangle with its position and size (position is the center of the rectangle).

Indeed, the viewport is a totally different thing. It defines where the view is displayed (in the target window), not what it displays (from the 2D scene).
Laurent Gomila - SFML developer