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

Author Topic: size of view different from size of window  (Read 5837 times)

0 Members and 2 Guests are viewing this topic.

nestor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
size of view different from size of window
« on: January 05, 2011, 01:28:42 pm »
Hi, I made a view that is smaller than the size of the window, and I noticed that the sprites on the view are scaled, they have a smaller size than it's original. This doesn't happen if the size of the view equals the size of the window. My question is if I can avoid the sprites scaling.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
size of view different from size of window
« Reply #1 on: January 05, 2011, 03:28:52 pm »
The view is basicly the range of pixels you want to fit into your viewport.

If your view equals the viewport(in your case, whole window), there is no apparent scale, and the ratio will look good, but when you try to make a view different from the viewport, you will obvious get stretching or shrinking. Views are great for zoom and panning features for games.

If you don't want any resizing, you should only offset your current view, move it(panning) by a few pixels, but don't change its Width or Height. If this is not what you're looking for, probably neither are Views.

Imagine you have a screen with 1024x768 resolution.
If you make a view of 10x768, you are trying to fit a tiny 10-pixel-width column into the whole window, so you'll get major stretching, up to the point it's unrecognizable ;D

Correct me if i'm wrong : )

nestor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
size of view different from size of window
« Reply #2 on: January 05, 2011, 08:56:36 pm »
Quote from: "DevilWithin"
The view is basicly the range of pixels you want to fit into your viewport.

If your view equals the viewport(in your case, whole window), there is no apparent scale, and the ratio will look good, but when you try to make a view different from the viewport, you will obvious get stretching or shrinking. Views are great for zoom and panning features for games.

If you don't want any resizing, you should only offset your current view, move it(panning) by a few pixels, but don't change its Width or Height. If this is not what you're looking for, probably neither are Views.

Imagine you have a screen with 1024x768 resolution.
If you make a view of 10x768, you are trying to fit a tiny 10-pixel-width column into the whole window, so you'll get major stretching, up to the point it's unrecognizable ;D

Correct me if i'm wrong : )


I disagree with that, because it is supposed that I can create a view that can occupy only a portion of the screen, the view doesn't fit all the screen, indeed I can have two or more views in the same screen.
As I said when I posted the question, the sprites got smaller than they really are, not bigger as would be if you were right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
size of view different from size of window
« Reply #3 on: January 05, 2011, 09:24:16 pm »
Quote
I disagree with that, because it is supposed that I can create a view that can occupy only a portion of the screen, the view doesn't fit all the screen, indeed I can have two or more views in the same screen.

Who said that? The documentation says that the contents of a view are always mapped to the entire window. Unless you use SFML 2.

Quote
As I said when I posted the question, the sprites got smaller than they really are, not bigger as would be if you were right.

They can't be smaller. Can you tell us more about how you setup the window and the view? Or maybe show the relevant code directly?
Laurent Gomila - SFML developer

nestor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
size of view different from size of window
« Reply #4 on: January 06, 2011, 05:54:42 pm »
Quote
Who said that? The documentation says that the contents of a view are always mapped to the entire window. Unless you use SFML 2.


I am missing someting here. If the view is mapped to the entire window, why I can make a view of certain dimensions, if it will fit all the screen?

My idea about views was that i could make a view for, suppose the world, and another for the user interface, for example, and put them together, and move/scrool only the world view, whereas the user interface view remains static.

Is there a way to achieve this?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
size of view different from size of window
« Reply #5 on: January 06, 2011, 06:12:24 pm »
You should really read more about OpenGL or General Graphics. Check what a Orthographic projection is : )

Your view will be the amount of the world you want to see in your screen, a rectangle..

If you want really independent screens within your screen, use render targets, or scissor test, or even multiple viewports.

But for an interface, its way simpler:

One sf::View for the world position and another sf::View for the default screen(normally equals the resolution)

Activate WorldView
-> Draw World
Activate DefaultView
-> Draw Interface

Because you render the interface relative to the origin (0,0) of the world, you activate the defaultview, so you get it rendered always the same independtly from where your world view is in the moment : )

All the change you make is into worldview, to pan and zoom, to see different objects, easy enough : )

Notice this way the views always fit the screen, its normal : )

Hope it helps

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
size of view different from size of window
« Reply #6 on: January 06, 2011, 06:16:18 pm »
Quote
I am missing someting here. If the view is mapped to the entire window, why I can make a view of certain dimensions, if it will fit all the screen?

There are two things that are totally different:
1- the 2D world, it is as large as you want and has no base unit (1 can be 1 cm, 1 m, 1 km, 1 inch, etc.)
2- the window, which size is defined in pixels, and which shows a part of your 2D world

Now what do SFML views do? They simply define what part of the 2D world is shown in the window. It's exactly the same thing as the real world (2D world), a camera (sf::View) and a television (sf::Window).

So when you change the size of the view, it changes the region of the world that is displayed in the (entire) window. If the area is smaller, things will appear bigger, like a zoom.
Laurent Gomila - SFML developer

nestor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
size of view different from size of window
« Reply #7 on: January 06, 2011, 06:55:11 pm »
I understand.

It will be great to have various views as "cameras" focusing on different parts of the world for example, all in different sections of the screen.

Besides having the view limited to a portion of the screen, I can know exactly what it is viewed of the world, by checking it's rectangle, and the sprites one.

In the game I am developing I must avoid drawing all the sprites of the world, because it will be too slow. So, when I detect that the rectangle of the view doesn't intersects the rectangle of the sprite, I know that I must remove the sprite from the drawing list.

But now, if I draw an interface, I must use another rectangle for what is really visible on the screen, as the sprites in the region of the interface won't be visible.

Well it is logic now, thank you very much for the advice.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
size of view different from size of window
« Reply #8 on: January 06, 2011, 07:13:24 pm »
Quote
It will be great to have various views as "cameras" focusing on different parts of the world for example, all in different sections of the screen.

In SFML 2 you can define the viewport, which is the area in the window where the contents of the view are displayed.

Quote
But now, if I draw an interface, I must use another rectangle for what is really visible on the screen, as the sprites in the region of the interface won't be visible.

Don't you have two separate views?
Laurent Gomila - SFML developer

nestor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
size of view different from size of window
« Reply #9 on: January 06, 2011, 07:39:18 pm »
Quote
But now, if I draw an interface, I must use another rectangle for what is really visible on the screen, as the sprites in the region of the interface won't be visible.

Quote
Don't you have two separate views?


Yes I have 2 views, but there are some sprites of the world that would be drawed in the area of the screen of the interface. Of course that won't happen because the interface is drawn after the world, so the sprites are overwritten in the screen by the interface.

I must avoid calling the draw method of those sprites, because it is useless and spend time, just a bit, but it does.

 

anything