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

Author Topic: How to check whether or not an OpenGL context was created?  (Read 4465 times)

0 Members and 1 Guest are viewing this topic.

HKei

  • Newbie
  • *
  • Posts: 23
    • View Profile
How to check whether or not an OpenGL context was created?
« 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;
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to check whether or not an OpenGL context was created?
« Reply #1 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
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: How to check whether or not an OpenGL context was created?
« Reply #2 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;

HKei

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: How to check whether or not an OpenGL context was created?
« Reply #3 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to check whether or not an OpenGL context was created?
« Reply #4 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.
Laurent Gomila - SFML developer

 

anything