Class holding a valid drawing context. More...
#include <Context.hpp>
Public Member Functions | |
Context () | |
Default constructor. | |
~Context () | |
Destructor. | |
void | SetActive (bool active) |
Activate or deactivate explicitely the context. | |
Static Public Member Functions | |
static bool | SetReferenceActive () |
Make the current thread's reference context active. |
Class holding a valid drawing context.
If you need to make OpenGL / graphics 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, and for most of the classes from the Graphics package.
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 glClear(GL_DEPTH_BUFFER_BIT); // as well as using objects from the graphics package sf::Image image; image.LoadFromFile("image.png"); } // the context is automatically deactivated and destroyed // by the sf::Context destructor
Definition at line 46 of file Context.hpp.
sf::Context::Context | ( | ) |
Default constructor.
The constructor creates and activates the context
Definition at line 35 of file Context.cpp.
sf::Context::~Context | ( | ) |
Destructor.
The desctructor deactivates and destroys the context
Definition at line 43 of file Context.cpp.
void sf::Context::SetActive | ( | bool | active | ) |
Activate or deactivate explicitely the context.
active | True to activate, false to deactivate |
Definition at line 51 of file Context.cpp.
bool sf::Context::SetReferenceActive | ( | ) | [static] |
Make the current thread's reference context active.
This function is meant to be called internally; it is used to deactivate the current context by activating another one (so that we still have an active context on the current thread).
Definition at line 58 of file Context.cpp.