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

Author Topic: Fullscreen mode not working  (Read 6743 times)

0 Members and 1 Guest are viewing this topic.

akhena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Fullscreen mode not working
« on: June 09, 2012, 04:47:27 pm »
Hello everyone,

I would be glad to get some help here with my problem. It seems like I can't go in fullscreen mode without problems.

So first here is my minimal code :

#include <SFML/Graphics.hpp>

 int main()
 {
     // Create the main window
     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", sf::Style::Fullscreen);

     // Create a graphical text to display

     sf::Text text("Hello SFML", sf::Font::getDefaultFont(), 50);


     // Start the game loop
     while (window.isOpen())
     {
         // Process events
         sf::Event event;
         while (window.pollEvent(event))
         {
             // Close window : exit
             if (event.type == sf::Event::Closed)
                 window.close();
         }

         // Clear screen
         window.clear(sf::Color(200,200,128));

         // Draw the string
         window.draw(text);

         // Update the window
         window.display();
     }

     return EXIT_SUCCESS;
 }
 

When I run this, I get a black screen and nothing seems to work anymore. There are no response from keyboard inputs. I tried Ctrl-Alt-Del to no avail.

I'm on windows 7. Compiled with the latest SFML from GitHub. Tried to link on both release and debug dll.

I tried to debug to see how far I can go, but it stops at
void WindowImplWin32::switchToFullscreen(const VideoMode& mode)
{
    DEVMODE devMode;
    devMode.dmSize       = sizeof(devMode);
    devMode.dmPelsWidth  = mode.width;
    devMode.dmPelsHeight = mode.height;
    devMode.dmBitsPerPel = mode.bitsPerPixel;
    devMode.dmFields     = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;

    // Apply fullscreen mode
    if (ChangeDisplaySettings(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
 
this last line.

Might be obvious as it will indeed go in fullscreen.

If you see anything I could do to find what's wrong, that would be of great help.

PS : I realize this should have gone in the Window forum. If a mod wants to move it, be my guest. :)
« Last Edit: June 09, 2012, 04:55:47 pm by akhena »

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Fullscreen mode not working
« Reply #1 on: June 09, 2012, 05:37:01 pm »
The sf::Event::Closed verify when you close the window by clicking the X in the corner. Fullscreen remove that...and you don't verify any input, so it's just normal.
Add this in your event loop:
if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
        window.close();
That will fix it.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9946
    • View Profile
    • development blog
    • Email
Re: Fullscreen mode not working
« Reply #2 on: June 09, 2012, 07:41:42 pm »
I don't quite get what your problem is.

Does the program crash or is it still running?
What key input are you trying, because you don't catch any (except Alt+F14 which should emit sf::Event::Closed).

Does it all work in window mode?
Also what do you mean with 'it stops at' when debugging it?

Quote from: akhena
If a mod wants to move it, be my guest.
There are no mods, just Laurent but he reads ALL new posts everyday. :P

The sf::Event::Closed verify when you close the window by clicking the X in the corner. Fullscreen remove that...and you don't verify any input, so it's just normal.
Add this in your event loop:
if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
        window.close();
That will fix it.
This would only let him exit with the escape key (although he could do that already with Alt+F4) if he'd get as far as having a running window. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

akhena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Fullscreen mode not working
« Reply #3 on: June 10, 2012, 11:42:46 am »
Hello,

First thanks for taking a look into it. :)

I tried Rosme solution, but I was pretty convinced it wouldn't help. Sure I had no decent way to close my app, but Alt+F4 should have done the trick. Plus Ctrl+Alt+Del should have brought up the Task Manager. But it doesn't. Anyway I tried it, and here is my code.
 #include <SFML/Graphics.hpp>

 int main()
 {
     // Create the main window
     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window" , sf::Style::Fullscreen );

     // Create a graphical text to display

     sf::Text text("Hello SFML", sf::Font::getDefaultFont(), 50);

     // Start the game loop
     while (window.isOpen())
     {
         // Process events
         sf::Event event;
         while (window.pollEvent(event))
         {
             // Close window : exit
            /* if (event.type == sf::Event::Closed)
                 window.close();
                 */

             if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
         }

         // Clear screen
         window.clear(sf::Color(200,200,128));

         // Draw the string
         window.draw(text);

         // Update the window
         window.display();
     }

     return EXIT_SUCCESS;
 }
 
But the same problem happens.

I'll try to describe my problem a little bit better. When I launch that application, the screen turns completely black. And there's no reaction whatsoever to any mouse / keyboard input I do. So I "guess" the program crashes, but I don't see any confirmation of this. The only way out is the reset button of my desktop.

When I say I could only debug till that line, I meant that executing this last line, the screen turns completely black, and I can't go back to the debugger. I tried Alt+Tab, Alt+Esc and Alt+F4 and finally Alt+Ctrl+Del. But I'm still sitting in front of a black screen. So I have to reboot my computer.

This is rather cumbersome, because I don't see how to find out what's wrong, as I can't see anything.

Otherwise if I comment out the sf::Style::Fullscreen, I can successfully run the app in window mode. The background is greenish and I can red a white Hello SFML in the top left corner.

My config is : Intel i7-2600K using its on board graphic chip HD Graphics 3000. RAM : 8 Go. OS : Windows 7 64 bits.

PS : Nobody answered this, but I suppose the minimal code I provided works perfectly on other machines... ?
« Last Edit: June 10, 2012, 11:45:46 am by akhena »

capz

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Fullscreen mode not working
« Reply #4 on: June 10, 2012, 03:48:17 pm »
iv'e tried running the code snippet and for me, i can exit the app with escape, but in my case the background is set to the proper colour (same as windowed), but the sf::Text doesn't show up.

I also tried getting from info about the viewport:
sf::View view = window.getView();
sf::IntRect viewport = window.getViewport(view);
printf("viewport details: x %d, y %d, w %d, h %d\n", viewport.left, viewport.top, viewport.width, viewport.height);
 

which printed
Quote
viewport details: x 0, y 0, w 0, h 0

something does seem off ; /

I'm on Mac OS X (64bit),  Intel i7-2600, 12GB ram, AMD Radeon HD 6970M 2048 MB
« Last Edit: June 10, 2012, 03:50:00 pm by capz »

akhena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Fullscreen mode not working
« Reply #5 on: June 13, 2012, 03:02:54 pm »
Bump...

Anyone would have a brilliant idea to help me find the problem here ? :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9946
    • View Profile
    • development blog
    • Email
Re: Fullscreen mode not working
« Reply #6 on: June 13, 2012, 03:19:23 pm »
The source you provided works perfectly on my system with my libraries.

Which libraries are you using, did you compile them on your own?
Which compiler and debugger do you use?

Have you tried setting a break point somewhere in your application?

What antivirus software are you running on your PC?
Is there anyother software that could interfere with your applications?

Quote from: capz
viewport details: x 0, y 0, w 0, h 0
This doesn't look good, because the viewport should be set to (0, 0, 1, 1) so I'd spread over the whole window. (Starting at point (0, 0) using 100% in the right and bottom direction (1, 1)).
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

 

anything