*/
#include "drawscene.h"
-#include "main.h" // for g_settings
#include "settings.h"
#include "clouds.h"
#include "clientmap.h"
#include "util/timetaker.h"
#include "fontengine.h"
#include "guiscalingfilter.h"
+#include "filesys.h"
typedef enum {
LEFT = -1,
EYECOUNT = 2
} paralax_sign;
-
-void draw_selectionbox(video::IVideoDriver* driver, Hud& hud,
- std::vector<aabb3f>& hilightboxes, bool show_hud)
-{
- static const s16 selectionbox_width = rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
-
- if (!show_hud)
- return;
-
- video::SMaterial oldmaterial = driver->getMaterial2D();
- video::SMaterial m;
- m.Thickness = selectionbox_width;
- m.Lighting = false;
- driver->setMaterial(m);
- hud.drawSelectionBoxes(hilightboxes);
- driver->setMaterial(oldmaterial);
-}
-
void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
- std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
- scene::ISceneManager* smgr, bool draw_wield_tool, Client& client,
+ video::IVideoDriver* driver, scene::ISceneManager* smgr,
+ bool draw_wield_tool, Client& client,
gui::IGUIEnvironment* guienv )
{
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&leftMove);
}
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&rightMove);
}
irr::video::ECF_A8R8G8B8);
}
-video::ITexture* draw_image(const v2u32& screensize,
- paralax_sign psign, const irr::core::matrix4& startMatrix,
- const irr::core::vector3df& focusPoint, bool show_hud,
- video::IVideoDriver* driver, Camera& camera, scene::ISceneManager* smgr,
- Hud& hud, std::vector<aabb3f>& hilightboxes,
- bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
- video::SColor skycolor )
+video::ITexture* draw_image(const v2u32 &screensize,
+ paralax_sign psign, const irr::core::matrix4 &startMatrix,
+ const irr::core::vector3df &focusPoint, bool show_hud,
+ video::IVideoDriver *driver, Camera &camera, scene::ISceneManager *smgr,
+ Hud &hud, bool draw_wield_tool, Client &client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
{
static video::ITexture* images[2] = { NULL, NULL };
- static v2u32 last_screensize = v2u32(0,0);
+ static v2u32 last_screensize = v2u32(0, 0);
video::ITexture* image = NULL;
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&movement);
}
hud.drawCrosshair();
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
-
+ camera.drawNametags();
guienv->drawAll();
}
}
void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
- Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+ Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
/* create left view */
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
- focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+ focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
//Right eye...
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if(draw_wield_tool)
camera.drawWieldedTool(&rightMove);
}
}
void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
- Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+ Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
/* create left view */
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
- focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+ focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create right view */
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
- focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+ focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create hud overlay */
}
void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
- Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+ Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
/* create left view */
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
- focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+ focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create right view */
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
- focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+ focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create hud overlay */
camera.getCameraNode()->setTarget(oldTarget);
}
-void draw_plain(Camera& camera, bool show_hud, Hud& hud,
- std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
- bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv)
+void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
+ Hud& hud, video::IVideoDriver* driver,
+ scene::ISceneManager* smgr, const v2u32& screensize,
+ bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
+ video::SColor skycolor)
{
+#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
+ errorstream << "Pageflip 3D mode is not supported"
+ << " with your Irrlicht version!" << std::endl;
+#else
+ /* preserve old setup*/
+ irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
+
+ irr::core::matrix4 startMatrix =
+ camera.getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
+ - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ + camera.getCameraNode()->getAbsolutePosition();
+
+ //Left eye...
+ driver->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
+
+ irr::core::vector3df leftEye;
+ irr::core::matrix4 leftMove;
+ leftMove.setTranslation(
+ irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
+ 0.0f, 0.0f));
+ leftEye = (startMatrix * leftMove).getTranslation();
+
+ //clear the depth buffer, and color
+ driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+ camera.getCameraNode()->setPosition(leftEye);
+ camera.getCameraNode()->setTarget(focusPoint);
+ smgr->drawAll();
+ driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+ if (show_hud) {
+ hud.drawSelectionMesh();
+ if (draw_wield_tool)
+ camera.drawWieldedTool(&leftMove);
+ hud.drawHotbar(client.getPlayerItem());
+ hud.drawLuaElements(camera.getOffset());
+ camera.drawNametags();
+ }
+
+ guienv->drawAll();
+
+ //Right eye...
+ driver->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
+
+ irr::core::vector3df rightEye;
+ irr::core::matrix4 rightMove;
+ rightMove.setTranslation(
+ irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
+ 0.0f, 0.0f));
+ rightEye = (startMatrix * rightMove).getTranslation();
+
+ //clear the depth buffer, and color
+ driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+ camera.getCameraNode()->setPosition(rightEye);
+ camera.getCameraNode()->setTarget(focusPoint);
+ smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
+ if (show_hud) {
+ hud.drawSelectionMesh();
+ if (draw_wield_tool)
+ camera.drawWieldedTool(&rightMove);
+ hud.drawHotbar(client.getPlayerItem());
+ hud.drawLuaElements(camera.getOffset());
+ camera.drawNametags();
+ }
- if(draw_wield_tool)
- camera.drawWieldedTool();
+ guienv->drawAll();
+
+ camera.getCameraNode()->setPosition(oldPosition);
+ camera.getCameraNode()->setTarget(oldTarget);
+#endif
}
-void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
- Camera& camera, Client& client, LocalPlayer* player, Hud& hud,
- gui::IGUIEnvironment* guienv, std::vector<aabb3f> hilightboxes,
- const v2u32& screensize, video::SColor skycolor, bool show_hud)
+// returns (size / coef), rounded upwards
+inline int scaledown(int coef, int size)
+{
+ return (size + coef - 1) / coef;
+}
+
+void draw_plain(Camera &camera, bool show_hud,
+ Hud &hud, video::IVideoDriver *driver,
+ scene::ISceneManager *smgr, const v2u32 &screensize,
+ bool draw_wield_tool, Client &client, gui::IGUIEnvironment *guienv,
+ video::SColor skycolor)
+{
+ // Undersampling-specific stuff
+ static video::ITexture *image = NULL;
+ static v2u32 last_pixelated_size = v2u32(0, 0);
+ int undersampling = g_settings->getU16("undersampling");
+ v2u32 pixelated_size;
+ v2u32 dest_size;
+ if (undersampling > 0) {
+ pixelated_size = v2u32(scaledown(undersampling, screensize.X),
+ scaledown(undersampling, screensize.Y));
+ dest_size = v2u32(undersampling * pixelated_size.X, undersampling * pixelated_size.Y);
+ if (pixelated_size != last_pixelated_size) {
+ init_texture(driver, pixelated_size, &image, "mt_drawimage_img1");
+ last_pixelated_size = pixelated_size;
+ }
+ driver->setRenderTarget(image, true, true, skycolor);
+ }
+
+ // Render
+ smgr->drawAll();
+ driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+ if (show_hud) {
+ hud.drawSelectionMesh();
+ if (draw_wield_tool) {
+ camera.drawWieldedTool();
+ }
+ }
+
+ // Upscale lowres render
+ if (undersampling > 0) {
+ driver->setRenderTarget(0, true, true);
+ driver->draw2DImage(image,
+ irr::core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
+ irr::core::rect<s32>(0, 0, pixelated_size.X, pixelated_size.Y));
+ }
+}
+
+void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
+ Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
+ Minimap &mapper, gui::IGUIEnvironment *guienv,
+ const v2u32 &screensize, const video::SColor &skycolor,
+ bool show_hud, bool show_minimap)
{
TimeTaker timer("smgr");
catch(SettingNotFoundException) {}
#endif
- std::string draw_mode = g_settings->get("3d_mode");
-
- smgr->drawAll();
+ const std::string &draw_mode = g_settings->get("3d_mode");
if (draw_mode == "anaglyph")
{
- draw_anaglyph_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+ draw_anaglyph_3d_mode(camera, show_hud, hud, driver,
smgr, draw_wield_tool, client, guienv);
draw_crosshair = false;
}
else if (draw_mode == "interlaced")
{
- draw_interlaced_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+ draw_interlaced_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
draw_crosshair = false;
}
else if (draw_mode == "sidebyside")
{
- draw_sidebyside_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+ draw_sidebyside_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
show_hud = false;
}
else if (draw_mode == "topbottom")
{
- draw_top_bottom_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+ draw_top_bottom_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
show_hud = false;
}
+ else if (draw_mode == "pageflip")
+ {
+ draw_pageflip_3d_mode(camera, show_hud, hud, driver,
+ smgr, screensize, draw_wield_tool, client, guienv, skycolor);
+ draw_crosshair = false;
+ show_hud = false;
+ }
else {
- draw_plain(camera, show_hud, hud, hilightboxes, driver,
- draw_wield_tool, client, guienv);
+ draw_plain(camera, show_hud, hud, driver,
+ smgr, screensize, draw_wield_tool, client, guienv, skycolor);
}
/*
{
if (draw_crosshair)
hud.drawCrosshair();
+
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
+ camera.drawNametags();
+
+ if (show_minimap)
+ mapper.drawMinimap();
}
guienv->drawAll();
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
- gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds )
+ gui::IGUIEnvironment* guienv, ITextureSource *tsrc,
+ float dtime, int percent, bool clouds)
{
video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = porting::getWindowSize();
driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
// draw progress bar
- if ((percent >= 0) && (percent <= 100))
- {
- v2s32 barsize(
- // 342 is (approximately) 256/0.75 to keep bar on same size as
- // before with default settings
- 342 * porting::getDisplayDensity() *
- g_settings->getFloat("gui_scaling"),
- g_fontengine->getTextHeight() * 2);
-
- core::rect<s32> barrect(center - barsize / 2, center + barsize / 2);
- driver->draw2DRectangle(video::SColor(255, 255, 255, 255),barrect, NULL); // border
- driver->draw2DRectangle(video::SColor(255, 64, 64, 64), core::rect<s32> (
- barrect.UpperLeftCorner + 1,
- barrect.LowerRightCorner-1), NULL); // black inside the bar
- driver->draw2DRectangle(video::SColor(255, 128, 128, 128), core::rect<s32> (
- barrect.UpperLeftCorner + 1,
- core::vector2d<s32>(
- barrect.LowerRightCorner.X -
- (barsize.X - 1) + percent * (barsize.X - 2) / 100,
- barrect.LowerRightCorner.Y - 1)), NULL); // the actual progress
+ if ((percent >= 0) && (percent <= 100)) {
+ video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
+ video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png");
+
+ if (progress_img && progress_img_bg) {
+#ifndef __ANDROID__
+ const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
+ u32 imgW = rangelim(img_size.Width, 200, 600);
+ u32 imgH = rangelim(img_size.Height, 24, 72);
+#else
+ const core::dimension2d<u32> img_size(256, 48);
+ float imgRatio = (float) img_size.Height / img_size.Width;
+ u32 imgW = screensize.X / 2.2f;
+ u32 imgH = floor(imgW * imgRatio);
+#endif
+ v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
+
+ draw2DImageFilterScaled(
+ driver, progress_img_bg,
+ core::rect<s32>(img_pos.X,
+ img_pos.Y,
+ img_pos.X + imgW,
+ img_pos.Y + imgH),
+ core::rect<s32>(0, 0,
+ img_size.Width,
+ img_size.Height),
+ 0, 0, true);
+
+ draw2DImageFilterScaled(
+ driver, progress_img,
+ core::rect<s32>(img_pos.X,
+ img_pos.Y,
+ img_pos.X + (percent * imgW) / 100,
+ img_pos.Y + imgH),
+ core::rect<s32>(0, 0,
+ (percent * img_size.Width) / 100,
+ img_size.Height),
+ 0, 0, true);
+ }
}
+
guienv->drawAll();
driver->endScene();
-
guitext->remove();
//return guitext;