SFML community forums

Help => Window => Topic started by: Zuzu_Typ on July 17, 2016, 04:17:32 pm

Title: Switching between Window Styles at runtime using GLEW
Post by: Zuzu_Typ on July 17, 2016, 04:17:32 pm
Hello Community,

I'm currently working on a small game engine in C++ using SFML.

Since SFML doesn't support modern OpenGL out of the box, I use my own GLEW context.

I know you could simply disable the compatibility mode in SFML, but as I'm fairly new to C++ and I always have issues with Cmake so that seems out of question.

So my problem is that when I try to switch between sf::Style::Default and sf::Style::Fullscreen, the window stops working and freezes.

I'll try to give you only the necessary code, which is hard, since the window runs in a separate thread than my main application.

Here is what the toggleFullscreen function looks like

Code: [Select]
// close the window
window.close();
exists = false;

fullscreen = (fullscreen) ? false : true; // enable fullscreen

// recreate the window
if (fullscreen) {
sf::VideoMode mode(fullWidth, fullHeight); // fullscreen resolution

window.create(mode, title, sf::Style::Fullscreen); // use fullscreen style
}
else {
sf::VideoMode mode(width, height); // default resolution

window.create(mode, title, sf::Style::Default); // use default style
}

exists = true; // declare the window as opened

glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize GLEW" << std::endl;
Error::handle(1);
}

// Define the viewport dimensions
if (fullscreen) {
glViewport(0, 0, fullWidth, fullHeight);
}
else {
glViewport(0, 0, width, height);
}

// here I do OpenGL stuff, like creating shaders, buffers and prepare the texture that's supposed to be displayed

// note that I do not re use the already created shaders, since this part of the code is only temporary and new

// reload projection matrix
memory.projection = glm::perspective(45.0f, static_cast<GLfloat>(width) / static_cast<GLfloat>(height), 0.1f, 100.0f);

Is this sufficient code?

I also attached a GIF showing my output.

Thank you for your help and best regards,
--Zuzu_Typ--
Title: Re: Switching between Window Styles at runtime using GLEW
Post by: Jesper Juhl on July 17, 2016, 09:02:35 pm
"the window runs in a separate thread than my main application" - Why?
Title: Re: Switching between Window Styles at runtime using GLEW
Post by: Zuzu_Typ on July 17, 2016, 09:55:48 pm
To be able to calculate stuff independant of Vsync or framerate limit.

Also to take advantage of multi-threading and to challenge myself.

EDIT --
Actually, now that you say, it is probably a better idea to have the window in the main thread and instead put some of the calculations into a thread.

That should reduce problems with events.
Title: Re: Switching between Window Styles at runtime using GLEW
Post by: Hapax on July 17, 2016, 11:32:51 pm
To be able to calculate stuff independant of Vsync or framerate limit.
This can be done without multi-tasking.
(I should probably link this (http://gafferongames.com/game-physics/fix-your-timestep/))