VS2010+OSG3.2+CEGUI0.8.4环境下实现简单的HelloWorld程序

写文章之前必须要先吐槽一下CEGUI的兼容性,好多函数改了名称换了命名空间,以致于花了好长时间查看自带的Demo文件以及帮助文档,不过最终还是搞出来了,现将整个流程编写如下。

1.首先创建工程之前必须先链接OSG以及CEGUI的开发库,根据自身配置路径进行设置,现将本人设置路径贴出来以供参考,如下:

包含目录:

   E:\OSG\includeF:\CEGUI\cegui-0.8.4\cegui\includeF:\CEGUI\cegui-0.8.4\dependencies\includeF:\CEGUI\cegui-0.8.4\samples_framework\include

库目录:

   E:\OSG\libF:\CEGUI\cegui-0.8.4\libF:\CEGUI\cegui-0.8.4\dependencies\lib\dynamicF:\CEGUI\cegui-0.8.4\dependencies\lib\static

附加依赖项:

   OpenThreadsd.libosgd.libosgDBd.libosgUtild.libosgGAd.libosgViewerd.libosgTextd.libosgWidgetd.libCEGUIBase-0_d.libCEGUIOpenGLRenderer-0_d.libglew.libglu.libopengl.lib

2.创建CEGUIDrawable,实现对CEGUI的渲染。

#pragma once
#include <osg/Drawable>
#include <osg/RenderInfo>
#include <CEGUI/CEGUI.h>
#include <CEGUI/System.h>
#include <CEGUI/DefaultResourceProvider.h>
#include <CEGUI/RendererModules/OpenGL/GL.h>
#include <CEGUI/RendererModules/OpenGL/GLRenderer.h>
#include <CEGUI/Scheme.h>
#include <CEGUI/SchemeManager.h>
#include <CEGUI/Font.h>
#include <CEGUI/FontManager.h>
#include <CEGUI/Image.h>
#include <CEGUI/ImageManager.h>
#include <CEGUI/Window.h>
#include <CEGUI/WindowManager.h>
#include <CEGUI/WindowRenderer.h>
#include "CEGUIEventCallback.h"class CEGUIDrawable : public osg::Drawable
{
public:CEGUIDrawable(void);~CEGUIDrawable(void);
public:CEGUIDrawable(const CEGUIDrawable&drawable,const osg::CopyOp   &copyop=osg::CopyOp::SHALLOW_COPY):Drawable(drawable,copyop){}META_Object(osg,CEGUIDrawable);void InitCEGUI();  //初始化CEGUI,添加所需要的资源以及设定相关属性void drawImplementation(osg::RenderInfo& renderInfo) const;//这个函数在基类Drawable里是一个纯虚函数,实现OpenGL渲染时必须重写};#include "StdAfx.h"
#include "CEGUIDrawable.h"CEGUIDrawable::CEGUIDrawable(void)
{setSupportsDisplayList(false);//CEGUI仅支持单线程,必须进行设置才能渲染CEGUI::OpenGLRenderer& myRenderer =CEGUI::OpenGLRenderer::create();myRenderer.enableExtraStateSettings(true);//必须进行设置才能让字体显示setEventCallback(new CEGUIEventCallback);//事件处理函数CEGUI::System::create(myRenderer);CEGUI::DefaultResourceProvider* rp = static_cast(CEGUI::System::getSingleton().getResourceProvider());rp->setResourceGroupDirectory("schemes", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\schemes");rp->setResourceGroupDirectory("imagesets", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\imagesets");rp->setResourceGroupDirectory("fonts", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\fonts");rp->setResourceGroupDirectory("layouts", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\layouts");rp->setResourceGroupDirectory("looknfeels", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\looknfeel");rp->setResourceGroupDirectory("lua_scripts", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\lua_scripts");// This is only really needed if you are using Xerces and need to specify the schemas locationrp->setResourceGroupDirectory("schemas", "F:\\CEGUI\\cegui-0.8.4\\datafiles\\xml_schemas");CEGUI::ImageManager::setImagesetDefaultResourceGroup("imagesets");CEGUI::Font::setDefaultResourceGroup("fonts");CEGUI::Scheme::setDefaultResourceGroup("schemes");CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");CEGUI::WindowManager::setDefaultResourceGroup("layouts");CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))parser->setProperty("SchemaDefaultResourceGroup", "schemas");}CEGUIDrawable::~CEGUIDrawable(void)
{
}void CEGUIDrawable::InitCEGUI()
{using namespace CEGUI;CEGUI::SchemeManager::getSingleton().createFromFile( "TaharezLook.scheme" );CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage( "TaharezLook/MouseArrow" );Font& defaultFont = FontManager::getSingleton().createFromFile("DejaVuSans-10.font");System::getSingleton().getDefaultGUIContext().setDefaultFont(&defaultFont);WindowManager& wmgr = WindowManager::getSingleton();Window* myRoot = (Window* )wmgr.createWindow( "DefaultWindow", "root" );System::getSingleton().getDefaultGUIContext().setRootWindow( myRoot );FrameWindow* fWnd = static_cast<FrameWindow* >(wmgr.createWindow( "TaharezLook/FrameWindow", "testWindow" ));myRoot->addChild( fWnd );fWnd->setPosition( UVector2(UDim( 0.25f,0.0f),UDim(0.25f,0.0f)));fWnd->setSize(USize(UDim(0.5f, 0.0f), UDim(0.5f,0.0f)));fWnd->setText( "Hello World!");
}void CEGUIDrawable::drawImplementation(osg::RenderInfo& renderInfo) const
{CEGUI::System::getSingleton().renderAllGUIContexts();
}

3.编写CEGUIEventCallback,实现对CEGUI的事件处理

#pragma once
#include <osgGA/GUIActionAdapter>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIEventHandler>
#include <CEGUI/System.h>
#include <CEGUI/GUIContext.h>class CEGUIEventCallback : public osgGA::GUIEventHandler
{
public:CEGUIEventCallback();~CEGUIEventCallback(void);
public:virtual bool handle(const osgGA::GUIEventAdapter &ea,osgGA::GUIActionAdapter &aa);
};#include "StdAfx.h"
#include "CEGUIEventCallback.h"CEGUIEventCallback::CEGUIEventCallback()
{
}CEGUIEventCallback::~CEGUIEventCallback(void)
{
}bool CEGUIEventCallback::handle(const osgGA::GUIEventAdapter &ea,osgGA::GUIActionAdapter &aa)
{switch(ea.getEventType()){case osgGA::GUIEventAdapter::DRAG:case osgGA::GUIEventAdapter::MOVE:{CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(ea.getX(),900-ea.getY());//CEGUI的坐标系统跟OSG坐标系统是不一样的,如果是全屏的话,CEGUI中的0在OSG中是900(以1440*900为例),所以需要进行调整,以便CEGUI与OSG屏幕一致return false;}case osgGA::GUIEventAdapter::PUSH:{CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(ea.getX(),900-ea.getY());//CEGUI的坐标系统跟OSG坐标系统是不一样的,如果是全屏的话,CEGUI中的0在OSG中是900(以1440*900为例),所以需要进行调整,以便CEGUI与OSG屏幕一致if (ea.getButton()==osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON){CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(CEGUI::LeftButton);}else{}return false;}case osgGA::GUIEventAdapter::RELEASE:{CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(ea.getX(),900-ea.getY());//CEGUI的坐标系统跟OSG坐标系统是不一样的,如果是全屏的话,CEGUI中的0在OSG中是900(以1440*900为例),所以需要进行调整,以便CEGUI与OSG屏幕一致if (ea.getButton()==osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON){CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(CEGUI::LeftButton);}else{}return false;}}return false;
}

4.编写main函数,实现窗口渲染

#include "stdafx.h"
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include "CEGUIDrawable.h"int _tmain(int argc, _TCHAR* argv[])
{osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded); //CEGUI仅支持单线程,必须进行设置viewer->realize(); //CEGUI仅支持单线程,必须进行设置viewer->getCamera()->getGraphicsContext()->makeCurrent(); //CEGUI仅支持单线程,必须进行设置osg::ref_ptr<osg::Geode> geode = new osg::Geode;osg::ref_ptr<CEGUIDrawable> cd = new CEGUIDrawable;geode->addDrawable(ceguiDrawable);ceguiDrawable->InitCEGUI();osg::ref_ptr<osg::Group> group = new osg::Group;group->addChild(geode);group->addChild(osgDB::readNodeFile("glider.osg"));viewer->setSceneData(group);return viewer->run();
}

原文出处:

转载链接

VS2010+OSG3.2+CEGUI0.8.4环境下实现简单的HelloWorld程序相关推荐

  1. 在 windows 环境下,编写一个批处理程序(算命大师.bat)

    在 windows 环境下,编写一个批处理程序(算命大师.bat) 标题 在 windows 环境下,编写一个批处理程序(算命大师.bat) **题目:**在 windows 环境下,编写一个批处理程 ...

  2. 操原上机(一)在 Windows 环境下,编写一个批处理程序(算命大师.bat)

    要求 在 Windows 环境下,编写一个批处理程序(算命大师.bat),程序运行后,输入:出生年月日(例如 2000-07-31).系统输出相应的属相和星座,例如:你属兔, 狮子座.要求:输入进行合 ...

  3. 在AE10.1环境下调试其他版本的程序

    不同人的可能使用的开发环境不一样,使用SDK版本也不一样,比如用ArcEngine9.3开发的程序在ArcEngine10.1下就不能运行,需要重新调试,才能运行. 这里的例子程序是其他网友在ArcE ...

  4. Linux环境下的堆栈--调试C程序

    完整的调试过程,跟踪堆栈变化,32位下. 注意64位和此不同. a.c代码: #include <stdio.h> int main() { AFunc(5,6);return 0; } ...

  5. Linux环境下实现简单进度条

    进度条是我们生活中可见的,但是大家却从来不知道其怎么实现的,下面就是linux环境下的进度条的简单实现 这里应该提一下缓冲区的概念: 计算机中的缓冲区: 缓冲器为暂时置放输出或输入资料的内存. 缓冲器 ...

  6. linux如何运行java程序,Linux环境下运行简单java程序

    一.安装java 1.下载jdk8 选择对应jdk版本下载.(Tips:可在Windows下载完成后,通过FTP或者SSH到发送到Linux上) 2. 登录Linux,切换到root用户 su roo ...

  7. windows10_64位环境下RadAsm的8086汇编语言程序

    前言: 当我们在win10环境下使用RadAsm编写汇编时,发现并不能够运行,因为Win64已经废弃了对16位程序的支持,甚至连debug都废除了.而且使用虚拟机太麻烦,有两种解决方案: 方法一:第一 ...

  8. MNIST数据集合在PaddlePaddle环境下使用简单神经网络识别效果

    简 介: 通过PaddlePaddle构造的简单神经网络对于MNIST数据库进行实验,可以看到使用普通的稠密网络,便可以达到很高的识别效果.训练结果存在一定的随机性.这取决于训练其实的条件.由于在Pa ...

  9. linux打开应用程序的命令,Windows环境下如何通过命令打开程序!

    大家应该有在电视/电影里看到这样的一幕:一个戴着墨镜的大神坐在电脑前,神情严肃,手指飞快地在电脑键盘上敲打着,电脑上的命令闪动着,而大神全程都没碰一下鼠标. 电影当然有夸张的成分,但在实际工作生活中, ...

最新文章

  1. js将字符串中所有反斜杠\替换成正斜杠/
  2. centos 推荐使用epel源
  3. 国内企业应如何实施ITSM
  4. 杠件受力分析 第一章 杠件受力分析
  5. Spark 1.2 集群环境安装
  6. Word2010-页眉中字数未满但自动换行
  7. windows双屏切换
  8. 实体店想多赚钱就要学会互联网思维
  9. python解析器打包_打包发布Python模块的方法详解
  10. 【HIVE 之 DDL,DML】
  11. 学习历程(一)第一个微信打卡器
  12. mysql5.7企业版下载_MySQL v5.7.20 官方正式版(32/64位 安装版与zip解压版)
  13. 电脑硬件常见故障维修技巧
  14. HTML-form表单+iframe
  15. 李兴平中国最牛的个人站长
  16. JavaScript:实现GnomeSort侏儒排序算法(附完整源码)
  17. php 上传 照片流,在 iPhone 上使用“我的照片流”的方法!
  18. Centos 7(linux)echo 用法的注意事项
  19. HTML 全页面内容自由编辑与 HTML 页面全部黑白风格处理
  20. python生成热度图_Python - 场景热力图绘制[转]

热门文章

  1. (考研湖科大教书匠计算机网络)第一章概述-第二节:三种交换方式(电路交换、报文交换和分组交换)
  2. redis性能监控(一): Redis Info 命令 - 获取 Redis 服务器的各种信息和统计数值
  3. 使用Python读取串口数据
  4. postgres数据库对比工具
  5. Android10有哪些功能,如何尝试Android 10的五大最佳功能
  6. 25-基于51单片机温湿度的检测及控制的设计
  7. 深度图像转点云数据(激光雷达数据)
  8. 揭开中国人使用计算机互联网的序幕的人,_____发出了中国第一封电子邮件,从此揭开了中国人使用Internet的.._简答题试题答案...
  9. 关于高德地图 所有省的 adcode
  10. 【AutoGPT】LangChain 快速入门指南(中文版)