2 #include <irrlicht.h>
\r
3 #include "exampleHelper.h"
\r
7 static IrrlichtDevice *device = nullptr;
\r
8 static int test_fail = 0;
\r
10 void test_irr_array();
\r
11 void test_irr_string();
\r
13 static video::E_DRIVER_TYPE chooseDriver(const char *arg_)
\r
15 if (core::stringc(arg_) == "null")
\r
16 return video::EDT_NULL;
\r
18 if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES1))
\r
19 return video::EDT_OGLES1;
\r
20 if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES2))
\r
21 return video::EDT_OGLES2;
\r
22 return video::EDT_OPENGL;
\r
25 static inline void check(bool ok, const char *msg)
\r
30 device->getLogger()->log((core::stringc("FAILED TEST: ") + msg).c_str(), ELL_ERROR);
\r
34 void run_unit_tests() {
\r
35 std::cout << "Running unit tests:" << std::endl;
\r
39 } catch (const std::exception &e) {
\r
40 std::cerr << e.what() << std::endl;
\r
43 std::cout << std::endl;
\r
46 int main(int argc, char *argv[])
\r
50 SIrrlichtCreationParameters p;
\r
51 p.DriverType = chooseDriver(argc > 1 ? argv[1] : "");
\r
52 p.WindowSize = core::dimension2du(640, 480);
\r
54 p.LoggingLevel = ELL_DEBUG;
\r
56 device = createDeviceEx(p);
\r
62 device->getOSOperator()->getSystemMemory(&total, nullptr);
\r
63 core::stringc message = core::stringc("Total RAM in MiB: ") + core::stringc(total >> 10);
\r
64 device->getLogger()->log(message.c_str(), ELL_INFORMATION);
\r
65 check(total > 130 * 1024, "RAM amount");
\r
68 device->setWindowCaption(L"Hello World!");
\r
69 device->setResizable(true);
\r
71 video::IVideoDriver* driver = device->getVideoDriver();
\r
72 scene::ISceneManager* smgr = device->getSceneManager();
\r
73 gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
\r
75 guienv->addStaticText(L"sample text", core::rect<s32>(10,10,110,22), false);
\r
77 gui::IGUIButton* button = guienv->addButton(
\r
78 core::rect<s32>(10,30,110,30 + 32), 0, -1, L"sample button",
\r
81 gui::IGUIEditBox* editbox = guienv->addEditBox(L"",
\r
82 core::rect<s32>(10,70,60,70 + 16));
\r
84 const io::path mediaPath = getExampleMediaPath();
\r
86 scene::IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "coolguy_opt.x");
\r
87 check(mesh, "mesh loading");
\r
90 video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png");
\r
91 check(tex, "texture loading");
\r
92 scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
\r
95 node->setMaterialFlag(video::EMF_LIGHTING, false);
\r
96 node->setFrameLoop(0, 29);
\r
97 node->setAnimationSpeed(30);
\r
98 node->setMaterialTexture(0, tex);
\r
102 smgr->addCameraSceneNode(0, core::vector3df(0,4,5), core::vector3df(0,2,0));
\r
106 device->getTimer()->start();
\r
108 while (device->run())
\r
110 if (device->getTimer()->getTime() >= 1000)
\r
112 device->getTimer()->setTime(0);
\r
114 if (n == 1) // Tooltip display
\r
116 bzero(&event, sizeof(SEvent));
\r
117 event.EventType = irr::EET_MOUSE_INPUT_EVENT;
\r
118 event.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
\r
119 event.MouseInput.X = button->getAbsolutePosition().getCenter().X;
\r
120 event.MouseInput.Y = button->getAbsolutePosition().getCenter().Y;
\r
121 device->postEventFromUser(event);
\r
123 else if (n == 2) // Text input focus
\r
124 guienv->setFocus(editbox);
\r
125 else if (n == 3) // Keypress for Text input
\r
127 bzero(&event, sizeof(SEvent));
\r
128 event.EventType = irr::EET_KEY_INPUT_EVENT;
\r
129 event.KeyInput.Char = L'a';
\r
130 event.KeyInput.Key = KEY_KEY_A;
\r
131 event.KeyInput.PressedDown = true;
\r
132 device->postEventFromUser(event);
\r
133 event.KeyInput.PressedDown = false;
\r
134 device->postEventFromUser(event);
\r
137 device->closeDevice();
\r
140 driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH,
\r
141 video::SColor(255,100,100,150));
\r
144 driver->endScene();
\r
147 check(core::stringw(L"a") == editbox->getText(), "EditBox text");
\r
149 device->getLogger()->log("Done.", ELL_INFORMATION);
\r
151 return test_fail > 0 ? 1 : 0;
\r