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
// 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--