News | About | Download | Documentation | Development | Links
Lets make this overview a little bit less dry, and put in some code.
// Init modules
CL_SetupCore::init();
CL_SetupDisplay::init();
CL_SetupGL::init();
// Create a window
CL_DisplayWindow window("My first window", 640, 480);
// Insert your code here
CL_Display::clear();
// Deinit modules
CL_SetupGL::deinit();
CL_SetupDisplay::deinit();
CL_SetupCore::deinit();
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.
// Create two windows
CL_DisplayWindow window1("My first window", 320, 200);
CL_DisplayWindow window2("My second window", 800, 600);
window1.get-gc()->clear();
window2.get-gc()->clear();
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().
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).
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:
CL_Display::set_current_window(CL_DisplayWindow *window)
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:
int width = CL_Display::get_width(); int height = CL_Display::get_height(); CL_Display::clear(CL_Color::white); CL_Display::draw_line(0, 0, width, height, CL_Color(255, 0, 0)); CL_Display::flip();
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:
CL_DisplayWindow *window = CL_Display::get_current_window(); CL_GraphicContext *gc = window->get_gc(); int width = window->get_width(); int height = window->get_height(); gc->clear(CL_Color(255, 255, 255)); gc->draw_line(0, 0, 100, 100, CL_Color::red); window->flip();