SFML community forums

Help => Window => Topic started by: HKei on February 02, 2013, 05:51:10 pm

Title: How to check whether or not an OpenGL context was created?
Post by: HKei on February 02, 2013, 05:51:10 pm
If context creation fails for some reason (e.g. the specified OpenGL version isn't supported by the driver), how does SFML behave and how can I react to this?

i.e. here

#include <iostream>
#include <string>
#include <stdexcept>

#include <GL/glew.h>

#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

const int MAJOR_VERSION=4;
const int MINOR_VERSION=2;

int main()
{
    try {
        sf::Window window{sf::VideoMode{800,600,32},"SFML Window", sf::Style::Default,
            sf::ContextSettings{24,8,2,MAJOR_VERSION,MINOR_VERSION}};
        // I wanna know here if there's a valid OpenGL 4.2 context, and if not,
       // throw an std::runtime_error
    } catch (std::runtime_error& e) {
        std::cerr << e.what() << std::endl;
    }
    return 0;
}
 
Title: Re: How to check whether or not an OpenGL context was created?
Post by: Laurent on February 02, 2013, 06:11:35 pm
It can never fail, there's always a version that your GPU supports.

Quote from: the tutorial
If any of these settings is not supported by the graphics card, SFML tries to find the closest valid match
Title: Re: How to check whether or not an OpenGL context was created?
Post by: Foaly on February 02, 2013, 06:13:45 pm
In SFML 2 you can get the OpenGL version, that SFML is using for the Context like this:
std::cout << "OpenGL version used: " << m_renderWindow.getSettings().majorVersion << "." << m_renderWindow.getSettings().minorVersion << std::endl;
Title: Re: How to check whether or not an OpenGL context was created?
Post by: HKei on February 02, 2013, 09:20:04 pm
I meant "fail" in the meaning of "I didn't get the version I requested". I remember using a library (don't remember which though) that would fall back to OpenGL 2.1if I requested 4.0, which wasn't supported by my graphics card at the time.  Or are you saying that doesn't happen?
Title: Re: How to check whether or not an OpenGL context was created?
Post by: Laurent on February 02, 2013, 10:14:49 pm
SFML will create a context with the closest supported version. If you request 4.0 but only support 3.1, you'll get a 3.1 context.