aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/examples/06.2DGraphics/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/examples/06.2DGraphics/main.cpp332
1 files changed, 166 insertions, 166 deletions
diff --git a/libraries/irrlicht-1.8/examples/06.2DGraphics/main.cpp b/libraries/irrlicht-1.8/examples/06.2DGraphics/main.cpp
index 40e311a..5b6a8df 100644
--- a/libraries/irrlicht-1.8/examples/06.2DGraphics/main.cpp
+++ b/libraries/irrlicht-1.8/examples/06.2DGraphics/main.cpp
@@ -1,166 +1,166 @@
1/** Example 006 2D Graphics 1/** Example 006 2D Graphics
2 2
3This Tutorial shows how to do 2d graphics with the Irrlicht Engine. 3This Tutorial shows how to do 2d graphics with the Irrlicht Engine.
4It shows how to draw images, keycolor based sprites, 4It shows how to draw images, keycolor based sprites,
5transparent rectangles, and different fonts. You may consider 5transparent rectangles, and different fonts. You may consider
6this useful if you want to make a 2d game with the engine, or if 6this useful if you want to make a 2d game with the engine, or if
7you want to draw a cool interface or head up display for your 3d game. 7you want to draw a cool interface or head up display for your 3d game.
8 8
9As always, I include the header files, use the irr namespace, 9As always, I include the header files, use the irr namespace,
10and tell the linker to link with the .lib file. 10and tell the linker to link with the .lib file.
11*/ 11*/
12#include <irrlicht.h> 12#include <irrlicht.h>
13#include "driverChoice.h" 13#include "driverChoice.h"
14 14
15using namespace irr; 15using namespace irr;
16 16
17#ifdef _MSC_VER 17#ifdef _MSC_VER
18#pragma comment(lib, "Irrlicht.lib") 18#pragma comment(lib, "Irrlicht.lib")
19#endif 19#endif
20 20
21/* 21/*
22At first, we let the user select the driver type, then start up the engine, set 22At first, we let the user select the driver type, then start up the engine, set
23a caption, and get a pointer to the video driver. 23a caption, and get a pointer to the video driver.
24*/ 24*/
25int main() 25int main()
26{ 26{
27 // ask user for driver 27 // ask user for driver
28 video::E_DRIVER_TYPE driverType=driverChoiceConsole(); 28 video::E_DRIVER_TYPE driverType=driverChoiceConsole();
29 if (driverType==video::EDT_COUNT) 29 if (driverType==video::EDT_COUNT)
30 return 1; 30 return 1;
31 31
32 // create device 32 // create device
33 33
34 IrrlichtDevice *device = createDevice(driverType, 34 IrrlichtDevice *device = createDevice(driverType,
35 core::dimension2d<u32>(512, 384)); 35 core::dimension2d<u32>(512, 384));
36 36
37 if (device == 0) 37 if (device == 0)
38 return 1; // could not create selected driver. 38 return 1; // could not create selected driver.
39 39
40 device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo"); 40 device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");
41 41
42 video::IVideoDriver* driver = device->getVideoDriver(); 42 video::IVideoDriver* driver = device->getVideoDriver();
43 43
44 /* 44 /*
45 All 2d graphics in this example are put together into one texture, 45 All 2d graphics in this example are put together into one texture,
46 2ddemo.png. Because we want to draw colorkey based sprites, we need to 46 2ddemo.png. Because we want to draw colorkey based sprites, we need to
47 load this texture and tell the engine, which part of it should be 47 load this texture and tell the engine, which part of it should be
48 transparent based on a colorkey. 48 transparent based on a colorkey.
49 49
50 In this example, we don't tell it the color directly, we just say "Hey 50 In this example, we don't tell it the color directly, we just say "Hey
51 Irrlicht Engine, you'll find the color I want at position (0,0) on the 51 Irrlicht Engine, you'll find the color I want at position (0,0) on the
52 texture.". Instead, it would be also possible to call 52 texture.". Instead, it would be also possible to call
53 driver->makeColorKeyTexture(images, video::SColor(0,0,0,0)), to make 53 driver->makeColorKeyTexture(images, video::SColor(0,0,0,0)), to make
54 e.g. all black pixels transparent. Please note that 54 e.g. all black pixels transparent. Please note that
55 makeColorKeyTexture just creates an alpha channel based on the color. 55 makeColorKeyTexture just creates an alpha channel based on the color.
56 */ 56 */
57 video::ITexture* images = driver->getTexture("../../media/2ddemo.png"); 57 video::ITexture* images = driver->getTexture("../../media/2ddemo.png");
58 driver->makeColorKeyTexture(images, core::position2d<s32>(0,0)); 58 driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
59 59
60 /* 60 /*
61 To be able to draw some text with two different fonts, we first load 61 To be able to draw some text with two different fonts, we first load
62 them. Ok, we load just one. As the first font we just use the default 62 them. Ok, we load just one. As the first font we just use the default
63 font which is built into the engine. Also, we define two rectangles 63 font which is built into the engine. Also, we define two rectangles
64 which specify the position of the images of the red imps (little flying 64 which specify the position of the images of the red imps (little flying
65 creatures) in the texture. 65 creatures) in the texture.
66 */ 66 */
67 gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont(); 67 gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
68 gui::IGUIFont* font2 = 68 gui::IGUIFont* font2 =
69 device->getGUIEnvironment()->getFont("../../media/fonthaettenschweiler.bmp"); 69 device->getGUIEnvironment()->getFont("../../media/fonthaettenschweiler.bmp");
70 70
71 core::rect<s32> imp1(349,15,385,78); 71 core::rect<s32> imp1(349,15,385,78);
72 core::rect<s32> imp2(387,15,423,78); 72 core::rect<s32> imp2(387,15,423,78);
73 73
74 /* 74 /*
75 Prepare a nicely filtering 2d render mode for special cases. 75 Prepare a nicely filtering 2d render mode for special cases.
76 */ 76 */
77 driver->getMaterial2D().TextureLayer[0].BilinearFilter=true; 77 driver->getMaterial2D().TextureLayer[0].BilinearFilter=true;
78 driver->getMaterial2D().AntiAliasing=video::EAAM_FULL_BASIC; 78 driver->getMaterial2D().AntiAliasing=video::EAAM_FULL_BASIC;
79 79
80 /* 80 /*
81 Everything is prepared, now we can draw everything in the draw loop, 81 Everything is prepared, now we can draw everything in the draw loop,
82 between the begin scene and end scene calls. In this example, we are 82 between the begin scene and end scene calls. In this example, we are
83 just doing 2d graphics, but it would be no problem to mix them with 3d 83 just doing 2d graphics, but it would be no problem to mix them with 3d
84 graphics. Just try it out, and draw some 3d vertices or set up a scene 84 graphics. Just try it out, and draw some 3d vertices or set up a scene
85 with the scene manager and draw it. 85 with the scene manager and draw it.
86 */ 86 */
87 while(device->run() && driver) 87 while(device->run() && driver)
88 { 88 {
89 if (device->isWindowActive()) 89 if (device->isWindowActive())
90 { 90 {
91 u32 time = device->getTimer()->getTime(); 91 u32 time = device->getTimer()->getTime();
92 92
93 driver->beginScene(true, true, video::SColor(255,120,102,136)); 93 driver->beginScene(true, true, video::SColor(255,120,102,136));
94 94
95 /* 95 /*
96 First, we draw 3 sprites, using the alpha channel we 96 First, we draw 3 sprites, using the alpha channel we
97 created with makeColorKeyTexture. The last parameter 97 created with makeColorKeyTexture. The last parameter
98 specifies that the drawing method should use this alpha 98 specifies that the drawing method should use this alpha
99 channel. The last-but-one parameter specifies a 99 channel. The last-but-one parameter specifies a
100 color, with which the sprite should be colored. 100 color, with which the sprite should be colored.
101 (255,255,255,255) is full white, so the sprite will 101 (255,255,255,255) is full white, so the sprite will
102 look like the original. The third sprite is drawn 102 look like the original. The third sprite is drawn
103 with the red channel modulated based on the time. 103 with the red channel modulated based on the time.
104 */ 104 */
105 105
106 // draw fire & dragons background world 106 // draw fire & dragons background world
107 driver->draw2DImage(images, core::position2d<s32>(50,50), 107 driver->draw2DImage(images, core::position2d<s32>(50,50),
108 core::rect<s32>(0,0,342,224), 0, 108 core::rect<s32>(0,0,342,224), 0,
109 video::SColor(255,255,255,255), true); 109 video::SColor(255,255,255,255), true);
110 110
111 // draw flying imp 111 // draw flying imp
112 driver->draw2DImage(images, core::position2d<s32>(164,125), 112 driver->draw2DImage(images, core::position2d<s32>(164,125),
113 (time/500 % 2) ? imp1 : imp2, 0, 113 (time/500 % 2) ? imp1 : imp2, 0,
114 video::SColor(255,255,255,255), true); 114 video::SColor(255,255,255,255), true);
115 115
116 // draw second flying imp with colorcylce 116 // draw second flying imp with colorcylce
117 driver->draw2DImage(images, core::position2d<s32>(270,105), 117 driver->draw2DImage(images, core::position2d<s32>(270,105),
118 (time/500 % 2) ? imp1 : imp2, 0, 118 (time/500 % 2) ? imp1 : imp2, 0,
119 video::SColor(255,(time) % 255,255,255), true); 119 video::SColor(255,(time) % 255,255,255), true);
120 120
121 /* 121 /*
122 Drawing text is really simple. The code should be self 122 Drawing text is really simple. The code should be self
123 explanatory. 123 explanatory.
124 */ 124 */
125 125
126 // draw some text 126 // draw some text
127 if (font) 127 if (font)
128 font->draw(L"This demo shows that Irrlicht is also capable of drawing 2D graphics.", 128 font->draw(L"This demo shows that Irrlicht is also capable of drawing 2D graphics.",
129 core::rect<s32>(130,10,300,50), 129 core::rect<s32>(130,10,300,50),
130 video::SColor(255,255,255,255)); 130 video::SColor(255,255,255,255));
131 131
132 // draw some other text 132 // draw some other text
133 if (font2) 133 if (font2)
134 font2->draw(L"Also mixing with 3d graphics is possible.", 134 font2->draw(L"Also mixing with 3d graphics is possible.",
135 core::rect<s32>(130,20,300,60), 135 core::rect<s32>(130,20,300,60),
136 video::SColor(255,time % 255,time % 255,255)); 136 video::SColor(255,time % 255,time % 255,255));
137 137
138 /* 138 /*
139 Next, we draw the Irrlicht Engine logo (without 139 Next, we draw the Irrlicht Engine logo (without
140 using a color or an alpha channel). Since we slightly scale 140 using a color or an alpha channel). Since we slightly scale
141 the image we use the prepared filter mode. 141 the image we use the prepared filter mode.
142 */ 142 */
143 driver->enableMaterial2D(); 143 driver->enableMaterial2D();
144 driver->draw2DImage(images, core::rect<s32>(10,10,108,48), 144 driver->draw2DImage(images, core::rect<s32>(10,10,108,48),
145 core::rect<s32>(354,87,442,118)); 145 core::rect<s32>(354,87,442,118));
146 driver->enableMaterial2D(false); 146 driver->enableMaterial2D(false);
147 147
148 /* 148 /*
149 Finally draw a half-transparent rect under the mouse cursor. 149 Finally draw a half-transparent rect under the mouse cursor.
150 */ 150 */
151 core::position2d<s32> m = device->getCursorControl()->getPosition(); 151 core::position2d<s32> m = device->getCursorControl()->getPosition();
152 driver->draw2DRectangle(video::SColor(100,255,255,255), 152 driver->draw2DRectangle(video::SColor(100,255,255,255),
153 core::rect<s32>(m.X-20, m.Y-20, m.X+20, m.Y+20)); 153 core::rect<s32>(m.X-20, m.Y-20, m.X+20, m.Y+20));
154 154
155 driver->endScene(); 155 driver->endScene();
156 } 156 }
157 } 157 }
158 158
159 device->drop(); 159 device->drop();
160 160
161 return 0; 161 return 0;
162} 162}
163 163
164/* 164/*
165That's all. I hope it was not too difficult. 165That's all. I hope it was not too difficult.
166**/ 166**/