2010년 1월 27일 수요일

어라 코드하이라이트 지원하네

환경설정 보다 알았네
그런데 지원언어가 많지 않다.

음.. 그냥 지금처럼 emacs 에서 html 뽑아서 붙이는쪽이 끌리는데..
어쨌건 기억해 두자.

여태껏 집에서 돌리던 리파지토리 서버를 내리고 드랍박스에서 리파지토리를 돌리고 있어서 전처럼 필요할때 집에 로그인해서 코드를 꺼내가기 힘들어졌으니 앞으로 코드조각들을 블로그에 올려둬야 할 판인데 자주 써먹게되겠군.


오우거 시작코드를 스크래치부터 짜보고 있는데 그 코드 올려본다.

[code cpp]
/*
  흠. 외부데이타를 읽을게 많아서 초기기동이 상당히 성가시다.
  setupResourceLocations() 함수를 참고해보자.
*/
#include <iostream>
#include <string>
#include "Ogre.h"

using namespace std;
using namespace Ogre;


class MyFrameListener : public FrameListener
{
public:
    virtual bool frameStarted(const FrameEvent& e)
    {
        return true;
    }
    virtual bool frameEnded(const FrameEvent& e)
    {
        return true;
    }
};


class OgreApp
{
public:
    OgreApp()
    {
        setupLog();
        setupRoot();
        setupRenderWindow();
        setupSceneManager();
        setupCamera();
        setupViewport();
        setupResourceLocations();
        createScene();
    }
   
    virtual ~OgreApp()
    {
        delete root_;
        delete logMgr_;
    }

    void run()
    {
        while(true)
        {
            if(!root_->renderOneFrame())
                break;
            messageLoop();
        }
    }

    void addFrameListener(FrameListener* fl)
    {
        root_->addFrameListener(fl);
    }

private:
    LogManager*   logMgr_;
    Root*         root_;
    RenderWindow* window_;
    SceneManager* sceneMgr_;
    Camera*       cam_;
    Viewport*     vp_;


    void setupLog()
    {
        logMgr_ = new LogManager;
        LogManager::getSingleton().createLog("ogre.log", true, true, false);
        logMgr_->setLogDetail(LL_BOREME);
    }

    void setupRoot()
    {
        root_ = new Root("", "");
        loadPlugin("RenderSystem_Direct3D9");
        loadPlugin("Plugin_OctreeSceneManager");           
        root_->setRenderSystem(*root_->getAvailableRenderers()->begin());
        root_->initialise(false);
    }
    void loadPlugin(const char* name)
    {
        string n = name;
#if _DEBUG
        n += "_d";
#endif
        root_->loadPlugin(n);
    }
    void setupRenderWindow()
    {
        root_->getRenderSystem()->setConfigOption("Full Screen", "No");
        root_->getRenderSystem()->setConfigOption("Video Mode", "1024 x 768 @ 32-bit colour");
        window_ = root_->createRenderWindow("Manual Ogre Window", 1024, 768, false, 0);
    }
    void setupSceneManager()
    {
        sceneMgr_ = root_->createSceneManager(ST_GENERIC, "MySceneManager");
    }

    void setupCamera()
    {
        cam_ = sceneMgr_->createCamera("MainCam");
        // Z 방향으로 500 거리에 카메라 위치
        cam_->setPosition(Vector3(0,0,500));
        // Z 쪽으로 향하게
        cam_->lookAt(Vector3(0,0,-300));
        cam_->setAspectRatio(1.33333f);
        cam_->setNearClipDistance(5);
        cam_->setFarClipDistance(1000);
    }
    void setupViewport()
    {
        vp_ = window_->addViewport(cam_);
        vp_->setBackgroundColour(ColourValue(0,0,0));
    }
    void setupResourceLocations()
    {
        //addResourceLocation("/packs/OgreCore.zip", "Zip", "Boostrap");
        addResourceLocation("/materials/programs", "FileSystem", "General");
        addResourceLocation("/materials/scripts", "FileSystem", "General");
        addResourceLocation("/materials/textures", "FileSystem", "General");
        addResourceLocation("/models", "FileSystem", "General");
        ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // 그룹별로 초기화도 가능하다 기억해두자.
    }
    void addResourceLocation(const char* name, const char* type, const char* group)
    {
        const char* ogrehome = getenv("OGRE_HOME");
        if(!ogrehome) throw runtime_error("need OGRE_HOME env");

        ResourceGroupManager::getSingleton().addResourceLocation(string(ogrehome) + "/media" + name,
                                                                 type,
                                                                 group);       
    }
    void createScene()
    {
        sceneMgr_->setAmbientLight(ColourValue(0.5,0.5,0.5));
        Light* l = sceneMgr_->createLight("MainLight");
        l->setPosition(20,80,50);
        Entity* ent = sceneMgr_->createEntity("head", "ogrehead.mesh");
        //ent->setMaterialName("Examples/EnvMappedRustySteel");
        sceneMgr_->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
    }

    void messageLoop()
    {
        MSG msg;
        while(PeekMessage(&msg, NULL, 0, 0,  PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
};




int main()
{
    MyFrameListener fl;
   
    OgreApp app;
    app.addFrameListener(&fl);
    app.run();
}
[/code]

댓글 없음: