2014-04-27 16:09:21 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drawscene.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "clouds.h"
|
2014-06-12 23:38:34 +02:00
|
|
|
#include "clientmap.h"
|
2014-04-27 16:09:21 +02:00
|
|
|
#include "util/timetaker.h"
|
2014-11-23 13:40:43 +01:00
|
|
|
#include "fontengine.h"
|
2015-03-09 14:32:11 +01:00
|
|
|
#include "guiscalingfilter.h"
|
2017-03-10 13:26:24 +01:00
|
|
|
#include "filesys.h"
|
2014-04-27 16:09:21 +02:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LEFT = -1,
|
|
|
|
RIGHT = 1,
|
|
|
|
EYECOUNT = 2
|
|
|
|
} paralax_sign;
|
|
|
|
|
|
|
|
void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
|
2016-02-07 04:08:43 +01:00
|
|
|
video::IVideoDriver* driver, scene::ISceneManager* smgr,
|
|
|
|
bool draw_wield_tool, Client& client,
|
2014-04-27 16:09:21 +02:00
|
|
|
gui::IGUIEnvironment* guienv )
|
|
|
|
{
|
|
|
|
|
|
|
|
/* 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...
|
|
|
|
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(0, 200, 200, 255));
|
|
|
|
driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
|
|
|
|
driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
|
|
|
|
driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
|
|
|
|
+ irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
|
|
|
|
+ irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
|
|
|
|
camera.getCameraNode()->setPosition(leftEye);
|
|
|
|
camera.getCameraNode()->setTarget(focusPoint);
|
|
|
|
smgr->drawAll();
|
|
|
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
2016-02-07 04:08:43 +01:00
|
|
|
if (show_hud) {
|
|
|
|
hud.drawSelectionMesh();
|
2014-04-27 16:09:21 +02:00
|
|
|
if (draw_wield_tool)
|
|
|
|
camera.drawWieldedTool(&leftMove);
|
|
|
|
}
|
|
|
|
|
|
|
|
guienv->drawAll();
|
|
|
|
|
|
|
|
//Right eye...
|
|
|
|
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
|
|
|
|
driver->clearZBuffer();
|
|
|
|
driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_GREEN
|
|
|
|
+ irr::video::ECP_BLUE;
|
|
|
|
driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
|
|
|
|
driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
|
|
|
|
+ irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
|
|
|
|
+ irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
|
|
|
|
camera.getCameraNode()->setPosition(rightEye);
|
|
|
|
camera.getCameraNode()->setTarget(focusPoint);
|
|
|
|
smgr->drawAll();
|
|
|
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
2016-02-07 04:08:43 +01:00
|
|
|
if (show_hud) {
|
|
|
|
hud.drawSelectionMesh();
|
2014-04-27 16:09:21 +02:00
|
|
|
if (draw_wield_tool)
|
|
|
|
camera.drawWieldedTool(&rightMove);
|
|
|
|
}
|
|
|
|
|
|
|
|
guienv->drawAll();
|
|
|
|
|
|
|
|
driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
|
|
|
|
driver->getOverrideMaterial().EnableFlags = 0;
|
|
|
|
driver->getOverrideMaterial().EnablePasses = 0;
|
|
|
|
camera.getCameraNode()->setPosition(oldPosition);
|
|
|
|
camera.getCameraNode()->setTarget(oldTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
|
2014-09-25 20:33:17 +02:00
|
|
|
video::ITexture** texture, const char* name)
|
2014-04-27 16:09:21 +02:00
|
|
|
{
|
2014-08-29 01:35:35 +02:00
|
|
|
if (*texture != NULL)
|
2014-04-27 16:09:21 +02:00
|
|
|
{
|
2014-08-29 01:35:35 +02:00
|
|
|
driver->removeTexture(*texture);
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
2014-08-29 01:35:35 +02:00
|
|
|
*texture = driver->addRenderTargetTexture(
|
2014-09-25 20:33:17 +02:00
|
|
|
core::dimension2d<u32>(screensize.X, screensize.Y), name,
|
|
|
|
irr::video::ECF_A8R8G8B8);
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
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)
|
2014-04-27 16:09:21 +02:00
|
|
|
{
|
|
|
|
static video::ITexture* images[2] = { NULL, NULL };
|
2016-02-07 04:08:43 +01:00
|
|
|
static v2u32 last_screensize = v2u32(0, 0);
|
2014-04-27 16:09:21 +02:00
|
|
|
|
|
|
|
video::ITexture* image = NULL;
|
|
|
|
|
2014-08-29 01:35:35 +02:00
|
|
|
if (screensize != last_screensize) {
|
2014-09-25 20:33:17 +02:00
|
|
|
init_texture(driver, screensize, &images[1], "mt_drawimage_img1");
|
|
|
|
init_texture(driver, screensize, &images[0], "mt_drawimage_img2");
|
2014-08-29 01:35:35 +02:00
|
|
|
last_screensize = screensize;
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 20:33:17 +02:00
|
|
|
if (psign == RIGHT)
|
|
|
|
image = images[1];
|
|
|
|
else
|
|
|
|
image = images[0];
|
2015-01-19 05:29:19 +01:00
|
|
|
|
2014-04-27 16:09:21 +02:00
|
|
|
driver->setRenderTarget(image, true, true,
|
|
|
|
irr::video::SColor(255,
|
|
|
|
skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
|
|
|
|
|
|
|
|
irr::core::vector3df eye_pos;
|
|
|
|
irr::core::matrix4 movement;
|
|
|
|
movement.setTranslation(
|
|
|
|
irr::core::vector3df((int) psign *
|
|
|
|
g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
|
|
|
|
eye_pos = (startMatrix * movement).getTranslation();
|
|
|
|
|
|
|
|
//clear the depth buffer
|
|
|
|
driver->clearZBuffer();
|
|
|
|
camera.getCameraNode()->setPosition(eye_pos);
|
|
|
|
camera.getCameraNode()->setTarget(focusPoint);
|
|
|
|
smgr->drawAll();
|
|
|
|
|
|
|
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
if (show_hud) {
|
|
|
|
hud.drawSelectionMesh();
|
2014-04-27 16:09:21 +02:00
|
|
|
if (draw_wield_tool)
|
|
|
|
camera.drawWieldedTool(&movement);
|
|
|
|
}
|
|
|
|
|
|
|
|
guienv->drawAll();
|
|
|
|
|
|
|
|
/* switch back to real renderer */
|
|
|
|
driver->setRenderTarget(0, true, true,
|
|
|
|
irr::video::SColor(0,
|
|
|
|
skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
video::ITexture* draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
|
|
|
|
bool show_hud, Hud& hud, Client& client, bool draw_crosshair,
|
|
|
|
video::SColor skycolor, gui::IGUIEnvironment* guienv, Camera& camera )
|
|
|
|
{
|
|
|
|
static video::ITexture* image = NULL;
|
2014-09-25 20:33:17 +02:00
|
|
|
init_texture(driver, screensize, &image, "mt_drawimage_hud");
|
2014-04-27 16:09:21 +02:00
|
|
|
driver->setRenderTarget(image, true, true,
|
|
|
|
irr::video::SColor(255,0,0,0));
|
|
|
|
|
|
|
|
if (show_hud)
|
|
|
|
{
|
|
|
|
if (draw_crosshair)
|
|
|
|
hud.drawCrosshair();
|
|
|
|
hud.drawHotbar(client.getPlayerItem());
|
|
|
|
hud.drawLuaElements(camera.getOffset());
|
2016-02-15 14:01:01 +01:00
|
|
|
camera.drawNametags();
|
2014-04-27 16:09:21 +02:00
|
|
|
guienv->drawAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
driver->setRenderTarget(0, true, true,
|
|
|
|
irr::video::SColor(0,
|
|
|
|
skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
|
2016-02-07 04:08:43 +01:00
|
|
|
Hud& hud, video::IVideoDriver* driver,
|
2014-04-27 16:09:21 +02:00
|
|
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
|
|
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
|
|
|
video::SColor skycolor )
|
|
|
|
{
|
|
|
|
/* save current info */
|
|
|
|
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();
|
|
|
|
|
|
|
|
/* create left view */
|
|
|
|
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
2016-02-07 04:08:43 +01:00
|
|
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
2014-04-27 16:09:21 +02:00
|
|
|
draw_wield_tool, client, guienv, skycolor);
|
|
|
|
|
|
|
|
//Right eye...
|
|
|
|
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
|
|
|
|
driver->clearZBuffer();
|
|
|
|
camera.getCameraNode()->setPosition(rightEye);
|
|
|
|
camera.getCameraNode()->setTarget(focusPoint);
|
|
|
|
smgr->drawAll();
|
|
|
|
|
|
|
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
if (show_hud) {
|
|
|
|
hud.drawSelectionMesh();
|
2014-04-27 16:09:21 +02:00
|
|
|
if(draw_wield_tool)
|
|
|
|
camera.drawWieldedTool(&rightMove);
|
|
|
|
}
|
|
|
|
guienv->drawAll();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < screensize.Y; i+=2 ) {
|
2014-08-29 00:54:46 +02:00
|
|
|
#if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
|
|
|
|
driver->draw2DImage(left_image, irr::core::position2d<s32>(0, i),
|
|
|
|
#else
|
2014-04-27 16:09:21 +02:00
|
|
|
driver->draw2DImage(left_image, irr::core::position2d<s32>(0, screensize.Y-i),
|
2014-08-29 00:54:46 +02:00
|
|
|
#endif
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, i,screensize.X, i+1), 0,
|
|
|
|
irr::video::SColor(255, 255, 255, 255),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
camera.getCameraNode()->setPosition(oldPosition);
|
|
|
|
camera.getCameraNode()->setTarget(oldTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
|
2016-02-07 04:08:43 +01:00
|
|
|
Hud& hud, video::IVideoDriver* driver,
|
2014-04-27 16:09:21 +02:00
|
|
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
|
|
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
|
|
|
video::SColor skycolor )
|
|
|
|
{
|
|
|
|
/* save current info */
|
|
|
|
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();
|
|
|
|
|
|
|
|
/* create left view */
|
|
|
|
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
2016-02-07 04:08:43 +01:00
|
|
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
2014-04-27 16:09:21 +02:00
|
|
|
draw_wield_tool, client, guienv, skycolor);
|
|
|
|
|
|
|
|
/* create right view */
|
|
|
|
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
|
2016-02-07 04:08:43 +01:00
|
|
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
2014-04-27 16:09:21 +02:00
|
|
|
draw_wield_tool, client, guienv, skycolor);
|
|
|
|
|
|
|
|
/* create hud overlay */
|
|
|
|
video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
|
|
|
|
false, skycolor, guienv, camera );
|
|
|
|
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
|
|
|
|
//makeColorKeyTexture mirrors texture so we do it twice to get it right again
|
|
|
|
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, left_image,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, hudtexture,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, right_image,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, hudtexture,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
|
|
|
|
|
|
|
|
left_image = NULL;
|
|
|
|
right_image = NULL;
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
camera.getCameraNode()->setPosition(oldPosition);
|
|
|
|
camera.getCameraNode()->setTarget(oldTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
|
2016-02-07 04:08:43 +01:00
|
|
|
Hud& hud, video::IVideoDriver* driver,
|
2014-04-27 16:09:21 +02:00
|
|
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
|
|
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
|
|
|
video::SColor skycolor )
|
|
|
|
{
|
|
|
|
/* save current info */
|
|
|
|
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();
|
|
|
|
|
|
|
|
/* create left view */
|
|
|
|
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
2016-02-07 04:08:43 +01:00
|
|
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
2014-04-27 16:09:21 +02:00
|
|
|
draw_wield_tool, client, guienv, skycolor);
|
|
|
|
|
|
|
|
/* create right view */
|
|
|
|
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
|
2016-02-07 04:08:43 +01:00
|
|
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
2014-04-27 16:09:21 +02:00
|
|
|
draw_wield_tool, client, guienv, skycolor);
|
|
|
|
|
|
|
|
/* create hud overlay */
|
|
|
|
video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
|
|
|
|
false, skycolor, guienv, camera );
|
|
|
|
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
|
|
|
|
//makeColorKeyTexture mirrors texture so we do it twice to get it right again
|
|
|
|
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, left_image,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, hudtexture,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, right_image,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
|
|
|
|
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, hudtexture,
|
2014-04-27 16:09:21 +02:00
|
|
|
irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
|
|
|
|
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
|
|
|
|
|
|
|
|
left_image = NULL;
|
|
|
|
right_image = NULL;
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
camera.getCameraNode()->setPosition(oldPosition);
|
|
|
|
camera.getCameraNode()->setTarget(oldTarget);
|
|
|
|
}
|
|
|
|
|
2015-12-14 22:01:32 +01:00
|
|
|
void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
|
2016-02-07 04:08:43 +01:00
|
|
|
Hud& hud, video::IVideoDriver* driver,
|
2015-12-14 22:01:32 +01:00
|
|
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
|
|
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
|
|
|
video::SColor skycolor)
|
|
|
|
{
|
2016-12-24 14:26:03 +01:00
|
|
|
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
|
|
|
|
errorstream << "Pageflip 3D mode is not supported"
|
|
|
|
<< " with your Irrlicht version!" << std::endl;
|
|
|
|
#else
|
2015-12-14 22:01:32 +01:00
|
|
|
/* 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) {
|
2016-02-07 04:08:43 +01:00
|
|
|
hud.drawSelectionMesh();
|
2015-12-14 22:01:32 +01:00
|
|
|
if (draw_wield_tool)
|
|
|
|
camera.drawWieldedTool(&leftMove);
|
|
|
|
hud.drawHotbar(client.getPlayerItem());
|
|
|
|
hud.drawLuaElements(camera.getOffset());
|
2016-02-15 14:01:01 +01:00
|
|
|
camera.drawNametags();
|
2015-12-14 22:01:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (show_hud) {
|
2016-02-07 04:08:43 +01:00
|
|
|
hud.drawSelectionMesh();
|
2015-12-14 22:01:32 +01:00
|
|
|
if (draw_wield_tool)
|
|
|
|
camera.drawWieldedTool(&rightMove);
|
|
|
|
hud.drawHotbar(client.getPlayerItem());
|
|
|
|
hud.drawLuaElements(camera.getOffset());
|
2016-02-15 14:01:01 +01:00
|
|
|
camera.drawNametags();
|
2015-12-14 22:01:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
guienv->drawAll();
|
|
|
|
|
|
|
|
camera.getCameraNode()->setPosition(oldPosition);
|
|
|
|
camera.getCameraNode()->setTarget(oldTarget);
|
2016-12-24 14:26:03 +01:00
|
|
|
#endif
|
2015-12-14 22:01:32 +01:00
|
|
|
}
|
|
|
|
|
2017-01-12 10:19:36 +01:00
|
|
|
// returns (size / coef), rounded upwards
|
|
|
|
inline int scaledown(int coef, int size)
|
2014-04-27 16:09:21 +02:00
|
|
|
{
|
2017-01-12 10:19:36 +01:00
|
|
|
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();
|
2014-05-26 22:11:42 +02:00
|
|
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
2016-02-07 04:08:43 +01:00
|
|
|
if (show_hud) {
|
|
|
|
hud.drawSelectionMesh();
|
|
|
|
if (draw_wield_tool) {
|
|
|
|
camera.drawWieldedTool();
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 10:19:36 +01:00
|
|
|
|
|
|
|
// 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));
|
|
|
|
}
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
2017-01-12 10:19:36 +01:00
|
|
|
Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
|
2017-03-16 10:34:54 +01:00
|
|
|
Minimap &mapper, gui::IGUIEnvironment *guienv,
|
2016-02-07 04:08:43 +01:00
|
|
|
const v2u32 &screensize, const video::SColor &skycolor,
|
|
|
|
bool show_hud, bool show_minimap)
|
2014-04-27 16:09:21 +02:00
|
|
|
{
|
2015-01-19 05:29:19 +01:00
|
|
|
TimeTaker timer("smgr");
|
2014-04-27 16:09:21 +02:00
|
|
|
|
2015-01-19 05:29:19 +01:00
|
|
|
bool draw_wield_tool = (show_hud &&
|
|
|
|
(player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
|
|
|
|
camera.getCameraMode() < CAMERA_MODE_THIRD );
|
2014-04-27 16:09:21 +02:00
|
|
|
|
2015-01-19 05:29:19 +01:00
|
|
|
bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
|
|
|
|
(camera.getCameraMode() != CAMERA_MODE_THIRD_FRONT));
|
2014-04-27 16:09:21 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
2015-01-19 05:29:19 +01:00
|
|
|
try {
|
|
|
|
draw_crosshair = !g_settings->getBool("touchtarget");
|
|
|
|
}
|
|
|
|
catch(SettingNotFoundException) {}
|
2014-04-21 14:10:59 +02:00
|
|
|
#endif
|
|
|
|
|
2017-03-22 21:41:02 +01:00
|
|
|
const std::string &draw_mode = g_settings->get("3d_mode");
|
2014-04-27 16:09:21 +02:00
|
|
|
|
2015-01-19 05:29:19 +01:00
|
|
|
if (draw_mode == "anaglyph")
|
|
|
|
{
|
2016-02-07 04:08:43 +01:00
|
|
|
draw_anaglyph_3d_mode(camera, show_hud, hud, driver,
|
2015-01-19 05:29:19 +01:00
|
|
|
smgr, draw_wield_tool, client, guienv);
|
|
|
|
draw_crosshair = false;
|
|
|
|
}
|
|
|
|
else if (draw_mode == "interlaced")
|
|
|
|
{
|
2016-02-07 04:08:43 +01:00
|
|
|
draw_interlaced_3d_mode(camera, show_hud, hud, driver,
|
2015-01-19 05:29:19 +01:00
|
|
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
|
|
|
draw_crosshair = false;
|
|
|
|
}
|
|
|
|
else if (draw_mode == "sidebyside")
|
|
|
|
{
|
2016-02-07 04:08:43 +01:00
|
|
|
draw_sidebyside_3d_mode(camera, show_hud, hud, driver,
|
2015-01-19 05:29:19 +01:00
|
|
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
|
|
|
show_hud = false;
|
|
|
|
}
|
|
|
|
else if (draw_mode == "topbottom")
|
|
|
|
{
|
2016-02-07 04:08:43 +01:00
|
|
|
draw_top_bottom_3d_mode(camera, show_hud, hud, driver,
|
2015-01-19 05:29:19 +01:00
|
|
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
|
|
|
show_hud = false;
|
|
|
|
}
|
2015-12-14 22:01:32 +01:00
|
|
|
else if (draw_mode == "pageflip")
|
|
|
|
{
|
2016-02-07 04:08:43 +01:00
|
|
|
draw_pageflip_3d_mode(camera, show_hud, hud, driver,
|
2015-12-14 22:01:32 +01:00
|
|
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
|
|
|
draw_crosshair = false;
|
|
|
|
show_hud = false;
|
|
|
|
}
|
2015-01-19 05:29:19 +01:00
|
|
|
else {
|
2016-02-07 04:08:43 +01:00
|
|
|
draw_plain(camera, show_hud, hud, driver,
|
2017-01-12 10:19:36 +01:00
|
|
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
2015-01-19 05:29:19 +01:00
|
|
|
}
|
2014-05-24 12:15:11 +02:00
|
|
|
|
2015-01-19 05:29:19 +01:00
|
|
|
/*
|
|
|
|
Post effects
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
client.getEnv().getClientMap().renderPostFx(camera.getCameraMode());
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
|
|
|
|
2015-01-19 05:29:19 +01:00
|
|
|
//TODO how to make those 3d too
|
|
|
|
if (show_hud)
|
|
|
|
{
|
|
|
|
if (draw_crosshair)
|
|
|
|
hud.drawCrosshair();
|
2016-02-15 14:01:01 +01:00
|
|
|
|
2015-01-19 05:29:19 +01:00
|
|
|
hud.drawHotbar(client.getPlayerItem());
|
|
|
|
hud.drawLuaElements(camera.getOffset());
|
2016-02-15 14:01:01 +01:00
|
|
|
camera.drawNametags();
|
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
if (show_minimap)
|
|
|
|
mapper.drawMinimap();
|
2015-01-19 05:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
guienv->drawAll();
|
|
|
|
|
|
|
|
timer.stop(true);
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Draws a screen with a single text on it.
|
|
|
|
Text will be removed when the screen is drawn the next time.
|
|
|
|
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
|
|
|
|
*/
|
|
|
|
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
|
2014-11-23 13:40:43 +01:00
|
|
|
gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds )
|
2014-04-27 16:09:21 +02:00
|
|
|
{
|
2014-11-23 13:40:43 +01:00
|
|
|
video::IVideoDriver* driver = device->getVideoDriver();
|
|
|
|
v2u32 screensize = porting::getWindowSize();
|
|
|
|
|
2014-11-28 20:06:34 +01:00
|
|
|
v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
|
2014-11-23 13:40:43 +01:00
|
|
|
v2s32 center(screensize.X / 2, screensize.Y / 2);
|
|
|
|
core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
|
2014-04-27 16:09:21 +02:00
|
|
|
|
|
|
|
gui::IGUIStaticText *guitext = guienv->addStaticText(
|
2014-11-23 13:40:43 +01:00
|
|
|
text.c_str(), textrect, false, false);
|
2014-04-27 16:09:21 +02:00
|
|
|
guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
|
|
|
|
|
|
|
|
bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
|
|
|
|
if (cloud_menu_background)
|
|
|
|
{
|
|
|
|
g_menuclouds->step(dtime*3);
|
|
|
|
g_menuclouds->render();
|
2014-11-23 13:40:43 +01:00
|
|
|
driver->beginScene(true, true, video::SColor(255, 140, 186, 250));
|
2014-04-27 16:09:21 +02:00
|
|
|
g_menucloudsmgr->drawAll();
|
|
|
|
}
|
|
|
|
else
|
2014-11-23 13:40:43 +01:00
|
|
|
driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
|
2014-04-27 16:09:21 +02:00
|
|
|
|
2014-11-23 13:40:43 +01:00
|
|
|
// draw progress bar
|
2017-03-10 13:26:24 +01:00
|
|
|
if ((percent >= 0) && (percent <= 100)) {
|
2017-03-13 08:07:14 +01:00
|
|
|
const std::string &texture_path = g_settings->get("texture_path");
|
|
|
|
std::string tp_progress_bar = texture_path + "/progress_bar.png";
|
|
|
|
std::string tp_progress_bar_bg = texture_path + "/progress_bar_bg.png";
|
|
|
|
|
|
|
|
if (!(fs::PathExists(tp_progress_bar) &&
|
|
|
|
fs::PathExists(tp_progress_bar_bg))) {
|
|
|
|
std::string gamepath = fs::RemoveRelativePathComponents(
|
|
|
|
porting::path_share + DIR_DELIM + "textures");
|
|
|
|
tp_progress_bar = gamepath + "/base/pack/progress_bar.png";
|
|
|
|
tp_progress_bar_bg = gamepath + "/base/pack/progress_bar_bg.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
video::ITexture *progress_img =
|
|
|
|
driver->getTexture(tp_progress_bar.c_str());
|
|
|
|
video::ITexture *progress_img_bg =
|
|
|
|
driver->getTexture(tp_progress_bar_bg.c_str());
|
|
|
|
|
|
|
|
if (progress_img && progress_img_bg) {
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
2014-04-27 16:09:21 +02:00
|
|
|
}
|
2017-03-10 13:26:24 +01:00
|
|
|
|
2014-04-27 16:09:21 +02:00
|
|
|
guienv->drawAll();
|
|
|
|
driver->endScene();
|
|
|
|
guitext->remove();
|
|
|
|
|
|
|
|
//return guitext;
|
|
|
|
}
|