[c++] Ogre 라이브러리와 GUI 시스템

이번 포스트에서는 Ogre 라이브러리와 함께 GUI 시스템을 사용하는 방법에 대해 알아보겠습니다.

Ogre란 무엇인가요?

Ogre는 객체 지향적인 3D 그래픽 라이브러리로써 게임 개발 및 시뮬레이션 애플리케이션을 위해 사용됩니다.

Ogre 라이브러리 설치하기

가장 먼저 Ogre 라이브러리를 설치해야 합니다. Ogre의 최신 버전은 공식 웹사이트에서 다운로드할 수 있습니다.

설치가 완료되면, 여러분의 프로젝트에 Ogre를 추가해야 합니다.

#include <Ogre.h>

위 코드는 Ogre 헤더 파일을 포함하는 방법을 보여줍니다.

Ogre를 사용하여 3D 객체 그리기

이제 Ogre를 사용하여 삼각형을 그려보겠습니다.

// 초기화
Ogre::Root* root = new Ogre::Root("plugins.cfg");
root->showConfigDialog();
Ogre::RenderWindow* window = root->initialise(true, "Ogre App");

// 씬 매니저 생성
Ogre::SceneManager* sceneMgr = root->createSceneManager(Ogre::ST_GENERIC);

// 카메라 생성
Ogre::Camera* camera = sceneMgr->createCamera("MainCam");

// 뷰포트 생성
Ogre::Viewport* vp = window->addViewport(camera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));

// 삼각형 그리기
Ogre::ManualObject* triangle = sceneMgr->createManualObject("triangle");
triangle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
triangle->position(0, 0, 0);
triangle->position(100, 0, 0);
triangle->position(0, 100, 0);
triangle->end();
sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(triangle);

// 렌더링 루프
while(true)
{
    Ogre::WindowEventUtilities::messagePump();
    if(window->isClosed()) break;
    root->renderOneFrame();
}

GUI 시스템과의 통합

Ogre와 GUI 시스템을 통합하여 사용하는 경우를 살펴보겠습니다. 사용자 인터페이스를 간단하게 표시하기 위해 CEGUI 라이브러리를 사용할 수 있습니다.

CEGUI의 사용법은 공식 문서에서 확인할 수 있습니다.

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

마무리

Ogre를 사용하여 3D 객체를 렌더링하는 방법과 CEGUI를 사용하여 GUI를 통합하는 방법에 대해 알아보았습니다. 자세한 내용은 각 라이브러리의 공식 문서를 참고하시기 바랍니다.