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

Author Topic: fullscreen and opengl  (Read 6631 times)

0 Members and 1 Guest are viewing this topic.

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
fullscreen and opengl
« on: January 09, 2011, 05:34:40 am »
Hi, simple question:

I have an OpenGL application. To toggle fullscreen i use window.create(..).
Especially switching TO fullscreen this doesn't seem to work too well (i get a green screen, which is the color i clear with glClearColor())

Do I have to reload all OpenGL related resources (such as settings and textures) when I switch to full-screen?
If so, is there another way?

Thanks
- Zenon

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
fullscreen and opengl
« Reply #1 on: January 09, 2011, 01:02:49 pm »
Quote
Do I have to reload all OpenGL related resources (such as settings and textures) when I switch to full-screen?

No, should be ok.

Which version of SFML do you use? Can you show your code?
Laurent Gomila - SFML developer

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
fullscreen and opengl
« Reply #2 on: January 09, 2011, 03:03:40 pm »
It doesn't seem to be ok, in fact it exibits behaviour as though I have to reload the opengl settings.
It's worth mentioning that I'm on a windows machine, actually, as I've read that that other media library, SDL, had this problem on windows. Of course, I switched to SFML, for more than just that problem.

Anyway, all my code is OO, and the project has gotten pretty big at this point, so I won't post all the code. These are the related parts:
Edit: WINDOW::<var name> is a global static class that stores any changes in resolution or state (like fullscreen), and allows all sub-classes read-only access to the window size, and a read-write for the fullscreen variable. I'm aware this is not very OOP-oriented.
1. The initiazliation happens like so:
Code: [Select]
// create the window
createWindow();

// set the framerate limit
currentWindow.SetFramerateLimit(tmpFRL); // tmpFRL is read from a file, or defaults to 0

// NOW
// init glew
GLenum error = glewInit();
if (error != GLEW_OK)
{
cout << "Error Initializing GLEW!\n";
cerr << "Error: " << glewGetString(error) << endl;
initOk = false;
}

// setup opengl
setupOpenGL();



2. Create window looks like this:
Code: [Select]
void Game::createWindow()
{
int targetWidth = (WINDOW::FULLSCREEN) ? (fullscreenWidth) : (WINDOW::WIDTH);
int targetHeight = (WINDOW::FULLSCREEN) ? (fullscreenHeight) : (WINDOW::HEIGHT);

currentWindow.Create(sf::VideoMode(targetWidth, targetHeight, 32),
"my title is here",
(WINDOW::FULLSCREEN) ? (sf::Style::Fullscreen) :
(sf::Style::Resize | sf::Style::Close | sf::Style::Titlebar),
currentWindowSettings);
fullscreen = WINDOW::FULLSCREEN;
WINDOW::HEIGHT = currentWindow.GetHeight();
WINDOW::WIDTH = currentWindow.GetWidth();
}


This load fine, even in fullscreen.

3. I try to change to fullscreen in the update(..) function, which is executed right before drawing begins. It looks like so:
Code: [Select]
void Game::update()
{
// World function update
pWorld->update(timer.GetElapsedTime() );
timer.Reset();

    // the WINDOW::FULLSCREEN can be set by a number of other classes
if (fullscreen != WINDOW::FULLSCREEN)
{
// need to go fullscreen
if (WINDOW::FULLSCREEN)
{
currentWindow.Create(sf::VideoMode(fullscreenWidth, fullscreenHeight, 32),
"my title was here",
sf::Style::Fullscreen,
currentWindowSettings);
}
// else, need to go windowed
else
{
currentWindow.Create(sf::VideoMode(windowedWidth, windowedHeight, 32),
"my title was here",
sf::Style::Resize | sf::Style::Close | sf::Style::Titlebar,
currentWindowSettings);
}
// update the global height and width to be correct
WINDOW::HEIGHT = currentWindow.GetHeight();
WINDOW::WIDTH = currentWindow.GetWidth();
// update the local state to match the global state
fullscreen = WINDOW::FULLSCREEN;
}
}


As mentioned the above code, when executed to go or leave fullscreen, messes up my graphics setup. More precisely, it seems to disable all lighting, and lower my farplane to something under 5.0. I haven't tested it with texture loading yet, but I doubt it will be good.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
fullscreen and opengl
« Reply #3 on: January 09, 2011, 04:21:27 pm »
Quote
More precisely, it seems to disable all lighting, and lower my farplane to something under 5.0. I haven't tested it with texture loading yet, but I doubt it will be good.

This is a very different problem. You have a new context when you re-create the window, so all your previous states are lost. But resources will still be available, because SFML has a global context that is shared with others, and which prevents resources to be lost like in all other OpenGL based libraries.
Laurent Gomila - SFML developer

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
fullscreen and opengl
« Reply #4 on: January 09, 2011, 04:34:32 pm »
Laurent, that's what I was asking in the first post, and actually what I assumed the problem is.

When you say resources are still available, do you mean that any loaded textures, for example, will still be reachable with their GLuint id? Or do you mean that they simply won't disappear from memory, though still be unreachable?

In any case, it looks like I can't switch to fullscreen with sf::window.create(..) without reloading the settings, at the least.

I've looked through the documentation for 1.6, I don't suppose there's something I missed and there's another way to toggle fullscreen?

Thanks.
- Zenon

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
fullscreen and opengl
« Reply #5 on: January 09, 2011, 04:53:02 pm »
Quote
Laurent, that's what I was asking in the first post, and actually what I assumed the problem is.

Yeah, sorry. I first focused on resources and totally forgot about states.

Quote
When you say resources are still available, do you mean that any loaded textures, for example, will still be reachable with their GLuint id? Or do you mean that they simply won't disappear from memory, though still be unreachable?

They are still reachable and usable with their ID.

Quote
In any case, it looks like I can't switch to fullscreen with sf::window.create(..) without reloading the settings, at the least.

You'll have to reload the states, yes.

Quote
I've looked through the documentation for 1.6, I don't suppose there's something I missed and there's another way to toggle fullscreen?

No, as far as I know fullscreen requires to re-create the window, and thus to create a new context.

However there may be something that I can do to help, if there's a Linux and OS X equivalent to wglCopyContext I can make a copy of the previous context when creating the new one.
Laurent Gomila - SFML developer

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
fullscreen and opengl
« Reply #6 on: January 09, 2011, 05:18:46 pm »
Well, I have separated my opengl init, all except light setup, which is a different class, I suppose I can try to re-initialize all the states after a switch. Or alternatively just care about the stored startup state in my ini file, and not allow runtime switching, until after a restart.

I'm not aware of any such functionality in Linux or OS X, especially since I have little no experience coding on OS X.

Thanks for your help, it's cleared up my problems, now I just have to find solutions.

- Zenon

trojanfoe

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
fullscreen and opengl
« Reply #7 on: April 04, 2011, 11:47:35 am »
@ZenonSeth: Did you get it working OK?  I am interested in how you did this as I am about to start using SFML to create a cross-platform game and the ability to toggle fullscreen in OpenGL is a big deal for me.