Use cegui in DirectX 3D

Source: Internet
Author: User
I. Introduction to cegui
Cegui, short for Crazy Eddie's Gui, is a free object-oriented interface library developed in C ++ for game developers, provides graphical APIs for Windows and their components in 3D environments. Cegui used the lgpl authorization protocol before 0.4.1 (including 0.4.1), and adopted the more relaxed mit protocol since version 0.5. Items currently using cegui (from http://www.cegui.org.uk ):


Project xenocide


Blitzmax


Plant covered Gui

You can get more knowledge about cegui from the link below:
(1) http://www.cegui.org.uk/wiki/index.php/Main_Page
(2) http://sourceforge.net/projects/crayzedsgui/
(3) http://www.cegui.org.uk/wiki/index.php/FAQ

Ii. cegui structure Overview
You can download the cegui SDK from the link given in the previous section. This SDK is provided in the form of DLL. The following describes the functions and categories of these DLL files:

3. Use cegui in DirectX
Cegui is a cross-platform graphical interface library. Its platform independence is achieved by encapsulating the platform. In the previous section, we analyzed the SDK structure of cegui and provided directx8.1/9.0 support for its rendering subsystem on the Windows platform, therefore, it is difficult to infer that cegui can be used in self-written programs.
3.1 cegui resource organization
The cegui Resource Directory is datafiles, which is organized as follows:

  • Configs: resource configuration file
  • Fonts: font Resources
  • Imagesets: various image resources (such as skin images)
  • Layouts: Layout file (which can be obtained using ceguilayout)
  • Lookfeel: Skin configuration file
  • Lua_scripts: Lua script file
  • Schemes: Scheme of the XML configuration file

We mainly focus on the files in layouts. These XML files can be obtained by ceguilayout, the built-in interface design tool of cegui. As shown in:

3.2 use cegui in the program
In this section, I will use MFC + directx9.0c + cegui to create a demo. Below I will only list some key code. At the end of this article, I will provide the source code download link for the demo. If you are not familiar with using DirectX 3D in the MFC or Win32 SDK, refer to the article about setting up the direct3d getting started framework.
(1) create a DirectX 3D device m_d3ddevice;
(2) create a cegui: render object:
M_pceguirender = new cegui: directx9renderer (m_d3ddevice, 0 );
(3) create a cegui: System Object:
New cegui: System (m_pceguirender );
(4) Rendering cegui:
If (m_d3ddevice) // only use device methods if we have a valid device.
{
//
// Draw the scene:
//
M_d3ddevice-> beginscene ();
M_d3ddevice-> clear (0, 0, d3dclear_target | d3dclear_zbuffer, d3dcolor_xrgb (50, 0, 50), 1.0f, 0 );
/// Render meshs
Drawmesh ();
/// Render cegui
Cegui: System: getsingleton (). rendergui ();

M_d3ddevice-> endscene ();
M_d3ddevice-> present (0, 0, 0, 0 );
}
(5) header files to be introduced
# Include <cegui. h>
# Include <ceguidefaultresourceprovider. h>
(6) import to Warehouse
Ceguibase_d.lib (debug version)
Directx9guirenderer_d.lib (debug version)
(7) set the default resource and its path in the program
You must set the path of the resource (that is, datafiles). Otherwise, the system will encounter an exception that cannot find the resource during running. The Code is as follows:
/// Default resource path for cegui Initialization
Cegui: defaultresourceprovider * Rp = static_cast <cegui: defaultresourceprovider *>
(Cegui: System: getsingleton (). getresourceprovider ());
RP-> setresourcegroupdirectory ("schemes", "../datafiles/Schemes /");
RP-> setresourcegroupdirectory ("imagesets", "../datafiles/imagesets /");
RP-> setresourcegroupdirectory ("fonts", "../datafiles/fonts /");
RP-> setresourcegroupdirectory ("layouts", "../datafiles/layouts /");
RP-> setresourcegroupdirectory ("looknfeels", "../datafiles/looknfeel /");
RP-> setresourcegroupdirectory ("lua_scripts", "../datafiles/lua_scripts/"); // <comment out the row if the Lua script is not used
/// Set the default resource used
Cegui: imageset: setdefaultresourcegroup ("imagesets ");
Cegui: Font: setdefaultresourcegroup ("fonts ");
Cegui: Scheme: setdefaultresourcegroup ("schemes ");
Cegui: widgetlookmanager: setdefaultresourcegroup ("looknfeels ");
Cegui: windowmanager: setdefaultresourcegroup ("layouts ");
Cegui: scriptmodule: setdefaultresourcegroup ("lua_scripts"); // <comment out the line if the Lua script is not used
Note: One premise of this setting is that datafiles exists in the project root directory.
(8) restore the rendered state changed by cegui
By analyzing the source code of cegui, we know that cegui changes some rendering States during rendering, especially those related to depth. Therefore, you must open these states before rendering 3D objects:
M_d3ddevice-> setrenderstate (d3drs_zenable, d3dzb_true );
M_d3ddevice-> setrenderstate (d3drs_zwriteenable, true );

Click to download source code

Note:
1. This project is developed with vs2003 and uses directx9.0c August and cegui SDK 0.5.0b-vc71.
2. Copy the gamegui. layout file in layout to datafiles/layouts in the cegui SDK.
3. This project only requires ceguibase_d.dll, ceguiexpatparser_d.dll, ceguifalagardwrbase_d.dll, and directx9guirender_d.dll (debug version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.