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

Author Topic: Trouble setting the viewport  (Read 5913 times)

0 Members and 1 Guest are viewing this topic.

rcplusplus

  • Newbie
  • *
  • Posts: 15
    • View Profile
Trouble setting the viewport
« on: September 09, 2013, 02:28:16 am »
I made a very simple app to test JSFML and learn how to use views, but when I tried to set the viewport, nothing happened; the view still takes up the whole screen when it should take up half. I looked through my code a few times, but I was unable to catch the problem. I've tested similar code in the c++ version and it works, so I'm not sure if there's a difference in how I need to use the viewports in java or if I'm making a silly error...

If anyone could point me to the problem I'd really be grateful.

        RenderWindow window = new RenderWindow();
        ContextSettings ctxSettings = new ContextSettings(8);
        int screenWidth = 720;
        int screenHeight = 480;
        window.create(new VideoMode(screenWidth, screenHeight),
                              "JSFML Test",
                               RenderWindow.CLOSE | RenderWindow.TITLEBAR,
                               ctxSettings);

        window.setVerticalSyncEnabled(true);
       
        Texture bgTexture = new Texture();
       
        // load the bg picture with an InputStream
       
        Vector2i worldSize = bgTexture.getSize();
       
        RectangleShape bg = new RectangleShape();
        bg.setPosition(0,0);
        bg.setSize(new Vector2f(bgTexture.getSize()));
        bg.setTexture(bgTexture);
       
        View view = new View(window.getDefaultView().getCenter(), new Vector2f(screenWidth, screenHeight));
        view.setViewport(new FloatRect(0, 0, 0.5f, 1.f));
        window.setView(view);
       
        RectangleShape player1 = new RectangleShape();
        player1.setSize(new Vector2f(20, 20));
        player1.setPosition(0, 0);
        player1.setFillColor(Color.RED);
        int player1MoveSpeed = 200;
       
        Clock clock = new Clock();
        while (window.isOpen())
        {
            window.clear();
                   
            window.draw(bg);
            window.draw(player1);
                   
            window.display();

            float dt = clock.restart().asSeconds();        
           
            // move the player at `player1MoveSpeed`
           
            for (Event event : window.pollEvents())
            {
                switch (event.type)
                {
                    case CLOSED:
                        window.close();
                        break;
                }
            }
        }
 

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Trouble setting the viewport
« Reply #1 on: September 10, 2013, 11:36:18 am »
Hi, I cannot see any mistake in your code right now.
If the same works in C++, it might indeed be a binding problem. I will give this a shot later today and report back.
JSFML - The Java binding to SFML.

rcplusplus

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Trouble setting the viewport
« Reply #2 on: September 16, 2013, 01:02:30 am »
Hi sorry to bother you, but have there been any developments?

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Trouble setting the viewport
« Reply #3 on: September 16, 2013, 04:13:03 am »
Hello, sorry for the late reply, busy days / weeks / months. ;D

You found quite a simple but serious bug: float rectangles passed to C++ are read as integers, ie all values of your float rect are rounded down to 0. That was probably a copy & paste mistake and I've just pushed the fix. However, there is no quick workaround for you right now. :( I hope I can pack up another release one of these days.

Thanks for finding and reporting!
« Last Edit: September 16, 2013, 04:20:34 am by pdinklag »
JSFML - The Java binding to SFML.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Trouble setting the viewport
« Reply #4 on: September 19, 2013, 02:00:04 pm »
"Luckily", I didn't build one yet, because I just found and fixed another critical issue of a similar kind. :-[
Unless I find even more, I hope I can pack up another release this weekend.
JSFML - The Java binding to SFML.

Raranak

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Trouble setting the viewport
« Reply #5 on: November 15, 2013, 01:07:29 am »
Is there any news for another release soon? I've encountered the same problem with viewports.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Trouble setting the viewport
« Reply #6 on: November 28, 2013, 06:58:55 am »
I will release a new version this weekend.
However, Hiura and myself are currently not able to build Mac OS X binaries, so the update won't be available for Macs.  :-\
JSFML - The Java binding to SFML.

 

anything