Analysis
1. Procedure
Generally, for a simple program, the Irrlicht engine is generally used as follows:
Preprocessing:
(1) include the <irrlicht. h> header file
# Include <irrlicht. h>
(2) set the namespace
Using namespace irr;
Setting the namespace makes subsequent programming a little easier, just like using the using namespace std; when using C ++ for programming, std: cout <→ cout <.
(3) notify the compiler to connect to the irr Library File
# Ifdef _ IRR_WINDOWS _
# Pragma comment (lib, "Irrlicht. lib ")
# Pragma comment (linker, "/subsystem: windows/ENTRY: mainCRTStartup ")
# Endif
If you do not perform the preceding operations, an error will be reported in the Link section during program compilation. Therefore, this step is very important and must not be forgotten.
At this point, the preprocessing step is complete. Next, we will provide the program with a main function as the entry of the program.
The steps required in the main function are as follows:
(1) create a device
(2) Use the scenario manager, GUI environment, and video device pointers for Rendering Control.
(3) loop in the case of device-> Run. Render control of all content in driver-> beginScene () and driver-> endScene. (We mentioned earlier that the driver is a pointer to IVideoDriver and is responsible for 2D/3D rendering)
(4) release the device
In general, the device is released using the device-> drop (); statement.
In this way, a very basic program based on the Irrlicht engine is completed. On this basis, we can perform various addition operations, such as adding a mesh model and an FPS camera, add terrain, add sky boxes, and so on. These operations will be mentioned in future articles.
2. helloWorld program example
Next, we will show you a simple program written based on the process described above. In the program, we add comments to the sections that need to be understood and noticed to explain the role of statements in the program, hope it will help you understand it!
#include <irrlicht.h> comment(lib, "Irrlicht.lib") comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") IrrlichtDevice *device =<u32>(, ), , , , (! device->setWindowCaption(L* driver = device->* smgr = device->* guienv = device-> guienv->addStaticText(L<s32>(,,,), smgr->addCameraSceneNode(, vector3df(,,-), vector3df(,,(device-> driver->beginScene(, , SColor(,,,->->-> device->