【CEGUI】CEGUI入门篇之初始化(一)[通俗易懂]

【CEGUI】CEGUI入门篇之初始化(一)[通俗易懂]以下内容翻译自http://static.cegui.org.uk/docs/0.8.7/rendering_tutorial.html1、简介初始化CEGUI时,不管其渲染API或渲染引擎是什么,都包括三个基本步骤:(1)创建一个基于CEGUI::Renderer对象的实例。(2)创建CEGUI::System对象,参数为上一步创建的Renderer实例。(3)每一帧都调用CEGUI:

大家好,又见面了,我是你们的朋友全栈君。

以下内容翻译自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 GUI
    CEGUI::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 GUI
    CEGUI::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 gui
    CEGUI::System::getSingleton().renderAllGUIContexts();
// end the scene
myIrrlichtDriver->endScene();
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/163720.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • jsrender

    jsrender

  • 基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)

    基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)

  • Python 换行符以及如何在 Python 输出时不换行

    Python 换行符以及如何在 Python 输出时不换行Python中的换行符用于标记行的结尾和新行的开始。如果你想将输出打印到控制台并使用文件,那么你非常需要知道如何使用它。在本文中,你将学习:如何在Python中识别换行符 如何在字符串和打印语句中使用换行符 如何编写不会在字符串末尾添加换行符的打印语句我们开始吧!✨????换行符Python中的换行符是:它包含两个字符:一条反斜线 字母n如果你在字符串中看到此字符,则表示当前行在该点结束,并在其后立即开始新行:你也可以在格式化字符串(f-stri…

    2022年10月21日
  • method_FISTA(Fast iterative shrinkage-thresholding algorithm)

    method_FISTA(Fast iterative shrinkage-thresholding algorithm)前言:FISTA(Afastiterativeshrinkage-thresholdingalgorithm)是一种快速的迭代阈值收缩算法(ISTA)。FISTA和ISTA都是基于梯度下降的思想,在迭代过程中进行了更为聪明(smarter)的选择,从而达到更快的迭代速度。理论证明:FISTA和ISTA的迭代收敛速度分别为O(1/k2)和O(1/k)。  本篇博文先从解决优化问题的传统方法“

  • 配置mysql读写分离[通俗易懂]

    配置mysql读写分离[通俗易懂]准备起码三台服务器我这里准备了192.168.0.63mycat192.168.0.64主192.168.0.65从然后是部署环境下载jbk和mycat,然后上传新建/usr/java/文件夹将jdk-8u321-linux-x64.tar.gz解压到该目录[root@xuegod63~]#mkdir/usr/java[root@xuegod63~]#tarxfjdk-8u321-linux-x64.tar.gz-C/usr/java/…

  • Md编辑器_wife可以看电视但不能打游戏

    Md编辑器_wife可以看电视但不能打游戏文章目录为什么写这个?0.介绍一下md?1纯md语法的使用1.1快捷键1.2字符效果和横线等1.2.1横线1.2.2删除线1.2.3斜体字1.2.4粗体1.2.5粗斜体1.2.6上标与下标1.2.7**缩写(同HTML的abbr标签)**1.2.8引用Blockquotes1.3各级标签标签1标签2标签3标签4标签5标签61.4.列表1.4.1无序列表(…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号