Skip to content

class SF::Context
inherits Reference #

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
   glClear(GL_DEPTH_BUFFER_BIT)
end
# the context is automatically deactivated and destroyed
# by the SF::Context destructor

Included modules

SF::GlResource SF::NonCopyable

Class methods#

.active_context_id : UInt64 #

Get the currently active context's ID

The context ID is used to identify contexts when managing unshareable OpenGL resources.

Returns: The active context's ID or 0 if no context is currently active

View source

.extension_available?(name : String) : Bool #

Check whether a given OpenGL extension is available

  • name - Name of the extension to check for

Returns: True if available, false if unavailable

View source

.new(settings : ContextSettings, width : Int, height : Int) #

Construct a in-memory context

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

  • settings - Creation parameters
  • width - Back buffer width
  • height - Back buffer height
View source

.new #

Default constructor

The constructor creates and activates the context

View source

Methods#

#active=(active : Bool) : Bool #

Activate or deactivate explicitly the context

  • active - True to activate, false to deactivate

Returns: True on success, false on failure

View source

#finalize #

Destructor

The destructor deactivates and destroys the context

View source

#settings : ContextSettings #

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.

Returns: Structure containing the settings

View source