I am trying out sfml and want to draw simple 2D graphic on top of 3D object.

sf::ContextSettings settings;
settings.depthBits = 24;
settings.majorVersion = 4;
settings.minorVersion = 1;//opengl v4.1
settings.attributeFlags =  sf::ContextSettings::Core;

sf::RenderWindow window( sf::VideoMode(1200,800),"sfml", sf::Style::Default, settings);

sf::CircleShape qs;

        sf::Event evnt;
        while (window.pollEvent(evnt)) {
            switch (evnt.type) {
                case sf::Event::Closed:
        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);



the sf::ContextSettings is set so that I can use openGL to draw 3D graphic. but with this settings, my qs not showing in the window. if I comment out the settings.majorVersion = 4; and settings.minorVersion = 1;, then it appear.

I am rather new and not sure how it works.

  1. Is this possible to be resolved?

  2. Is it correct to think that I want to use sfml for interface graphic and OpenGL for 3D? How do people normally do it?


1 Answer 1


I apologize if my answer in relation to this on Stack Overflow didn't properly explain the cause and effect of this.

The problem is that the SFML graphics module relies on some legacy OpenGL functionality. This means that if you create a (>= 3.2) core context then that functionality isn't available.

Thus you must specify that you need a backwards compatible context, which is done by setting:

settings.attributeFlags = sf::ContextSettings::Default;

Here's an excerpt from the SFML 2.4.2 documentation.

When requesting a context with a version greater or equal to 3.2, you have the option of specifying whether the context should follow the core or compatibility profile of all newer (>= 3.2) OpenGL specifications. For versions 3.0 and 3.1 there is only the core profile. By default a compatibility context is created. You only need to specify the core flag if you want a core profile context to use with your own OpenGL rendering. Warning: The graphics module will not function if you request a core profile context. Make sure the attributes are set to Default if you want to use the graphics module.

Note that when it comes to OS X there's another condition as well.

Apple only supports choosing between either a legacy context (OpenGL 2.1) or a core context (OpenGL version depends on the operating system version but is at least 3.2). Compatibility contexts are not supported. Further information is available on the OpenGL Capabilities Tables page. OS X also currently does not support debug contexts.

  • \$\begingroup\$ Seems like learning OpenGL with OS X is not a good options. \$\endgroup\$
    – sooon
    Commented Apr 11, 2017 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .