Hi,
My code is causing errors in the console window:
"Failed to activate the window's context" and sometimes something about creating the OpenGL context.
The errors are thrown repeatedly.
#include <SFML/Graphics.hpp>
#include <atomic>
#include <iostream>
struct gameClass
{
gameClass(): cSettings(24,8,16,4,4), window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, cSettings) {}
sf::ContextSettings cSettings;
sf::Window window;
std::atomic_bool glHasControl;
};
int drawGLScene(gameClass* gameCore) // Here's where we draw
{
gameCore->window.setActive(true);
while (gameCore->glHasControl.load(std::memory_order_acquire))
gameCore->window.display();
gameCore->window.setActive(false);
return 1; // Everything went OK
}
int main()
{
gameClass gameCore;
sf::ContextSettings settings = gameCore.window.getSettings();
std::cout << "depth bits:" << settings.depthBits << std::endl;
std::cout << "stencil bits:" << settings.stencilBits << std::endl;
std::cout << "antialiasing level:" << settings.antialiasingLevel << std::endl;
std::cout << "version:" << settings.majorVersion << "." << settings.minorVersion << std::endl;
gameCore.window.setVerticalSyncEnabled(true);
gameCore.glHasControl.store(true, std::memory_order_release);
sf::Thread displayThread(&drawGLScene, &gameCore);
displayThread.launch();
while (gameCore.window.isOpen())
{
sf::Event event;
while (gameCore.window.pollEvent(event))
{
gameCore.glHasControl.store(false, std::memory_order_release);
displayThread.wait();
gameCore.window.setActive(true);
if (event.type == sf::Event::Closed)
gameCore.window.close();
}
}
return 0;
}
-Jared