Irrlicht-Hello World

Source: Internet
Author: User

All IRR engine files are in the IRR namespace, And the IRR namespace is divided into five modules:

Core: contains some engine core classes, including various data structures and custom data structures.

Gui: some common graphical user interfaces implement various common controls.

IO: reads some internal input/output, XML, zip, and INI files.

Scene: it is mainly responsible for scene management, including scene nodes, cameras, particle system mesh, announcement boards, lights, animations, Sky boxes, and terrain.

Video: responsible for video driver settings. 2D and 3D rendering are all implemented here, including texture, material, lighting, images, vertices, and other rendering attributes.

All things in irrlicht scenarios are scenario nodes, which are centrally managed by scenemanager.

Steps:

1. Create a device.

2. Obtain the scenario manager, video devices, and GUI environment pointers for Rendering Control.

3. drawall between beginscene and endscene.

4. Release the device.

 # 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 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
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 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
Write their names.
*/
Using Namespace Core;
Using Namespace Scene;
Using Namespace Video;
Using Namespace Io;
Using Namespace Gui;

/*
To be able to use the irrlicht. dll file, we need to link with the irrlicht. Lib.
We cocould set this option in the project settings, but to make it easy, we use
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 cocould 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 now use main () on every platform.
*/
Int Main ()
{
/*
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
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 shoshould be 16 or 32.
Parameter is often ignored when running in specified wed mode.

-Fullscreen: Specifies if we want the device to run in fullscreen Mode
Or not.

-Stencilbuffer: Specifies if we want to use the stencel buffer (
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 counter with unsupported drivers,
Dimensions, etc.
*/
Irrlichtdevice * Device =
Createdevice (Video: edt_software, dimension2d < U32 > ( 640 , 480 ), 16 ,
False , False , False , 0 );

If ( ! Device)
Return 1 ;

/*
Set the caption of the window to some nice text. Note that there is
'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 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 ();
Iguienvironment * Guienv = Device -> Getguienvironment ();

/*
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
As lower right corner.
*/
Guienv -> Addstatictext (L " Hello world! This is the irrlicht software Renderer! " ,
Rect < S32 > ( 10 , 10 , 260 , 22 ), True );

/*
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 sysydney. md2, it wocould 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 sysydney was modelled by Brian Collins.
*/
Ianimatedmesh * Mesh = Smgr -> Getmesh ( " Http://www.cnblogs.com/media/sydney.md2 " );
If ( ! Mesh)
{
Device -> Drop ();
Return 1 ;
}
Ianimatedmeshscenenode * Node = Smgr -> Addanimatedmeshscenenode (mesh );

/*
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 wocould be totally black otherwise. Then we set the frame loop,
Such that the predefined stand animation is used. And last, we apply
Texture to the mesh. Without it the mesh wocould be drawn using only
Color.
*/
If (Node)
{
Node -> Setmaterialflag (emf_lighting, False );
Node -> Setmd2animation (Scene: emat_stand );
Node -> Setmaterialtexture ( 0 , Driver -> Gettexture ( " Http://www.cnblogs.com/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), 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
Device in a while () loop, until the device does not want to run any
More. This wocould 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 () 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 ));

Smgr -> Drawall ();
Guienv -> Drawall ();

Driver -> Endscene ();
}

/*
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 ;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.