Merge revisions 1572:1596 from 1.4 branch: Some late bugfixes of the 1.4.2 release. Tutorial generation mechanism.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1598 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-09-29 20:46:43 +00:00
parent 9d3b46ab0a
commit 8db1da30c2
46 changed files with 2874 additions and 1766 deletions

View File

@ -1,4 +1,3 @@
Changes in version 1.5 (... 2008)
- WindowsCE-Bugfix
@ -209,7 +208,7 @@ Changes in version 1.5 (... 2008)
- Finally added StarSonata patch with table element and TabControl additions. Table is based on MultiColor listbox by Acki, and has loads of changes by CuteAlien.
-------------------------------------------
Changes in version 1.4.2 (x.x.2008)
Changes in version 1.4.2 (22.9.2008)
- Unified the handling of zwrite enable with transparent materials on all hw accelerated drivers. This means that all transparent materials will now disable ZWrite, ignoring the material flag.
There is a scene manager attribute, though, which will revert this behavior to the usual SMaterial driven way. Simply call

View File

@ -1277,3 +1277,40 @@ New overload/missing method (completing the findLast... and find...Char methods)
Changed signature (Added return value)
string<T>& trim()
Changes for Version 1.4.2
-------------------------
This is once more a bugfix release of the 1.4 branch, and hence pretty API-consistent and backward compatible. The major reason to publish this release is the OpenGL bug, which made several OpenGL 2.x drivers run in SW emulation.
However, we also introduced some driver consistency fixes, which might affect your application's behavior. So read through the next points thoroughly.
SceneParameters.h (and general video driver behavior)
The way Irrlicht handles zbuffer writing with transparent materials has changed. This was an issue ever since, because the default behavior in Irrlicht is to disable writing to the z-buffer for all really transparent, i.e. blending materials. This avoids problems with intersecting faces, but can also break renderings. And this is now consistent for both OpenGL and Direct3D.
If transparent materials should use the SMaterial flag for ZWriteEnable just as other material types use the newly introduced attribute scene::ALLOW_ZWRITE_ON_TRANSPARENT like this:
SceneManager->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
All transparent materials will henceforth work as specified by the material flag, until the scenemanager attribute is set to false.
SMaterialLayer.h
The texture matrix now uses irrAllocator for memory handling. This shouldn't be noticeable from the user application (besides fixed heap corruptions on Windows machines), but is still mentioned for completeness.
ISceneNode.h
Documentation error. The docs said that children of a scene node are not visible if the node itself is set to visible. This is of course wrong, children inherit non-visibility of the parent and are hence invisible if the parent is. If the parent is visible, the visibility flag of the child determines its status.
SColor.h
Removed methods (use the unsigned versions and cast in your app if necessary)
inline s32 getRedSigned(u16 color)
inline s32 getGreenSigned(u16 color)
inline s32 getBlueSigned(u16 color)
IParticleSystemSceneNode.h
Changed default values (the old direction default was no real direction)
virtual IParticleAnimatedMeshSceneNodeEmitter* createAnimatedMeshSceneNodeEmitter(...)
virtual IParticleCylinderEmitter* createCylinderEmitter(...)
virtual IParticleMeshEmitter* createMeshEmitter(...)
IBoneSceneNode.h
Changed signature (Made const)
virtual E_BONE_SKINNING_SPACE getSkinningSpace() const=0;
IrrlichtDevice.h
Changed signature (Return value bool instead of void). Returns whether the event has been handled somewhere.
virtual bool postEventFromUser(const SEvent& event) = 0;

View File

@ -1,65 +1,67 @@
/** Example 001 HelloWorld
/*
This Tutorial shows how to set up the IDE for using the
Irrlicht Engine and how to write a simple HelloWorld
program with it. The program will show how to use the
basics of the VideoDriver, the GUIEnvironment and the
SceneManager.
Microsoft Visual C++ 6.0 and .NET is used as
example IDE, but you will also be able to understand everything
if you are using a different one or even another operating
system than windows.
This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how
to write a simple HelloWorld program with it. The program will show how to use
the basics of the VideoDriver, the GUIEnvironment, and the SceneManager.
Microsoft Visual Studio is used as an IDE, but you will also be able to
understand everything if you are using a different one or even another
operating system than windows.
To use the engine, we will have to include the header file
irrlicht.h, which can be found in the Irrlicht Engine SDK
directory \include.
To let the compiler find this header file, the directory where
it is located should be specified somewhere. This is different
for every IDE and compiler you use. I explain shortly how to
do this in Microsift Visual Studio C++ 6.0 and .NET:
You have to include the header file <irrlicht.h> in order to use the engine. The
header file can be found in the Irrlicht Engine SDK directory \c include. To let
the compiler find this header file, the directory where it is located has to be
specified. This is different for every IDE and compiler you use. Let's explain
shortly how to do this in Microsoft Visual Studio:
- If you use Version 6.0, select the Menu Extras -> Options.
- If you use Version 6.0, select the Menu Extras -> Options.
Select the directories tab, and select the 'Include' Item in the combo box.
Add the \include directory of the irrlicht engine folder to the list of directories.
Now the compiler will find the Irrlicht.h header file. We also
need the irrlicht.lib to be found, so stay
in that dialog, select 'Libraries' in the combo box and add the
\lib\VisualStudio directory.
Add the \c include directory of the irrlicht engine folder to the list of
directories. Now the compiler will find the Irrlicht.h header file. We also
need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries'
in the combo box and add the \c lib/VisualStudio directory.
\image html "vc6optionsdir.jpg"
\image latex "vc6optionsdir.jpg"
\image html "vc6include.jpg"
\image latex "vc6include.jpg"
- If your IDE is Visual Studio .NET, select Tools -> Options.
Select the projects entry and then select VC++ directories.
Select 'show directories for include files' in the combo box, and
add the \include directory of the irrlicht engine folder to the list of directories.
Now the compiler will find the Irrlicht.h header file. We also
need the irrlicht.lib to be found, so stay
in that dialog, select 'show directories for Library files' and add the
\lib\VisualStudio directory.
Select the projects entry and then select VC++ directories. Select 'show
directories for include files' in the combo box, and add the \c include
directory of the irrlicht engine folder to the list of directories. Now the
compiler will find the Irrlicht.h header file. We also need the irrlicht.lib
to be found, so stay in that dialog, select 'show directories for Library
files' and add the \c lib/VisualStudio directory.
\image html "vcnetinclude.jpg"
\image latex "vcnetinclude.jpg"
That's it, with your IDE set up like this, you will now be able to
develop applications with the Irrlicht Engine.
That's it. With your IDE set up like this, you will now be able to develop
applications with the Irrlicht Engine.
Lets start!
After we have set up the IDE, the compiler will know where to find the Irrlicht
Engine header files so we can include it now in our code.
*/
#include <irrlicht.h>
/*
In the Irrlicht Engine, everything can be found in the namespace
'irr'. So if you want to use a class of the engine, you have to
write an irr:: before the name of the class. For example to use
the IrrlichtDevice write: irr::IrrlichtDevice. To get rid of the
irr:: in front of the name of every class, we tell the compiler
that we use that namespace from now on, and we will not have to
write that 'irr::'.
In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if
you want to use a class of the engine, you have to write irr:: before the name
of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice.
To get rid of the irr:: in front of the name of every class, we tell the
compiler that we use that namespace from now on, and we will not have to write
irr:: anymore.
*/
using namespace irr;
/*
There are 5 sub namespaces in the Irrlicht Engine. Take a look
at them, you can read a detailed description of them in the
documentation by clicking on the top menu item 'Namespace List'
or using this link: http://irrlicht.sourceforge.net/docu/namespaces.html.
Like the irr Namespace, we do not want these 5 sub namespaces now,
to keep this example simple. Hence we tell the compiler again
that we do not want always to write their names:
/*
There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can
read a detailed description of them in the documentation by clicking on the top
menu item 'Namespace List' or by using this link:
http://irrlicht.sourceforge.net/docu/namespaces.html
Like the irr namespace, we do not want these 5 sub namespaces now, to keep this
example simple. Hence, we tell the compiler again that we do not want always to
write their names.
*/
using namespace core;
using namespace scene;
@ -68,46 +70,57 @@ using namespace io;
using namespace gui;
/*
To be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but
to make it easy, we use a pragma comment lib:
To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib.
We could set this option in the project settings, but to make it easy, we use a
pragma comment lib for VisualStudio. On Windows platforms, we have to get rid
of the console window, which pops up when starting a program with main(). This
is done by the second pragma. We could also use the WinMain method, though
losing platform independence then.
*/
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
/*
This is the main method. We can use int main() on every platform.
On Windows platforms, we could also use the WinMain method
if we would want to get rid of the console window, which pops up when
starting a program with main(), but to keep this example simple,
we use main().
This is the main method. We can now use main() on every platform.
*/
int main()
{
/*
The most important function of the engine is the 'createDevice'
function. The Irrlicht Device can be created with it, which is the
root object for doing everything with the engine.
createDevice() has 7 paramters:
deviceType: Type of the device. This can currently be the Null-device,
the Software device, the second software renderer, D3D8, D3D9, or OpenGL.
In this example we use EDT_SOFTWARE, but to try out, you might want to change it to
EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8 , EDT_DIRECT3D9, or EDT_OPENGL.
windowSize: Size of the Window or FullscreenMode to be created. In this
example we use 640x480.
bits: Amount of bits per pixel when in fullscreen mode. This should
be 16 or 32. This parameter is ignored when running in windowed mode.
fullscreen: Specifies if we want the device to run in fullscreen mode
or not.
stencilbuffer: Specifies if we want to use the stencil buffer for drawing shadows.
vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen
mode.
eventReceiver: An object to receive events. We do not want to use this
parameter here, and set it to 0.
*/
The most important function of the engine is the createDevice()
function. The IrrlichtDevice is created by it, which is the root
object for doing anything with the engine. createDevice() has 7
parameters:
- deviceType: Type of the device. This can currently be the Null-device,
one of the two software renderers, D3D8, D3D9, or OpenGL. In this
example we use EDT_SOFTWARE, but to try out, you might want to
change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8,
EDT_DIRECT3D9, or EDT_OPENGL.
- windowSize: Size of the Window or screen in FullScreenMode to be
created. In this example we use 640x480.
- bits: Amount of color bits per pixel. This should be 16 or 32. The
parameter is often ignored when running in windowed mode.
- fullscreen: Specifies if we want the device to run in fullscreen mode
or not.
- stencilbuffer: Specifies if we want to use the stencil buffer (for
drawing shadows).
- vsync: Specifies if we want to have vsync enabled, this is only useful
in fullscreen mode.
- eventReceiver: An object to receive events. We do not want to use this
parameter here, and set it to 0.
Always check the return value to cope with unsupported drivers,
dimensions, etc.
*/
IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
@ -116,19 +129,21 @@ int main()
createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
#endif
if (!device)
return 1;
/*
Set the caption of the window to some nice text. Note that there is
a 'L' in front of the string. The Irrlicht Engine uses wide character
Set the caption of the window to some nice text. Note that there is an
'L' in front of the string. The Irrlicht Engine uses wide character
strings when displaying text.
*/
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
/*
Get a pointer to the video driver, the SceneManager and the
graphical user interface environment, so that
we do not always have to write device->getVideoDriver(),
device->getSceneManager() and device->getGUIEnvironment().
Get a pointer to the VideoDriver, the SceneManager and the graphical
user interface environment, so that we do not always have to write
device->getVideoDriver(), device->getSceneManager(), or
device->getGUIEnvironment().
*/
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
@ -136,58 +151,65 @@ int main()
/*
We add a hello world label to the window, using the GUI environment.
The text is placed at the position (10,10) as top left corner and
(260,22) as lower right corner.
*/
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<s32>(10,10,260,22), true);
/*
To display something interesting, we load a Quake 2 model
and display it. We only have to get the Mesh from the Scene
Manager (getMesh()) and add a SceneNode to display the mesh.
(addAnimatedMeshSceneNode()). Instead of writing the filename
sydney.md2, it would also be possible to load a Maya object file
(.obj), a complete Quake3 map (.bsp) or a Milshape file (.ms3d).
By the way, that cool Quake 2 model called sydney was modelled
by Brian Collins.
To show something interesting, we load a Quake 2 model and display it.
We only have to get the Mesh from the Scene Manager with getMesh() and add
a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We
check the return value of getMesh() to become aware of loading problems
and other errors.
Instead of writing the filename sydney.md2, it would also be possible
to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any
other supported file format. By the way, that cool Quake 2 model
called sydney was modelled by Brian Collins.
*/
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
return 1;
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
/*
To let the mesh look a little bit nicer, we change its material a
little bit: We disable lighting because we do not have a dynamic light
in here, and the mesh would be totally black. Then we set the frame
loop, so that the animation is looped between the frames 0 and 310.
And at last, we apply a texture to the mesh. Without it the mesh
would be drawn using only a color.
To let the mesh look a little bit nicer, we change its material. We
disable lighting because we do not have a dynamic light in here, and
the mesh would be totally black otherwise. Then we set the frame loop,
such that the predefined STAND animation is used. And last, we apply a
texture to the mesh. Without it the mesh would be drawn using only a
color.
*/
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation ( scene::EMAT_STAND );
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}
/*
To look at the mesh, we place a camera into 3d space at the position
(0, 30, -40). The camera looks from there to (0,5,0).
(0, 30, -40). The camera looks from there to (0,5,0), which is
approximately the place where our md2 model is.
*/
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
/*
Ok, now we have set up the scene, lets draw everything:
We run the device in a while() loop, until the device does not
want to run any more. This would be when the user closed the window
or pressed ALT+F4 in windows.
Ok, now we have set up the scene, lets draw everything: We run the
device in a while() loop, until the device does not want to run any
more. This would be when the user closes the window or presses ALT+F4
(or whatever keycode closes a window).
*/
while(device->run())
{
/*
Anything can be drawn between a beginScene() and an endScene()
call. The beginScene clears the screen with a color and also the
depth buffer if wanted. Then we let the Scene Manager and the
GUI Environment draw their content. With the endScene() call
everything is presented on the screen.
call. The beginScene() call clears the screen with a color and
the depth buffer, if desired. Then we let the Scene Manager and
the GUI Environment draw their content. With the endScene()
call everything is presented on the screen.
*/
driver->beginScene(true, true, SColor(255,100,101,140));
@ -198,17 +220,18 @@ int main()
}
/*
After we are finished, we have to delete the Irrlicht Device
created before with createDevice(). In the Irrlicht Engine,
you will have to delete all objects you created with a method or
function which starts with 'create'. The object is simply deleted
by calling ->drop().
See the documentation at
http://irrlicht.sourceforge.net//docu/classirr_1_1IUnknown.html#a3
for more information.
After we are done with the render loop, we have to delete the Irrlicht
Device created before with createDevice(). In the Irrlicht Engine, you
have to delete all objects you created with a method or function which
starts with 'create'. The object is simply deleted by calling ->drop().
See the documentation at irr::IReferenceCounted::drop() for more
information.
*/
device->drop();
return 0;
}
/*
That's it. Compile and run.
**/

View File

@ -1,49 +1,52 @@
/*
This Tutorial shows how to load a Quake 3 map into the
engine, create a SceneNode for optimizing the speed of
rendering and how to create a user controlled camera.
/** Example 002 Quake3Map
Lets start like the HelloWorld example: We include
the irrlicht header files and an additional file to be able
to ask the user for a driver type using the console.
This Tutorial shows how to load a Quake 3 map into the engine, create a
SceneNode for optimizing the speed of rendering, and how to create a user
controlled camera.
Please note that you should know the basics of the engine before starting this
tutorial. Just take a short look at the first tutorial, if you haven't done
this yet: http://irrlicht.sourceforge.net/tut001.html
Lets start like the HelloWorld example: We include the irrlicht header files
and an additional file to be able to ask the user for a driver type using the
console.
*/
#include <irrlicht.h>
#include <iostream>
/*
As already written in the HelloWorld example, in the Irrlicht
Engine, everything can be found in the namespace 'irr'.
To get rid of the irr:: in front of the name of every class,
we tell the compiler that we use that namespace from now on,
and we will not have to write that 'irr::'.
There are 5 other sub namespaces 'core', 'scene', 'video',
'io' and 'gui'. Unlike in the HelloWorld example,
we do not a 'using namespace' for these 5 other namespaces
because in this way you will see what can be found in which
namespace. But if you like, you can also include the namespaces
like in the previous example. Code just like you want to.
As already written in the HelloWorld example, in the Irrlicht Engine everything
can be found in the namespace 'irr'. To get rid of the irr:: in front of the
name of every class, we tell the compiler that we use that namespace from now
on, and we will not have to write that 'irr::'. There are 5 other sub
namespaces 'core', 'scene', 'video', 'io' and 'gui'. Unlike in the HelloWorld
example, we do not call 'using namespace' for these 5 other namespaces, because
in this way you will see what can be found in which namespace. But if you like,
you can also include the namespaces like in the previous example.
*/
using namespace irr;
/*
Again, to be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but
to make it easy, we use a pragma comment lib:
Again, to be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but to make it
easy, we use a pragma comment lib:
*/
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
/*
Ok, lets start. Again, we use the main() method as start, not the
WinMain(), because its shorter to write.
Ok, lets start. Again, we use the main() method as start, not the WinMain().
*/
int main()
{
/*
Like in the HelloWorld example, we create an IrrlichtDevice with
createDevice(). The difference now is that we ask the user to select
which hardware accelerated driver to use. The Software device would be
createDevice(). The difference now is that we ask the user to select
which video driver to use. The Software device might be
too slow to draw a huge Quake 3 map, but just for the fun of it, we make
this decision possible too.
this decision possible, too.
*/
// ask user for driver
@ -79,36 +82,40 @@ int main()
/*
Get a pointer to the video driver and the SceneManager so that
we do not always have to write device->getVideoDriver() and
device->getSceneManager().
we do not always have to call irr::IrrlichtDevice::getVideoDriver() and
irr::IrrlichtDevice::getSceneManager().
*/
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
/*
To display the Quake 3 map, we first need to load it. Quake 3 maps
are packed into .pk3 files wich are nothing other than .zip files.
So we add the .pk3 file to our FileSystem. After it was added,
we are able to read from the files in that archive as they would
directly be stored on disk.
are packed into .pk3 files which are nothing else than .zip files.
So we add the .pk3 file to our irr::io::IFileSystem. After it was added,
we are able to read from the files in that archive as if they are
directly stored on the disk.
*/
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
/*
Now we can load the mesh by calling getMesh(). We get a pointer returned
to a IAnimatedMesh. As you know, Quake 3 maps are not really animated,
they are only a huge chunk of static geometry with some materials
attached. Hence the IAnimated mesh consists of only one frame,
so we get the "first frame" of the "animation", which is our quake level
and create an OctTree scene node with it, using addOctTreeSceneNode().
The OctTree optimizes the scene a little bit, trying to draw only
geometry which is currently visible. An alternative to the OctTree
would be a MeshSceneNode, which would draw always the complete geometry
of the mesh, without optimization. Try it out: Write addMeshSceneNode
instead of addOctTreeSceneNode and compare the primitives drawn by the
video driver. (There is a getPrimitiveCountDrawn() method in the
IVideoDriver class). Note that this optimization with the Octree is only
useful when drawing huge meshes consisting of lots of geometry.
/*
Now we can load the mesh by calling
irr::scene::ISceneManager::getMesh(). We get a pointer returned to an
irr::scene::IAnimatedMesh. As you might know, Quake 3 maps are not
really animated, they are only a huge chunk of static geometry with
some materials attached. Hence the IAnimatedMesh consists of only one
frame, so we get the "first frame" of the "animation", which is our
quake level and create an OctTree scene node with it, using
irr::scene::ISceneManager::addOctTreeSceneNode().
The OctTree optimizes the scene a little bit, trying to draw only geometry
which is currently visible. An alternative to the OctTree would be a
irr::scene::IMeshSceneNode, which would always draw the complete
geometry of the mesh, without optimization. Try it: Use
irr::scene::ISceneManager::addMeshSceneNode() instead of
addOctTreeSceneNode() and compare the primitives drawn by the video
driver. (There is a irr::video::IVideoDriver::getPrimitiveCountDrawn()
method in the irr::video::IVideoDriver class). Note that this
optimization with the OctTree is only useful when drawing huge meshes
consisting of lots of geometry.
*/
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
@ -118,58 +125,70 @@ int main()
// node = smgr->addMeshSceneNode(mesh->getMesh(0));
/*
Because the level was modelled not around the origin (0,0,0), we translate
the whole level a little bit.
Because the level was not modelled around the origin (0,0,0), we
translate the whole level a little bit. This is done on
irr::scene::ISceneNode level using the methods
irr::scene::ISceneNode::setPosition() (in this case),
irr::scene::ISceneNode::setRotation(), and
irr::scene::ISceneNode::setScale().
*/
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
/*
Now we only need a Camera to look at the Quake 3 map.
And we want to create a user controlled camera. There are some
different cameras available in the Irrlicht engine. For example the
Maya Camera which can be controlled compareable to the camera in Maya:
Now we only need a camera to look at the Quake 3 map.
We want to create a user controlled camera. There are some
cameras available in the Irrlicht engine. For example the
MayaCamera which can be controlled like the camera in Maya:
Rotate with left mouse button pressed, Zoom with both buttons pressed,
translate with right mouse button pressed. This could be created with
addCameraSceneNodeMaya(). But for this example, we want to create a
camera which behaves like the ones in first person shooter games (FPS).
irr::scene::ISceneManager::addCameraSceneNodeMaya(). But for this
example, we want to create a camera which behaves like the ones in
first person shooter games (FPS) and hence use
irr::scene::ISceneManager::addCameraSceneNodeFPS().
*/
smgr->addCameraSceneNodeFPS();
/*
The mouse cursor needs not to be visible, so we make it invisible.
The mouse cursor needs not be visible, so we hide it via the
irr::IrrlichtDevice::ICursorControl.
*/
device->getCursorControl()->setVisible(false);
/*
We have done everything, so lets draw it. We also write the current
frames per second and the drawn primitives to the caption of the
window. The 'if (device->isWindowActive())' line is optional, but
prevents the engine render to set the position of the mouse cursor
after task switching when other program are active.
frames per second and the primitives drawn into the caption of the
window. The test for irr::IrrlichtDevice::isWindowActive() is optional,
but prevents the engine to grab the mouse cursor after task switching
when other programs are active. The call to
irr::IrrlichtDevice::yield() will avoid the busy loop to eat up all CPU
cycles when the window is not active.
*/
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(0,200,200,200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
if (device->isWindowActive())
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
str += driver->getName();
str += "] FPS:";
str += fps;
driver->beginScene(true, true, video::SColor(255,200,200,200));
smgr->drawAll();
driver->endScene();
device->setWindowCaption(str.c_str());
lastFPS = fps;
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
/*
@ -179,3 +198,6 @@ int main()
return 0;
}
/*
That's it. Compile and play around with the program.
**/

View File

@ -1,14 +1,15 @@
/*
This Tutorial is a tutorial for more advanced developers.
/** Example 003 Custom SceneNode
This Tutorial is more advanced than the previous ones.
If you are currently just playing around with the Irrlicht
engine, please look at other examples first.
engine, you may want to look at other examples first.
This tutorials shows how to create a custom scene node and
how to use it in the engine. A custom scene node is needed,
if you want to implement a render technique, the Irrlicht
Engine is currently not supporting. For example you can write
a indoor portal based renderer or a advanced terrain scene
node with it. With creating custom scene nodes, you can
easily extend the Irrlicht Engine and adapt it to your
how to use it in the engine. A custom scene node is needed
if you want to implement a render technique the Irrlicht
Engine currently does not support. For example, you can write
an indoor portal based renderer or an advanced terrain scene
node with it. By creating custom scene nodes, you can
easily extend the Irrlicht Engine and adapt it to your own
needs.
I will keep the tutorial simple: Keep everything very
@ -16,45 +17,49 @@ short, everything in one .cpp file, and I'll use the engine
here as in all other tutorials.
To start, I include the header files, use the irr namespace,
and tell the linker to link with the .lib file.
and tell the linker to link with the .lib file.
*/
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
/*
Here comes the most sophisticated part of this tutorial:
Here comes the more sophisticated part of this tutorial:
The class of our very own custom scene node. To keep it simple,
our scene node will not be an indoor portal renderer nor a terrain
scene node, but a simple tetraeder, a 3d object consiting of 4
scene node, but a simple tetraeder, a 3d object consisting of 4
connected vertices, which only draws itself and does nothing more.
Note that this scenario does not require a custom scene node in Irrlicht.
Instead one would create a mesh from the geometry and pass it to a
irr::scene::IMeshSceneNode. This example just illustrates creation of a custom
scene node in a very simple setting.
To let our scene node be able to be inserted into the Irrlicht
Engine scene, the class we create needs only be derived from the
ISceneNode class and has to override some methods.
To let our scene node be able to be inserted into the Irrlicht
Engine scene, the class we create needs to be derived from the
irr::scene::ISceneNode class and has to override some methods.
*/
class CSampleSceneNode : public scene::ISceneNode
{
/*
First, we declare some member variables. Some space to
hold data for our tetraeder: The bounding box, 4 vertices, and
the material of the tetraeder.
First, we declare some member variables:
The bounding box, 4 vertices, and the material of the tetraeder.
*/
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[4];
video::SMaterial Material;
/*
The parameters of the constructor specify the parent of the scene node,
a pointer to the scene manager, and an id of the scene node.
In the constructor itself, we call the parent classes constructor,
set some properties of the material we use to draw the scene nodem and
In the constructor we call the parent class' constructor,
set some properties of the material, and
create the 4 vertices of the tetraeder we will draw later.
*/
@ -72,33 +77,35 @@ public:
Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0);
/*
The Irrlicht Engine needs to know the bounding box of your scene node.
It will use it for doing automatic culling and other things. Hence we
need to create a bounding box from the 4 vertices we use.
If you do not want the engine to use the box for automatic culling,
and/or don't want to create the box, you could also write
AutomaticCullingEnabled = false;.
The Irrlicht Engine needs to know the bounding box of a scene node.
It will use it for automatic culling and other things. Hence, we
need to create a bounding box from the 4 vertices we use.
If you do not want the engine to use the box for automatic culling,
and/or don't want to create the box, you could also call
irr::scene::ISceneNode::setAutomaticCulling() with irr::scene::EAC_OFF.
*/
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
/*
Before it is drawn, the OnRegisterSceneNode() method of every scene node in the scene
is called by the scene manager. If the scene node wishes to draw itself,
it may register itself in the scene manager to be drawn. This is necessary to
tell the scene manager when it should call the ::render method. For example
normal scene nodes render their content one after another, while
stencil buffer shadows would like to be drawn after all other scene nodes. And
camera or light scene nodes need to be rendered before all other scene
nodes (if at all).
So here we simply register the scene node to get render normally. If we would like
to let it be rendered like cameras or light, we would have to call
Before it is drawn, the irr::scene::ISceneNode::OnRegisterSceneNode()
method of every scene node in the scene is called by the scene manager.
If the scene node wishes to draw itself, it may register itself in the
scene manager to be drawn. This is necessary to tell the scene manager
when it should call irr::scene::ISceneNode::render(). For
example, normal scene nodes render their content one after another,
while stencil buffer shadows would like to be drawn after all other
scene nodes. And camera or light scene nodes need to be rendered before
all other scene nodes (if at all). So here we simply register the
scene node to render normally. If we would like to let it be rendered
like cameras or light, we would have to call
SceneManager->registerNodeForRendering(this, SNRT_LIGHT_AND_CAMERA);
After this, we call the OnRegisterSceneNode-method of the base class ISceneNode,
which simply lets also all the child scene nodes of this node register themselves.
After this, we call the actual
irr::scene::ISceneNode::OnRegisterSceneNode() method of the base class,
which simply lets also all the child scene nodes of this node register
themselves.
*/
virtual void OnRegisterSceneNode()
{
@ -109,7 +116,7 @@ public:
}
/*
In the render() method most of the interesting stuff happenes: The
In the render() method most of the interesting stuff happens: The
Scene node renders itself. We override this method and draw the
tetraeder.
*/
@ -124,13 +131,14 @@ public:
}
/*
At least, we create three small additional methods.
GetBoundingBox() returns the bounding box of this scene node,
GetMaterialCount() returns the amount of materials in this scene node
(our tetraeder only has one material), and getMaterial() returns the
And finally we create three small additional methods.
irr::scene::ISceneNode::getBoundingBox() returns the bounding box of
this scene node, irr::scene::ISceneNode::getMaterialCount() returns the
amount of materials in this scene node (our tetraeder only has one
material), and irr::scene::ISceneNode::getMaterial() returns the
material at an index. Because we have only one material here, we can
return the only one meterial, assuming that no one ever calls getMaterial()
with an index greater than 0.
return the only one material, assuming that no one ever calls
getMaterial() with an index greater than 0.
*/
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
@ -172,7 +180,7 @@ int main()
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
@ -194,43 +202,55 @@ int main()
smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
// Create our scene node. I don't check the result of calling new, as it
// should throw an exception rather than returning 0 on failure.
// Because the new node will create itself with a reference count of 1, and
// then will have another reference added by its parent scene node when it is
// added to the scene, I need to drop my reference to it. Best practice is
// to drop it only *after* I have finished using it, regardless of what the
// reference count of the object is after creation.
CSampleSceneNode *myNode =
/*
Create our scene node. I don't check the result of calling new, as it
should throw an exception rather than returning 0 on failure. Because
the new node will create itself with a reference count of 1, and then
will have another reference added by its parent scene node when it is
added to the scene, I need to drop my reference to it. Best practice is
to drop it only *after* I have finished using it, regardless of what
the reference count of the object is after creation.
*/
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
// To animate something in this boring scene consisting only of one tetraeder,
// and to show, that you now can use your scene node like any other scene
// node in the engine, we add an animator to the scene node, which rotates
// the node a little bit.
scene::ISceneNodeAnimator* anim =
/*
To animate something in this boring scene consisting only of one
tetraeder, and to show that you now can use your scene node like any
other scene node in the engine, we add an animator to the scene node,
which rotates the node a little bit.
irr::scene::ISceneManager::createRotationAnimator() could return 0, so
should be checked.
*/
scene::ISceneNodeAnimator* anim =
smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f));
// createRotationAnimator() could return 0, so should be checked
if(anim)
{
myNode->addAnimator(anim);
// I'm done referring to anim, so must drop this reference now because it
// was produced by a createFoo() function.
/*
I'm done referring to anim, so must
irr::IReferenceCounted::drop() this reference now because it
was produced by a createFoo() function. As I shouldn't refer to
it again, ensure that I can't by setting to 0.
*/
anim->drop();
anim = 0; // As I shouldn't refer to it again, ensure that I can't
anim = 0;
}
// I'm done with my CSampleSceneNode object, and so must drop my reference
/*
I'm done with my CSampleSceneNode object, and so must drop my reference.
This won't delete the object, yet, because it is still attached to the
scene graph, which prevents the deletion until the graph is deleted or the
custom scene node is removed from it.
*/
myNode->drop();
myNode = 0; // As I shouldn't refer to it again, ensure that I can't
/*
/*
Now draw everything and finish.
*/
u32 frames=0;
while(device->run())
{
@ -256,3 +276,6 @@ int main()
return 0;
}
/*
That's it. Compile and play around with the program.
**/

View File

@ -1,4 +1,5 @@
/*
/** Example 004 Movement
This Tutorial shows how to move and animate SceneNodes. The
basic concept of SceneNodeAnimators is shown as well as manual
movement of nodes using the keyboard.
@ -11,15 +12,17 @@ and tell the linker to link with the .lib file.
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
/*
To receive events like mouse and keyboard input, or GUI events like
"the OK button has been clicked", we need an object which is derived from the
IEventReceiver object. There is only one method to override: OnEvent.
This method will be called by the engine once when an event happens.
What we really want to know is whether a key is being held down,
and so we will remember the current state of each key.
To receive events like mouse and keyboard input, or GUI events like "the OK
button has been clicked", we need an object which is derived from the
irr::IEventReceiver object. There is only one method to override:
irr::IEventReceiver::OnEvent(). This method will be called by the engine once
when an event happens. What we really want to know is whether a key is being
held down, and so we will remember the current state of each key.
*/
class MyEventReceiver : public IEventReceiver
{
@ -53,10 +56,11 @@ private:
/*
The event receiver for moving a scene node is ready. So lets just create
an Irrlicht Device and the scene node we want to move. We also create some
other additional scene nodes, to show that there are also some different
possibilities to move and animate scene nodes.
The event receiver for keeping the pressed keys is ready, the actual responses
will be made inside the render loop, right before drawing the scene. So lets
just create an irr::IrrlichtDevice and the scene node we want to move. We also
create some other additional scene nodes, to show that there are also some
different possibilities to move and animate scene nodes.
*/
int main()
{
@ -92,14 +96,12 @@ int main()
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
/*
Create the node for moving it with the 'W' and 'S' key. We create a
sphere node, which is a built in geometry primitive. We place the node
Create the node which will be moved with the 'W' and 'S' key. We create a
sphere node, which is a built-in geometry primitive. We place the node
at (0,0,30) and assign a texture to it to let it look a little bit more
interesting. Because we have no dynamic lights in this scene we disable
lighting for each model (otherwise the models would be black).
@ -112,15 +114,14 @@ int main()
node->setMaterialFlag(video::EMF_LIGHTING, false);
}
/*
Now we create another node, moving using a scene node animator. Scene
/*
Now we create another node, movable using a scene node animator. Scene
node animators modify scene nodes and can be attached to any scene node
like mesh scene nodes, billboards, lights and even camera scene nodes.
Scene node animators are not only able to modify the position of a
scene node, they can also animate the textures of an object for
example. We create a cube scene node and attach a 'fly circle' scene
node to it, letting this node fly around our sphere scene node.
example. We create a cube scene node and attach a 'fly circle' scene
node animator to it, letting this node fly around our sphere scene node.
*/
scene::ISceneNode* n = smgr->addCubeSceneNode();
@ -138,7 +139,7 @@ int main()
}
/*
The last scene node we add to show possibilities of scene node animators is
The last scene node we add to show possibilities of scene node animators is
a md2 model, which uses a 'fly straight' animator to run between to points.
*/
scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/sydney.md2"));
@ -146,7 +147,7 @@ int main()
if (anms)
{
scene::ISceneNodeAnimator* anim =
smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
core::vector3df(-100,0,60), 2500, true);
if (anim)
{
@ -155,14 +156,16 @@ int main()
}
/*
To make to model look right we set the frames between which the animation
should loop, rotate the model around 180 degrees, and adjust the animation speed
and the texture.
To set the right animation (frames and speed), we would also be able to just
call "anms->setMD2Animation(scene::EMAT_RUN)" for the 'run' animation
instead of "setFrameLoop" and "setAnimationSpeed",
but this only works with MD2 animations, and so you know how to start other animations.
but it a good advice to use not hardcoded frame-numbers...
To make the model look right we disable lighting, set the
frames between which the animation should loop, rotate the
model around 180 degrees, and adjust the animation speed and
the texture. To set the right animation (frames and speed), we
would also be able to just call
"anms->setMD2Animation(scene::EMAT_RUN)" for the 'run'
animation instead of "setFrameLoop" and "setAnimationSpeed",
but this only works with MD2 animations, and so you know how to
start other animations. But a good advice is to not use
hardcoded frame-numbers...
*/
anms->setMaterialFlag(video::EMF_LIGHTING, false);
@ -228,7 +231,7 @@ int main()
{
core::stringw tmp(L"Movement Example - Irrlicht Engine [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
@ -244,3 +247,6 @@ int main()
return 0;
}
/*
That's it. Compile and play around with the program.
**/

View File

@ -1,8 +1,9 @@
/*
/** Example 005 User Interface
This tutorial shows how to use the built in User Interface of
the Irrlicht Engine. It will give a brief overview and show
how to create and use windows, buttons, scroll bars, static
texts and list boxes.
how to create and use windows, buttons, scroll bars, static
texts, and list boxes.
As always, we include the header files, and use the irrlicht
namespaces. We also store a pointer to the Irrlicht device,
@ -32,13 +33,13 @@ IGUIListBox* listbox = 0;
/*
The Event Receiver is not only capable of getting keyboard and
mouse input events, but also events of the graphical user interface
(gui). There are events for almost everything: Button click,
mouse input events, but also events of the graphical user interface
(gui). There are events for almost everything: Button click,
Listbox selection change, events that say that a element was hovered
and so on. To be able to react to some of these events, we create
an event receiver.
and so on. To be able to react to some of these events, we create
an event receiver.
We only react to gui events, and if it's such an event, we get the
id of the caller (the gui element which caused the event) and get
id of the caller (the gui element which caused the event) and get
the pointer to the gui environment.
*/
class MyEventReceiver : public IEventReceiver
@ -55,12 +56,12 @@ public:
{
/*
If a scrollbar changed its scroll position, and it is 'our'
scrollbar (the one with id 104), then we change the
transparency of all gui elements. This is a very easy task:
There is a skin object, in which all color settings are stored.
We simply go through all colors stored in the skin and change
their alpha value.
If a scrollbar changed its scroll position, and it is
'our' scrollbar (the one with id 104), then we change
the transparency of all gui elements. This is a very
easy task: There is a skin object, in which all color
settings are stored. We simply go through all colors
stored in the skin and change their alpha value.
*/
case EGET_SCROLL_BAR_CHANGED:
if (id == 104)
@ -80,7 +81,7 @@ public:
/*
If a button was clicked, it could be one of 'our'
three buttons. If it is the first, we shut down the engine.
If it is the second, we create a little window with some
If it is the second, we create a little window with some
text on it. We also add a string to the list box to log
what happened. And if it is the third button, we create
a file open dialog, and add also this as string to the list box.
@ -98,15 +99,15 @@ public:
{
listbox->addItem(L"Window created");
cnt += 30;
if (cnt > 200)
if (cnt > 200)
cnt = 0;
IGUIWindow* window = env->addWindow(
rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt),
rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt),
false, // modal?
L"Test window");
env->addStaticText(L"Please close me",
env->addStaticText(L"Please close me",
rect<s32>(35,35,140,50),
true, // border?
false, // wordwrap?
@ -134,9 +135,9 @@ public:
/*
Ok, now for the more interesting part. First, create the
Irrlicht device. As in some examples before, we ask the user which
driver he wants to use for this example:
Ok, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example:
*/
int main()
{
@ -182,7 +183,7 @@ int main()
/*
To make the font a little bit nicer, we load an external font
and set it as the new default font in the skin.
and set it as the new default font in the skin.
To keep the standard font for tool tip text, we set it to
the built-in font.
*/
@ -208,7 +209,7 @@ int main()
/*
Now, we add a static text and a scrollbar, which modifies the
transparency of all gui elements. We set the maximum value of
the scrollbar to 255, because that's the maximal value for
the scrollbar to 255, because that's the maximal value for
a color value.
Then we create an other static text and a list box.
*/
@ -224,7 +225,9 @@ int main()
listbox = env->addListBox(rect<s32>(50, 140, 250, 210));
env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));
// add the engine logo
/*
And at last, we create a nice Irrlicht Engine logo in the top left corner.
*/
env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
position2d<int>(10,10));
@ -247,3 +250,6 @@ int main()
return 0;
}
/*
**/

View File

@ -1,171 +1,175 @@
/*
This Tutorial shows how to do 2d graphics with the Irrlicht Engine.
It shows how to draw images, keycolor based sprites,
transparent rectangles and different fonts. You will may consider
this useful if you want to make a 2d game with the engine, or if
you want to draw a cool interface or head up display for your 3d game.
As always, I include the header files, use the irr namespace,
and tell the linker to link with the .lib file.
*/
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
/*
At first, we let the user select the driver type, then
start up the engine, set a caption, and get a pointer
to the video driver.
*/
int main()
{
// let user select driver type
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
// create device
IrrlichtDevice *device = createDevice(driverType,
core::dimension2d<s32>(512, 384));
if (device == 0)
return 1; // could not create selected driver.
device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");
video::IVideoDriver* driver = device->getVideoDriver();
/*
All 2d graphics in this example are put together into one texture,
2ddemo.bmp. Because we want to draw colorkey based sprites, we need
to load this texture and tell the engine, which
part of it should be transparent based on a colorkey. In this example,
we don't tell it the color directly, we just say "Hey Irrlicht Engine,
you'll find the color I want at position (0,0) on the texture.".
Instead, it would be also possible to call
driver->makeColorKeyTexture(images, video::SColor(0,0,0,0)), to make
e.g. all black pixels transparent. Please note, that makeColorKeyTexture
just creates an alpha channel based on the color.
*/
video::ITexture* images = driver->getTexture("../../media/2ddemo.bmp");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
/*
To be able to draw some text with two different fonts, we load them.
Ok, we load just one, as first font we just use the default font which is
built into the engine.
Also, we define two rectangles, which specify the position of the
images of the red imps (little flying creatures) in the texture.
*/
gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
gui::IGUIFont* font2 = device->getGUIEnvironment()->getFont("../../media/fonthaettenschweiler.bmp");
core::rect<s32> imp1(349,15,385,78);
core::rect<s32> imp2(387,15,423,78);
/*
Everything is prepared, now we can draw everything in the draw loop,
between the begin scene and end scene calls. In this example, we
are just doing 2d graphics, but it would be no problem to mix them
with 3d graphics. Just try it out, and draw some 3d vertices or set
up a scene with the scene manager and draw it.
*/
while(device->run() && driver)
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, video::SColor(0,120,102,136));
/*
First, we draw 3 sprites, using the alpha channel we created with
makeColorKeyTexture. The last parameter specifiys that the drawing
method should use thiw alpha channel. The parameter before the last
one specifies a color, with wich the sprite should be colored.
(255,255,255,255) is full white, so the sprite will look like the
original. The third sprite is drawed colored based on the time.
*/
// draw fire & dragons background world
driver->draw2DImage(images, core::position2d<s32>(50,50),
core::rect<s32>(0,0,342,224), 0,
video::SColor(255,255,255,255), true);
// draw flying imp
driver->draw2DImage(images, core::position2d<s32>(164,125),
(time/500 % 2) ? imp1 : imp2, 0,
video::SColor(255,255,255,255), true);
// draw second flying imp with colorcylce
driver->draw2DImage(images, core::position2d<s32>(270,105),
(time/500 % 2) ? imp1 : imp2, 0,
video::SColor(255,(time) % 255,255,255), true);
/*
Drawing text is really simple. The code should be self explanatory.
*/
// draw some text
if (font)
font->draw(L"This demo shows that Irrlicht is also capable of drawing 2D graphics.",
core::rect<s32>(130,10,300,50),
video::SColor(255,255,255,255));
// draw some other text
if (font2)
font2->draw(L"Also mixing with 3d graphics is possible.",
core::rect<s32>(130,20,300,60),
video::SColor(255,time % 255,time % 255,255));
/*
At last, we draw the Irrlicht Engine logo (without using a color or
an alpha channel) and a transparent 2d Rectangle at the position of
the mouse cursor.
*/
// draw logo
driver->draw2DImage(images, core::position2d<s32>(10,10),
core::rect<s32>(354,87,442,118));
// draw transparent rect under cursor
core::position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DRectangle(video::SColor(100,255,255,255),
core::rect<s32>(m.X-20, m.Y-20, m.X+20, m.Y+20));
driver->endScene();
}
}
/*
That's all, it was not really difficult, I hope.
*/
device->drop();
return 0;
}
/** Example 006 2D Graphics
This Tutorial shows how to do 2d graphics with the Irrlicht Engine.
It shows how to draw images, keycolor based sprites,
transparent rectangles, and different fonts. You may consider
this useful if you want to make a 2d game with the engine, or if
you want to draw a cool interface or head up display for your 3d game.
As always, I include the header files, use the irr namespace,
and tell the linker to link with the .lib file.
*/
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
/*
At first, we let the user select the driver type, then start up the engine, set
a caption, and get a pointer to the video driver.
*/
int main()
{
// let user select driver type
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
// create device
IrrlichtDevice *device = createDevice(driverType,
core::dimension2d<s32>(512, 384));
if (device == 0)
return 1; // could not create selected driver.
device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");
video::IVideoDriver* driver = device->getVideoDriver();
/*
All 2d graphics in this example are put together into one texture,
2ddemo.bmp. Because we want to draw colorkey based sprites, we need to
load this texture and tell the engine, which part of it should be
transparent based on a colorkey.
In this example, we don't tell it the color directly, we just say "Hey
Irrlicht Engine, you'll find the color I want at position (0,0) on the
texture.". Instead, it would be also possible to call
driver->makeColorKeyTexture(images, video::SColor(0,0,0,0)), to make
e.g. all black pixels transparent. Please note that
makeColorKeyTexture just creates an alpha channel based on the color.
*/
video::ITexture* images = driver->getTexture("../../media/2ddemo.bmp");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
/*
To be able to draw some text with two different fonts, we first load
them. Ok, we load just one. As the first font we just use the default
font which is built into the engine. Also, we define two rectangles
which specify the position of the images of the red imps (little flying
creatures) in the texture.
*/
gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
gui::IGUIFont* font2 = device->getGUIEnvironment()->getFont("../../media/fonthaettenschweiler.bmp");
core::rect<s32> imp1(349,15,385,78);
core::rect<s32> imp2(387,15,423,78);
/*
Everything is prepared, now we can draw everything in the draw loop,
between the begin scene and end scene calls. In this example, we are
just doing 2d graphics, but it would be no problem to mix them with 3d
graphics. Just try it out, and draw some 3d vertices or set up a scene
with the scene manager and draw it.
*/
while(device->run() && driver)
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, video::SColor(255,120,102,136));
/*
First, we draw 3 sprites, using the alpha channel we
created with makeColorKeyTexture. The last parameter
specifies that the drawing method should use this alpha
channel. The last-but-one parameter specifies a
color, with which the sprite should be colored.
(255,255,255,255) is full white, so the sprite will
look like the original. The third sprite is drawn
with the red channel modulated based on the time.
*/
// draw fire & dragons background world
driver->draw2DImage(images, core::position2d<s32>(50,50),
core::rect<s32>(0,0,342,224), 0,
video::SColor(255,255,255,255), true);
// draw flying imp
driver->draw2DImage(images, core::position2d<s32>(164,125),
(time/500 % 2) ? imp1 : imp2, 0,
video::SColor(255,255,255,255), true);
// draw second flying imp with colorcylce
driver->draw2DImage(images, core::position2d<s32>(270,105),
(time/500 % 2) ? imp1 : imp2, 0,
video::SColor(255,(time) % 255,255,255), true);
/*
Drawing text is really simple. The code should be self
explanatory.
*/
// draw some text
if (font)
font->draw(L"This demo shows that Irrlicht is also capable of drawing 2D graphics.",
core::rect<s32>(130,10,300,50),
video::SColor(255,255,255,255));
// draw some other text
if (font2)
font2->draw(L"Also mixing with 3d graphics is possible.",
core::rect<s32>(130,20,300,60),
video::SColor(255,time % 255,time % 255,255));
/*
At last, we draw the Irrlicht Engine logo (without
using a color or an alpha channel) and a transparent 2d
Rectangle at the position of the mouse cursor.
*/
// draw logo
driver->draw2DImage(images, core::position2d<s32>(10,10),
core::rect<s32>(354,87,442,118));
// draw transparent rect under cursor
core::position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DRectangle(video::SColor(100,255,255,255),
core::rect<s32>(m.X-20, m.Y-20, m.X+20, m.Y+20));
driver->endScene();
}
}
device->drop();
return 0;
}
/*
That's all. I hope it was not too difficult.
**/

View File

@ -1,15 +1,15 @@
/*
In this tutorial, I will show how to collision detection with the Irrlicht Engine.
I will describe 3 methods: Automatic collision detection for moving through 3d worlds
with stair climbing and sliding, manual triangle picking and manual
/** Example 007 Collision
In this tutorial, I will show how to detect collisions with the Irrlicht Engine.
I will describe 3 methods: Automatic collision detection for moving through 3d
worlds with stair climbing and sliding, manual triangle picking, and manual
scene node picking.
To start, we take the program from tutorial 2, which loaded and displayed a quake 3
level. We will use the level to walk in it and to pick triangles from it. In addition
we'll place 3 animated models into it for scene node picking. The following code
starts up the engine and loads
a quake 3 level. I will not explain it, because it should already be known from tutorial
2.
To start, we take the program from tutorial 2, which loads and displays a quake
3 level. We will use the level to walk in it and to pick triangles from it. In
addition we'll place 3 animated models into it for scene node picking. The
following code starts up the engine and loads a quake 3 level. I will not
explain it, because it should already be known from tutorial 2.
*/
#include <irrlicht.h>
#include <iostream>
@ -20,7 +20,6 @@ using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
// let user select driver type
@ -50,41 +49,40 @@ int main()
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<s32>(640, 480), 16, false);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* q3node = 0;
if (q3levelmesh)
q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
/*
So far so good, we've loaded the quake 3 level like in tutorial 2. Now, here
comes something different: We create a triangle selector. A triangle selector
is a class which can fetch the triangles from scene nodes for doing different
things with them, for example collision detection. There are different triangle
selectors, and all can be created with the ISceneManager. In this example,
we create an OctTreeTriangleSelector, which optimizes the triangle output a
little bit by reducing it like an octree. This is very useful for huge meshes
like quake 3 levels.
After we created the triangle selector, we attach it to the q3node. This is not
necessary, but in this way, we do not need to care for the selector, for example
dropping it after we do not need it anymore.
So far so good, we've loaded the quake 3 level like in tutorial 2. Now,
here comes something different: We create a triangle selector. A
triangle selector is a class which can fetch the triangles from scene
nodes for doing different things with them, for example collision
detection. There are different triangle selectors, and all can be
created with the ISceneManager. In this example, we create an
OctTreeTriangleSelector, which optimizes the triangle output a little
bit by reducing it like an octree. This is very useful for huge meshes
like quake 3 levels. After we created the triangle selector, we attach
it to the q3node. This is not necessary, but in this way, we do not
need to care for the selector, for example dropping it after we do not
need it anymore.
*/
scene::ITriangleSelector* selector = 0;
if (q3node)
{
{
q3node->setPosition(core::vector3df(-1350,-130,-1400));
selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
@ -93,34 +91,41 @@ int main()
/*
We add a first person shooter camera to the scene for being able to move in the quake 3
level like in tutorial 2. But this, time, we add a special animator to the
camera: A Collision Response animator. This thing modifies the scene node to which
it is attached to in that way, that it may no more move through walls and is affected
by gravity. The only thing we have to tell the animator is how the world looks like,
how big the scene node is, how gravity and so on. After the collision response animator
is attached to the camera, we do not have to do anything more for collision detection,
anything is done automaticly, all other collision detection code below is for picking.
And please note another cool feature: The collsion response animator can be attached
also to all other scene nodes, not only to cameras. And it can be mixed with other
scene node animators. In this way, collision detection and response in the Irrlicht
engine is really, really easy.
Now we'll take a closer look on the parameters of createCollisionResponseAnimator().
The first parameter is the TriangleSelector, which specifies how the world, against
collision detection is done looks like. The second parameter is the scene node, which
is the object, which is affected by collision detection, in our case it is the camera.
The third defines how big the object is, it is the radius of an ellipsoid. Try it out
and change the radius to smaller values, the camera will be able to move closer to walls
after this. The next parameter is the direction and speed of gravity. You could
set it to (0,0,0) to disable gravity. And the last value is just a translation: Without
this, the ellipsoid with which collision detection is done would be around the camera,
and the camera would be in the middle of the ellipsoid. But as human beings, we are
used to have our eyes on top of the body, with which we collide with our world, not
in the middle of it. So we place the scene node 50 units over the center of the
ellipsoid with this parameter. And that's it, collision detection works now.
We add a first person shooter camera to the scene for being able to
move in the quake 3 level like in tutorial 2. But this, time, we add a
special animator to the camera: A Collision Response animator. This
thing modifies the scene node to which it is attached to in that way,
that it may no more move through walls and is affected by gravity. The
only thing we have to tell the animator is how the world looks like,
how big the scene node is, how gravity and so on. After the collision
response animator is attached to the camera, we do not have to do
anything more for collision detection, anything is done automaticly,
all other collision detection code below is for picking. And please
note another cool feature: The collsion response animator can be
attached also to all other scene nodes, not only to cameras. And it can
be mixed with other scene node animators. In this way, collision
detection and response in the Irrlicht engine is really, really easy.
Now we'll take a closer look on the parameters of
createCollisionResponseAnimator(). The first parameter is the
TriangleSelector, which specifies how the world, against collision
detection is done looks like. The second parameter is the scene node,
which is the object, which is affected by collision detection, in our
case it is the camera. The third defines how big the object is, it is
the radius of an ellipsoid. Try it out and change the radius to smaller
values, the camera will be able to move closer to walls after this. The
next parameter is the direction and speed of gravity. You could set it
to (0,0,0) to disable gravity. And the last value is just a
translation: Without this, the ellipsoid with which collision detection
is done would be around the camera, and the camera would be in the
middle of the ellipsoid. But as human beings, we are used to have our
eyes on top of the body, with which we collide with our world, not in
the middle of it. So we place the scene node 50 units over the center
of the ellipsoid with this parameter. And that's it, collision
detection works now.
*/
scene::ICameraSceneNode* camera =
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, true);
camera->setPosition(core::vector3df(-100,50,-150));
@ -128,7 +133,7 @@ int main()
{
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-3,0),
core::vector3df(0,-3,0),
core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();
@ -137,7 +142,7 @@ int main()
/*
Because collision detection is no big deal in irrlicht, I'll describe how to
do two different types of picking in the next section. But before this,
I'll prepare the scene a little. I need three animated characters which we
I'll prepare the scene a little. I need three animated characters which we
could pick later, a dynamic light for lighting them,
a billboard for drawing where we found an intersection, and, yes, I need to
get rid of this mouse cursor. :)
@ -194,16 +199,16 @@ int main()
/*
For not making it to complicated, I'm doing picking inside the drawing loop.
We take two pointers for storing the current and the last selected scene node and
start the loop.
For not making it to complicated, I'm doing picking inside the drawing
loop. We take two pointers for storing the current and the last
selected scene node and start the loop.
*/
scene::ISceneNode* selectedSceneNode = 0;
scene::ISceneNode* lastSelectedSceneNode = 0;
int lastFPS = -1;
while(device->run())
@ -214,14 +219,16 @@ int main()
smgr->drawAll();
/*
After we've drawn the whole scene whit smgr->drawAll(), we'll do the first
picking: We want to know which triangle of the world we are looking at. In addition,
we want the exact point of the quake 3 level we are looking at.
For this, we create a 3d line starting at the position of the camera and going
through the lookAt-target of it. Then we ask the collision manager if this line
collides with a triangle of the world stored in the triangle selector. If yes,
we draw the 3d triangle and set the position of the billboard to the intersection
point.
After we've drawn the whole scene with smgr->drawAll(), we'll
do the first picking: We want to know which triangle of the
world we are looking at. In addition, we want the exact point
of the quake 3 level we are looking at. For this, we create a
3d line starting at the position of the camera and going
through the lookAt-target of it. Then we ask the collision
manager if this line collides with a triangle of the world
stored in the triangle selector. If yes, we draw the 3d
triangle and set the position of the billboard to the
intersection point.
*/
core::line3d<f32> line;
@ -235,7 +242,7 @@ int main()
line, selector, intersection, tri))
{
bill->setPosition(intersection);
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->setMaterial(material);
driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
@ -243,12 +250,13 @@ int main()
/*
Another type of picking supported by the Irrlicht Engine is scene node picking
based on bouding boxes. Every scene node has got a bounding box, and because of
that, it's very fast for example to get the scene node which the camera looks
at. Again, we ask the collision manager for this, and if we've got a scene node,
we highlight it by disabling Lighting in its material, if it is not the
billboard or the quake 3 level.
Another type of picking supported by the Irrlicht Engine is
scene node picking based on bounding boxes. Every scene node has
got a bounding box, and because of that, it's very fast for
example to get the scene node which the camera looks at. Again,
we ask the collision manager for this, and if we've got a scene
node, we highlight it by disabling Lighting in its material, if
it is not the billboard or the quake 3 level.
*/
selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);
@ -275,19 +283,21 @@ int main()
if (lastFPS != fps)
{
core::stringw str = L"Collision detection example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
core::stringw str = L"Collision detection example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
selector->drop();
device->drop();
return 0;
}
/*
**/

View File

@ -1,20 +1,25 @@
/* This tutorials describes how to do special effects. It shows how to use stencil
buffer shadows, the particle system, billboards, dynamic light and the water
/** Example 008 SpecialFX
This tutorials describes how to do special effects. It shows how to use stencil
buffer shadows, the particle system, billboards, dynamic light, and the water
surface scene node.
We start like in some tutorials before. Please note that this time, the 'shadows' flag in
createDevice() is set to true, for we want to have a dynamic shadow casted from
an animated character. If your this example runs to slow, set it to false.
The Irrlicht Engine checks if your hardware doesn't support the stencil
buffer, and disables shadows by itself, but just in case the demo runs slow
on your hardware.*/
We start like in some tutorials before. Please note that this time, the
'shadows' flag in createDevice() is set to true, for we want to have a dynamic
shadow casted from an animated character. If this example runs too slow,
set it to false. The Irrlicht Engine checks if your hardware doesn't support
the stencil buffer, and disables shadows by itself, but just in case the demo
runs slow on your hardware.
*/
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
@ -25,7 +30,7 @@ int main()
std::cin >> i;
bool shadows = (i == 'y');
const bool shadows = (i == 'y');
// ask user for driver
@ -49,7 +54,10 @@ int main()
default: return 1;
}
// create device and exit if creation failed
/*
Create device and exit if creation failed. We make the stencil flag
optional to avoid slow screen modes for runs without shadows.
*/
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<s32>(640, 480),
@ -63,41 +71,39 @@ int main()
/*
For our environment, we load a .3ds file. It is a small room I modelled
with Anim8or and exported it into the 3ds format because the Irrlicht Engine
did not support the .an8 format when I wrote this tutorial. I am a very bad
3d graphic artist, and so the texture mapping is not very nice in this model.
Luckily I am a better programmer than artist, and so the Irrlicht Engine
is able to create a cool texture mapping for me: Just use the mesh manipulator
and create a planar texture mapping for the mesh. If you want to see the mapping
I made with Anim8or, uncomment this line. I also did not figure out how to
set the material right in Anim8or, it has a specular light color which I don't really
like. I'll switch it off too with this code.
with Anim8or and exported into the 3ds format because the Irrlicht
Engine does not support the .an8 format. I am a very bad 3d graphic
artist, and so the texture mapping is not very nice in this model.
Luckily I am a better programmer than artist, and so the Irrlicht
Engine is able to create a cool texture mapping for me: Just use the
mesh manipulator and create a planar texture mapping for the mesh. If
you want to see the mapping I made with Anim8or, uncomment this line. I
also did not figure out how to set the material right in Anim8or, it
has a specular light color which I don't really like. I'll switch it
off too with this code.
*/
scene::IAnimatedMesh* mesh = smgr->getMesh(
"../../media/room.3ds");
scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/room.3ds");
smgr->getMeshManipulator()->makePlanarTextureMapping(
mesh->getMesh(0), 0.004f);
smgr->getMeshManipulator()->makePlanarTextureMapping(mesh->getMesh(0), 0.004f);
scene::ISceneNode* node = 0;
node = smgr->addAnimatedMeshSceneNode(mesh);
node->setMaterialTexture(0, driver->getTexture("../../media/wall.jpg"));
node->setMaterialTexture(0, driver->getTexture("../../media/wall.jpg"));
node->getMaterial(0).SpecularColor.set(0,0,0,0);
/*
Now, for the first special effect: Animated water. It works like this: The
WaterSurfaceSceneNode takes a mesh as input and makes
it wave like a water surface. And if we let this scene node use a nice
material like the EMT_REFLECTION_2_LAYER, it looks really cool. We are
doing this with the next few lines of code. As input mesh, we create a hill
plane mesh, without hills. But any other mesh could be used for this, you could
even use the room.3ds (which would look really strange) if you wanted to.
Now, for the first special effect: Animated water. It works like this:
The WaterSurfaceSceneNode takes a mesh as input and makes it wave like
a water surface. And if we let this scene node use a nice material like
the EMT_REFLECTION_2_LAYER, it looks really cool. We are doing this
with the next few lines of code. As input mesh, we create a hill plane
mesh, without hills. But any other mesh could be used for this, you
could even use the room.3ds (which would look really strange) if you
want to.
*/
// add animated water
mesh = smgr->addHillPlaneMesh("myHill",
core::dimension2d<f32>(20,20),
core::dimension2d<u32>(40,40), 0, 0,
@ -113,10 +119,10 @@ int main()
node->setMaterialType(video::EMT_REFLECTION_2_LAYER);
/*
The second special effect is very basic, I bet you saw it already in some
Irrlicht Engine demos: A transparent billboard combined with a dynamic light.
We simply create a light scene node, let it fly around, an to make it look
more cool, we attach a billboard scene node to it.
The second special effect is very basic, I bet you saw it already in
some Irrlicht Engine demos: A transparent billboard combined with a
dynamic light. We simply create a light scene node, let it fly around,
and to make it look more cool, we attach a billboard scene node to it.
*/
// create light
@ -136,55 +142,62 @@ int main()
node->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));
/*
The next special effect is a lot more interesting: A particle system. The particle
system in the Irrlicht Engine is quit modular and extensible and yet easy to use.
There is a particle system scene node into which you can put particle emitters, which
make particles come out of nothing. These emitters are quite flexible and usually have
lots of parameters like direction, amount and color of the particles they should create.
There are different emitters, for example a point emitter which lets particles pop out
at a fixed point. If the particle emitters available in the engine are not enough for
you, you can easily create your own ones, you'll simply have to create a class derived
from the IParticleEmitter interface and attach it to the particle system using setEmitter().
In this example we create a box particle emitter, which creates particles randomly
inside a box. The parameters define the box, direction of the particles, minimal and
maximal new particles per second, color and minimal and maximal livetime of the particles.
The next special effect is a lot more interesting: A particle system.
The particle system in the Irrlicht Engine is quite modular and
extensible, but yet easy to use. There is a particle system scene node
into which you can put a particle emitter, which makes particles come out
of nothing. These emitters are quite flexible and usually have lots of
parameters like direction, amount, and color of the particles they
create.
Because only with emitters particle system would be a little bit boring,
there are particle affectors, which modify particles during they fly around. They can
be added to the particle system, simulating additional effects like gravity or wind.
The particle affector we use in this example is an affector, which modifies the color
of the particles: It lets them fade out. Like the particle emitters, additional
particle affectors can also be implemented by you, simply derive a class from
IParticleAffector and add it with addAffector().
There are different emitters, for example a point emitter which lets
particles pop out at a fixed point. If the particle emitters available
in the engine are not enough for you, you can easily create your own
ones, you'll simply have to create a class derived from the
IParticleEmitter interface and attach it to the particle system using
setEmitter(). In this example we create a box particle emitter, which
creates particles randomly inside a box. The parameters define the box,
direction of the particles, minimal and maximal new particles per
second, color, and minimal and maximal lifetime of the particles.
After we set a nice material to the particle system, we have a cool looking camp fire.
By adjusting material, texture, particle emitter and affector parameters, it is also
easily possible to create smoke, rain, explosions, snow, and so on.
Because only with emitters particle system would be a little bit
boring, there are particle affectors which modify particles while
they fly around. Affectors can be added to a particle system for
simulating additional effects like gravity or wind.
The particle affector we use in this example is an affector which
modifies the color of the particles: It lets them fade out. Like the
particle emitters, additional particle affectors can also be
implemented by you, simply derive a class from IParticleAffector and
add it with addAffector().
After we set a nice material to the particle system, we have a cool
looking camp fire. By adjusting material, texture, particle emitter,
and affector parameters, it is also easily possible to create smoke,
rain, explosions, snow, and so on.
*/
// create a particle system
scene::IParticleSystemSceneNode* ps = 0;
ps = smgr->addParticleSystemSceneNode(false);
scene::IParticleSystemSceneNode* ps =
smgr->addParticleSystemSceneNode(false);
ps->setPosition(core::vector3df(-70,60,40));
ps->setScale(core::vector3df(2,2,2));
ps->setParticleSize(core::dimension2d<f32>(20.0f, 20.0f));
scene::IParticleEmitter* em = ps->createBoxEmitter(
core::aabbox3d<f32>(-7,0,-7,7,1,7),
core::vector3df(0.0f,0.06f,0.0f),
80,100,
video::SColor(0,255,255,255), video::SColor(0,255,255,255),
800,2000);
core::aabbox3d<f32>(-7,0,-7,7,1,7), // emitter size
core::vector3df(0.0f,0.06f,0.0f), // initial direction
80,100, // emit rate
video::SColor(0,255,255,255), // darkest color
video::SColor(0,255,255,255), // brightest color
800,2000); // min and max age
ps->setEmitter(em);
em->drop();
ps->setEmitter(em); // this grabs the emitter
em->drop(); // so we can drop it here without deleting it
scene::IParticleAffector* paf =
ps->createFadeOutParticleAffector();
scene::IParticleAffector* paf = ps->createFadeOutParticleAffector();
ps->addAffector(paf);
ps->addAffector(paf); // same goes for the affector
paf->drop();
ps->setMaterialFlag(video::EMF_LIGHTING, false);
@ -192,24 +205,23 @@ int main()
ps->setMaterialTexture(0, driver->getTexture("../../media/fire.bmp"));
ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
/*
Next we add a volumetric light node, which adds a glowing fake area light to
the scene. Like with the billboards and particle systems we also assign a
texture for the desired effect, though this time we'll use a texture animator
/*
Next we add a volumetric light node, which adds a glowing fake area light to
the scene. Like with the billboards and particle systems we also assign a
texture for the desired effect, though this time we'll use a texture animator
to create the illusion of a magical glowing area effect.
*/
scene::IVolumeLightSceneNode * n = smgr->addVolumeLightSceneNode(0, -1,
32, // Subdivisions on U axis
32, // Subdivisions on V axis
video::SColor(0, 255, 255, 255), // foot color
video::SColor(0, 0, 0, 0) // tail color
);
if (n)
32, // Subdivisions on U axis
32, // Subdivisions on V axis
video::SColor(0, 255, 255, 255), // foot color
video::SColor(0, 0, 0, 0)); // tail color
if (n)
{
n->setScale(core::vector3df(56.0f, 56.0f, 56.0f));
n->setPosition(core::vector3df(-120,50,40));
// load textures for animation
core::array<video::ITexture*> textures;
for (s32 g=7; g > 0; --g)
@ -218,12 +230,12 @@ int main()
tmp = "../../media/portal";
tmp += g;
tmp += ".bmp";
video::ITexture* t = driver->getTexture( tmp.c_str () );
video::ITexture* t = driver->getTexture( tmp.c_str() );
textures.push_back(t);
}
// create texture animator
scene::ISceneNodeAnimator *glow = smgr->createTextureAnimator(textures, 150);
scene::ISceneNodeAnimator* glow = smgr->createTextureAnimator(textures, 150);
// add the animator
n->addAnimator(glow);
@ -233,17 +245,19 @@ int main()
}
/*
As our last special effect, we want a dynamic shadow be casted from an animated
character. For this we load a DirectX .x model and place it into our world.
For creating the shadow, we simply need to call addShadowVolumeSceneNode().
The color of shadows is only adjustable globally for all shadows, by calling
ISceneManager::setShadowColor(). Voila, here is our dynamic shadow.
As our last special effect, we want a dynamic shadow be casted from an
animated character. For this we load a DirectX .x model and place it
into our world. For creating the shadow, we simply need to call
addShadowVolumeSceneNode(). The color of shadows is only adjustable
globally for all shadows, by calling ISceneManager::setShadowColor().
Voila, here is our dynamic shadow.
Because the character is a little bit too small for this scene, we make it bigger
using setScale(). And because the character is lighted by a dynamic light, we need
to normalize the normals to make the lighting on it correct. This is always necessary if
the scale of a dynamic lighted model is not (1,1,1). Otherwise it would get too dark or
too bright because the normals will be scaled too.
Because the character is a little bit too small for this scene, we make
it bigger using setScale(). And because the character is lighted by a
dynamic light, we need to normalize the normals to make the lighting on
it correct. This is always necessary if the scale of a dynamic lighted
model is not (1,1,1). Otherwise it would get too dark or too bright
because the normals will be scaled too.
*/
// add animated character
@ -260,7 +274,7 @@ int main()
smgr->setShadowColor(video::SColor(150,0,0,0));
// make the model a little bit bigger and normalize its normals
// because of this for correct lighting
// because of the scaling, for correct lighting
anode->setScale(core::vector3df(2,2,2));
anode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
@ -274,8 +288,7 @@ int main()
// disable mouse cursor
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
s32 lastFPS = -1;
while(device->run())
if (device->isWindowActive())
@ -286,7 +299,7 @@ int main()
driver->endScene();
int fps = driver->getFPS();
const s32 fps = driver->getFPS();
if (lastFPS != fps)
{
@ -305,3 +318,5 @@ int main()
return 0;
}
/*
**/

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +1,42 @@
/*
This tutorial shows how to use shaders for D3D8, D3D9 and OpenGL
with the engine and how to create new material types with them. It also
shows how to disable the generation of mipmaps at texture loading, and
how to use text scene nodes.
/** Example 010 Shaders
This tutorial does not explain how shaders work. I would recommend to read the D3D
or OpenGL documentation, to search a tutorial, or to read a book about this.
This tutorial shows how to use shaders for D3D8, D3D9, and OpenGL with the
engine and how to create new material types with them. It also shows how to
disable the generation of mipmaps at texture loading, and how to use text scene
nodes.
At first, we need to include all headers and do the stuff we always do, like
in nearly all other tutorials:
This tutorial does not explain how shaders work. I would recommend to read the
D3D or OpenGL documentation, to search a tutorial, or to read a book about
this.
At first, we need to include all headers and do the stuff we always do, like in
nearly all other tutorials:
*/
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
/*
Because we want to use some interesting shaders in this tutorials, we
need to set some data for them to make them able to compute nice
colors. In this example, we'll use a simple vertex shader which will
calculate the color of the vertex based on the position of the camera.
For this, the shader needs the following data: The inverted world matrix
for transforming the normal, the clip matrix for transforming the position,
the camera position and the world position of the object for the calculation
of the angle of light, and the color of the light. To be able to tell the
shader all this data every frame, we have to derive a class from the
IShaderConstantSetCallBack interface and override its only method,
namely OnSetConstants(). This method will be called every time the material
is set.
Because we want to use some interesting shaders in this tutorials, we need to
set some data for them to make them able to compute nice colors. In this
example, we'll use a simple vertex shader which will calculate the color of the
vertex based on the position of the camera.
For this, the shader needs the following data: The inverted world matrix for
transforming the normal, the clip matrix for transforming the position, the
camera position and the world position of the object for the calculation of the
angle of light, and the color of the light. To be able to tell the shader all
this data every frame, we have to derive a class from the
IShaderConstantSetCallBack interface and override its only method, namely
OnSetConstants(). This method will be called every time the material is set.
The method setVertexShaderConstant() of the IMaterialRendererServices interface
is used to set the data the shader needs. If the user chose to use a High Level shader
language like HLSL instead of Assembler in this example, you have to set the
variable name as parameter instead of the register index.
is used to set the data the shader needs. If the user chose to use a High Level
shader language like HLSL instead of Assembler in this example, you have to set
the variable name as parameter instead of the register index.
*/
IrrlichtDevice* device = 0;
@ -83,7 +84,7 @@ public:
else
services->setVertexShaderConstant(reinterpret_cast<f32*>(&pos), 8, 1);
// set light color
// set light color
video::SColorf col(0.0f,1.0f,1.0f,0.0f);
@ -105,9 +106,9 @@ public:
};
/*
The next few lines start up the engine. Just like in most other tutorials
before. But in addition, we ask the user if he wants this example to use
high level shaders if he selected a driver which is capable of doing so.
The next few lines start up the engine just like in most other tutorials
before. But in addition, we ask the user if he wants to use high level shaders
in this example, if he selected a driver which is capable of doing so.
*/
int main()
{
@ -135,7 +136,7 @@ int main()
}
// ask the user if we should use high level shaders for this example
if (driverType == video::EDT_DIRECT3D9 ||
if (driverType == video::EDT_DIRECT3D9 ||
driverType == video::EDT_OPENGL)
{
printf("Please press 'y' if you want to use high level shaders.\n");
@ -157,15 +158,15 @@ int main()
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
/*
Now for the more interesting parts.
If we are using Direct3D, we want to load vertex and pixel shader programs, if we have
OpenGL, we want to use ARB fragment and vertex programs. I wrote the
corresponding programs down into the files d3d8.ps, d3d8.vs, d3d9.ps, d3d9.vs,
opengl.ps and opengl.vs. We only need the right filenames now. This is done in the
following switch. Note, that it is not necessary to write the shaders into text
files, like in this example. You can even write the shaders directly as strings
into the cpp source file, and use later addShaderMaterial() instead of
addShaderMaterialFromFiles().
Now for the more interesting parts. If we are using Direct3D, we want
to load vertex and pixel shader programs, if we have OpenGL, we want to
use ARB fragment and vertex programs. I wrote the corresponding
programs down into the files d3d8.ps, d3d8.vs, d3d9.ps, d3d9.vs,
opengl.ps and opengl.vs. We only need the right filenames now. This is
done in the following switch. Note, that it is not necessary to write
the shaders into text files, like in this example. You can even write
the shaders directly as strings into the cpp source file, and use later
addShaderMaterial() instead of addShaderMaterialFromFiles().
*/
c8* vsFileName = 0; // filename for the vertex shader
@ -205,15 +206,16 @@ int main()
}
/*
In addition, we check if the hardware and the selected renderer is capable
of executing the shaders we want. If not, we simply set the filename string
to 0. This is not necessary, but useful in this example: For example, if
the hardware is able to execute vertex shaders but not pixel shaders, we create
a new material which only uses the vertex shader, and no pixel shader.
Otherwise, if we would tell the engine to create this material and the engine
sees that the hardware wouldn't be able to fullfill the request completely,
it would not create any new material at all. So in this example you would see
at least the vertex shader in action, without the pixel shader.
In addition, we check if the hardware and the selected renderer is
capable of executing the shaders we want. If not, we simply set the
filename string to 0. This is not necessary, but useful in this
example: For example, if the hardware is able to execute vertex shaders
but not pixel shaders, we create a new material which only uses the
vertex shader, and no pixel shader. Otherwise, if we would tell the
engine to create this material and the engine sees that the hardware
wouldn't be able to fullfill the request completely, it would not
create any new material at all. So in this example you would see at
least the vertex shader in action, without the pixel shader.
*/
if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
@ -233,22 +235,26 @@ int main()
}
/*
Now lets create the new materials.
As you maybe know from previous examples, a material type in the Irrlicht engine
is set by simply changing the MaterialType value in the SMaterial struct. And this
value is just a simple 32 bit value, like video::EMT_SOLID. So we only need the
engine to create a new value for us which we can set there.
To do this, we get a pointer to the IGPUProgrammingServices and call
addShaderMaterialFromFiles(), which returns such a new 32 bit value. That's all.
The parameters to this method are the following:
First, the names of the files containing the code of the vertex and the pixel shader.
If you would use addShaderMaterial() instead, you would not need file names, then you
could write the code of the shader directly as string.
The following parameter is a pointer to the IShaderConstantSetCallBack class we wrote
at the beginning of this tutorial. If you don't want to set constants, set this to 0.
The last paramter tells the engine which material it should use as base material.
To demonstrate this, we create two materials with a different base material, one
with EMT_SOLID and one with EMT_TRANSPARENT_ADD_COLOR.
Now lets create the new materials. As you maybe know from previous
examples, a material type in the Irrlicht engine is set by simply
changing the MaterialType value in the SMaterial struct. And this value
is just a simple 32 bit value, like video::EMT_SOLID. So we only need
the engine to create a new value for us which we can set there. To do
this, we get a pointer to the IGPUProgrammingServices and call
addShaderMaterialFromFiles(), which returns such a new 32 bit value.
That's all.
The parameters to this method are the following: First, the names of
the files containing the code of the vertex and the pixel shader. If
you would use addShaderMaterial() instead, you would not need file
names, then you could write the code of the shader directly as string.
The following parameter is a pointer to the IShaderConstantSetCallBack
class we wrote at the beginning of this tutorial. If you don't want to
set constants, set this to 0. The last paramter tells the engine which
material it should use as base material.
To demonstrate this, we create two materials with a different base
material, one with EMT_SOLID and one with EMT_TRANSPARENT_ADD_COLOR.
*/
// create materials
@ -293,10 +299,10 @@ int main()
}
/*
Now time for testing out the materials. We create a test cube
and set the material we created. In addition, we add a text scene node to
the cube and a rotation animator to make it look more interesting and
important.
Now it's time for testing the materials. We create a test cube and set
the material we created. In addition, we add a text scene node to the
cube and a rotation animator to make it look more interesting and
important.
*/
// create test scene node 1, with the new created material type 1
@ -307,8 +313,8 @@ int main()
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
smgr->addTextSceneNode(gui->getBuiltInFont(),
L"PS & VS & EMT_SOLID",
smgr->addTextSceneNode(gui->getBuiltInFont(),
L"PS & VS & EMT_SOLID",
video::SColor(255,255,255,255), node);
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(
@ -328,8 +334,8 @@ int main()
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType2);
smgr->addTextSceneNode(gui->getBuiltInFont(),
L"PS & VS & EMT_TRANSPARENT",
smgr->addTextSceneNode(gui->getBuiltInFont(),
L"PS & VS & EMT_TRANSPARENT",
video::SColor(255,255,255,255), node);
anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
@ -337,11 +343,11 @@ int main()
anim->drop();
/*
Then we add a third cube without a shader on it, to be able to compare the
cubes.
Then we add a third cube without a shader on it, to be able to compare
the cubes.
*/
// add a scene node with no shader
// add a scene node with no shader
node = smgr->addCubeSceneNode(50);
node->setPosition(core::vector3df(0,50,25));
@ -394,13 +400,13 @@ int main()
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Vertex and pixel shader example [";
str += driver->getName();
str += "] FPS:";
str += fps;
core::stringw str = L"Irrlicht Engine - Vertex and pixel shader example [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
@ -409,3 +415,6 @@ int main()
return 0;
}
/*
Compile and run this, and I hope you have fun with your new little shader writing tool :).
**/

View File

@ -1,27 +1,26 @@
/*
This tutorial shows how to use one of the built in more complex materials in irrlicht:
Per pixel lighted surfaces using normal maps and parallax mapping. It will also show
how to use fog and moving particle systems. And don't panic: You dont need any
experience with shaders to use these materials in Irrlicht.
/** Example 011 Per-Pixel Lighting
At first, we need to include all headers and do the stuff we always do, like
in nearly all other tutorials.
This tutorial shows how to use one of the built in more complex materials in
irrlicht: Per pixel lighted surfaces using normal maps and parallax mapping. It
will also show how to use fog and moving particle systems. And don't panic: You
dont need any experience with shaders to use these materials in Irrlicht.
At first, we need to include all headers and do the stuff we always do, like in
nearly all other tutorials.
*/
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
/*
For this example, we need an event receiver, to make it possible for the user
to switch between the three available material types. In addition, the event
receiver will create some small GUI window which displays what material is
currently being used. There is nothing special done in this class, so maybe
you want to skip reading it.
currently being used. There is nothing special done in this class, so maybe you
want to skip reading it.
*/
class MyEventReceiver : public IEventReceiver
{
@ -120,13 +119,14 @@ private:
Room->setMaterialType(type);
/*
We need to add a warning if the materials will not be able to be
displayed 100% correctly. This is no problem, they will be renderered
using fall back materials, but at least the user should know that
it would look better on better hardware.
We simply check if the material renderer is able to draw at full
quality on the current hardware. The IMaterialRenderer::getRenderCapability()
returns 0 if this is the case.
We need to add a warning if the materials will not be able to
be displayed 100% correctly. This is no problem, they will be
renderered using fall back materials, but at least the user
should know that it would look better on better hardware. We
simply check if the material renderer is able to draw at full
quality on the current hardware. The
IMaterialRenderer::getRenderCapability() returns 0 if this is
the case.
*/
video::IMaterialRenderer* renderer = Driver->getMaterialRenderer(type);
@ -186,11 +186,11 @@ int main()
/*
Before we start with the interesting stuff, we do some simple things:
Store pointers to the most important parts of the engine (video driver,
scene manager, gui environment) to safe us from typing too much,
add an irrlicht engine logo to the window and a user controlled
first person shooter style camera. Also, we let the engine now
that it should store all textures in 32 bit. This necessary because
for parallax mapping, we need 32 bit textures.
scene manager, gui environment) to safe us from typing too much, add an
irrlicht engine logo to the window and a user controlled first person
shooter style camera. Also, we let the engine know that it should store
all textures in 32 bit. This necessary because for parallax mapping, we
need 32 bit textures.
*/
video::IVideoDriver* driver = device->getVideoDriver();
@ -213,21 +213,21 @@ int main()
/*
Because we want the whole scene to look a little bit scarier, we add some fog
to it. This is done by a call to IVideoDriver::setFog(). There you can set
various fog settings. In this example, we use pixel fog, because it will
work well with the materials we'll use in this example.
Because we want the whole scene to look a little bit scarier, we add
some fog to it. This is done by a call to IVideoDriver::setFog(). There
you can set various fog settings. In this example, we use pixel fog,
because it will work well with the materials we'll use in this example.
Please note that you will have to set the material flag EMF_FOG_ENABLE
to 'true' in every scene node which should be affected by this fog.
*/
driver->setFog(video::SColor(0,138,125,81), true, 250, 1000, 0, true);
/*
To be able to display something interesting, we load a mesh from a .3ds file
which is a room I modeled with anim8or. It is the same room as
from the specialFX example. Maybe you remember from that tutorial,
I am no good modeler at all and so I totally messed up the texture
mapping in this model, but we can simply repair it with the
To be able to display something interesting, we load a mesh from a .3ds
file which is a room I modeled with anim8or. It is the same room as
from the specialFX example. Maybe you remember from that tutorial, I am
no good modeler at all and so I totally messed up the texture mapping
in this model, but we can simply repair it with the
IMeshManipulator::makePlanarTextureMapping() method.
*/
@ -241,17 +241,19 @@ int main()
roomMesh->getMesh(0), 0.003f);
/*
Now for the first exciting thing: If we successfully loaded the mesh
we need to apply textures to it. Because we want this room to be
displayed with a very cool material, we have to do a little bit more
than just set the textures. Instead of only loading a color map as usual,
we also load a height map which is simply a grayscale texture. From this
height map, we create a normal map which we will set as second texture of the
room. If you already have a normal map, you could directly set it, but I simply
didn´t find a nice normal map for this texture.
The normal map texture is being generated by the makeNormalMapTexture method
of the VideoDriver. The second parameter specifies the height of the heightmap.
If you set it to a bigger value, the map will look more rocky.
Now for the first exciting thing: If we successfully loaded the
mesh we need to apply textures to it. Because we want this room
to be displayed with a very cool material, we have to do a
little bit more than just set the textures. Instead of only
loading a color map as usual, we also load a height map which
is simply a grayscale texture. From this height map, we create
a normal map which we will set as second texture of the room.
If you already have a normal map, you could directly set it,
but I simply didn't find a nice normal map for this texture.
The normal map texture is being generated by the
makeNormalMapTexture method of the VideoDriver. The second
parameter specifies the height of the heightmap. If you set it
to a bigger value, the map will look more rocky.
*/
video::ITexture* colorMap = driver->getTexture("../../media/rockwall.bmp");
@ -260,14 +262,16 @@ int main()
driver->makeNormalMapTexture(normalMap, 9.0f);
/*
But just setting color and normal map is not everything. The material we want to
use needs some additional informations per vertex like tangents and binormals.
Because we are too lazy to calculate that information now, we let Irrlicht do
this for us. That's why we call IMeshManipulator::createMeshWithTangents(). It
creates a mesh copy with tangents and binormals from any other mesh.
After we've done that, we simply create a standard mesh scene node with this
mesh copy, set color and normal map and adjust some other material settings.
Note that we set EMF_FOG_ENABLE to true to enable fog in the room.
But just setting color and normal map is not everything. The
material we want to use needs some additional informations per
vertex like tangents and binormals. Because we are too lazy to
calculate that information now, we let Irrlicht do this for us.
That's why we call IMeshManipulator::createMeshWithTangents().
It creates a mesh copy with tangents and binormals from another
mesh. After we've done that, we simply create a standard
mesh scene node with this mesh copy, set color and normal map
and adjust some other material settings. Note that we set
EMF_FOG_ENABLE to true to enable fog in the room.
*/
scene::IMesh* tangentMesh = smgr->getMeshManipulator()->createMeshWithTangents(
@ -288,13 +292,13 @@ int main()
}
/*
After we've created a room shaded by per pixel lighting, we add a sphere
into it with the same material, but we'll make it transparent. In addition,
because the sphere looks somehow like a familiar planet, we make it rotate.
The procedure is similar as before. The difference is that we are loading
the mesh from an .x file which already contains a color map so we do not
need to load it manually. But the sphere is a little bit too small for our
needs, so we scale it by the factor 50.
After we've created a room shaded by per pixel lighting, we add a
sphere into it with the same material, but we'll make it transparent.
In addition, because the sphere looks somehow like a familiar planet,
we make it rotate. The procedure is similar as before. The difference
is that we are loading the mesh from an .x file which already contains
a color map so we do not need to load it manually. But the sphere is a
little bit too small for our needs, so we scale it by the factor 50.
*/
// add earth sphere
@ -341,10 +345,11 @@ int main()
}
/*
Per pixel lighted materials only look cool when there are moving lights. So we
add some. And because moving lights alone are so boring, we add billboards
to them, and a whole particle system to one of them.
We start with the first light which is red and has only the billboard attached.
Per pixel lighted materials only look cool when there are moving
lights. So we add some. And because moving lights alone are so boring,
we add billboards to them, and a whole particle system to one of them.
We start with the first light which is red and has only the billboard
attached.
*/
// add light 1 (nearly red)
@ -369,15 +374,16 @@ int main()
bill->setMaterialTexture(0, driver->getTexture("../../media/particlered.bmp"));
/*
Now the same again, with the second light. The difference is that we add a particle
system to it too. And because the light moves, the particles of the particlesystem
will follow. If you want to know more about how particle systems are created in
Irrlicht, take a look at the specialFx example.
Maybe you will have noticed that we only add 2 lights, this has a simple reason: The
low end version of this material was written in ps1.1 and vs1.1, which doesn't allow
more lights. You could add a third light to the scene, but it won't be used to
shade the walls. But of course, this will change in future versions of Irrlicht were
higher versions of pixel/vertex shaders will be implemented too.
Now the same again, with the second light. The difference is that we
add a particle system to it too. And because the light moves, the
particles of the particlesystem will follow. If you want to know more
about how particle systems are created in Irrlicht, take a look at the
specialFx example. Maybe you will have noticed that we only add 2
lights, this has a simple reason: The low end version of this material
was written in ps1.1 and vs1.1, which doesn't allow more lights. You
could add a third light to the scene, but it won't be used to shade the
walls. But of course, this will change in future versions of Irrlicht
where higher versions of pixel/vertex shaders will be implemented too.
*/
// add light 2 (gray)
@ -463,3 +469,5 @@ int main()
return 0;
}
/*
**/

View File

@ -1,15 +1,18 @@
/*
This tutorial will briefly show how to use the terrain renderer of Irrlicht. It will also
show the terrain renderer triangle selector to be able to do collision detection with
terrain.
/** Example 012 Terrain Rendering
Note that the Terrain Renderer in Irrlicht is based on Spintz' GeoMipMapSceneNode, lots
of thanks go to him.
DeusXL provided a new elegant 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 the 'W' key so we can switch to wireframe
mode and if he presses 'D' we toggle to material between solid and detail mapped.
This tutorial will briefly show how to use the terrain renderer of Irrlicht. It
will also show the terrain renderer triangle selector to be able to do
collision detection with terrain.
Note that the Terrain Renderer in Irrlicht is based on Spintz'
GeoMipMapSceneNode, lots of thanks go to him. DeusXL provided a new elegant
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.
*/
#include <irrlicht.h>
#include <iostream>
@ -46,7 +49,7 @@ public:
return true;
case irr::KEY_KEY_D: // toggle detail map
Terrain->setMaterialType(
Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
video::EMT_DETAIL_MAP : video::EMT_SOLID);
return true;
}
@ -101,7 +104,7 @@ int main()
First, we add standard stuff to the scene: A nice irrlicht engine
logo, a small help text, a user controlled camera, and we disable
the mouse cursor.
*/
*/
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
@ -122,7 +125,7 @@ int main()
core::rect<s32>(10,440,250,475), true, true, 0, -1, true);
// add camera
scene::ICameraSceneNode* camera =
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0,100.0f,1200.f);
camera->setPosition(core::vector3df(1900*2,255*2,3700*2));
@ -133,31 +136,34 @@ int main()
device->getCursorControl()->setVisible(false);
/*
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 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 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 the texture: The first texture will be repeated only one time over
the whole terrain, and the second one (detail map) 20 times.
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
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
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
the texture: The first texture will be repeated only one time over the
whole terrain, and the second one (detail map) 20 times.
*/
// add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../../media/terrain-heightmap.bmp",
0, // parent node
-1, // node id
core::vector3df(0.f, 0.f, 0.f), // position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(40.f, 4.4f, 40.f), // scale
video::SColor ( 255, 255, 255, 255 ), // vertexColor,
5, // maxLOD
scene::ETPS_17, // patchSize
4 // smoothFactor
0, // parent node
-1, // node id
core::vector3df(0.f, 0.f, 0.f), // position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(40.f, 4.4f, 40.f), // scale
video::SColor ( 255, 255, 255, 255 ), // vertexColor
5, // maxLOD
scene::ETPS_17, // patchSize
4 // smoothFactor
);
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
@ -172,10 +178,10 @@ int main()
/*
To be able to do collision with the terrain, we create a triangle selector.
If you want to know what triangle selectors do, just take a look into the
If you want to know what triangle selectors do, just take a look into the
collision tutorial. The terrain triangle selector works together with the
terrain. To demonstrate this, we create a collision response animator
and attach it to the camera, so that the camera will not be able to fly
terrain. To demonstrate this, we create a collision response animator
and attach it to the camera, so that the camera will not be able to fly
through the terrain.
*/
@ -187,23 +193,24 @@ int main()
// create collision response animator and attach it to the camera
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(60,100,60),
core::vector3df(0,0,0),
core::vector3df(0,0,0),
core::vector3df(0,50,0));
selector->drop();
camera->addAnimator(anim);
anim->drop();
/*
To make the user be able to switch between normal and wireframe mode, we create
an instance of the event reciever from above and let Irrlicht know about it. In
addition, we add the skybox which we already used in lots of Irrlicht examples.
To make the user be able to switch between normal and wireframe mode,
we create an instance of the event reciever from above and let Irrlicht
know about it. In addition, we add the skybox which we already used in
lots of Irrlicht examples.
*/
// create event receiver
MyEventReceiver receiver(terrain);
device->setEventReceiver(&receiver);
// create skybox
// create skybox
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
smgr->addSkyBoxSceneNode(
@ -218,7 +225,7 @@ int main()
/*
That's it, draw everything. Now you know how to use terrain in Irrlicht.
That's it, draw everything.
*/
int lastFPS = -1;
@ -256,3 +263,6 @@ int main()
return 0;
}
/*
Now you know how to use terrain in Irrlicht.
**/

View File

@ -1,10 +1,11 @@
/*
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. In addition, this tutorial shows how to enable specular
highlights.
/** Example 013 Render To Texture
In the beginning, everything as usual. Include the needed headers, ask the user for the rendering
driver, create the Irrlicht Device:
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.
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:
*/
#include <irrlicht.h>
@ -54,10 +55,10 @@ int main()
/*
Now, we load an animated mesh to be displayed. As in most examples,
we'll take the fairy md2 model. The difference here: We set the shininess
of the model to a value other than 0 which is the default value. This
enables specular highlights on the model if dynamic lighting is on.
The value influences the size of the highlights.
we'll take the fairy md2 model. The difference here: We set the
shininess of the model to a value other than 0 which is the default
value. This enables specular highlights on the model if dynamic
lighting is on. The value influences the size of the highlights.
*/
// load and display animated fairy mesh
@ -75,9 +76,10 @@ int main()
}
/*
To make specular highlights appear on the model, we need a dynamic light in the scene.
We add one directly in vicinity of the model. In addition, to make the model not that
dark, we set the ambient light to gray.
To make specular highlights appear on the model, we need a dynamic
light in the scene. We add one directly in vicinity of the model. In
addition, to make the model not that dark, we set the ambient light to
gray.
*/
// add white light
@ -88,8 +90,9 @@ int main()
smgr->setAmbientLight(video::SColor(0,60,60,60));
/*
The next is just some standard stuff: Add a user controlled camera to the scene, disable
mouse cursor, and add a test cube and let it rotate to make the scene more interesting.
The next is just some standard stuff: Add a user controlled camera to
the scene, disable mouse cursor, and add a test cube and let it rotate
to make the scene more interesting.
*/
// add fps camera
@ -115,14 +118,16 @@ int main()
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::createRenderTargetTexture() 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. And 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 textures. If
it is not, we simply display a warning text.
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::createRenderTargetTexture()
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. And 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 textures. If it is not, we simply display a
warning text.
*/
// create render target
@ -156,11 +161,12 @@ int main()
}
/*
Nearly finished. Now we need to draw everything. Every frame, we draw the scene twice.
Once from the fixed camera into the render target texture and once as usual. When rendering
into the render target, we need to disable the visibilty of the test cube, because it has
the render target texture applied to it.
That's, wasn't quite complicated I hope. :)
Nearly finished. Now we need to draw everything. Every frame, we draw
the scene twice. Once from the fixed camera into the render target
texture and once as usual. When rendering into the render target, we
need to disable the visibilty of the test cube, because it has the
render target texture applied to it. That's it, wasn't too complicated
I hope. :)
*/
int lastFPS = -1;
@ -175,18 +181,18 @@ int main()
// draw scene into render target
// set render target texture
driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));
driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));
// make cube invisible and set fixed camera as active camera
test->setVisible(false);
smgr->setActiveCamera(fixedCam);
// draw whole scene into render buffer
smgr->drawAll();
smgr->drawAll();
// set back old render target
// The buffer might have been distorted, so clear it
driver->setRenderTarget(0, true, true, 0);
driver->setRenderTarget(0, true, true, 0);
// make the cube visible and set the user controlled camera as active one
test->setVisible(true);
@ -194,7 +200,7 @@ int main()
}
// draw scene normally
smgr->drawAll();
smgr->drawAll();
env->drawAll();
driver->endScene();
@ -218,3 +224,6 @@ int main()
device->drop(); // drop device
return 0;
}
/*
**/

View File

@ -1,5 +1,13 @@
// this example only runs in windows and demonstrates that Irrlicht
// can run inside a win32 window.
/** Example 014 Win32 Window
This example only runs under MS Windows and demonstrates that Irrlicht can
render inside a win32 window. MFC and .NET Windows.Forms windows are possible,
too.
In the begining, we create a windows window using the windows API. I'm not
going to explain this code, because it is windows specific. See the MSDN or a
windows book for details.
*/
#include <irrlicht.h>
#ifndef _IRR_WINDOWS_
@ -41,9 +49,6 @@ static LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message, WPARAM wParam, LP
}
int main()
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hpre, LPSTR cmd, int cc)
{
@ -99,6 +104,12 @@ int main()
HWND hIrrlichtWindow = CreateWindow("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
50, 80, 320, 220, hWnd, NULL, hInstance, NULL);
/*
So now that we have some window, we can create an Irrlicht device
inside of it. We use Irrlicht createEx() function for this. We only
need the handle (HWND) to that window, set it as windowsID parameter
and start up the engine as usual. That's it.
*/
// create irrlicht device in the button window
irr::SIrrlichtCreationParameters param;
@ -141,13 +152,17 @@ int main()
// do message queue
// Instead of this, you can also simply use your own message loop
// using GetMessage, DispatchMessage and whatever. Calling
// Device->run() will cause Irrlicht to dispatch messages internally too.
// You need not call Device->run() if you want to do your own message
// dispatching loop, but Irrlicht will not be able to fetch
// user input then and you have to do it on your own using the window
// messages, DirectInput, or whatever.
/*
Now the only thing missing is the drawing loop using
IrrlichtDevice::run(). We do this as usual. But instead of this, there
is another possibility: You can also simply use your own message loop
using GetMessage, DispatchMessage and whatever. Calling
Device->run() will cause Irrlicht to dispatch messages internally too.
You need not call Device->run() if you want to do your own message
dispatching loop, but Irrlicht will not be able to fetch user input
then and you have to do it on your own using the window messages,
DirectInput, or whatever.
*/
while (device->run())
{
@ -156,8 +171,10 @@ int main()
driver->endScene();
}
// the alternative, own message dispatching loop without Device->run() would
// look like this:
/*
The alternative, own message dispatching loop without Device->run()
would look like this:
*/
/*MSG msg;
while (true)
@ -187,3 +204,6 @@ int main()
}
#endif // if windows
/*
That's it, Irrlicht now runs in your own windows window.
**/

View File

@ -1,8 +1,9 @@
/*
/** Example 015 Loading Scenes from .irr Files
Since version 1.1, Irrlicht is able to save and load
the full scene graph into an .irr file, an xml based
format. There is an editor available to edit
those files, named irrEdit on http://www.ambiera.com/irredit,
those files, named irrEdit (http://www.ambiera.com/irredit)
which can also be used as world and particle editor.
This tutorial shows how to use .irr files.
@ -13,7 +14,9 @@ Lets start: Create an Irrlicht device and setup the window.
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
@ -38,7 +41,7 @@ int main()
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 1;
}
}
// create device and exit if creation failed
@ -53,30 +56,35 @@ int main()
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
/* Now load our .irr file.
.irr files can store the whole scene graph including animators, materials
and particle systems. And there is also the possibility to store arbitrary
user data for every scene node in that file. To keep this
example simple, we are simply loading the scene here. See the documentation
at ISceneManager::loadScene and ISceneManager::saveScene for more information.
So to load and display a complicated huge scene, we only need a single call
to loadScene().
/*
Now load our .irr file.
.irr files can store the whole scene graph including animators,
materials and particle systems. And there is also the possibility to
store arbitrary user data for every scene node in that file. To keep
this example simple, we are simply loading the scene here. See the
documentation at ISceneManager::loadScene and ISceneManager::saveScene
for more information. So to load and display a complicated huge scene,
we only need a single call to loadScene().
*/
// load the scene
smgr->loadScene("../../media/example.irr");
// Now we'll create a camera, and give it a collision response animator
// that's built from the mesh nodes in the scene we just loaded.
/*
Now we'll create a camera, and give it a collision response animator
that's built from the mesh nodes in the scene we just loaded.
*/
scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 50, 100);
// Create a meta triangle selector to hold several triangle selectors.
scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
// Now we will find all the nodes in the scene and create triangle
// selectors for all suitable nodes. Typically, you would want to make a
// more informed decision about which nodes to performs collision checks
// on; you could capture that information in the node name or Id.
/*
Now we will find all the nodes in the scene and create triangle
selectors for all suitable nodes. Typically, you would want to make a
more informed decision about which nodes to performs collision checks
on; you could capture that information in the node name or Id.
*/
core::array<scene::ISceneNode *> nodes;
smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes
@ -88,41 +96,44 @@ int main()
switch(node->getType())
{
case scene::ESNT_CUBE:
case scene::ESNT_ANIMATED_MESH: // Because the selector won't animate with the mesh,
// and is only being used for camera collision, we'll just use an approximate
// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
selector = smgr->createTriangleSelectorFromBoundingBox(node);
break;
case scene::ESNT_ANIMATED_MESH:
// Because the selector won't animate with the mesh,
// and is only being used for camera collision, we'll just use an approximate
// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
selector = smgr->createTriangleSelectorFromBoundingBox(node);
break;
case scene::ESNT_MESH:
case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
case scene::ESNT_TERRAIN:
selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
break;
selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
break;
case scene::ESNT_OCT_TREE:
selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
default:
// Don't create a selector for this node type
break;
// Don't create a selector for this node type
break;
}
if(selector)
{
// Add it to the meta selector, which will take a reference to it
meta->addTriangleSelector(selector);
// And drop my reference to it, so that the meta selector owns it.
selector->drop();
// Add it to the meta selector, which will take a reference to it
meta->addTriangleSelector(selector);
// And drop my reference to it, so that the meta selector owns it.
selector->drop();
}
}
// Now that the mesh scene nodes have had triangle selectors created and added
// to the meta selector, create a collision response animator from that meta selector.
/*
Now that the mesh scene nodes have had triangle selectors created and added
to the meta selector, create a collision response animator from that meta selector.
*/
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
meta, camera, core::vector3df(5,5,5),
core::vector3df(0,0,0));
@ -138,8 +149,10 @@ int main()
scene::ISceneNode * cube = smgr->getSceneNodeFromType(scene::ESNT_CUBE);
if(cube)
camera->setTarget(cube->getAbsolutePosition());
// and draw everything.
/*
That's it. Draw everything and finish as usual.
*/
int lastFPS = -1;
@ -154,19 +167,21 @@ int main()
if (lastFPS != fps)
{
core::stringw str = L"Load Irrlicht File example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
core::stringw str = L"Load Irrlicht File example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
/*
**/

View File

@ -1,4 +1,5 @@
/*
/** Example 016 Quake3 Map Shader Support
This Tutorial shows how to load a Quake 3 map into the
engine, create a SceneNode for optimizing the speed of
rendering and how to create a user controlled camera.
@ -38,9 +39,9 @@ to ask the user for a driver type using the console.
/*
As already written in the HelloWorld example, in the Irrlicht
Engine, everything can be found in the namespace 'irr'.
Engine, everything can be found in the namespace 'irr'.
To get rid of the irr:: in front of the name of every class,
we tell the compiler that we use that namespace from now on,
we tell the compiler that we use that namespace from now on,
and we will not have to write that 'irr::'.
There are 5 other sub namespaces 'core', 'scene', 'video',
'io' and 'gui'. Unlike in the HelloWorld example,
@ -53,7 +54,7 @@ using namespace irr;
using namespace scene;
/*
Again, to be able to use the Irrlicht.DLL file, we need to link with the
Again, to be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but
to make it easy, we use a pragma comment lib:
*/
@ -109,14 +110,14 @@ private:
/*
Ok, lets start.
Ok, lets start.
*/
int IRRCALLCONV main(int argc, char* argv[])
{
/*
Like in the HelloWorld example, we create an IrrlichtDevice with
createDevice(). The difference now is that we ask the user to select
createDevice(). The difference now is that we ask the user to select
which hardware accelerated driver to use. The Software device would be
too slow to draw a huge Quake 3 map, but just for the fun of it, we make
this decision possible too.
@ -188,7 +189,7 @@ int IRRCALLCONV main(int argc, char* argv[])
/*
/*
Now we can load the mesh by calling getMesh(). We get a pointer returned
to a IAnimatedMesh. As you know, Quake 3 maps are not really animated,
they are only a huge chunk of static geometry with some materials
@ -196,11 +197,11 @@ int IRRCALLCONV main(int argc, char* argv[])
so we get the "first frame" of the "animation", which is our quake level
and create an OctTree scene node with it, using addOctTreeSceneNode().
The OctTree optimizes the scene a little bit, trying to draw only geometry
which is currently visible. An alternative to the OctTree would be a
AnimatedMeshSceneNode, which would draw always the complete geometry of
which is currently visible. An alternative to the OctTree would be a
AnimatedMeshSceneNode, which would draw always the complete geometry of
the mesh, without optimization. Try it out: Write addAnimatedMeshSceneNode
instead of addOctTreeSceneNode and compare the primitives drawed by the
video driver. (There is a getPrimitiveCountDrawed() method in the
video driver. (There is a getPrimitiveCountDrawed() method in the
IVideoDriver class). Note that this optimization with the Octree is only
useful when drawing huge meshes consisting of lots of geometry.
*/
@ -291,14 +292,14 @@ int IRRCALLCONV main(int argc, char* argv[])
}
/*
Now we only need a Camera to look at the Quake 3 map.
And we want to create a user controlled camera. There are some
different cameras available in the Irrlicht engine. For example the
Maya Camera which can be controlled compareable to the camera in Maya:
Rotate with left mouse button pressed, Zoom with both buttons pressed,
translate with right mouse button pressed. This could be created with
addCameraSceneNodeMaya(). But for this example, we want to create a
camera which behaves like the ones in first person shooter games (FPS).
Now we only need a Camera to look at the Quake 3 map. And we want to
create a user controlled camera. There are some different cameras
available in the Irrlicht engine. For example the Maya Camera which can
be controlled compareable to the camera in Maya: Rotate with left mouse
button pressed, Zoom with both buttons pressed, translate with right
mouse button pressed. This could be created with
addCameraSceneNodeMaya(). But for this example, we want to create a
camera which behaves like the ones in first person shooter games (FPS).
*/
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
@ -379,8 +380,8 @@ int IRRCALLCONV main(int argc, char* argv[])
/*
We have done everything, so lets draw it. We also write the current
frames per second and the drawn primitives to the caption of the
window. The 'if (device->isWindowActive())' line is optional, but
prevents the engine render to set the position of the mouse cursor
window. The 'if (device->isWindowActive())' line is optional, but
prevents the engine render to set the position of the mouse cursor
after task switching when other program are active.
*/
int lastFPS = -1;
@ -425,4 +426,5 @@ int IRRCALLCONV main(int argc, char* argv[])
return 0;
}
/*
**/

View File

@ -0,0 +1,38 @@
# Makefile for Irrlicht Examples
# It's usually sufficient to change just the target name and source file list
# and be sure that CXX is set to a valid compiler
Target = 17.SplitScreen
Sources = main.cpp
# general compiler settings
CPPFLAGS = -I../../include -I/usr/X11R6/include
CXXFLAGS = -O3 -ffast-math
#CXXFLAGS = -g -Wall
#default target is Linux
all: all_linux
ifeq ($(HOSTTYPE), x86_64)
LIBSELECT=64
endif
# target specific settings
all_linux: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L../../lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11
all_linux clean_linux: SYSTEM=Linux
all_win32: LDFLAGS = -L../../lib/Win32-gcc -lIrrlicht -lopengl32 -lm
all_win32 clean_win32: SYSTEM=Win32-gcc
all_win32 clean_win32: SUF=.exe
# name of the binary - only valid for targets which set SYSTEM
DESTPATH = ../../bin/$(SYSTEM)/$(Target)$(SUF)
all_linux all_win32:
$(warning Building...)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS)
clean: clean_linux clean_win32
$(warning Cleaning...)
clean_linux clean_win32:
@$(RM) $(DESTPATH)
.PHONY: all all_win32 clean clean_linux clean_win32

View File

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "17.SplitScreen", "SplitScreen.vcproj", "{EB3B38EA-5CE7-4983-845B-880661E69D09}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{EB3B38EA-5CE7-4983-845B-880661E69D09}.Debug.ActiveCfg = Debug|Win32
{EB3B38EA-5CE7-4983-845B-880661E69D09}.Debug.Build.0 = Debug|Win32
{EB3B38EA-5CE7-4983-845B-880661E69D09}.Release.ActiveCfg = Release|Win32
{EB3B38EA-5CE7-4983-845B-880661E69D09}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="17.SplitScreen"
ProjectGUID="{EB3B38EA-5CE7-4983-845B-880661E69D09}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="..\..\bin\Win32-VisualStudio\17.SplitScreen.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib\Win32-visualstudio"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/SplitScreen.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="TRUE">
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/QIfist /Oa"
Optimization="3"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="4"
BufferSecurityCheck="FALSE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"
CallingConvention="1"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="..\..\bin\Win32-VisualStudio\17.SplitScreen.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\lib\Win32-visualstudio"
GenerateDebugInformation="FALSE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\main.cpp">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,190 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="17.SplitScreen_vc8"
ProjectGUID="{EB3B38EA-5CE7-4983-845B-880661E69D09}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="..\..\bin\Win32-VisualStudio\17.SplitScreen.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib\Win32-visualstudio"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/SplitScreen.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="0"
CallingConvention="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="..\..\bin\Win32-VisualStudio\17.SplitScreen.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib\Win32-visualstudio"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,188 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="17.SplitScreen_vc9"
ProjectGUID="{EB3B38EA-5CE7-4983-845B-880661E69D09}"
RootNamespace="17.SplitScreen_vc9"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="..\..\bin\Win32-VisualStudio\17.SplitScreen.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib\Win32-visualstudio"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/SplitScreen.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="0"
CallingConvention="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="..\..\bin\Win32-VisualStudio\17.SplitScreen.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib\Win32-visualstudio"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,59 @@
[Project]
FileName=example.dev
Name=Irrlicht Example 17 SplitScreen
UnitCount=1
Type=1
Ver=1
ObjFiles=
Includes=..\..\include
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=../../lib/Win32-gcc/libIrrlicht.a_@@_
IsCpp=1
Icon=
ExeOutput=../../bin/Win32-gcc
ObjectOutput=obj
OverrideOutput=1
OverrideOutputName=17.SplitScreen.exe
HostApplication=
Folders=
CommandLine=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000000000000000000
UseCustomMakefile=0
CustomMakefile=
[Unit1]
FileName=main.cpp
CompileCpp=1
Folder=Projekt1
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[VersionInfo]
Major=0
Minor=1
Release=1
Build=1
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Irrlicht Engine example compiled using DevCpp and gcc
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0

View File

@ -0,0 +1,229 @@
/** Example 017 Splitscreen
A tutorial by Max Winkel.
In this tutorial we'll learn how to use splitscreen (e.g. for racing-games)
with Irrlicht. We'll create a viewport divided
into 4 parts, wtih 3 fixed cameras and one user-controlled.
Ok, let's start with the headers (I think there's
nothing to say about it)
*/
#include <irrlicht.h>
#include <stdio.h>
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
//Namespaces for the engine
using namespace irr;
using namespace video;
using namespace core;
using namespace scene;
using namespace io;
using namespace gui;
/*
Now we'll define the resolution in a constant for use in
initializing the device and setting up the viewport. In addition
we set up a global variable saying splitscreen is active or not.
*/
//Resolution
const int ResX=800;
const int ResY=600;
const bool fullScreen=false;
//Use SplitScreen?
bool SplitScreen=true;
/*
Now we need four pointers to our cameras which are created later:
*/
//cameras
ICameraSceneNode *camera[4]={0,0,0,0};
/*
In our event-receiver we switch the SplitScreen-variable,
whenever the user press the S-key. All other events are sent
to the FPS camera.
*/
class MyEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent& event)
{
//Key S enables/disables SplitScreen
if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_KEY_S && event.KeyInput.PressedDown)
{
SplitScreen = !SplitScreen;
return true;
}
//Send all other events to camera4
if (camera[3])
return camera[3]->OnEvent(event);
return false;
}
};
/*
Ok, now the main-function:
First, we initialize the device, get the SourceManager and
VideoDriver, load an animated mesh from .md2 and a map from
.pk3. Because that's old stuff, I won't explain every step.
Just take care of the maps position.
*/
int main()
{
//Instance of the EventReceiver
MyEventReceiver receiver;
//Initialise the engine
IrrlichtDevice *device = createDevice(
EDT_OPENGL, dimension2d<s32>(ResX,ResY), 32, fullScreen, false, false, &receiver);
ISceneManager *smgr = device->getSceneManager();
IVideoDriver *driver = device->getVideoDriver();
//Load model
IAnimatedMesh *model = smgr->getMesh("../../media/sydney.md2");
if (!model)
return 1;
IAnimatedMeshSceneNode *model_node = smgr->addAnimatedMeshSceneNode(model);
//Load texture
ITexture *texture = driver->getTexture("../../media/sydney.bmp");
model_node->setMaterialTexture(0,texture);
//Disable lighting (we've got no light)
model_node->setMaterialFlag(EMF_LIGHTING,false);
//Load map
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
IAnimatedMesh *map = smgr->getMesh("20kdm2.bsp");
if (map)
{
ISceneNode *map_node = smgr->addOctTreeSceneNode(map->getMesh(0));
//Set position
map_node->setPosition(vector3df(-850,-220,-850));
}
/*
Now we create our four cameras. One is looking at the model
from the front, one from the top and one from the side. In
addition there's a FPS-camera which can be controlled by the
user.
*/
// Create 3 fixed and one user-controlled cameras
//Front
camera[0] = smgr->addCameraSceneNode(0, vector3df(50,0,0), vector3df(0,0,0));
//Top
camera[1] = smgr->addCameraSceneNode(0, vector3df(0,50,0), vector3df(0,0,0));
//Left
camera[2] = smgr->addCameraSceneNode(0, vector3df(0,0,50), vector3df(0,0,0));
//User-controlled
camera[3] = smgr->addCameraSceneNodeFPS();
/*
Create a variable for counting the fps and hide the mouse:
*/
//Hide mouse
device->getCursorControl()->setVisible(false);
//We want to count the fps
int lastFPS = -1;
/*
There wasn't much new stuff - till now!
Only by defining four cameras, the game won't be splitscreen.
To do this you need several steps:
- Set the viewport to the whole screen
- Begin a new scene (Clear screen)
- The following 3 steps are repeated for every viewport in the splitscreen
- Set the viewport to the area you wish
- Activate the camera which should be "linked" with the viewport
- Render all objects
- If you have a GUI:
- Set the viewport the whole screen
- Display the GUI
- End scene
Sounds a little complicated, but you'll see it isn't:
*/
while(device->run())
{
//Set the viewpoint to the whole screen and begin scene
driver->setViewPort(rect<s32>(0,0,ResX,ResY));
driver->beginScene(true,true,SColor(255,100,100,100));
//If SplitScreen is used
if (SplitScreen)
{
//Activate camera1
smgr->setActiveCamera(camera[0]);
//Set viewpoint to the first quarter (left top)
driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2));
//Draw scene
smgr->drawAll();
//Activate camera2
smgr->setActiveCamera(camera[1]);
//Set viewpoint to the second quarter (right top)
driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY/2));
//Draw scene
smgr->drawAll();
//Activate camera3
smgr->setActiveCamera(camera[2]);
//Set viewpoint to the third quarter (left bottom)
driver->setViewPort(rect<s32>(0,ResY/2,ResX/2,ResY));
//Draw scene
smgr->drawAll();
//Set viewport the last quarter (right bottom)
driver->setViewPort(rect<s32>(ResX/2,ResY/2,ResX,ResY));
}
//Activate camera4
smgr->setActiveCamera(camera[3]);
//Draw scene
smgr->drawAll();
driver->endScene();
/*
As you can probably see, the image is rendered for every
viewport seperately. That means, that you'll loose much performance.
Ok, if you're aksing "How do I have to set the viewport
to get this or that screen?", don't panic. It's really
easy: In the rect-function you define 4 coordinates:
- X-coordinate of the corner left top
- Y-coordinate of the corner left top
- X-coordinate of the corner right bottom
- Y-coordinate of the corner right bottom
That means, if you want to split the screen into 2 viewports
you would give the following coordinates:
- 1st viewport: 0,0,ResX/2,ResY
- 2nd viewport: ResX/2,0,ResX,ResY
If you didn't fully understand, just play arround with the example
to check out what happens.
Now we just view the current fps and shut down the engine,
when the user wants to:
*/
//Get and show fps
if (driver->getFPS() != lastFPS)
{
lastFPS = driver->getFPS();
wchar_t tmp[1024];
swprintf( tmp, 1024, L"Irrlicht SplitScreen-Example (FPS: %d)", lastFPS);
device->setWindowCaption(tmp);
}
}
//Delete device
device->drop();
return 0;
}
/*
That's it! Just compile and play around with the program.
Note: With the S-Key you can switch between using splitscreen
and not.
**/

View File

@ -45,7 +45,7 @@ void CDemo::run()
resolution.Height = 480;
}
device = createDevice(driverType,resolution, 32, fullscreen, shadows, vsync, this);
device = createDevice(driverType, resolution, 32, fullscreen, shadows, vsync, this);
if (!device)
return;

View File

@ -4,7 +4,7 @@
#ifndef __C_DEMO_H_INCLUDED__
#define __C_DEMO_H_INCLUDED__
//#define USE_IRRKLANG
#define USE_IRRKLANG
//#define USE_SDL_MIXER
#include <irrlicht.h>

View File

@ -10,32 +10,30 @@ class CSceneNodeAnimatorFollowBoundingBox : public irr::scene::ISceneNodeAnimato
public:
//! constructor
CSceneNodeAnimatorFollowBoundingBox( irr::scene::ISceneNode* tofollow, const core::vector3df &offset, u32 frequency, s32 phase )
CSceneNodeAnimatorFollowBoundingBox(irr::scene::ISceneNode* tofollow,
const core::vector3df &offset, u32 frequency, s32 phase)
: Offset(offset), ToFollow(tofollow), Frequency(frequency), Phase(phase)
{
Frequency = frequency;
Phase = phase;
Offset = offset;
ToFollow = tofollow;
if ( ToFollow )
ToFollow->grab ();
if (ToFollow)
ToFollow->grab();
}
//! destructor
virtual ~CSceneNodeAnimatorFollowBoundingBox()
{
if ( ToFollow )
ToFollow->drop ();
if (ToFollow)
ToFollow->drop();
}
//! animates a scene node
virtual void animateNode(irr::scene::ISceneNode* node, u32 timeMs)
{
if ( 0 == node || node->getType () != irr::scene::ESNT_LIGHT)
if (0 == node || node->getType() != irr::scene::ESNT_LIGHT)
return;
irr::scene::ILightSceneNode* l = (irr::scene::ILightSceneNode*) node;
if ( ToFollow )
if (ToFollow)
{
core::vector3df now = l->getPosition();
now += ToFollow->getBoundingBox().getCenter();
@ -45,7 +43,7 @@ public:
irr::video::SColorHSL color;
irr::video::SColor rgb(0);
color.Hue = ( ( timeMs + Phase ) % Frequency ) * ( 2.f * irr::core::PI / Frequency );
color.Hue = ( (timeMs + Phase) % Frequency ) * ( 2.f * irr::core::PI / Frequency );
color.Saturation = 1.f;
color.Luminance = 0.5f;
color.toRGB(rgb);
@ -55,7 +53,6 @@ public:
l->setLightData(light);
}
private:
core::vector3df Offset;
@ -65,8 +62,6 @@ private:
};
CMainMenu::CMainMenu()
: startButton(0), MenuDevice(0), selected(2), start(false), fullscreen(true),
music(true), shadows(false), additive(false), transparent(true), vsync(false)
@ -74,11 +69,10 @@ CMainMenu::CMainMenu()
}
bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
bool& outAdditive, bool &outVSync, video::E_DRIVER_TYPE& outDriver)
bool& outAdditive, bool &outVSync, video::E_DRIVER_TYPE& outDriver)
{
MenuDevice = createDevice( outDriver, //Varmint: 2007/12/18 video::EDT_BURNINGSVIDEO,
MenuDevice = createDevice(video::EDT_BURNINGSVIDEO,
core::dimension2d<s32>(512, 384), 16, false, false, false, this);
if (MenuDevice->getFileSystem()->existFile("irrlicht.dat"))
@ -95,7 +89,7 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
MenuDevice->setWindowCaption(str.c_str());
// set new Skin
gui::IGUISkin* newskin = guienv->createSkin( gui::EGST_BURNING_SKIN);
gui::IGUISkin* newskin = guienv->createSkin(gui::EGST_BURNING_SKIN);
guienv->setSkin(newskin);
newskin->drop();
@ -106,7 +100,6 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
// add images
const s32 leftX = 260;
// add tab control
@ -144,49 +137,35 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
guienv->addCheckBox(vsync, core::rect<int>(20,185+d,230,210+d),
optTab, 7, L"Vertical synchronisation");
// add text
/*wchar_t* text = L"Welcome to the Irrlicht Engine. Please select "\
L"the settings you prefer and press 'Start Demo'. "\
L"Right click for changing menu style.";
guienv->addStaticText(text, core::rect<int>(10, 220, 220, 280),
true, true, optTab);*/
// add about text
wchar_t* text2 = L"This is the tech demo of the Irrlicht engine. To start, "\
L"select a MenuDevice which works best with your hardware and press 'start demo'. "\
L"What you currently see is displayed using the Burning Software Renderer (Thomas Alten). "\
L"select a video driver which works best with your hardware and press 'Start Demo'.\n"\
L"What you currently see is displayed using the Burning Software Renderer (Thomas Alten).\n"\
L"The Irrlicht Engine was written by me, Nikolaus Gebhardt. The models, "\
L"maps and textures were placed at my disposal by B.Collins, M.Cook and J.Marton. The music was created by "\
L"M.Rohde and is played back by Audiere."\
L"For more informations, please visit the homepage of the Irrlicht engine:\nhttp://www.irrlicht.sourceforge.net";
L"M.Rohde and is played back by irrKlang.\n"\
L"For more informations, please visit the homepage of the Irrlicht engine:\nhttp://irrlicht.sourceforge.net";
guienv->addStaticText(text2, core::rect<int>(10, 10, 230, 320),
true, true, aboutTab);
// add md2 model
scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
if (modelNode)
{
modelNode->setPosition ( core::vector3df ( 0.f, 0.f, -5.f ) );
modelNode->setPosition( core::vector3df(0.f, 0.f, -5.f) );
modelNode->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp"));
modelNode->setMaterialFlag(video::EMF_LIGHTING, true);
modelNode->getMaterial(0).Shininess = 28.f;
modelNode->getMaterial(0).NormalizeNormals = true;
modelNode->setMD2Animation ( scene::EMAT_STAND );
//modelNode->setMD2Animation ( scene::EMAT_JUMP );
//modelNode->setDebugDataVisible ( scene::EDS_BBOX_ALL );
//modelNode->setFrameLoop ( 0, 0 );
modelNode->setMD2Animation(scene::EMAT_STAND);
}
// set ambient light ( no sun light in the catacombs )
smgr->setAmbientLight ( video::SColorf ( 0.f, 0.f, 0.f ) );
// set ambient light (no sun light in the catacombs)
smgr->setAmbientLight( video::SColorf(0.f, 0.f, 0.f) );
scene::ISceneNodeAnimator* anim;
scene::ISceneNode* bill;
@ -197,16 +176,15 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
video::SColorf(0.86f, 0.38f, 0.05f), 200.0f);
// add fly circle animator to light 1
anim = smgr->createFlyCircleAnimator (core::vector3df(0,0,0),30.0f, -0.004f, core::vector3df ( 0.41f, 0.4f, 0.0f ) );
anim = smgr->createFlyCircleAnimator(core::vector3df(0,0,0),30.0f, -0.004f, core::vector3df(0.41f, 0.4f, 0.0f));
light1->addAnimator(anim);
anim->drop();
// let the lights follow the model...
anim = new CSceneNodeAnimatorFollowBoundingBox ( modelNode, core::vector3df(0,16,0), 4000, 0 );
anim = new CSceneNodeAnimatorFollowBoundingBox(modelNode, core::vector3df(0,16,0), 4000, 0);
//light1->addAnimator(anim);
anim->drop();
// attach billboard to the light
bill = smgr->addBillboardSceneNode(light1, core::dimension2d<f32>(10, 10));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
@ -220,12 +198,12 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
video::SColorf(0.9f, 1.0f, 0.f, 0.0f), 200.0f);
// add fly circle animator to light 1
anim = smgr->createFlyCircleAnimator (core::vector3df(0,0,0),30.0f, 0.004f, core::vector3df ( 0.41f, 0.4f, 0.0f ) );
anim = smgr->createFlyCircleAnimator(core::vector3df(0,0,0),30.0f, 0.004f, core::vector3df(0.41f, 0.4f, 0.0f));
light2->addAnimator(anim);
anim->drop();
// let the lights follow the model...
anim = new CSceneNodeAnimatorFollowBoundingBox ( modelNode, core::vector3df(0,-8,0), 2000, 0 );
anim = new CSceneNodeAnimatorFollowBoundingBox( modelNode, core::vector3df(0,-8,0), 2000, 0 );
//light2->addAnimator(anim);
anim->drop();
@ -242,21 +220,23 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
video::SColorf(0.f, 0.0f, 0.9f, 0.0f), 40.0f);
// add fly circle animator to light 2
anim = smgr->createFlyCircleAnimator (core::vector3df(0,0,0),40.0f, 0.004f, core::vector3df ( -0.41f, -0.4f, 0.0f ) );
anim = smgr->createFlyCircleAnimator(core::vector3df(0,0,0),40.0f, 0.004f, core::vector3df(-0.41f, -0.4f, 0.0f));
light3->addAnimator(anim);
anim->drop();
// let the lights follow the model...
anim = new CSceneNodeAnimatorFollowBoundingBox ( modelNode, core::vector3df(0,8,0), 8000, 0 );
anim = new CSceneNodeAnimatorFollowBoundingBox(modelNode, core::vector3df(0,8,0), 8000, 0);
//light3->addAnimator(anim);
anim->drop();
// attach billboard to the light
bill = smgr->addBillboardSceneNode(light3, core::dimension2d<f32>(10, 10));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, driver->getTexture("../../media/portal1.bmp"));
if (bill)
{
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, driver->getTexture("../../media/portal1.bmp"));
}
#endif
// create a fixed camera
@ -274,9 +254,8 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
// query original skin color
getOriginalSkinColor ();
getOriginalSkinColor();
// set transparency
setTransparency();
@ -289,10 +268,9 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
{
driver->beginScene(false, true, video::SColor(0,0,0,0));
if ( irrlichtBack )
if (irrlichtBack)
driver->draw2DImage(irrlichtBack,
core::position2d<int>(0,0)
);
core::position2d<int>(0,0));
smgr->drawAll();
guienv->drawAll();
@ -321,7 +299,6 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
}
bool CMainMenu::OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT &&
@ -369,7 +346,7 @@ bool CMainMenu::OnEvent(const SEvent& event)
{
selected = ((gui::IGUIListBox*)event.GUIEvent.Caller)->getSelected();
//startButton->setEnabled(selected != 4);
startButton->setEnabled( true );
startButton->setEnabled(true);
}
break;
case 2:
@ -410,21 +387,22 @@ void CMainMenu::getOriginalSkinColor()
irr::gui::IGUISkin * skin = MenuDevice->getGUIEnvironment()->getSkin();
for (s32 i=0; i<gui::EGDC_COUNT ; ++i)
{
SkinColor [ i ] = skin->getColor ( (gui::EGUI_DEFAULT_COLOR)i );
SkinColor[i] = skin->getColor( (gui::EGUI_DEFAULT_COLOR)i );
}
}
void CMainMenu::setTransparency()
{
irr::gui::IGUISkin * skin = MenuDevice->getGUIEnvironment()->getSkin();
for (u32 i=0; i<gui::EGDC_COUNT ; ++i)
{
video::SColor col = SkinColor [ i ];
video::SColor col = SkinColor[i];
if ( false == transparent )
col.setAlpha( 255);
if (false == transparent)
col.setAlpha(255);
skin->setColor((gui::EGUI_DEFAULT_COLOR)i, col);
}

View File

@ -6,7 +6,7 @@
#define __IRR_COMPILE_CONFIG_H_INCLUDED__
//! Irrlicht SDK Version
#define IRRLICHT_SDK_VERSION "1.4.1"
#define IRRLICHT_SDK_VERSION "1.4.2"
//! The defines for different operating system are:
//! _IRR_XBOX_PLATFORM_ for XBox
@ -82,7 +82,7 @@ to the compiler settings: -DIRR_COMPILE_WITH_DX9_DEV_PACK
and this to the linker settings: -ld3dx9 -ld3dx8 **/
#if defined(_IRR_WINDOWS_API_) && (!defined(__GNUC__) || defined(IRR_COMPILE_WITH_DX9_DEV_PACK))
//#define _IRR_COMPILE_WITH_DIRECT3D_8_
#define _IRR_COMPILE_WITH_DIRECT3D_8_
#define _IRR_COMPILE_WITH_DIRECT3D_9_
#endif

View File

@ -141,7 +141,7 @@
#include "SMeshBufferTangents.h"
#include "SViewFrustum.h"
/*! \mainpage Irrlicht Engine 1.4.1 API documentation
/*! \mainpage Irrlicht Engine 1.4.2 API documentation
*
* <div align="center"><img src="logobig.png" ></div>
*

BIN
media/016shot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
media/017shot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1,5 +1,5 @@
==========================================================================
The Irrlicht Engine SDK version 1.4.1
The Irrlicht Engine SDK version 1.4.2
==========================================================================
Welcome the Irrlicht Engine SDK.

Binary file not shown.

Binary file not shown.

View File

@ -444,7 +444,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = ../../../include/
INPUT = ../../../include/ tut.txt
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
@ -504,7 +504,7 @@ EXAMPLE_RECURSIVE = NO
# directories that contain image that are included in the documentation (see
# the \image command).
IMAGE_PATH =
IMAGE_PATH = ../../../media
# The INPUT_FILTER tag can be used to specify a program that doxygen should
# invoke to filter for each input file. Doxygen will invoke the filter program

View File

@ -444,7 +444,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = ../../../include/
INPUT = ../../../include/ tut.txt
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
@ -504,7 +504,7 @@ EXAMPLE_RECURSIVE = NO
# directories that contain image that are included in the documentation (see
# the \image command).
IMAGE_PATH =
IMAGE_PATH = ../../../media
# The INPUT_FILTER tag can be used to specify a program that doxygen should
# invoke to filter for each input file. Doxygen will invoke the filter program
@ -761,13 +761,13 @@ LATEX_HEADER =
# contain links (just like the HTML output) instead of page references
# This makes the output suitable for online browsing using a pdf viewer.
PDF_HYPERLINKS = NO
PDF_HYPERLINKS = YES
# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
# plain latex in the generated Makefile. Set this option to YES to get a
# higher quality PDF documentation.
USE_PDFLATEX = NO
USE_PDFLATEX = YES
# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
# command to the generated LaTeX files. This will instruct LaTeX to keep

View File

@ -14,6 +14,6 @@
| <a class="qindex" href="namespacemembers.html"><font color="#FFFFFF">
Namespace&nbsp;Members</font></a> | <a class="qindex" href="functions.html"><font color="#FFFFFF">Class
members</font></a> | <a class="qindex" href="globals.html"><font color="#FFFFFF">File
members</font></a></font> </td>
members</font></a> | <a class="qindex" href="pages.html"><font color="#FFFFFF">Tutorials</font></a></font> </td>
</tr>
</table>

View File

@ -4,6 +4,25 @@ copy doxygen.css ..\..\..\doctemp\html
copy irrlicht.png ..\..\..\doctemp\html
copy logobig.png ..\..\..\doctemp\html
rem for /F %%i in ('dir ..\..\..\examples\[01]*\main.cpp') DO ..\sed.exe -f tutorials.sed %i >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\01.HelloWorld\main.cpp >tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\02.Quake3Map\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\03.CustomSceneNode\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\04.Movement\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\05.UserInterface\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\06.2DGraphics\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\07.Collision\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\08.SpecialFX\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\09.MeshViewer\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\10.Shaders\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\11.PerPixelLighting\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\12.TerrainRendering\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\13.RenderToTexture\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\14.Win32Window\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\15.LoadIrrFile\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\16.Quake3MapShader\main.cpp >>tut.txt
..\sed.exe -f tutorials.sed ..\..\..\examples\17.SplitScreen\main.cpp >>tut.txt
..\doxygen.exe doxygen.cfg
pause
pause

View File

@ -1,4 +1,9 @@
doxygen doxygen.cfg
rm tut.txt || true;
for i in ../../../examples/[01]*/main.cpp; do
sed -f tutorials.sed $i >>tut.txt;
done
doxygen doxygen-pdf.cfg
cp doxygen.css irrlicht.png logobig.png ../../../doctemp/html

View File

@ -0,0 +1,13 @@
# Page start and end are delimited by /** and **/
# we keep the end unchanged, the header is extended
s/\/\*\* Example \(0*\)\([0-9]*\) \(.*\)$/\/\*\* \\page example\1\2 Tutorial \2: \3\n \\image html \"\1\2shot.jpg\"\n \\image latex \"\1\2shot.jpg\"/
# All other comments start and end code sections
s/\([^\*]\)\*\//\1\\code/
s/^\*\//\\code/
s/\/\*\([^\*]\)/\\endcode \1/
s/\/\*$/\\endcode\n/
#remove DOS line endings
s/\r//g

BIN
scripts/doc/sed.exe Normal file

Binary file not shown.

9
scripts/doc/sed.txt Normal file
View File

@ -0,0 +1,9 @@
GNU sed version 4.0.7 - compiled for Win32.
Native executable requires only the Microsoft
C runtime MSVCRT.DLL, not an emulation layer
like Cygwin. This .EXE file was obtained from
http://unxutils.sourceforge.net on 2003-10-21.
For documentation, GPL license, source code,
etc., visit http://unxutils.sourceforge.net.
Downloaded from http://www.student.northpark.edu/pemente/sed/

View File

@ -11,7 +11,7 @@
# norootforbuild
Name: libIrrlicht1
Version: 1.4.beta
Version: 1.4.2
Release: 0.pm.1
Summary: The Irrlicht Engine SDK
License: see readme.txt

View File

@ -589,8 +589,8 @@ bool C3DSMeshFileLoader::readTrackChunk(io::IReadFile* file, ChunkData& data,
file->read(&vec.Z, sizeof(f32));
#ifdef __BIG_ENDIAN__
vec.X = os::Byteswap::byteswap(vec.X);
vec.Y = os::Byteswap::byteswap(vec.X);
vec.Z = os::Byteswap::byteswap(vec.X);
vec.Y = os::Byteswap::byteswap(vec.Y);
vec.Z = os::Byteswap::byteswap(vec.Z);
#endif
data.read += 12;
vec-=pivot;

View File

@ -1,5 +1,5 @@
VERSION = 1.4
# Irrlicht Engine 1.4
VERSION = 1.4.2
# Irrlicht Engine 1.4.2
# Makefile for Linux
#
# To use, just run: