以下内容翻译自http://static.cegui.org.uk/docs/0.8.7/rendering_tutorial.html

1、简介

初始化CEGUI时,不管其渲染API或渲染引擎是什么,都包括三个基本步骤:
(1)创建一个基于CEGUI::Renderer对象的实例。
(2)创建CEGUI::System对象,参数为上一步创建的Renderer实例。
(3)每一帧都调用CEGUI::System::renderAllGUIContexts函数进行渲染。

很显然,我们需要加载一些数据并作一些初始化工作,这部分内容将在“CEGUI入门篇之使用ResourceProvider加载资源(二)”和“CEGUI入门篇之数据文件及默认初始化(三)”中介绍,同时为了与CEGUI控件进行交互,还需要注入输入事件到CEGUI系统,这部分内容将在“CEGUI入门篇之事件注入(五)”中介绍。

2、简单方法:使用Renderer的bootstrapSystem函数

在我们选择的渲染API或渲染引擎中,使用相关Renderer类中的静态函数bootstrapSystem是一种让CEGUI跑起来的最快速简单的方法,除非要做一些高级的或不寻常的事情,否则这便是最佳选择,一个函数调用就完成了CEGUI初始化中所有需要创建的对象,另外还有个destroySystem函数用于随后的清理工作。

Ogre3D和Irrlicht引擎各自有它们自己集成的资源加载和图片解析功能,通过实现CEGUI::ResourceProvider和CEGUI::ImageCodec接口来完成,这需要我们创建这些对象并将CEGUI::Renderer对象作为参数传递给CEGUI::System::create函数,这些对象构造过程相对复杂,不过bootstrapSystem函数自动完成了这些操作。

所以,初始化CEGUI就是简单地调用一个bootstrapSystem函数。

OpenGL1.2——

header:

// Bootstrap CEGUI::System with an OpenGLRenderer object that uses the
// current GL viewport, the DefaultResourceProvider, and the default
// ImageCodec.
//
// NB: Your OpenGL context must already be initialised when you call this; CEGUI
// will not create the OpenGL context itself.
CEGUI::OpenGLRenderer& myRenderer =CEGUI::OpenGLRenderer::bootstrapSystem();

OpenGL3.2或OpenGL ES2.0——

header:

// Bootstrap CEGUI::System with an OpenGL3Renderer object that uses the
// current GL viewport, the DefaultResourceProvider, and the default
// ImageCodec.
//
// NB: Your OpenGL context must already be initialised when you call this; CEGUI
// will not create the OpenGL context itself. Nothing special has to be done to
// choose between desktop OpenGL and OpenGL ES: the type is automatically
// determined by the type of the current OpenGL context.
CEGUI::OpenGL3Renderer& myRenderer =CEGUI::OpenGL3Renderer::bootstrapSystem();

Direct3D——

header:

// Bootstrap CEGUI::System with a Direct3D9Renderer object that uses the
// DefaultResourceProvider, and the default ImageCodec.
CEGUI::Direct3D9Renderer& myRenderer =
    CEGUI::Direct3D9Renderer::bootstrapSystem( myD3D9Device );

Ogre3D——

header:

// Bootstrap CEGUI::System with an OgreRenderer object that uses the
// default Ogre rendering window as the default output surface, an Ogre based
// ResourceProvider, and an Ogre based ImageCodec.
CEGUI::OgreRenderer& myRenderer =CEGUI::OgreRenderer::bootstrapSystem();

Irrlicht——

header:

// Bootstrap CEGUI::System with an IrrlichtRenderer object, an Irrlicht based
// ResourceProvider, and an Irrlicht based ImageCodec.
CEGUI::IrrlichtRenderer& myRenderer =CEGUI::IrrlichtRenderer::bootstrapSystem( myIrrlichtDevice );

3、复杂方法:手动创建CEGUI对象

有时候出于某种原因不使用bootstrapSystem函数,这就需要手动创建CEGUI初始化时所需的对象,包括基于CEGUI::Renderer的对象和CEGUI::System对象,下面分别介绍。

Direct3D9——

header:

CEGUI::Direct3D9Renderer& myRenderer =CEGUI::Direct3D9Renderer::create( myD3D9Device );
CEGUI::System::create( myRenderer );

Direct3D10——

header:

CEGUI::Direct3D10Renderer& myRenderer =CEGUI::Direct3D10Renderer::create( myD3D10Device );
CEGUI::System::create( myRenderer );

OpenGL1.2——

header:

// Create an OpenGLRenderer object that uses the current GL viewport as
// the default output surface.
CEGUI::OpenGLRenderer& myRenderer =CEGUI::OpenGLRenderer::create();
CEGUI::System::create( myRenderer );

OpenGL3.2或OpenGL ES2.0——

header:

// Create an OpenGL3Renderer object that uses the current GL viewport as
// the default output surface.
CEGUI::OpenGL3Renderer& myRenderer =CEGUI::OpenGL3Renderer::create();
CEGUI::System::create( myRenderer );

Ogre3D——

header:

// Create an OgreRenderer object that uses the default Ogre rendering
// window as the default output surface.
CEGUI::OgreRenderer& myRenderer =CEGUI::OgreRenderer::create();
CEGUI::System::create( myRenderer );

Irrlicht——

header:

CEGUI::IrrlichtRenderer& myRenderer =CEGUI::IrrlichtRenderer::create( myIrrlichtDevice );
CEGUI::System::create( myRenderer );

4、清理工作

最后还要记得清理CEGUI Renderer和CEGUI System,顺序执行下面两个步骤:
(1)销毁CEGUI System。

CEGUI::System::destroy();

(2)销毁CEGUI Render(例如d_renderer的类型为Renderer*,当然也可以是引用,通过static_cast转换为具体的子类OpenGL3Renderer)。

CEGUI::OpenGL3Renderer::destroy(static_cast<CEGUI::OpenGL3Renderer&>(*d_renderer)); 

另外,为了避免内存泄漏,还需要销毁手动创建的GUI Contexts、Textures和GeometryBuffers,而CEGUI的Windows、Images等普通元素则会在Renderer、System销毁时被自动销毁,但是如果在程序运行时创建了大量的Windows等普通元素,也需要手动销毁这些对象以降低内存负荷。

5、渲染GUI

渲染GUI的方法可能因渲染引擎的不同而不同,相同的是在渲染循环最后都要调用CEGUI::System::renderAllGUIContexts函数,对于Ogre3D引擎来说,自动执行了这一函数,其它引擎的用法如下所示。

Direct3D9——

// Start the scene
myD3DDevice->BeginScene();
// clear display
myD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
// user function to draw 3D scene
draw3DScene();// draw GUICEGUI::System::getSingleton().renderAllGUIContexts();
// end the scene
myD3DDevice->EndScene();
// finally present the frame.
myD3DDevice->Present(0, 0, 0, 0);

Direct3D10——

// define colour view will be cleared to
float clear_colour[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
// clear display
myD3DDevice->ClearRenderTargetView(myRenderTargetView, clear_colour);
// user function to draw 3D scene
draw3DScene();// draw GUICEGUI::System::getSingleton().renderAllGUIContexts();
// present the newly drawn frame.
mySwapChain->Present(0, 0);

OpenGL——

// user function to draw 3D scene
draw3DScene();
// make sure that before calling renderAllGUIContexts, that any bound textures
// and shaders used to render the scene above are disabled using
// glBindTexture(0) and glUseProgram(0) respectively also set
// glActiveTexture(GL_TEXTURE_0) // draw GUI// NB: When using the old desktop OpenGL 1.2 renderer, this call should not// occur between glBegin/glEnd calls.CEGUI::System::getSingleton().renderAllGUIContexts();

Irrlicht——

// start the scene
myIrrlichtDriver->beginScene(true, true, irr::video::SColor(150,50,50,50));
// draw main scene
myIrrlichtSceneManager->drawAll();// draw guiCEGUI::System::getSingleton().renderAllGUIContexts();
// end the scene
myIrrlichtDriver->endScene();

【CEGUI】CEGUI入门篇之初始化(一)相关推荐

  1. 【CEGUI】CEGUI入门篇之数据文件及默认初始化(三)

    以下内容翻译自http://static.cegui.org.uk/docs/0.8.7/datafile_tutorial.html 开始之前需要了解CEGUI Render和System的创建及R ...

  2. 【CEGUI】CEGUI入门篇之创建window(四)

    以下内容翻译自http://static.cegui.org.uk/docs/0.8.7/window_tutorial.html 这里介绍CEGUI window的创建及如何让window在屏幕上显 ...

  3. Python入门篇-数据结构堆排序Heap Sort

    Python入门篇-数据结构堆排序Heap Sort 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.堆Heap 堆是一个完全二叉树每个非叶子结点都要大于或者等于其左右孩子结点的 ...

  4. HwBinder入门篇-Android10.0 HwBinder通信原理(一)

    摘要:本节主要来讲解Android10.0 HwBinder的通信原理概要 阅读本文大约需要花费18分钟. 文章首发微信公众号:IngresGe 专注于Android系统级源码分析,Android的平 ...

  5. Android10.0 Binder通信原理(二)-Binder入门篇

    摘要:本节主要来讲解Android10.0 Binder的设计原理,如何设计一个Binder通信 阅读本文大约需要花费15分钟. 文章首发微信公众号:IngresGe 专注于Android系统级源码分 ...

  6. 运动控制器编程_快速入门 | 篇二十一:运动控制器ZHMI组态编程简介一

    点击上方"正运动小助手",随时关注新动态! 运动控制器ZHMI组态编程简介一  今天我们来学习一下,运动控制器的ZHMI组态编程简介.本文主要从产品概述.控制器连接触摸屏使用.HM ...

  7. kdir测试软件,[OK210开发板体验]入门篇(4)编程入门(NFS登录、驱动入门)

    前面分别介绍了 [OK210开发板体验]的第一篇:开箱验板 [OK210开发板验]的第二篇:板载资源 [OK210开发板体验]的第三篇:开发环境(软件安装,开发环境,烧写系统) 今天是[OK210开发 ...

  8. Python入门篇-高级数据类型集合(set)和字典(dict)

    Python入门篇-高级数据类型集合(set)和字典(dict) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.集合(set) 1>.集合的特点 约定set 翻译为集合c ...

  9. python sub 不区分大小写_Python网络爬虫入门篇

    1. 预备知识 学习者需要预先掌握Python的数字类型.字符串类型.分支.循环.函数.列表类型.字典类型.文件和第三方库使用等概念和编程方法. Python入门篇:https://www.cnblo ...

最新文章

  1. gst-crypto GStreamer插件
  2. leetcode算法题--连续子数组的最大和
  3. C++实现图片的base64编码
  4. 新年到,献给从一线工程师到CTO的实用指南:《2019区块链开发者报告》
  5. javascript php 之间传递 中文 避免乱码
  6. consul的安装搭建
  7. python recv_Python socket.recv方法代码示例
  8. C语言线程创建与锁机制
  9. 开源 微软 语音识别_能用嘴,绝不动手!支持跨屏的语音输入法,它来了!
  10. react与微信小程序
  11. 2002-11-17梦笔记
  12. 戴尔optiplex3020主板接线_戴尔XPS 13 2020上手,12999元的高端精致怪,让苹果也很有压力!...
  13. linux chmod 使用方法,linux中chmod命令的使用方法
  14. 线性代数辅导讲义(第五章 特征值特征向量)
  15. 离散数学——主析取范式与主合取范式原理探究
  16. bind服务器响应,DNS和Bind服务器
  17. 计算机图表制作教程,echarts入门教程 5分钟上手制作ECharts图表
  18. 怎么选择自己合适的LED驱动IC?
  19. C语言基础-计算一个整数各个位数之和
  20. 第3期:12306页面制作

热门文章

  1. Java文件上传大杀器-绕waf(针对commons-fileupload组件)
  2. Android 图片弹跳动画
  3. Linux仿Ubuntu图标包,优秀的 Ubuntu 14.04 图标主题
  4. TCP滑动窗口,流量控制,拥塞控制详解
  5. 拿到赛季第五冠和职业生涯排名赛
  6. 反射型xss和Dom型xss区别
  7. CodeBlocks调试简要教程
  8. Spring之底层架构核心概念解析
  9. android架构中最底层是什么层,Android体系架构
  10. 约瑟夫环-猴子选大王(变型题)