Documentation of SFML 2.4.1

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
sf::Context Class Reference

Class holding a valid drawing context. More...

#include <Context.hpp>

Inheritance diagram for sf::Context:
sf::GlResource sf::NonCopyable

Public Member Functions

 Context ()
 Default constructor. More...
 ~Context ()
 Destructor. More...
bool setActive (bool active)
 Activate or deactivate explicitly the context. More...
const ContextSettingsgetSettings () const
 Get the settings of the context. More...
 Context (const ContextSettings &settings, unsigned int width, unsigned int height)
 Construct a in-memory context. More...

Static Public Member Functions

static bool isExtensionAvailable (const char *name)
 Check whether a given OpenGL extension is available. More...
static GlFunctionPointer getFunction (const char *name)
 Get the address of an OpenGL function. More...
static const ContextgetActiveContext ()
 Get the currently active context. More...

Static Private Member Functions

static void ensureGlContext ()
 Empty function for ABI compatibility, use acquireTransientContext instead. More...

Detailed Description

Class holding a valid drawing context.

If you need to make OpenGL calls without having an active window (like in a thread), you can use an instance of this class to get a valid context.

Having a valid context is necessary for every OpenGL call.

Note that a context is only active in its current thread, if you create a new thread it will have no valid context by default.

To use a sf::Context instance, just construct it and let it live as long as you need a valid context. No explicit activation is needed, all it has to do is to exist. Its destructor will take care of deactivating and freeing all the attached resources.

Usage example:

void threadFunction(void*)
sf::Context context;
// from now on, you have a valid context
// you can make OpenGL calls
// the context is automatically deactivated and destroyed
// by the sf::Context destructor

Definition at line 50 of file Context.hpp.

Constructor & Destructor Documentation

sf::Context::Context ( )

Default constructor.

The constructor creates and activates the context

sf::Context::~Context ( )


The destructor deactivates and destroys the context

sf::Context::Context ( const ContextSettings settings,
unsigned int  width,
unsigned int  height 

Construct a in-memory context.

This constructor is for internal use, you don't need to bother with it.

settingsCreation parameters
widthBack buffer width
heightBack buffer height

Member Function Documentation

static const Context* sf::Context::getActiveContext ( )

Get the currently active context.

The currently active context or NULL if none is active
static GlFunctionPointer sf::Context::getFunction ( const char *  name)

Get the address of an OpenGL function.

nameName of the function to get the address of
Address of the OpenGL function, 0 on failure
const ContextSettings& sf::Context::getSettings ( ) const

Get the settings of the context.

Note that these settings may be different than the ones passed to the constructor; they are indeed adjusted if the original settings are not directly supported by the system.

Structure containing the settings
static bool sf::Context::isExtensionAvailable ( const char *  name)

Check whether a given OpenGL extension is available.

nameName of the extension to check for
True if available, false if unavailable
bool sf::Context::setActive ( bool  active)

Activate or deactivate explicitly the context.

activeTrue to activate, false to deactivate
True on success, false on failure

The documentation for this class was generated from the following file: