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

Author Topic: Conceptual clarification of Views  (Read 1376 times)

0 Members and 1 Guest are viewing this topic.

jessopher

  • Newbie
  • *
  • Posts: 4
    • View Profile
Conceptual clarification of Views
« on: September 11, 2011, 10:02:35 am »
I'm very new to SFML, and am trying to wrap my head around how views are supposed to be used/understood.

Mostly I am a confused about point of reference, and relationship between SFML objects. I went through the view tutorial, and then downloaded and compiled the source at the bottom of the tutorial.

In the example, it says that the sizes of the two views (the user created, and default view) are the same. However, the background sprite is resized so that it is larger than both. My question, is where is the background 'drawn to', and what is the point of 2 views if you only ever actually 'view' one of them.

The ordering is throwing me off. First you create the background sprite, and its resized. Then you create the alternate view, with the same dimensions as the RenderWindow. Then you move the alternate view (im guessing in relation to the default view). You set the alternate as the default, and then draw to the window (or the view?). Right here everything starts breaking down for me. First, theres no room for the background sprite if we are drawing to a view, so I imagine the edges would be lopped off. But they are not.

Now we switch back to the default view, and draw the overlay (to the view?).

In the comments, when the alternate view is created, theres a mention of setting the center and halfsize's in relation to the background sprite. Why I see the relationship between the dimensions used, and the positions... but this all begs the question, what are these views views of? I am not seeing a clear relationship between the two views (if its a child-parent relationship).

If I had a few more examples of view scrolling maybe i'd understand.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Conceptual clarification of Views
« Reply #1 on: September 11, 2011, 10:49:37 am »
Quote
In the example, it says that the sizes of the two views (the user created, and default view) are the same. However, the background sprite is resized so that it is larger than both. My question, is where is the background 'drawn to'

The background, like every other 2D entity, is "drawn" in the 2D world. Then the view, acting like a camera, decides which area of the 2D scene will be displayed in the window.

Quote
what is the point of 2 views if you only ever actually 'view' one of them.

There's no point having 2 views if you only use one. In the tutorial's code, the second one is used to display the user interface (here it's just a single text showing the demo instructions).

Quote
Then you move the alternate view (im guessing in relation to the default view).

No, there's no relationship between views, never. A view is moved in the 2D world. It's exactly the same thing as moving a camera in a 3D world.

Quote
First, theres no room for the background sprite if we are drawing to a view, so I imagine the edges would be lopped off. But they are not.

I'm not sure I understand what you mean here. The background sprite is bigger than the view, so you can only see a part of it in the window.

Quote
what are these views views of? I am not seeing a clear relationship between the two views (if its a child-parent relationship).

There's no relation, views map areas of the 2D world to render targets (windows).
Laurent Gomila - SFML developer

jessopher

  • Newbie
  • *
  • Posts: 4
    • View Profile
Conceptual clarification of Views
« Reply #2 on: September 12, 2011, 01:18:01 am »
Alright, well then maybe this question will shed some light on it. Ive tried searching the forums, and ive looked through the documentation and tutorials. What happens when you switch between views? I've boiled my confusion down to a small subset of the sample code. Im not confused about any of the sprite stuff, or the centering of the secondary view. Mainly just how everything is drawn.
Code: [Select]

     // Set the view
        App.SetView(View);

        // Clear screen
        App.Clear();

        // Draw background
        App.Draw(Background);

So we are drawing the background here, 'in relation to' View, correct?
Code: [Select]

        // Draw cursor
...
        App.Draw(Cursor);

 basically the same thing is going on here.
Code: [Select]

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

        // Draw some instructions
        App.Draw(Text);

 and now we draw the interface... 'in relation to' the default view
Code: [Select]

        // Finally, display rendered frame on screen
        App.Display();


and here its all flipped out to the hardware for rendering

Is this a reasonable assessment of how things are happening here? If this is the case, then the camera analogy is what lost me.

edit:

basically, drawing is done with regard to the position of the view. The 2d world this is kind of confusing too, because the views arent 'of' the 2d world, per se, they are used to build it up. the position and size of the 'View' view is just used to determine what part of the background (both size and position within the image) are drawn.  I think ive got it. I think a projector is a better analogy than a camera. Again I am way green on SFML in general, and this is a much different concept than a 3d camera, which is not very much about construction, and more about rendering perspective.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Conceptual clarification of Views
« Reply #3 on: September 12, 2011, 07:59:35 am »
I think you got it.

However I still think that the camera analogy is a good one. There's really nothing different between a sf::View and a 3D camera, except the additional dimension. They even are the same thing internally (a projection matrix).
Laurent Gomila - SFML developer