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

Author Topic: latest SFML snapshot doesn't restore resolution on linux  (Read 4321 times)

0 Members and 1 Guest are viewing this topic.

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« on: January 20, 2010, 08:42:17 pm »
I just downloaded the snapshot from here: http://www.sfml-dev.org/download.php. I'm running on Ubuntu 9.10 and after the application exited the resolution was not restored(it remained under the resolution of the sfml application). Is this a problem with SFML or i am forgetting something?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
latest SFML snapshot doesn't restore resolution on linux
« Reply #1 on: January 20, 2010, 08:47:28 pm »
Does the same thing happen with SFML 1.5?

Can you show your code?
Laurent Gomila - SFML developer

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #2 on: January 20, 2010, 08:48:25 pm »
Quote from: "Laurent"
Does the same thing happen with SFML 1.5?

Can you show your code?


The code is kind of long, i'll make some minimal example right away!

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #3 on: January 20, 2010, 09:14:31 pm »
Quote from: "AdrianM"
Quote from: "Laurent"
Does the same thing happen with SFML 1.5?

Can you show your code?


The code is kind of long, i'll make some minimal example right away!


Further tests did not show up the problem anymore. It just happened the first time i ran the sfml application. Now it seems it's working fine. I'll tests on other machines and report back!
Thanks for the fast reply!

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #4 on: January 20, 2010, 09:37:20 pm »
After further experimentation i have managed to reproduce(every time i was fast enough) a somewhat weird issue. First of all here's the code:

Code: [Select]


////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <fstream>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window

    sf::RenderWindow* pApplication = new sf::RenderWindow;
    pApplication->Create(sf::VideoMode(800, 600, 32),
"Testing!",sf::Style::Fullscreen);

    // Create a clock for measuring the time elapsed
    sf::Clock Clock;

    // Set the color and depth clear values
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Start the game loop
    while (pApplication->IsOpened())
    {
        // Process events
        sf::Event Event;
        while (pApplication->GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
            {
                delete pApplication;
                //pApplication->Close();
            }

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                pApplication->Close();

            // Resize event : adjust viewport
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }

        // Set the active window before using OpenGL commands
        // It's useless here because the active window is always the same,
        // but don't forget it if you use multiple windows
        pApplication->SetActive();

        // Clear color and depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Apply some transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.f, 0.f, -200.f);
        glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
        glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
        glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);

        // Draw a cube
        glBegin(GL_QUADS);

            glColor3f(1.f, 0.f, 0.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f( 50.f,  50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);

            glColor3f(1.f, 0.f, 0.f);
            glVertex3f(-50.f, -50.f, 50.f);
            glVertex3f(-50.f,  50.f, 50.f);
            glVertex3f( 50.f,  50.f, 50.f);
            glVertex3f( 50.f, -50.f, 50.f);

            glColor3f(0.f, 1.f, 0.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f(-50.f,  50.f,  50.f);
            glVertex3f(-50.f, -50.f,  50.f);

            glColor3f(0.f, 1.f, 0.f);
            glVertex3f(50.f, -50.f, -50.f);
            glVertex3f(50.f,  50.f, -50.f);
            glVertex3f(50.f,  50.f,  50.f);
            glVertex3f(50.f, -50.f,  50.f);

            glColor3f(0.f, 0.f, 1.f);
            glVertex3f(-50.f, -50.f,  50.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f,  50.f);

            glColor3f(0.f, 0.f, 1.f);
            glVertex3f(-50.f, 50.f,  50.f);
            glVertex3f(-50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f,  50.f);

        glEnd();

        // Finally, display the rendered frame on screen
        pApplication->Display();
    }

    return EXIT_SUCCESS;
}


Now for the problem: run the application and just after you see the desktop run it again but very fast, so the resolution switch is not complete. The application will either run in window mode or run as usual but not preserve the resolution. I'm running on Ubuntu 9.10 here. Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
latest SFML snapshot doesn't restore resolution on linux
« Reply #5 on: January 20, 2010, 11:36:12 pm »
Does it happen:

- when you close the window => "delete pApplication", which leads to an undefined behaviour because you don't exit the main loop and still use the pointer

or

- when you press escape => "pApplication->Close()", which leads to a memory leak because you never delete the window, and thus the desktop resolution is never restored

:?:
Laurent Gomila - SFML developer

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #6 on: January 20, 2010, 11:51:53 pm »
Quote from: "Laurent"
Does it happen:

- when you close the window => "delete pApplication", which leads to an undefined behaviour because you don't exit the main loop and still use the pointer

or

- when you press escape => "pApplication->Close()", which leads to a memory leak because you never delete the window, and thus the desktop resolution is never restored

:?:


When i press Escape. I thought close was just enough to close the window and restore the resolution, hmm...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
latest SFML snapshot doesn't restore resolution on linux
« Reply #7 on: January 21, 2010, 07:14:35 am »
Quote
When i press Escape. I thought close was just enough to close the window and restore the resolution, hmm...

That's right, actually ;)
But you should still delete your instance anyway. Or better: don't allocate it with new.
Laurent Gomila - SFML developer

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #8 on: January 21, 2010, 12:31:02 pm »
Quote from: "Laurent"
Quote
When i press Escape. I thought close was just enough to close the window and restore the resolution, hmm...

That's right, actually ;)
But you should still delete your instance anyway. Or better: don't allocate it with new.


Yes you are right! Here is another code. After compiling the application and running:

./Application & ./Application from the console the app is executed in two instances. The first instance is ok, but the second is just in windowed mode and can't be closed. Is this intended behaviour?

Code: [Select]


////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <fstream>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window

    sf::RenderWindow Application(sf::VideoMode(800, 600, 32),
"Testing!",sf::Style::Fullscreen);

    // Create a clock for measuring the time elapsed
    sf::Clock Clock;

    // Set the color and depth clear values
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Start the game loop
    while (Application.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (Application.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
            {
                Application.Close();
                break;
            }

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            {
                Application.Close();
                break;
            }
            // Resize event : adjust viewport
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }

        // Set the active window before using OpenGL commands
        // It's useless here because the active window is always the same,
        // but don't forget it if you use multiple windows
        Application.SetActive();

        // Clear color and depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Apply some transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.f, 0.f, -200.f);
        glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
        glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
        glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);

        // Draw a cube
        glBegin(GL_QUADS);

            glColor3f(1.f, 0.f, 0.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f( 50.f,  50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);

            glColor3f(1.f, 0.f, 0.f);
            glVertex3f(-50.f, -50.f, 50.f);
            glVertex3f(-50.f,  50.f, 50.f);
            glVertex3f( 50.f,  50.f, 50.f);
            glVertex3f( 50.f, -50.f, 50.f);

            glColor3f(0.f, 1.f, 0.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f(-50.f,  50.f,  50.f);
            glVertex3f(-50.f, -50.f,  50.f);

            glColor3f(0.f, 1.f, 0.f);
            glVertex3f(50.f, -50.f, -50.f);
            glVertex3f(50.f,  50.f, -50.f);
            glVertex3f(50.f,  50.f,  50.f);
            glVertex3f(50.f, -50.f,  50.f);

            glColor3f(0.f, 0.f, 1.f);
            glVertex3f(-50.f, -50.f,  50.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f,  50.f);

            glColor3f(0.f, 0.f, 1.f);
            glVertex3f(-50.f, 50.f,  50.f);
            glVertex3f(-50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f,  50.f);

        glEnd();

        // Finally, display the rendered frame on screen
        Application.Display();
    }

    return 0;
}


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
latest SFML snapshot doesn't restore resolution on linux
« Reply #9 on: January 21, 2010, 03:02:52 pm »
Quote
The first instance is ok, but the second is just in windowed mode and can't be closed. Is this intended behaviour?

Yes, only one fullscreen window is allowed.
Laurent Gomila - SFML developer

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #10 on: January 21, 2010, 04:06:47 pm »
Quote from: "Laurent"
Quote
The first instance is ok, but the second is just in windowed mode and can't be closed. Is this intended behaviour?

Yes, only one fullscreen window is allowed.


Okay, but sometimes it may happen something as i stated above: a sfml application exits from fullscreen mode, does not finish it's business with freeing resources and restoring resolution and i click another fullscreen application. In this moment the second application is just hanged there. Do you plan to address this issue in the future ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
latest SFML snapshot doesn't restore resolution on linux
« Reply #11 on: January 21, 2010, 04:12:40 pm »
Well, I'm not even sure that this is an issue. Can't you just wait until the resolution switch is finished after closing the SFML app?
Laurent Gomila - SFML developer

AdrianM

  • Newbie
  • *
  • Posts: 43
    • View Profile
latest SFML snapshot doesn't restore resolution on linux
« Reply #12 on: January 21, 2010, 07:04:48 pm »
Quote from: "Laurent"
Well, I'm not even sure that this is an issue. Can't you just wait until the resolution switch is finished after closing the SFML app?


Well, yes, i can do that, no problem, just wanted to see what are your thoughts about this and if one must considere it an issue or not. :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
latest SFML snapshot doesn't restore resolution on linux
« Reply #13 on: January 21, 2010, 07:11:22 pm »
Honestly I have no idea. What you could do is to test another fullscreen program instead of your SFML app, and see if you get the same thing.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6259
  • Thor Developer
    • View Profile
    • Bromeon
latest SFML snapshot doesn't restore resolution on linux
« Reply #14 on: January 21, 2010, 07:25:54 pm »
I don't know if this really helps, but a problem I recently came across:

This code leads to OpenGL errors because Close() is invoked and the OpenGL functions are still called (even if only for one frame). This can be fixed by a return statement (instead of break, which only exits the inner loop) after Application.Close();.

Laurent, maybe you should fix this in your OpenGL sample, too.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

 

anything