CEGUI0.8.4例子

#define GLUT_DISABLE_ATEXIT_HACK
#pragma comment(lib,"glew32.lib")
#include<stdlib.h>
#include<gl/glew.h>
#include<gl/glut.h>
#include<CEGUI/CEGUI.h>
#include<CEGUI/RendererModules/OpenGL/GL3Renderer.h>
#include <CEGUI/RendererModules/OpenGL/GLRenderer.h>
#include<GL/glfw.h>
#include<CEGuiOpenGL3BaseApplication.h>
#include <CEGuiOpenGLBaseApplication.h>
#include<CEGUI/WindowManager.h>
void render(void);
void keyFunc(unsigned char , int , int );
int resource_group(void);
int load_data_files(void);
int create_window(void);
void Reshape(int w, int h);
int window_id;
bool keep_running = true;

int main(int argc, char *argv[])
{
glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(640, 480);
glutCreateWindow(argv[0]);
// glutSetCursor(GLUT_CURSOR_NONE); //隐藏原有光标

glutReshapeFunc(Reshape);
GLenum err = glewInit();
CEGUI::OpenGL3Renderer& myRenderer = CEGUI::OpenGL3Renderer::create();
CEGUI::System::create(myRenderer);

resource_group();
load_data_files();
glutDisplayFunc(render);
glutMainLoop();
return 0;
}

void Reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void render(void)
{
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
create_window();
CEGUI::System::getSingleton().renderAllGUIContexts();
glutSwapBuffers();
}

void keyFunc(unsigned char key, int x, int y)
{
switch (key)
{
case 113:
case 81:
case 27:
keep_running = false;
break;
}
}

int resource_group(void) //设置默认资源组
{
CEGUI::DefaultResourceProvider *rp = static_cast<CEGUI::DefaultResourceProvider*>
(CEGUI::System::getSingleton().getResourceProvider());

rp->setResourceGroupDirectory("schemes", "E:\\VTK\\CEGUI\\example\\datafiles\\schemes/");
rp->setResourceGroupDirectory("imagesets", "E:\\VTK\\CEGUI\\example\\datafiles\\imagesets/");
rp->setResourceGroupDirectory("fonts","E:\\VTK\\CEGUI\\example\\datafiles\\fonts/");
rp->setResourceGroupDirectory("layouts","E:\\VTK\\CEGUI\\example\\datafiles\\layouts/");
rp->setResourceGroupDirectory("looknfeels","E:\\VTK\\CEGUI\\example\\datafiles\\looknfeel/");

//rp->setResourceGroupDirectory("schemas","E:\\VTK\\CEGUI\\example\\datafiles\\XMLRefSchema/");

CEGUI::ImageManager::setImagesetDefaultResourceGroup("imagesets");
rp->setDefaultResourceGroup("E:\\VTK\\CEGUI\\example\\datafiles/");
CEGUI::Font::setDefaultResourceGroup("fonts");
CEGUI::Scheme::setDefaultResourceGroup("schemes");
CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
CEGUI::WindowManager::setDefaultResourceGroup("layouts");
// CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");
CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
parser->setProperty("SchemaDefaultResourceGroup", "schemas");
return 1;

}

int load_data_files(void) //载入资源文件
{
CEGUI::SchemeManager::getSingleton().createFromFile( "TaharezLook.scheme" );

CEGUI::FontManager::getSingleton().createFromFile( "DejaVuSans-10.font" );

CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont( "DejaVuSans-10" );

CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage( "TaharezLook/MouseArrow" );

CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultTooltipType( "WindowsLook/Tooltip" );

return 1;
}

int create_window(void) //创建一个窗口
{
using namespace CEGUI;

WindowManager &wmgr = WindowManager::getSingleton();

Window* myRoot = wmgr.createWindow("DefaultWindow", "root");
System::getSingleton().getDefaultGUIContext().setRootWindow( myRoot );

FrameWindow *fWnd = (FrameWindow*)wmgr.createWindow("TaharezLook/FrameWindow", "testWindow");
myRoot->addChild(fWnd);

// position a quarter of the way in from the top-left of parent.
fWnd->setPosition( UVector2( UDim( 0.25f, 0.0f ), UDim( 0.25f, 0.0f ) ) );
// set size to be half the size of the parent
fWnd->setSize( USize( UDim( 0.5f, 0.0f ), UDim( 0.5f, 0.0f ) ) );

fWnd->setText("Hello World!!");
/*Window* myRoot = WindowManager::getSingleton().loadLayoutFromFile( "1.layout" );
System::getSingleton().getDefaultGUIContext().setRootWindow( myRoot );*/
return 1;
}

上一篇:运用C#生成docx格式的报表


下一篇:VSPackge插件系列:如何正确获取DTE