标签:
#define GLUT_DISABLE_ATEXIT_HACK #include <iostream> #include <gl/GLUT.H> #include <gl/GL.h> #include <tchar.h> #include <CEGUI/CEGUI.h> #include <cegui/RendererModules/OpenGL/GLRenderer.h> #pragma comment(lib, "glu32.lib") #pragma comment(lib, "CEGUIBase-0_d.lib") #pragma comment(lib, "CEGUIOpenGLRenderer-0_d.lib") #pragma comment(lib, "CEGUIExpatParser_d.lib") #define EDIT_CONTROL_NAME "Root/EditBox" using namespace CEGUI; int G_lastFrameTime = 0; bool G_quitFlag = false; void mouseMotion(int x, int y); void mouseButton(int button, int state, int x, int y); void KeyCharDown(unsigned char key, int x, int y); void KeyCharUp(unsigned char key, int x, int y); void RenderScene(); void InitGUI(); bool btnClick(const CEGUI::EventArgs& args); void mouseButton(int button, int state, int x, int y); void mouseMove(int x, int y); void display(void) { int thistime = glutGet(GLUT_ELAPSED_TIME); float elapsed = static_cast<float>(thistime - G_lastFrameTime); G_lastFrameTime = thistime; CEGUI::System::getSingleton().injectTimePulse(elapsed / 1000.f); glClear(GL_COLOR_BUFFER_BIT); CEGUI::System::getSingleton().renderAllGUIContexts(); glFlush(); glutPostRedisplay(); glutSwapBuffers(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow("test"); // glutSetCursor(GLUT_CURSOR_NONE); InitGUI(); glutDisplayFunc(display); glutMouseFunc(mouseButton); glutPassiveMotionFunc(mouseMove); //glutMotionFunc(mouseMotion); glutMainLoop(); return 0; } bool btnClick(const CEGUI::EventArgs& args) { std::cout << "clicked" << std::endl; //glutPostRedisplay(); return true; } void InitGUI() { using namespace CEGUI; CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::bootstrapSystem(); //create(); // CEGUI::System& sys = CEGUI::System::create(myRenderer); 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/"); // 从下载的文件中考出来的文件中looknfeel叫looknfeels 注意修改 rp->setResourceGroupDirectory("looknfeels", "../datafiles/looknfeel/"); rp->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/"); rp->setResourceGroupDirectory("schemas", "../datafiles/xml_schemas/"); // set the default resource groups to be used 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"); CEGUI::SchemeManager::getSingleton().createFromFile( "TaharezLook.scheme" ); WindowManager& winMgr = WindowManager::getSingleton(); Window* root = winMgr.loadLayoutFromFile("mytest.layout"); CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(root); CEGUI::PushButton* addBtn = (CEGUI::PushButton*)root->getChild("Add"); addBtn->subscribeEvent(CEGUI::PushButton::EventMouseClick, CEGUI::Event::Subscriber(&btnClick)); addBtn->setText( "Hello World!" ); } void mouseButton(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON) { if (state == GLUT_UP) { CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(CEGUI::LeftButton); } else { CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(CEGUI::LeftButton); } } } void mouseMove(int x, int y) { CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(x, y); }
layout文件:
<?xml version="1.0" ?> <GUILayout version="4"> <Window type="DefaultWindow" name="root"> <Window name="Add" type="TaharezLook/Button"> <Property name="Position" value="{{0.3,0},{0.3,0}}" /> <Property name="MaxSize" value="{{1,0},{1,0}}" /> <Property name="Size" value="{{0.3,0},{0.15,0}}" /> <Property name="Text" value="Add" /> </Window> </Window> </GUILayout>
CEGUI 0.8.4 + OpenGL 的Hello World程序
标签:
原文地址:http://www.cnblogs.com/llc0503/p/4844747.html