OpenGL CEGUIウィンドウの作成
ここではコードのみを示し、原理についてはCEGUIの公式サイトのチュートリアルを参照してください.この映画はCEGUI公式サイトのチュートリアルに対応します: The Beginner Guide to Getting CEGUI Rendering - How to initialise CEGUI to render properly. The Beginner Guide to Resource Groups - How to define resource group locations and specify default resource groups. The Beginner Guide to Loading Data Files and Initialisation - How to load some data files and perform basic system initialisation. The Beginner Guide to Creating a CEGUI Window - How to create a simple window and get it on screen.
glut_loop.cpp
#include#include #include #include #include #include #define DATA_FILES "/home/XXX/program/cegui/datafiles/"void render(void);void keyFunc(unsigned char , int , int );int resource_group(void);int load_data_files(void);int create_window(void);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);window_id=glutCreateWindow("GLUT Loop");glutSetCursor(GLUT_CURSOR_NONE);////既存カーソルGLenum err=glewInit();CEGUI::::::::::::::::::::::::::::::::::::::::::::::::::::OpenGLRenderer*myRenderer=new CEGUI::OpenGLRenderer(0); new CEGUI::System(myRenderer); resource_group(); load_data_files(); create_window(); while (keep_running) { glutMainLoopEvent(); render(); CEGUI::System::getSingleton().renderGUI(); glutSwapBuffers(); } glutDestroyWindow(window_id); return 0;}void render(void){ glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);}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::System::getSingleton().getResourceProvider()); rp->setResourceGroupDirectory("schemes", DATA_FILES "schemes/"); rp->setResourceGroupDirectory("imagesets", DATA_FILES "imagesets/"); rp->setResourceGroupDirectory("fonts", DATA_FILES "fonts/"); rp->setResourceGroupDirectory("layouts", DATA_FILES "layouts/"); rp->setResourceGroupDirectory("looknfeels", DATA_FILES "looknfeel/"); rp->setResourceGroupDirectory("schemas", DATA_FILES "XMLRefSchema/"); CEGUI::Imageset::setDefaultResourceGroup("imagesets"); CEGUI::Font::setDefaultResourceGroup("fonts"); CEGUI::Scheme::setDefaultResourceGroup("schemes"); CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels"); CEGUI::WindowManager::setDefaultResourceGroup("layouts"); CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");}int load_data_files(void){ CEGUI::SchemeManager::getSingleton().loadScheme("TaharezLook.scheme"); if (!CEGUI::FontManager::getSingleton().isFontPresent("Commonwealth-10")) CEGUI::FontManager::getSingleton().createFont("Commonwealth-10"); CEGUI::System::getSingleton().setDefaultFont("Commonwealth-10"); CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow"); CEGUI::System::getSingleton().setDefaultTooltip("TaharezLook/Tooltip");}int create_window(void){ using namespace CEGUI; WindowManager &wmgr = WindowManager::getSingleton(); Window* myRoot = wmgr.createWindow("DefaultWindow", "root"); System::getSingleton().setGUISheet(myRoot); FrameWindow *fWnd = (FrameWindow*)wmgr.createWindow("TaharezLook/FrameWindow", "testWindow"); myRoot->addChildWindow(fWnd); fWnd->setPosition( UVector2( UDim(0.25f, 0), UDim(0.25f, 0) ) ); fWnd->setSize( UVector2( UDim(0.5f, 0), UDim(0.5f, 0) ) ); fWnd->setText("/nHello, world!/nI'm sihan.");}
Makefile:
これは、作成したウィンドウがまだ対応していないため、イベント処理関数の追加を開始します.
glut_loop.cpp
#include
Makefile:
# Makefile to compile glut_loop
glut_loop: glut_loop.o
g++ glut_loop.o -lglut -L/usr/local/lib/ -lCEGUIBase -lCEGUIOpenGLRenderer -lCEGUIXercesParser -o glut_loop
#
glut_loop.o: glut_loop.cpp
g++ -c glut_loop.cpp -I/usr/local/include/CEGUI
#
.PHONY: clean
clean:
rm -rf *.o glut_loop
これは、作成したウィンドウがまだ対応していないため、イベント処理関数の追加を開始します.