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

Author Topic: Black screen during fullscreen  (Read 4808 times)

0 Members and 1 Guest are viewing this topic.

Gallaecio

  • Newbie
  • *
  • Posts: 5
    • View Profile
Black screen during fullscreen
« on: October 20, 2012, 04:53:22 pm »
This is my code:

// Project.
#include "main.hpp"

// Third-Party Libraries.

    // OpenGL.
    #include "GL/glu.h"

    // SFML.
    #include "SFML/Window.hpp"

using sf::VideoMode;
using sf::Window;
using std::string;

Main::Main(GLsizei width, GLsizei height)
{
    glEnable(GL_DEPTH_TEST);
    reshape(width, height);
}

void Main::reshape(GLsizei width, GLsizei height)
{
    m_width = width;
    m_height = height;

    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.0, width/height, 1.0, 100.0);

    glMatrixMode(GL_MODELVIEW);
}

void Main::render()
{
    glLoadIdentity();
    gluLookAt(0.0, 1.0, 6.0,
              0.0, 0.0, 0.0,
              0.0, 1.0, 0.0);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
        glColor3f(1.0, 0.0, 0.0);
        glVertex3f(2.0, 2.5, -1.0);
        glColor3f(0.0, 1.0, 0.0);
        glVertex3f(-3.5, -2.5, -1.0);
        glColor3f(0.0, 0.0, 1.0);
        glVertex3f(2.0, -4.0, 0.0);
    glEnd();

    glBegin(GL_POLYGON);
        glColor3f(1.0, 1.0, 1.0);
        glVertex3f(-1.0, 2.0, 0.0);
        glColor3f(1.0, 1.0, 0.0);
        glVertex3f(-3.0, -0.5, 0.0);
        glColor3f(0.0, 1.0, 1.0);
        glVertex3f(-1.5, -3.0, 0.0);
        glColor3f(0.0, 0.0, 0.0);
        glVertex3f(1.0, -2.0, 0.0);
        glColor3f(1.0, 0.0, 1.0);
        glVertex3f(1.0, 1.0, 0.0);
    glEnd();
}


/**
 * Main function.
 */

int main(int argc, char* argv[])
{
    GLsizei width = 1600;
    GLsizei height = 900;
    GLsizei color = 32;

    bool fullscreen = false;

    string appName = "OpenGL Tests";

    // Create the application window with an OpenGL context to draw on.
    Window window(VideoMode(width, height, color), appName);
    window.setVerticalSyncEnabled(true);

    // Interface initialization.
    Main app(width, height);

    // Main loop.
    while (window.isOpen())
    {

        app.render();
        glFlush();
        window.display();

        // Event handling.
        sf::Event event;
        while(window.pollEvent(event))
        {
            if (event.type == sf::Event::KeyReleased)
            {
                if (event.key.code == sf::Keyboard::F)
                {
                    fullscreen = !fullscreen;
                    if (fullscreen)
                    {
                        VideoMode videoMode = sf::VideoMode::getDesktopMode();
                        if (videoMode.isValid())
                        {
                            window.create(videoMode, appName, sf::Style::Fullscreen);
                        }
                    }
                    else
                    {
                        VideoMode videoMode(width, height, color);
                        if (videoMode.isValid())
                        {
                            window.create(videoMode, appName);
                        }
                    }
                }
            }
            else if (event.type == sf::Event::Resized)
            {
                app.reshape((GLsizei) event.size.width, (GLsizei) event.size.height);
            }
            else if (event.type == sf::Event::Closed)
            {
                window.close(); break;
            }
        }

    }

  return 0;
}
 

It works just fine in windowed mode, but when I turn on the fullscreen mode by pressing F, the screen turns black and the figures rendered with OpenGL are not there. I can only see the system cursor.

Then, I press F again and I get back to the windowed mode normally. I can still see the figures, and I can resize the window and get them repainted correctly.

I am working under Chakra Linux using SFML 2.0 RC 1.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Black screen during fullscreen
« Reply #1 on: October 20, 2012, 09:30:56 pm »
And you're sure that it's not one thing in your functions that throw off things?
I don't really know something about OpenGL and I don't want to try to understand the code, but since the code is still quite big for a minimal & complete example, I guess it could be caused by some parts of your code.
Try to remove everything that's not necessary.

Also have you tried a 'normal' SFML example particularly the OpenGL example? Do they work fine in fullscreen mode?
Is your graphics driver uptodate?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gallaecio

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Black screen during fullscreen
« Reply #2 on: October 21, 2012, 07:27:45 am »
The OpenGL example works perfectly well, but it does not use fullscreen. My OpenGL code works too. The problem is only during fullscreen.

I posted so much code just in case, the relevant part should just be:

    bool fullscreen = false;
    while (window.isOpen())
    {
        // [OpenGL Code Runs here, omitted]
        window.display();

        sf::Event event;
        while(window.pollEvent(event))
        {
            if (event.type == sf::Event::KeyReleased)
            {
                if (event.key.code == sf::Keyboard::F)
                {
                    fullscreen = !fullscreen;
                    if (fullscreen)
                    {
                        VideoMode videoMode = sf::VideoMode::getDesktopMode();
                        window.create(videoMode, appName, sf::Style::Fullscreen);
                    }
                    else
                    {
                        VideoMode videoMode(width, height, color);
                        window.create(videoMode, appName);
                    }
                }
            }
            else if (event.type == sf::Event::Resized)
            {
                app.reshape((GLsizei) event.size.width, (GLsizei) event.size.height);
            }
            else if (event.type == sf::Event::Closed)
            {
                window.close(); break;
            }
        }
    }
 

Anyone sees something wrong in that code? The application does go fullscreen, but does not show the OpenGL figures, which are drawn based on the height and width of the screen (so they should appear).

Gallaecio

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Black screen during fullscreen
« Reply #3 on: October 21, 2012, 07:53:26 am »
After reading the topic opengl and fullscreen, I tried executing the OpenGL code of the reshape() function right after entering fullscreen mode. Now it works! :)

The code in question, displayed in my original post, was:

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(90.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 

 

anything