Skip to main content

History: QuickGUI Integration Tutorial

Preview of version: 11

Introduction

This tutorial explains how QuickGUI works on a high level, and includes what is needed by QuickGUI in order to be used in your application. For those who would like to see a full solution, a QuickGUIOgreDemo application is packaged with QuickGUI, which shows how Ogre and QuickGUI are used together.

History

Previously QuickGUI was built using Ogre as its primary method of rendering UI, however in this new version rendering has been abstracted out of the library. QuickGUI introduces many abstract classes that must be implemented and passed in for QuickGUI to operate. Not only does this remove QuickGUI's dependency on Ogre, but it gives the developer control over how rendering occurs. This is especially useful if you work in an environment with certain limitations, ie power of 2 texture sizes, or use a specific or custom graphics library. In any case, you are in complete control of the rendering, so you can always adjust it without modifying QuickGUI source!

What if I don't know how to write a solution using Ogre for manual rendering?

In this tutorial I will provide an implementation that uses Ogre 1.7. It's important to realize that you can write your own rendering solution, and that the provided solution may not be the most efficient for all scenarios.

Creating QuickGUI Core

The Core class is similar to Ogre's Root class, providing access to all main subsystems within QuickGUI, and allowing creation and destruction of Interface objects. An Interface is a class that represents a collection of Window and RenderTarget objects, and will be covered later in this tutorial.

Core constructor:

Copy to clipboard
/** * Constructor. The passed in ResourceManager and SkinEffectCreator classes will NOT be owned by QuickGUICore, as * they might be part of a class with scope larger than QuickGUI. Passing in a NULL value for the SkinEffectCreator * is valid, as long as your UI Skins do not have any Skin Effects. */ Core(ResourceManager* m, SkinEffectManager* sem);


NOTE: Both the constructor and destructor are public, and should be created/destroyed by your application.

As seen in the comments, a ResourceManager and SkinEffectManager are required. The SkinEffectManager is part of the Skinning system, and will be covered in another tutorial. Passing in NULL for the SkinEffectManager is perfectly acceptable, provided you don't use any SkinEffect's. (which should be covered in the same tutorial as the SkinEffectManager๐Ÿ˜Š)

ResourceManager

The ResourceManager class is an abstract class in QuickGUI, and meant to be derived and implemented by your application code. It performs the following functionality:

  • Access to Images by name. An Image is a class representing an image file on disk, and gives read-only access to pixel data. Depending on your implementation, this could also work for Images in memory.
  • Creation and destruction of RenderTexture objects. This class represents a texture in memory that supports drawing of Images and rectangles to it.
  • Creation and destruction of Texture objects. A Texture represents a image in memory, and provides both read and write access to pixel data.


Here is the provided implementation used by the QuickGUIOgreDemo application:
GUIResourceManager.h

NOTE: This class won't compile successfully until the Image, RenderTexture, and Texture classes have been defined and included!
NOTE: When you implement a ResourceManager for QuickGUI, you do not have to create a stand alone class specifically for QuickGUI. For example, your application could have a generic ResourceManager that inherits from the QuickGUI ResourceManager. Pass a pointer to this generic resource manager to the Core constructor, and QuickGUI will work just the same.

Image

A recognized QuickGUI Image must have the following interface:

Copy to clipboard
public: /** * Returns the ColorValue of the pixel at the position specified. */ virtual ColorValue getColorAtPosition(const Position& p) = 0; /** * Gets the name of this Image. */ virtual std::string getName() = 0; /** * Gets the size of this Image, in pixels. */ virtual Size getSize() = 0;

Here is the provided implementation used by the QuickGUIOgreDemo application:
Image.h

RenderTexture

The RenderTexture interface is quite large. Here are a few of the APIs required by the class:

  • clear
  • drawLine
  • drawImage
  • drawRect
  • drawTiledImage
  • getClippingBounds
  • setClippingBounds
  • writeContentsToFile

Here is the provided implementation used by the QuickGUIOgreDemo application:
RenderTexture.h
RenderTexture.cpp

It is strongly recommended to look through the source of these files to gain a better understanding of one approach to providing an implementation for this class.

Texture

A recognized QuickGUI Texture must have the following interface:

Copy to clipboard
public: /** * Copies a portion of an Image's contents to this Texture. * NOTE: width and height of 0 will be expanded to take the maximum width and height * of the source of destination area. */ virtual void copyImageToTexture(Image* i, Rect dest = Rect::ZERO, Rect source = Rect::ZERO) = 0; /** * Locks the pixel buffer for reading and writing purposes. */ virtual unsigned char* lockBuffer() = 0; /** * Unlocks the pixel buffer. */ virtual void unlockBuffer() = 0; /** * Writes the RenderTarget contents out to an image file. */ virtual void writeContentsToFile(const std::string& fileName) = 0;

NOTE: The Texture class inherits from the Image class, so the derived Texture class will need to implement all APIs defined by the Texture interface as well as the Image interface.

Here is the provided implementation used by the QuickGUIOgreDemo application:
Texture.h
Texture.cpp

So now we've provided QuickGUI with methods to retrieve image data, and draw them to textures in memory. Whats next?

QuickGUI Scene

As you might have guessed, QuickGUI works by generating Textures and displaying them. We've provided methods to generating Textures, but what about displaying them? The Scene class provides QuickGUI with this functionality via RenderTargets, the Overlay and UIPanel classes.

The Scene class should be thought of as the object reprensenting your 3d scene. Overlays are 2d Panels that are drawn on top of your view, and do not change with Camera orientation. UIPanels are 3d Panels inside your scene, that can change orientation, and get smaller, larger, or move out of view, depending on your Camera's position and orientation within the 3d scene. Its worth noting that the UIPanel doesn't have to be implemented if you don't want to support 3d UI. Likewise, the Overlay class doesn't have to be implemented if you don't want to suppoert 2d UI. Simply return NULL for the creation and accessor methods, allowing the Scene class to compile correctly.

Here is the provided implementation used by the QuickGUIOgreDemo application:
Scene.h
Scene.cpp

NOTE: This class won't compile successfully until the Overlay and UIPanel classes have been defined and included!

Overlay

The Overlay implementation is pretty easy to implement, since Ogre already has an Overlay implementation.๐Ÿ™€

Some of the APIs required by the QuickGUI Overlay interface:

  • getPosition
  • getRenderTexture
  • getSize
  • getWindow
  • getZOrder
  • offsetPosition
  • setPosition
  • setRenderTexture
  • setSize
  • setWindow
  • setZOrder


NOTE: The Overlay interface inherits from the QuickGUI RenderTarget interface, so the derived class will need to implement APIs required by both interfaces.

Here is the provided implementation used by the QuickGUIOgreDemo application:
Overlay.h
Overlay.cpp

Interface

History

Information Version
Mon 27 of Sep, 2010 22:09 GMT-0000 jacmoe 18
Wed 08 of Sep, 2010 16:59 GMT-0000 KungFooMasta 17
Mon 23 of Aug, 2010 07:09 GMT-0000 KungFooMasta 16
Mon 23 of Aug, 2010 06:18 GMT-0000 calder Changed "many abstract classes that must be implemented" to "a few ..." to make the process sound less scary. 15
Mon 23 of Aug, 2010 04:11 GMT-0000 KungFooMasta 14
Mon 23 of Aug, 2010 03:40 GMT-0000 KungFooMasta 13
Mon 23 of Aug, 2010 03:26 GMT-0000 KungFooMasta 12
Mon 23 of Aug, 2010 03:05 GMT-0000 KungFooMasta 11
Mon 23 of Aug, 2010 02:37 GMT-0000 KungFooMasta 10
Mon 23 of Aug, 2010 02:25 GMT-0000 KungFooMasta 9
Mon 23 of Aug, 2010 02:25 GMT-0000 KungFooMasta 8
Mon 23 of Aug, 2010 02:17 GMT-0000 KungFooMasta 7
Mon 23 of Aug, 2010 02:04 GMT-0000 KungFooMasta 6
Mon 23 of Aug, 2010 01:50 GMT-0000 KungFooMasta 5
Mon 23 of Aug, 2010 01:47 GMT-0000 KungFooMasta 4
Mon 23 of Aug, 2010 01:37 GMT-0000 KungFooMasta 3
Mon 23 of Aug, 2010 01:31 GMT-0000 KungFooMasta 2
Mon 23 of Aug, 2010 01:13 GMT-0000 KungFooMasta 1