• 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;
    }

  • 相关阅读:
    转:SkipList跳表
    git操作
    JAVA小工具打包
    Java数字证书操作
    mysql创建数据库和用户
    解决node-sass安装不了的问题
    vscode + angular
    ng2 quickstart-primeng
    ng2 quickstart
    使用淘宝的npm代理下载模块
  • 原文地址:https://www.cnblogs.com/wenguang1996/p/5086832.html
Copyright © 2020-2023  润新知