drawscene.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "drawscene.h"
  17. #include "main.h" // for g_settings
  18. #include "settings.h"
  19. #include "clouds.h"
  20. #include "clientmap.h"
  21. #include "util/timetaker.h"
  22. typedef enum {
  23. LEFT = -1,
  24. RIGHT = 1,
  25. EYECOUNT = 2
  26. } paralax_sign;
  27. void draw_selectionbox(video::IVideoDriver* driver, Hud& hud,
  28. std::vector<aabb3f>& hilightboxes, bool show_hud)
  29. {
  30. static const s16 selectionbox_width = rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
  31. if (!show_hud)
  32. return;
  33. video::SMaterial oldmaterial = driver->getMaterial2D();
  34. video::SMaterial m;
  35. m.Thickness = selectionbox_width;
  36. m.Lighting = false;
  37. driver->setMaterial(m);
  38. hud.drawSelectionBoxes(hilightboxes);
  39. driver->setMaterial(oldmaterial);
  40. }
  41. void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
  42. std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
  43. scene::ISceneManager* smgr, bool draw_wield_tool, Client& client,
  44. gui::IGUIEnvironment* guienv )
  45. {
  46. /* preserve old setup*/
  47. irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
  48. irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
  49. irr::core::matrix4 startMatrix =
  50. camera.getCameraNode()->getAbsoluteTransformation();
  51. irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
  52. - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
  53. + camera.getCameraNode()->getAbsolutePosition();
  54. //Left eye...
  55. irr::core::vector3df leftEye;
  56. irr::core::matrix4 leftMove;
  57. leftMove.setTranslation(
  58. irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
  59. 0.0f, 0.0f));
  60. leftEye = (startMatrix * leftMove).getTranslation();
  61. //clear the depth buffer, and color
  62. driver->beginScene( true, true, irr::video::SColor(0, 200, 200, 255));
  63. driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
  64. driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
  65. driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
  66. + irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
  67. + irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
  68. camera.getCameraNode()->setPosition(leftEye);
  69. camera.getCameraNode()->setTarget(focusPoint);
  70. smgr->drawAll();
  71. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  72. if (show_hud)
  73. {
  74. draw_selectionbox(driver, hud, hilightboxes, show_hud);
  75. if (draw_wield_tool)
  76. camera.drawWieldedTool(&leftMove);
  77. }
  78. guienv->drawAll();
  79. //Right eye...
  80. irr::core::vector3df rightEye;
  81. irr::core::matrix4 rightMove;
  82. rightMove.setTranslation(
  83. irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
  84. 0.0f, 0.0f));
  85. rightEye = (startMatrix * rightMove).getTranslation();
  86. //clear the depth buffer
  87. driver->clearZBuffer();
  88. driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_GREEN
  89. + irr::video::ECP_BLUE;
  90. driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
  91. driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
  92. + irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
  93. + irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
  94. camera.getCameraNode()->setPosition(rightEye);
  95. camera.getCameraNode()->setTarget(focusPoint);
  96. smgr->drawAll();
  97. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  98. if (show_hud)
  99. {
  100. draw_selectionbox(driver, hud, hilightboxes, show_hud);
  101. if (draw_wield_tool)
  102. camera.drawWieldedTool(&rightMove);
  103. }
  104. guienv->drawAll();
  105. driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
  106. driver->getOverrideMaterial().EnableFlags = 0;
  107. driver->getOverrideMaterial().EnablePasses = 0;
  108. camera.getCameraNode()->setPosition(oldPosition);
  109. camera.getCameraNode()->setTarget(oldTarget);
  110. }
  111. void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
  112. video::ITexture** texture)
  113. {
  114. if (*texture != NULL)
  115. {
  116. driver->removeTexture(*texture);
  117. }
  118. *texture = driver->addRenderTargetTexture(
  119. core::dimension2d<u32>(screensize.X, screensize.Y));
  120. }
  121. video::ITexture* draw_image(const v2u32& screensize,
  122. paralax_sign psign, const irr::core::matrix4& startMatrix,
  123. const irr::core::vector3df& focusPoint, bool show_hud,
  124. video::IVideoDriver* driver, Camera& camera, scene::ISceneManager* smgr,
  125. Hud& hud, std::vector<aabb3f>& hilightboxes,
  126. bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
  127. video::SColor skycolor )
  128. {
  129. static video::ITexture* images[2] = { NULL, NULL };
  130. static v2u32 last_screensize = v2u32(0,0);
  131. video::ITexture* image = NULL;
  132. if (screensize != last_screensize) {
  133. init_texture(driver, screensize, &images[1]);
  134. image = images[1];
  135. init_texture(driver, screensize, &images[0]);
  136. image = images[0];
  137. last_screensize = screensize;
  138. }
  139. driver->setRenderTarget(image, true, true,
  140. irr::video::SColor(255,
  141. skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
  142. irr::core::vector3df eye_pos;
  143. irr::core::matrix4 movement;
  144. movement.setTranslation(
  145. irr::core::vector3df((int) psign *
  146. g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
  147. eye_pos = (startMatrix * movement).getTranslation();
  148. //clear the depth buffer
  149. driver->clearZBuffer();
  150. camera.getCameraNode()->setPosition(eye_pos);
  151. camera.getCameraNode()->setTarget(focusPoint);
  152. smgr->drawAll();
  153. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  154. if (show_hud)
  155. {
  156. draw_selectionbox(driver, hud, hilightboxes, show_hud);
  157. if (draw_wield_tool)
  158. camera.drawWieldedTool(&movement);
  159. }
  160. guienv->drawAll();
  161. /* switch back to real renderer */
  162. driver->setRenderTarget(0, true, true,
  163. irr::video::SColor(0,
  164. skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
  165. return image;
  166. }
  167. video::ITexture* draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
  168. bool show_hud, Hud& hud, Client& client, bool draw_crosshair,
  169. video::SColor skycolor, gui::IGUIEnvironment* guienv, Camera& camera )
  170. {
  171. static video::ITexture* image = NULL;
  172. init_texture(driver, screensize, &image);
  173. driver->setRenderTarget(image, true, true,
  174. irr::video::SColor(255,0,0,0));
  175. if (show_hud)
  176. {
  177. if (draw_crosshair)
  178. hud.drawCrosshair();
  179. hud.drawHotbar(client.getPlayerItem());
  180. hud.drawLuaElements(camera.getOffset());
  181. guienv->drawAll();
  182. }
  183. driver->setRenderTarget(0, true, true,
  184. irr::video::SColor(0,
  185. skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
  186. return image;
  187. }
  188. void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
  189. Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
  190. scene::ISceneManager* smgr, const v2u32& screensize,
  191. bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
  192. video::SColor skycolor )
  193. {
  194. /* save current info */
  195. irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
  196. irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
  197. irr::core::matrix4 startMatrix =
  198. camera.getCameraNode()->getAbsoluteTransformation();
  199. irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
  200. - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
  201. + camera.getCameraNode()->getAbsolutePosition();
  202. /* create left view */
  203. video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
  204. focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
  205. draw_wield_tool, client, guienv, skycolor);
  206. //Right eye...
  207. irr::core::vector3df rightEye;
  208. irr::core::matrix4 rightMove;
  209. rightMove.setTranslation(
  210. irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
  211. 0.0f, 0.0f));
  212. rightEye = (startMatrix * rightMove).getTranslation();
  213. //clear the depth buffer
  214. driver->clearZBuffer();
  215. camera.getCameraNode()->setPosition(rightEye);
  216. camera.getCameraNode()->setTarget(focusPoint);
  217. smgr->drawAll();
  218. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  219. if (show_hud)
  220. {
  221. draw_selectionbox(driver, hud, hilightboxes, show_hud);
  222. if(draw_wield_tool)
  223. camera.drawWieldedTool(&rightMove);
  224. }
  225. guienv->drawAll();
  226. for (unsigned int i = 0; i < screensize.Y; i+=2 ) {
  227. #if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
  228. driver->draw2DImage(left_image, irr::core::position2d<s32>(0, i),
  229. #else
  230. driver->draw2DImage(left_image, irr::core::position2d<s32>(0, screensize.Y-i),
  231. #endif
  232. irr::core::rect<s32>(0, i,screensize.X, i+1), 0,
  233. irr::video::SColor(255, 255, 255, 255),
  234. false);
  235. }
  236. /* cleanup */
  237. camera.getCameraNode()->setPosition(oldPosition);
  238. camera.getCameraNode()->setTarget(oldTarget);
  239. }
  240. void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
  241. Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
  242. scene::ISceneManager* smgr, const v2u32& screensize,
  243. bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
  244. video::SColor skycolor )
  245. {
  246. /* save current info */
  247. irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
  248. irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
  249. irr::core::matrix4 startMatrix =
  250. camera.getCameraNode()->getAbsoluteTransformation();
  251. irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
  252. - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
  253. + camera.getCameraNode()->getAbsolutePosition();
  254. /* create left view */
  255. video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
  256. focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
  257. draw_wield_tool, client, guienv, skycolor);
  258. /* create right view */
  259. video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
  260. focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
  261. draw_wield_tool, client, guienv, skycolor);
  262. /* create hud overlay */
  263. video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
  264. false, skycolor, guienv, camera );
  265. driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
  266. //makeColorKeyTexture mirrors texture so we do it twice to get it right again
  267. driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
  268. driver->draw2DImage(left_image,
  269. irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
  270. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
  271. driver->draw2DImage(hudtexture,
  272. irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
  273. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
  274. driver->draw2DImage(right_image,
  275. irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
  276. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
  277. driver->draw2DImage(hudtexture,
  278. irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
  279. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
  280. left_image = NULL;
  281. right_image = NULL;
  282. /* cleanup */
  283. camera.getCameraNode()->setPosition(oldPosition);
  284. camera.getCameraNode()->setTarget(oldTarget);
  285. }
  286. void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
  287. Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
  288. scene::ISceneManager* smgr, const v2u32& screensize,
  289. bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
  290. video::SColor skycolor )
  291. {
  292. /* save current info */
  293. irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
  294. irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
  295. irr::core::matrix4 startMatrix =
  296. camera.getCameraNode()->getAbsoluteTransformation();
  297. irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
  298. - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
  299. + camera.getCameraNode()->getAbsolutePosition();
  300. /* create left view */
  301. video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
  302. focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
  303. draw_wield_tool, client, guienv, skycolor);
  304. /* create right view */
  305. video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
  306. focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
  307. draw_wield_tool, client, guienv, skycolor);
  308. /* create hud overlay */
  309. video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
  310. false, skycolor, guienv, camera );
  311. driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
  312. //makeColorKeyTexture mirrors texture so we do it twice to get it right again
  313. driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
  314. driver->draw2DImage(left_image,
  315. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
  316. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
  317. driver->draw2DImage(hudtexture,
  318. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
  319. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
  320. driver->draw2DImage(right_image,
  321. irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
  322. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
  323. driver->draw2DImage(hudtexture,
  324. irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
  325. irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
  326. left_image = NULL;
  327. right_image = NULL;
  328. /* cleanup */
  329. camera.getCameraNode()->setPosition(oldPosition);
  330. camera.getCameraNode()->setTarget(oldTarget);
  331. }
  332. void draw_plain(Camera& camera, bool show_hud, Hud& hud,
  333. std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
  334. bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv)
  335. {
  336. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  337. draw_selectionbox(driver, hud, hilightboxes, show_hud);
  338. if(draw_wield_tool)
  339. camera.drawWieldedTool();
  340. }
  341. void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
  342. Camera& camera, Client& client, LocalPlayer* player, Hud& hud,
  343. gui::IGUIEnvironment* guienv, std::vector<aabb3f> hilightboxes,
  344. const v2u32& screensize, video::SColor skycolor, bool show_hud)
  345. {
  346. //TODO check if usefull
  347. u32 scenetime = 0;
  348. {
  349. TimeTaker timer("smgr");
  350. bool draw_wield_tool = (show_hud &&
  351. (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
  352. camera.getCameraMode() < CAMERA_MODE_THIRD );
  353. bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
  354. (camera.getCameraMode() != CAMERA_MODE_THIRD_FRONT));
  355. #ifdef HAVE_TOUCHSCREENGUI
  356. try {
  357. draw_crosshair = !g_settings->getBool("touchtarget");
  358. }
  359. catch(SettingNotFoundException) {}
  360. #endif
  361. std::string draw_mode = g_settings->get("3d_mode");
  362. smgr->drawAll();
  363. if (draw_mode == "anaglyph")
  364. {
  365. draw_anaglyph_3d_mode(camera, show_hud, hud, hilightboxes, driver,
  366. smgr, draw_wield_tool, client, guienv);
  367. draw_crosshair = false;
  368. }
  369. else if (draw_mode == "interlaced")
  370. {
  371. draw_interlaced_3d_mode(camera, show_hud, hud, hilightboxes, driver,
  372. smgr, screensize, draw_wield_tool, client, guienv, skycolor);
  373. draw_crosshair = false;
  374. }
  375. else if (draw_mode == "sidebyside")
  376. {
  377. draw_sidebyside_3d_mode(camera, show_hud, hud, hilightboxes, driver,
  378. smgr, screensize, draw_wield_tool, client, guienv, skycolor);
  379. show_hud = false;
  380. }
  381. else if (draw_mode == "topbottom")
  382. {
  383. draw_top_bottom_3d_mode(camera, show_hud, hud, hilightboxes, driver,
  384. smgr, screensize, draw_wield_tool, client, guienv, skycolor);
  385. show_hud = false;
  386. }
  387. else {
  388. draw_plain(camera, show_hud, hud, hilightboxes, driver,
  389. draw_wield_tool, client, guienv);
  390. }
  391. /*
  392. Post effects
  393. */
  394. {
  395. client.getEnv().getClientMap().renderPostFx(camera.getCameraMode());
  396. }
  397. //TODO how to make those 3d too
  398. if (show_hud)
  399. {
  400. if (draw_crosshair)
  401. hud.drawCrosshair();
  402. hud.drawHotbar(client.getPlayerItem());
  403. hud.drawLuaElements(camera.getOffset());
  404. }
  405. guienv->drawAll();
  406. scenetime = timer.stop(true);
  407. }
  408. }
  409. /*
  410. Draws a screen with a single text on it.
  411. Text will be removed when the screen is drawn the next time.
  412. Additionally, a progressbar can be drawn when percent is set between 0 and 100.
  413. */
  414. /*gui::IGUIStaticText **/
  415. void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
  416. gui::IGUIEnvironment* guienv, gui::IGUIFont* font, float dtime,
  417. int percent, bool clouds )
  418. {
  419. video::IVideoDriver* driver = device->getVideoDriver();
  420. v2u32 screensize = driver->getScreenSize();
  421. const wchar_t *loadingtext = text.c_str();
  422. core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
  423. core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
  424. core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
  425. core::rect<s32> textrect(center - textsize/2, center + textsize/2);
  426. gui::IGUIStaticText *guitext = guienv->addStaticText(
  427. loadingtext, textrect, false, false);
  428. guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
  429. bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
  430. if (cloud_menu_background)
  431. {
  432. g_menuclouds->step(dtime*3);
  433. g_menuclouds->render();
  434. driver->beginScene(true, true, video::SColor(255,140,186,250));
  435. g_menucloudsmgr->drawAll();
  436. }
  437. else
  438. driver->beginScene(true, true, video::SColor(255,0,0,0));
  439. if (percent >= 0 && percent <= 100) // draw progress bar
  440. {
  441. core::vector2d<s32> barsize(256,32);
  442. core::rect<s32> barrect(center-barsize/2, center+barsize/2);
  443. driver->draw2DRectangle(video::SColor(255,255,255,255),barrect, NULL); // border
  444. driver->draw2DRectangle(video::SColor(255,64,64,64), core::rect<s32> (
  445. barrect.UpperLeftCorner+1,
  446. barrect.LowerRightCorner-1), NULL); // black inside the bar
  447. driver->draw2DRectangle(video::SColor(255,128,128,128), core::rect<s32> (
  448. barrect.UpperLeftCorner+1,
  449. core::vector2d<s32>(
  450. barrect.LowerRightCorner.X-(barsize.X-1)+percent*(barsize.X-2)/100,
  451. barrect.LowerRightCorner.Y-1)), NULL); // the actual progress
  452. }
  453. guienv->drawAll();
  454. driver->endScene();
  455. guitext->remove();
  456. //return guitext;
  457. }