Minor cleanups (mostly comments) for examples 12 & 13.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5795 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
bc035b510f
commit
0f3838b968
|
@ -10,9 +10,7 @@ simple solution for building larger area on small heightmaps -> terrain
|
|||
smoothing.
|
||||
|
||||
In the beginning there is nothing special. We include the needed header files
|
||||
and create an event listener to listen if the user presses a key: The 'W' key
|
||||
switches to wireframe mode, the 'P' key to pointcloud mode, and the 'D' key
|
||||
toggles between solid and detail mapped material.
|
||||
and create an event listener to listen if the user presses certain keys.
|
||||
*/
|
||||
#include <irrlicht.h>
|
||||
#include "driverChoice.h"
|
||||
|
@ -48,7 +46,7 @@ public:
|
|||
!Terrain->getMaterial(0).Wireframe);
|
||||
Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false);
|
||||
return true;
|
||||
case irr::KEY_KEY_P: // switch wire frame mode
|
||||
case irr::KEY_KEY_P: // switch point cloud mode
|
||||
Terrain->setMaterialFlag(video::EMF_POINTCLOUD,
|
||||
!Terrain->getMaterial(0).PointCloud);
|
||||
Terrain->setMaterialFlag(video::EMF_WIREFRAME, false);
|
||||
|
@ -128,7 +126,7 @@ int main()
|
|||
//set other font
|
||||
env->getSkin()->setFont(env->getFont(mediaPath + "fontlucida.png"));
|
||||
|
||||
// add some help text
|
||||
// add some help text (let's ignore 'P' and 'X' which are more about debugging)
|
||||
env->addStaticText(
|
||||
L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome",
|
||||
core::rect<s32>(10,421,250,475), true, true, 0, -1, true);
|
||||
|
@ -147,13 +145,13 @@ int main()
|
|||
/*
|
||||
Here comes the terrain renderer scene node: We add it just like any
|
||||
other scene node to the scene using
|
||||
ISceneManager::addTerrainSceneNode(). The only parameter we use is a
|
||||
ISceneManager::addTerrainSceneNode(). The first parameter is a
|
||||
file name to the heightmap we use. A heightmap is simply a gray scale
|
||||
texture. The terrain renderer loads it and creates the 3D terrain from
|
||||
it.
|
||||
|
||||
To make the terrain look more big, we change the scale factor of
|
||||
it to (40, 4.4, 40). Because we don't have any dynamic lights in the
|
||||
To make the terrain look bigger, we change it's scale factor to
|
||||
(40, 4.4, 40). Because we don't have any dynamic lights in the
|
||||
scene, we switch off the lighting, and we set the file
|
||||
terrain-texture.jpg as texture for the terrain and detailmap3.jpg as
|
||||
second texture, called detail map. At last, we set the scale values for
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
/** Example 013 Render To Texture
|
||||
|
||||
This tutorial shows how to render to a texture using Irrlicht. Render to
|
||||
texture is a feature with which it is possible to create nice special effects.
|
||||
texture is a feature where everything which would usually be rendered to
|
||||
the screen is instead written to a (special) texture. This can be used to
|
||||
create nice special effects.
|
||||
In addition, this tutorial shows how to enable specular highlights.
|
||||
|
||||
In the beginning, everything as usual. Include the needed headers, ask the user
|
||||
for the rendering driver, create the Irrlicht Device:
|
||||
for the rendering driver, create the Irrlicht device:
|
||||
*/
|
||||
|
||||
#include <irrlicht.h>
|
||||
|
@ -84,27 +86,36 @@ int main()
|
|||
*/
|
||||
|
||||
// create test cube
|
||||
scene::ISceneNode* test = smgr->addCubeSceneNode(60);
|
||||
scene::ISceneNode* cube = smgr->addCubeSceneNode(60);
|
||||
|
||||
// let the cube rotate and set some light settings
|
||||
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(
|
||||
core::vector3df(0.3f, 0.3f,0));
|
||||
|
||||
test->setPosition(core::vector3df(-100,0,-100));
|
||||
test->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
|
||||
test->addAnimator(anim);
|
||||
cube->setPosition(core::vector3df(-100,0,-100));
|
||||
cube->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
|
||||
cube->addAnimator(anim);
|
||||
anim->drop();
|
||||
|
||||
// set window caption
|
||||
device->setWindowCaption(L"Irrlicht Engine - Render to Texture and Specular Highlights example");
|
||||
|
||||
/*
|
||||
To test out the render to texture feature, we need a render target
|
||||
texture. These are not like standard textures, but need to be created
|
||||
first. To create one, we call IVideoDriver::addRenderTargetTexture()
|
||||
and specify the size of the texture. Please don't use sizes bigger than
|
||||
the frame buffer for this, because the render target shares the zbuffer
|
||||
with the frame buffer.
|
||||
To test out the render to texture feature, we need to define our
|
||||
new rendertarget. The rendertarget will need one texture to receive
|
||||
the result you would otherwise see on screen and one texture
|
||||
which is used as depth-buffer.
|
||||
|
||||
(Note: If you worked with older Irrlicht versions (before 1.9) you might be
|
||||
used to only create a rendertarget texture and no explicit rendertarget. While
|
||||
that's still possible, it's no longer recommended.)
|
||||
|
||||
The rendertarget textures are not like standard textures, but need to be created
|
||||
first. To create them, we call IVideoDriver::addRenderTargetTexture()
|
||||
and specify the size of the texture and the type.
|
||||
For depth-maps you can use types ECF_D16, ECF_D32 or ECF_D24S8. When ECF_D24S8
|
||||
you can also use a stencil-buffer.
|
||||
|
||||
Because we want to render the scene not from the user camera into the
|
||||
texture, we add another fixed camera to the scene. But before we do all
|
||||
this, we check if the current running driver is able to render to
|
||||
|
@ -113,19 +124,18 @@ int main()
|
|||
|
||||
// create render target
|
||||
video::IRenderTarget* renderTarget = 0;
|
||||
video::ITexture* renderTargetTex = 0;
|
||||
scene::ICameraSceneNode* fixedCam = 0;
|
||||
|
||||
|
||||
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
|
||||
{
|
||||
renderTargetTex = driver->addRenderTargetTexture(core::dimension2d<u32>(256, 256), "RTT1", video::ECF_A8R8G8B8);
|
||||
video::ITexture* renderTargetDepth = driver->addRenderTargetTexture(core::dimension2d<u32>(256, 256), "DepthStencil", video::ECF_D16);
|
||||
const core::dimension2d<u32> rtDim(256, 256); // always use same size for render target texture and it's depth-buffer
|
||||
video::ITexture* renderTargetTex = driver->addRenderTargetTexture(rtDim, "RTT1", video::ECF_A8R8G8B8);
|
||||
video::ITexture* renderTargetDepth = driver->addRenderTargetTexture(rtDim, "DepthStencil", video::ECF_D16);
|
||||
|
||||
renderTarget = driver->addRenderTarget();
|
||||
renderTarget->setTexture(renderTargetTex, renderTargetDepth);
|
||||
|
||||
test->setMaterialTexture(0, renderTargetTex); // set material of cube to render target
|
||||
cube->setMaterialTexture(0, renderTargetTex); // set material of cube to render target
|
||||
|
||||
// add fixed camera
|
||||
fixedCam = smgr->addCameraSceneNode(0, core::vector3df(10,10,-80),
|
||||
|
@ -174,22 +184,21 @@ int main()
|
|||
{
|
||||
// draw scene into render target
|
||||
|
||||
// set render target texture
|
||||
// set render target
|
||||
driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,0,0,255));
|
||||
|
||||
// make cube invisible and set fixed camera as active camera
|
||||
test->setVisible(false);
|
||||
cube->setVisible(false);
|
||||
smgr->setActiveCamera(fixedCam);
|
||||
|
||||
// draw whole scene into render buffer
|
||||
smgr->drawAll();
|
||||
|
||||
// set back old render target
|
||||
// The buffer might have been distorted, so clear it
|
||||
driver->setRenderTargetEx(0, 0, video::SColor(0));
|
||||
// set back old render target (the screen)
|
||||
driver->setRenderTargetEx(0, 0);
|
||||
|
||||
// make the cube visible and set the user controlled camera as active one
|
||||
test->setVisible(true);
|
||||
cube->setVisible(true);
|
||||
smgr->setActiveCamera(fpsCamera);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue