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

Author Topic: Switching between Window Styles at runtime using GLEW  (Read 2695 times)

0 Members and 1 Guest are viewing this topic.

Zuzu_Typ

  • Newbie
  • *
  • Posts: 3
    • View Profile
Switching between Window Styles at runtime using GLEW
« 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--

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Switching between Window Styles at runtime using GLEW
« Reply #1 on: July 17, 2016, 09:02:35 pm »
"the window runs in a separate thread than my main application" - Why?

Zuzu_Typ

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Switching between Window Styles at runtime using GLEW
« Reply #2 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.
« Last Edit: July 17, 2016, 10:27:50 pm by Zuzu_Typ »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Switching between Window Styles at runtime using GLEW
« Reply #3 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)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything