Chapter 2. Getting started

Table of Contents

Before creating widgets.
Initializing libUFO.
Connection to the windowing system.
Setting up a UFO window.
UFO in custom OpenGL windows.
Creating our first widget.
Running a UFO application.
The main loop
The main loop for custom windows

In this chapter you will learn the basic concepts of libUFO.

There are three sub-sections which explain the basic parts of the "Hello, World!" example.

Before creating widgets.

Initializing libUFO.

Before creating any other UFO object, you have to create the UFO toolkit.

This can be done by creating an instance of UXToolkit

UXToolkit tk;

The toolkit does some basic initialization, loads external modules and sets up some UFO properties.

Note

UToolkit itsself is a pure virtual class which may be implemented by yourself to give full control over global UFO methods.

Connection to the windowing system.

At next, you have to create a connection to the underlying windowing system to open an OpenGL window.

This can be done by creating an instance of UXDisplay

UXDisplay display;

The Display is responsible for loading system ressources (e.g. libraries like OpenGL, the windowing library like X11, Win32, QT etc).

Note

UDisplay itsself is a pure virtual class which may be implemented by yourself to give full control over UFO windowing.

You can specify explicitly which video driver you want to load by using a string argument which describes the video driver. At the time of writing, this may be GLX, WGL, SDL, or dummygl, if you want to load all system ressources yourself and open an OpenGL window yourself (see also Integrating libUFO into existing applications).

Example 2.1. Loading a specific video driver

This example shows how to load a specific video driver.

UXToolkit tk;
UXDisplay display("SDL");

Setting up a UFO window.

The UFO extension module (UX) contains a simple windowing manager. If you have created a display object, you can now create your first UFO frame (remember: The display object is responsible for system ressources.

Example 2.2. Creating a 640x480 sized UFO window

UXToolkit tk;
UXDisplay display;

UXFrame * frame = display.createFrame();
frame->setBounds(0, 0, 640, 480);
frame->setVisible(true);

UFO in custom OpenGL windows.

This section is only relevant if you have already your own OpenGL window and you want to draw UFO widgets within this window.

The procedure is slightly different: You have to use the dummygl video driver and create a custom UFO context for use with your window.

Furthermore, you have to pump system events yourself (see also Integrating into existing applications).

Example 2.3. Custom OpenGL windows

This example shows how to set up libUFO for use with custom OpenGL windows.

UXToolkit tk;
// Your OpenGL window should be open at this time
UXDisplay display("dummygl");

// The bounding rectangle of your OpenGL window
URectangle deviceBounds(0, 0, 640, 480);
// The desired bounding rectangle of the UFO context within
// that OpenGL window
URectangle contextBounds(0, 0, 640, 480);
UXContext context(deviceBounds, contextBounds);