News | About | Download | Documentation | Development | Links

ClanLib 2D API - Overview - Part 2

Creating a display window

Lets make this overview a little bit less dry, and put in some code.

First, we initialize the components we need. Note that we use SetupGL::init(), to use OpenGL to display our graphics. Currently OpenGL is the only supported display target in ClanLib 0.7. DirectX7, DirectX8, XLib targets are under development.

We then create a displaywindow using CL_DisplayWindow with the size 640x480. Afterwards we clear the display using CL_Display::clear().

ClanDisplay has support for multiple displaywindows. You can switch between them, make any of them fullscreen / windowed, close them or create any new ones.

Note that we call the clear() function a bit differently than in our previous example. Now we are using objects directly without calling the static function CL_Display::clear().

Using the display component

There are two ways to operate the display component in ClanLib, either using static functions (like in ClanLib 0.6), or through objects (i.e. CL_GraphicContext or CL_DisplayWindow).

The static approach

Using static functions in CL_Display always works on the current active displaywindow and graphiccontext, so you don't have to get a pointer to a CL_DisplayWindow or CL_GraphicContext. The static functions in CL_Display (and any other class in ClanLib that uses static functions) is actually just routing calls to the currently selected objects.

To set the currently selected displaywindow, use:

Note that the last created window is always set to default, so unless you are using more than one displaywindow, you don't have to think about this.

Example of use:

The object approach

The second approach is to explicitly specify which object you want to call your function on. There are mainly two objects you will use, CL_DisplayWindow and CL_GraphicContext.

To get a displaywindow object, you can either use CL_Display::get_current_window() to retrieve the current selected displaywindow, or store the displaywindows pointers as you create them.

To get the graphiccontext of a displaywindow, you call the get_gc() method on your displaywindow.

Example of use:

Move on to part three.



Questions or comments, write to the ClanLib mailing list.