중급 튜토리얼 7-1
Ogre3D 삽질란/Intermediate Tutorial 7 2009. 1. 15. 23:09
중급 튜토리얼 7 (번역 : n_Sys)
중급 튜토리얼 7: 텍스쳐에 렌더링하기
이 튜토리얼 진행에 있어서 문제가 생긴다면 Help Forum에 문의하세요.
목차 |
소개
이번 튜토리얼에서는 텍스쳐에 렌더링 하는 기본기를 가르쳐 드릴 계획입니다. 이 기법은 셰이더를 써서 구현되는 모션블러와 같은 다양한 특수효과와 함께 사용됩니다.
텍스쳐로 렌더링("RTT")하는 기법은 단순한 원리입니다. 출력되는 렌더링 데이터를 렌더윈도우가 아닌 텍스쳐로 바로 보냅니다. 이 텍스쳐는 하드디스크상의 일반 텍스쳐로도 사용될 수 있습니다.
이 튜토리얼에 대한 코드는 여기서 찾을 수 있습니다.
초기코드
프로젝트에 cpp파일을 하나 생성하고 다음 코드를 추가하세요 :
#include "ExampleApplication.h"
class RTTListener : public ExampleFrameListener
{
public:
RTTListener(RenderWindow *win, Camera *cam, SceneNode *sn)
: ExampleFrameListener(win, cam), mPlaneNode(sn)
{
}
bool frameStarted(const FrameEvent& evt)
{
mPlaneNode->yaw(Radian(evt.timeSinceLastFrame));
return ExampleFrameListener::frameStarted(evt);
}
protected:
SceneNode *mPlaneNode;
};
class RTTApplication : public ExampleApplication
{
protected:
MovablePlane *mPlane;
Entity *mPlaneEnt;
SceneNode *mPlaneNode;
void createScene()
{
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.2f, 0.2f, 0.2f));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20, 80, 50);
// Position the camera
mCamera->setPosition(60, 200, 70);
mCamera->lookAt(0, 0, 0);
// Create a material for the plane (just a simple texture, here grass.jpg)
MaterialPtr mat = MaterialManager::getSingleton().create("PlaneMat", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("grass_1024.jpg");
// Create a simple plane
mPlane = new MovablePlane("Plane");
mPlane->d = 0;
mPlane->normal = Vector3::UNIT_Y;
MeshManager::getSingleton().createPlane("PlaneMesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
*mPlane, 120, 120, 1, 1, true, 1, 1, 1, Vector3::UNIT_Z);
mPlaneEnt = mSceneMgr->createEntity("PlaneEntity", "PlaneMesh");
mPlaneEnt->setMaterialName("PlaneMat");
// Attach the plane to a scene node
mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mPlaneNode->attachObject(mPlaneEnt);
}
// Create a new frame listener
void createFrameListener()
{
mFrameListener = new RTTListener(mWindow, mCamera, mPlaneNode);
mRoot->addFrameListener(mFrameListener);
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
RTTApplication app;
try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(),
"An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occurred: " << e.getFullDescription();
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
컴파일 후 실행시켜보세요. Y축을 따라서 회전하는 단순한 평판이 보일 것 입니다.