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

Author Topic: Multiple views in a RenderWindow  (Read 10890 times)

0 Members and 1 Guest are viewing this topic.

reethok

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Multiple views in a RenderWindow
« on: May 16, 2013, 08:05:33 pm »
How do I put multiple views to a render window?

I have this code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow ventana(sf::VideoMode(300, 450, 32), "views",
                             sf::Style::Close);
    ventana.setFramerateLimit(30);

    sf::Sprite sprite;
    sf::Texture texture;

    texture.loadFromFile("asdf.png");
    sprite.setTexture(texture);

    sf::Sprite s_p;
    sf::Texture t_p;

    // 18x19
    t_p.loadFromFile("per.png");
    s_p.setTexture(t_p);

    sf::View view1(sf::FloatRect(0, 0, 149, 149));
    sf::View view2(sf::FloatRect(0, 0, 149, 149));
    view2.setRotation(90);
    sf::View view3(sf::FloatRect(0, 0, 149, 149));
    view3.setRotation(180);
    sf::View view4(sf::FloatRect(0, 0, 149, 149));
    view4.setRotation(270);
    sf::View view5(sf::FloatRect(0, 0, 149, 149));
    view5.setRotation(45);
    sf::View view6(sf::FloatRect(0, 0, 149, 149));
    view6..zoom(0.5f);

    for(int i = 0; i < 3600; i++)
    {
        ventana.clear();
        ventana.draw(sprite);
        ventana.display();
    }
}

I want to have a 150x150 world, in wich i have only a background image or color (preferably, for the 45° degree rotated view), and to set the views in the window this way:



What I want is to display the same world with different perspectives.

Thank you.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Multiple views in a RenderWindow
« Reply #1 on: May 16, 2013, 08:18:24 pm »
Read the tutorial on views, it has an exemple with split screen.

Note that you will have to draw your world 6 times, once in every view.
Laurent Gomila - SFML developer

reethok

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: Multiple views in a RenderWindow
« Reply #2 on: May 16, 2013, 08:46:04 pm »
Thanks for your answer. I have read the tutorial but it dont says how to draw the multiple views. Views are drawable items? So i draw each one in a different position of the window?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Multiple views in a RenderWindow
« Reply #3 on: May 16, 2013, 09:15:52 pm »
I have read the tutorial but it dont says how to draw the multiple views.
Read the sections "Defining how the view is viewed" and "Using a view". You have to draw the scene multiple times, every time with a different view.
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
Re: Multiple views in a RenderWindow
« Reply #4 on: May 16, 2013, 10:08:24 pm »
window.setView(view1);
window.draw(world);

window.setView(view2);
window.draw(world);

window.setView(view3);
window.draw(world);

etc.
Laurent Gomila - SFML developer

reethok

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: Multiple views in a RenderWindow
« Reply #5 on: May 17, 2013, 01:02:53 am »
Finally I did it. Thank you very much. Now my issue is that... the rotated views are a little distorted...



I think it is becouse the viewport dont have a exact size:

    sf::View view1(sf::FloatRect(0, 0, 150, 150));
    view1.setViewport(sf::FloatRect(0, 0, 0.5f, 0.33333f));

    sf::View view2(sf::FloatRect(0, 0, 150, 150));
    view2.setViewport(sf::FloatRect(0.5f, 0, 0.5f, 0.33333f));
    view2.setRotation(90);

    sf::View view3(sf::FloatRect(0, 0, 150, 150));
    view3.setViewport(sf::FloatRect(0, 0.33333f, 0.5f, 0.33333f));
    view3.setRotation(180);

    sf::View view4(sf::FloatRect(0, 0, 150, 150));
    view4.setViewport(sf::FloatRect(0.5f, 0.33333f, 0.5f, 0.33333f));
    view4.setRotation(270);

    sf::View view5(sf::FloatRect(0, 0, 150, 150));
    view5.setViewport(sf::FloatRect(0, 0.66666f, 0.5f, 0.33333f));
    view5.setRotation(45);

    sf::View view6(sf::FloatRect(0, 0, 149, 149));
    view6.setViewport(sf::FloatRect(0.5f, 0.66666f, 0.5f, 0.33333f));
    view6.zoom(0.5f);

I mean 0.33333f... etc. Should I use 1/3?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Multiple views in a RenderWindow
« Reply #6 on: May 17, 2013, 07:58:12 am »
Quote
I mean 0.33333f... etc. Should I use 1/3?
It wouldn't change anything.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Multiple views in a RenderWindow
« Reply #7 on: May 17, 2013, 12:31:45 pm »
I mean 0.33333f... etc. Should I use 1/3?
Just to make that clear, if you write it like this, you have an integer division. Therefore, 1/3 == 0.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

reethok

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: Multiple views in a RenderWindow
« Reply #8 on: May 17, 2013, 07:10:17 pm »
I know, just fast writing.

So, what should I do to mantain a perfect proportion? :/

 

anything