2009-02-10 00:30:59 -05:00
|
|
|
// $Id: irr_driver.cpp 694 2006-08-29 07:42:36Z hiker $
|
2009-02-03 19:31:40 -05:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2009 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// 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 General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#include "graphics/irr_driver.hpp"
|
|
|
|
|
2009-04-29 10:48:18 -04:00
|
|
|
#ifdef HAVE_GLUT
|
|
|
|
# ifdef __APPLE__
|
|
|
|
# include <GLUT/glut.h>
|
|
|
|
# else
|
|
|
|
# include <GL/glut.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2009-06-11 06:00:43 -04:00
|
|
|
#include "config/user_config.hpp"
|
2009-11-23 00:20:05 -05:00
|
|
|
#include "graphics/camera.hpp"
|
2009-06-11 06:00:43 -04:00
|
|
|
#include "graphics/material_manager.hpp"
|
2009-07-18 13:48:36 -04:00
|
|
|
#include "guiengine/engine.hpp"
|
2009-09-01 14:11:26 -04:00
|
|
|
#include "guiengine/modaldialog.hpp"
|
2009-10-13 15:14:17 -04:00
|
|
|
#include "guiengine/screen.hpp"
|
2009-03-11 23:49:31 -04:00
|
|
|
#include "io/file_manager.hpp"
|
2009-04-23 19:27:06 -04:00
|
|
|
#include "items/item_manager.hpp"
|
|
|
|
#include "items/powerup_manager.hpp"
|
|
|
|
#include "items/attachment_manager.hpp"
|
|
|
|
#include "items/projectile_manager.hpp"
|
|
|
|
#include "karts/kart_properties_manager.hpp"
|
2010-01-10 18:12:29 -05:00
|
|
|
#include "karts/player_kart.hpp"
|
2010-01-02 11:28:55 -05:00
|
|
|
#include "main_loop.hpp"
|
2009-04-29 10:48:18 -04:00
|
|
|
#include "modes/world.hpp"
|
2010-02-03 19:45:24 -05:00
|
|
|
#include "states_screens/dialogs/confirm_resolution_dialog.hpp"
|
2010-01-02 11:28:55 -05:00
|
|
|
#include "states_screens/state_manager.hpp"
|
2009-11-23 00:20:05 -05:00
|
|
|
#include "utils/constants.hpp"
|
2009-04-23 19:27:06 -04:00
|
|
|
|
2009-10-12 19:43:14 -04:00
|
|
|
using namespace irr::core;
|
|
|
|
using namespace irr::scene;
|
|
|
|
using namespace irr::video;
|
|
|
|
|
2010-02-03 16:56:45 -05:00
|
|
|
/** singleton */
|
2009-02-03 19:31:40 -05:00
|
|
|
IrrDriver *irr_driver = NULL;
|
|
|
|
|
2010-02-03 16:56:45 -05:00
|
|
|
const int MIN_SUPPORTED_HEIGHT = 480; //TODO: do some tests, 480 might be too small without a special menu
|
|
|
|
const int MIN_SUPPORTED_WIDTH = 800;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2009-02-03 19:31:40 -05:00
|
|
|
IrrDriver::IrrDriver()
|
|
|
|
{
|
2010-02-03 16:47:36 -05:00
|
|
|
m_res_switching = false;
|
2010-02-09 21:11:56 -05:00
|
|
|
m_device = NULL;
|
2009-02-10 00:30:59 -05:00
|
|
|
file_manager->dropFileSystem();
|
2009-04-23 19:27:06 -04:00
|
|
|
initDevice();
|
|
|
|
} // IrrDriver
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
IrrDriver::~IrrDriver()
|
|
|
|
{
|
2010-02-09 21:11:56 -05:00
|
|
|
//std::cout << "^^^^^^^^ Dropping m_device ^^^^^^^^\n";
|
|
|
|
assert(m_device != NULL);
|
2009-04-23 19:27:06 -04:00
|
|
|
m_device->drop();
|
2010-02-09 21:11:56 -05:00
|
|
|
m_device = NULL;
|
2009-04-23 19:27:06 -04:00
|
|
|
} // ~IrrDriver
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void IrrDriver::initDevice()
|
|
|
|
{
|
2009-05-10 20:23:40 -04:00
|
|
|
static bool firstTime = true;
|
2009-04-23 19:27:06 -04:00
|
|
|
|
2009-05-10 20:23:40 -04:00
|
|
|
// ---- the first time, get a list of available video modes
|
2010-01-30 14:53:06 -05:00
|
|
|
if (firstTime)
|
2009-04-23 20:14:04 -04:00
|
|
|
{
|
2010-02-09 21:11:56 -05:00
|
|
|
//std::cout << "^^^^^^^^ Creating m_device (as NULL) ^^^^^^^^\n";
|
2009-08-05 08:45:11 -04:00
|
|
|
m_device = createDevice(video::EDT_NULL);
|
2009-05-10 20:23:40 -04:00
|
|
|
|
|
|
|
video::IVideoModeList* modes = m_device->getVideoModeList();
|
|
|
|
const int count = modes->getVideoModeCount();
|
2009-06-07 11:20:51 -04:00
|
|
|
//std::cout << "--------------\n allowed modes \n--------------\n";
|
|
|
|
//std::cout << "Desktop depth : " << modes->getDesktopDepth() << std::endl;
|
|
|
|
//std::cout << "Desktop resolution : " << modes->getDesktopResolution().Width << "," << modes->getDesktopResolution().Height << std::endl;
|
2009-05-10 20:23:40 -04:00
|
|
|
|
2009-06-07 11:20:51 -04:00
|
|
|
//std::cout << "Found " << count << " valid modes\n";
|
2009-05-10 20:23:40 -04:00
|
|
|
for(int i=0; i<count; i++)
|
2009-05-09 16:20:16 -04:00
|
|
|
{
|
2009-05-10 20:23:40 -04:00
|
|
|
// only consider 32-bit resolutions for now
|
2010-02-03 16:56:45 -05:00
|
|
|
if (modes->getVideoModeDepth(i) >= 24)
|
2009-05-10 20:23:40 -04:00
|
|
|
{
|
2010-02-03 16:56:45 -05:00
|
|
|
const int w = modes->getVideoModeResolution(i).Width;
|
|
|
|
const int h = modes->getVideoModeResolution(i).Height;
|
|
|
|
if (h < MIN_SUPPORTED_HEIGHT || w < MIN_SUPPORTED_WIDTH) continue;
|
|
|
|
|
2009-05-10 20:23:40 -04:00
|
|
|
VideoMode mode;
|
2010-02-03 16:56:45 -05:00
|
|
|
mode.width = w;
|
|
|
|
mode.height = h;
|
2009-05-10 20:23:40 -04:00
|
|
|
m_modes.push_back( mode );
|
|
|
|
}
|
|
|
|
|
2009-06-07 11:20:51 -04:00
|
|
|
//std::cout <<
|
|
|
|
//"bits : " << modes->getVideoModeDepth(i) <<
|
|
|
|
//" resolution=" << modes->getVideoModeResolution(i).Width <<
|
|
|
|
//"x" << modes->getVideoModeResolution(i).Height << std::endl;
|
2009-05-09 16:20:16 -04:00
|
|
|
}
|
2010-02-09 21:11:56 -05:00
|
|
|
//std::cout << "^^^^^^^^ Closing m_device ^^^^^^^^\n";
|
2009-05-10 20:23:40 -04:00
|
|
|
m_device->closeDevice();
|
|
|
|
|
|
|
|
firstTime = false;
|
|
|
|
} // end if firstTime
|
|
|
|
|
2009-09-15 00:48:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int numDrivers = 5;
|
|
|
|
|
|
|
|
// Test if user has chosen a driver or if we should try all to find a woring
|
|
|
|
// one.
|
|
|
|
if( UserConfigParams::m_renderer != 0 )
|
|
|
|
{
|
|
|
|
numDrivers = 1;
|
|
|
|
}
|
|
|
|
|
2009-05-10 20:23:40 -04:00
|
|
|
// ---- open device
|
2009-02-03 19:31:40 -05:00
|
|
|
// Try different drivers: start with opengl, then DirectX
|
2009-09-15 00:48:14 -04:00
|
|
|
for(int driver_type=0; driver_type<numDrivers; driver_type++)
|
2009-02-03 19:31:40 -05:00
|
|
|
{
|
2009-09-15 00:48:14 -04:00
|
|
|
|
|
|
|
video::E_DRIVER_TYPE type;
|
|
|
|
|
|
|
|
// Test if user has chosen a driver or if we should try all to find a
|
|
|
|
// woring one.
|
|
|
|
if( UserConfigParams::m_renderer != 0 )
|
|
|
|
{
|
|
|
|
// Get the correct type.
|
|
|
|
type = getEngineDriverType( UserConfigParams::m_renderer );
|
|
|
|
} else {
|
|
|
|
// Get the correct type.
|
|
|
|
type = getEngineDriverType( driver_type );
|
|
|
|
}
|
|
|
|
|
2009-05-10 20:09:40 -04:00
|
|
|
// Try 32 and, upon failure, 24 then 16 bit per pixels
|
2009-05-09 20:55:46 -04:00
|
|
|
for(int bits=32; bits>15; bits -=8)
|
2009-02-03 19:31:40 -05:00
|
|
|
{
|
2010-02-09 21:11:56 -05:00
|
|
|
//std::cout << "^^^^^^^^ CREATING m_device ^^^^^^^^\n";
|
2009-02-28 19:46:47 -05:00
|
|
|
m_device = createDevice(type,
|
2009-08-05 08:45:11 -04:00
|
|
|
core::dimension2d<u32>(UserConfigParams::m_width,
|
|
|
|
UserConfigParams::m_height ),
|
2009-02-28 19:46:47 -05:00
|
|
|
bits, //bits per pixel
|
2009-06-20 21:10:43 -04:00
|
|
|
UserConfigParams::m_fullscreen,
|
2009-02-28 19:46:47 -05:00
|
|
|
false, // stencil buffers
|
|
|
|
false, // vsync
|
|
|
|
this // event receiver
|
|
|
|
);
|
|
|
|
if(m_device) break;
|
|
|
|
} // for bits=24, 16
|
|
|
|
if(m_device) break;
|
|
|
|
} // for edt_types
|
|
|
|
if(!m_device)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Couldn't initialise irrlicht device. Quitting.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2009-05-09 20:55:46 -04:00
|
|
|
|
|
|
|
|
2009-02-28 19:46:47 -05:00
|
|
|
// Stores the new file system pointer.
|
2009-02-10 00:30:59 -05:00
|
|
|
file_manager->setDevice(m_device);
|
|
|
|
m_device->setWindowCaption(L"SuperTuxKart");
|
|
|
|
m_scene_manager = m_device->getSceneManager();
|
2009-10-15 19:43:43 -04:00
|
|
|
// Force creation of mipmaps even if the mipmaps flag in a b3d file
|
|
|
|
// does not set the 'enable mipmap' flag.
|
|
|
|
m_scene_manager->getParameters()->setAttribute(scene::B3D_LOADER_IGNORE_MIPMAP_FLAG, true);
|
|
|
|
m_device->getVideoDriver()->setTextureCreationFlag(
|
|
|
|
video::ETCF_CREATE_MIP_MAPS,
|
|
|
|
true);
|
|
|
|
//m_device->getVideoDriver()->setTextureCreationFlag(
|
|
|
|
// video::ETCF_OPTIMIZED_FOR_SPEED ,
|
|
|
|
// true);
|
|
|
|
//m_device->getVideoDriver()->setTextureCreationFlag(
|
|
|
|
// video::ETCF_ALWAYS_16_BIT ,
|
|
|
|
// true);
|
2009-03-11 01:10:56 -04:00
|
|
|
m_gui_env = m_device->getGUIEnvironment();
|
2009-07-13 08:25:38 -04:00
|
|
|
m_video_driver = m_device->getVideoDriver();
|
2010-01-24 18:57:50 -05:00
|
|
|
//const std::string &font = file_manager->getFontFile("DomesticManners.xml");
|
|
|
|
//m_race_font = m_gui_env->getFont(font.c_str());
|
2010-01-07 17:55:38 -05:00
|
|
|
|
|
|
|
#if (IRRLICHT_VERSION_MAJOR == 1) && (IRRLICHT_VERSION_MINOR >= 7)
|
|
|
|
video::SMaterial& material2D = m_video_driver->getMaterial2D();
|
2010-01-24 11:48:13 -05:00
|
|
|
material2D.setFlag(video::EMF_ANTI_ALIASING, true);
|
2010-01-07 18:05:43 -05:00
|
|
|
for (unsigned int n=0; n<MATERIAL_MAX_TEXTURES; n++)
|
2010-01-07 18:04:59 -05:00
|
|
|
{
|
|
|
|
material2D.TextureLayer[n].BilinearFilter = true;
|
|
|
|
//material2D.TextureLayer[n].TextureWrap = ETC_CLAMP_TO_EDGE;
|
|
|
|
material2D.TextureLayer[n].TextureWrapU = ETC_CLAMP_TO_EDGE;
|
|
|
|
material2D.TextureLayer[n].TextureWrapV = ETC_CLAMP_TO_EDGE;
|
2010-01-24 11:48:13 -05:00
|
|
|
|
|
|
|
material2D.TextureLayer[n].LODBias = 8.0f;
|
2010-01-07 18:04:59 -05:00
|
|
|
}
|
2010-01-07 17:55:38 -05:00
|
|
|
material2D.AntiAliasing=video::EAAM_FULL_BASIC;
|
|
|
|
//m_video_driver->enableMaterial2D();
|
|
|
|
#endif
|
2010-01-30 14:53:06 -05:00
|
|
|
|
2010-02-03 16:47:36 -05:00
|
|
|
// set cursor visible by default (what's the default is not too clearly documented,
|
2010-01-30 14:53:06 -05:00
|
|
|
// so let's decide ourselves...)
|
|
|
|
m_device->getCursorControl()->setVisible(true);
|
|
|
|
m_pointer_shown = true;
|
2009-04-23 19:27:06 -04:00
|
|
|
}
|
2009-02-03 19:31:40 -05:00
|
|
|
|
2009-09-15 00:48:14 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
video::E_DRIVER_TYPE IrrDriver::getEngineDriverType( int index )
|
|
|
|
{
|
|
|
|
video::E_DRIVER_TYPE type;
|
|
|
|
std::string rendererName = "";
|
|
|
|
|
|
|
|
// Choose the driver type.
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
// TODO Change default renderer dependen on operating system?
|
|
|
|
// Direct3D9 for Windows and OpenGL for Unix like systems?
|
|
|
|
case 0:
|
|
|
|
type = video::EDT_OPENGL;
|
|
|
|
rendererName = "OpenGL";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
type = video::EDT_OPENGL;
|
|
|
|
rendererName = "OpenGL";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
type = video::EDT_DIRECT3D9;
|
|
|
|
rendererName = "Direct3D9";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
type = video::EDT_DIRECT3D8;
|
|
|
|
rendererName = "Direct3D8";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
type = video::EDT_SOFTWARE;
|
|
|
|
rendererName = "Software";
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
type = video::EDT_BURNINGSVIDEO;
|
|
|
|
rendererName = "Burning's Video Software";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = video::EDT_NULL;
|
|
|
|
rendererName = "Null Device";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ouput which render will be tried.
|
|
|
|
std::cout << "Trying " << rendererName << " rendering." << std::endl;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-02 20:50:09 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void IrrDriver::showPointer()
|
|
|
|
{
|
2010-01-30 14:53:06 -05:00
|
|
|
if (!m_pointer_shown)
|
|
|
|
{
|
|
|
|
m_pointer_shown = true;
|
|
|
|
this->getDevice()->getCursorControl()->setVisible(true);
|
|
|
|
}
|
2009-05-02 20:50:09 -04:00
|
|
|
} // showPointer
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void IrrDriver::hidePointer()
|
|
|
|
{
|
2010-01-30 14:53:06 -05:00
|
|
|
if (m_pointer_shown)
|
|
|
|
{
|
|
|
|
m_pointer_shown = false;
|
|
|
|
this->getDevice()->getCursorControl()->setVisible(false);
|
|
|
|
}
|
2009-05-02 20:50:09 -04:00
|
|
|
} // hidePointer
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-03 19:45:24 -05:00
|
|
|
|
|
|
|
void IrrDriver::changeResolution(const int w, const int h, const bool fullscreen)
|
|
|
|
{
|
|
|
|
// update user config values
|
|
|
|
UserConfigParams::m_prev_width = UserConfigParams::m_width;
|
|
|
|
UserConfigParams::m_prev_height = UserConfigParams::m_height;
|
|
|
|
UserConfigParams::m_prev_fullscreen = UserConfigParams::m_fullscreen;
|
|
|
|
|
|
|
|
UserConfigParams::m_width = w;
|
|
|
|
UserConfigParams::m_height = h;
|
|
|
|
UserConfigParams::m_fullscreen = fullscreen;
|
|
|
|
|
|
|
|
doApplyResSettings();
|
|
|
|
|
|
|
|
new ConfirmResolutionDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void IrrDriver::doApplyResSettings()
|
2009-02-03 19:31:40 -05:00
|
|
|
{
|
2010-02-03 16:47:36 -05:00
|
|
|
m_res_switching = true;
|
|
|
|
|
2009-04-23 19:34:41 -04:00
|
|
|
// show black before resolution switch so we don't see OpenGL's buffer garbage during switch
|
|
|
|
m_device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140));
|
|
|
|
m_device->getVideoDriver()->draw2DRectangle( SColor(255, 0, 0, 0),
|
|
|
|
core::rect<s32>(0, 0,
|
2009-06-20 21:10:43 -04:00
|
|
|
UserConfigParams::m_prev_width,
|
|
|
|
UserConfigParams::m_prev_height) );
|
2009-04-23 19:34:41 -04:00
|
|
|
m_device->getVideoDriver()->endScene();
|
2009-05-09 20:55:46 -04:00
|
|
|
|
2009-04-23 19:27:06 -04:00
|
|
|
// startScreen -> removeTextures();
|
|
|
|
attachment_manager -> removeTextures();
|
|
|
|
projectile_manager -> removeTextures();
|
|
|
|
item_manager -> removeTextures();
|
2009-12-30 16:28:59 -05:00
|
|
|
kart_properties_manager -> unloadAllKarts();
|
2009-04-23 19:27:06 -04:00
|
|
|
powerup_manager -> removeTextures();
|
2009-12-05 20:30:39 -05:00
|
|
|
GUIEngine::clear();
|
2009-05-27 23:15:43 -04:00
|
|
|
GUIEngine::cleanUp();
|
2009-05-09 20:55:46 -04:00
|
|
|
|
2010-02-09 21:11:56 -05:00
|
|
|
//std::cout << "^^^^^^^^ Closing m_device ^^^^^^^^\n";
|
2009-04-23 19:27:06 -04:00
|
|
|
m_device->closeDevice();
|
2010-02-09 21:11:56 -05:00
|
|
|
//std::cout << "^^^^^^^^ Dropping m_device ^^^^^^^^\n";
|
2009-02-03 19:31:40 -05:00
|
|
|
m_device->drop();
|
2010-02-03 19:45:24 -05:00
|
|
|
m_device = NULL;
|
|
|
|
m_video_driver = NULL;
|
|
|
|
m_gui_env = NULL;
|
|
|
|
m_scene_manager = NULL;
|
2009-04-23 19:27:06 -04:00
|
|
|
initDevice();
|
2009-05-09 20:55:46 -04:00
|
|
|
|
2009-04-23 19:27:06 -04:00
|
|
|
material_manager->reInit();
|
2009-05-09 20:55:46 -04:00
|
|
|
|
2010-02-06 21:05:21 -05:00
|
|
|
powerup_manager -> loadAllPowerups();
|
2009-08-27 02:22:52 -04:00
|
|
|
kart_properties_manager -> loadAllKarts();
|
2009-04-23 19:27:06 -04:00
|
|
|
item_manager -> loadDefaultItems();
|
|
|
|
projectile_manager -> loadData();
|
|
|
|
attachment_manager -> loadModels();
|
2009-05-09 20:55:46 -04:00
|
|
|
|
2009-07-18 13:48:36 -04:00
|
|
|
// Re-init GUI engine
|
2010-02-03 16:47:36 -05:00
|
|
|
GUIEngine::init(m_device, m_video_driver, StateManager::get());
|
2009-04-23 19:27:06 -04:00
|
|
|
GUIEngine::reshowCurrentScreen();
|
2010-02-03 16:47:36 -05:00
|
|
|
|
2009-07-15 23:24:17 -04:00
|
|
|
} // changeResolution
|
2009-05-09 20:55:46 -04:00
|
|
|
|
2010-02-03 19:45:24 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void IrrDriver::cancelResChange()
|
|
|
|
{
|
|
|
|
UserConfigParams::m_width = UserConfigParams::m_prev_width;
|
|
|
|
UserConfigParams::m_height = UserConfigParams::m_prev_height;
|
|
|
|
UserConfigParams::m_fullscreen = UserConfigParams::m_prev_fullscreen;
|
|
|
|
|
|
|
|
doApplyResSettings();
|
|
|
|
} // cancelResChange
|
|
|
|
|
2010-01-28 06:54:01 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Prints statistics about rendering, e.g. number of drawn and culled
|
|
|
|
* triangles etc. Note that printing this information will also slow
|
|
|
|
* down STK.
|
|
|
|
*/
|
|
|
|
void IrrDriver::printRenderStats()
|
|
|
|
{
|
|
|
|
io::IAttributes * attr = m_scene_manager->getParameters();
|
2010-01-28 07:01:28 -05:00
|
|
|
printf("[%ls], FPS:%03d Tri:%.03fm Cull %d/%d nodes (%d,%d,%d)\n",
|
2010-01-28 06:54:01 -05:00
|
|
|
m_video_driver->getName(),
|
|
|
|
m_video_driver->getFPS (),
|
|
|
|
(f32) m_video_driver->getPrimitiveCountDrawn( 0 ) * ( 1.f / 1000000.f ),
|
|
|
|
attr->getAttributeAsInt ( "culled" ),
|
|
|
|
attr->getAttributeAsInt ( "calls" ),
|
|
|
|
attr->getAttributeAsInt ( "drawn_solid" ),
|
|
|
|
attr->getAttributeAsInt ( "drawn_transparent" ),
|
|
|
|
attr->getAttributeAsInt ( "drawn_transparent_effect" )
|
|
|
|
);
|
|
|
|
|
|
|
|
} // printRenderStats
|
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Loads an animated mesh and returns a pointer to it.
|
|
|
|
* \param filename File to load.
|
|
|
|
*/
|
|
|
|
scene::IAnimatedMesh *IrrDriver::getAnimatedMesh(const std::string &filename)
|
|
|
|
{
|
2009-03-26 19:31:00 -04:00
|
|
|
scene::IAnimatedMesh *m = m_scene_manager->getMesh(filename.c_str());
|
2009-03-27 08:34:52 -04:00
|
|
|
if(m) setAllMaterialFlags(m);
|
2009-03-26 19:31:00 -04:00
|
|
|
return m;
|
2009-02-10 00:30:59 -05:00
|
|
|
} // getAnimatedMesh
|
|
|
|
|
2009-02-10 06:11:39 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-29 11:51:55 -04:00
|
|
|
|
2009-02-10 06:11:39 -05:00
|
|
|
/** Loads a non-animated mesh and returns a pointer to it.
|
|
|
|
* \param filename File to load.
|
|
|
|
*/
|
|
|
|
scene::IMesh *IrrDriver::getMesh(const std::string &filename)
|
|
|
|
{
|
|
|
|
scene::IAnimatedMesh *m = m_scene_manager->getMesh(filename.c_str());
|
|
|
|
if(!m) return NULL;
|
2009-03-26 19:31:00 -04:00
|
|
|
setAllMaterialFlags(m);
|
2009-02-10 06:11:39 -05:00
|
|
|
return m->getMesh(0);
|
|
|
|
} // getMesh
|
|
|
|
|
2009-03-26 19:31:00 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Sets the material flags in this mesh depending on the settings in
|
|
|
|
* material_manager.
|
|
|
|
* \param mesh The mesh to change the settings in.
|
|
|
|
*/
|
|
|
|
void IrrDriver::setAllMaterialFlags(scene::IAnimatedMesh *mesh) const
|
|
|
|
{
|
|
|
|
unsigned int n=mesh->getMeshBufferCount();
|
|
|
|
for(unsigned int i=0; i<n; i++)
|
|
|
|
{
|
|
|
|
scene::IMeshBuffer *mb = mesh->getMeshBuffer(i);
|
|
|
|
video::SMaterial &irr_material=mb->getMaterial();
|
|
|
|
for(unsigned int j=0; j<video::MATERIAL_MAX_TEXTURES; j++)
|
|
|
|
{
|
|
|
|
video::ITexture* t=irr_material.getTexture(j);
|
|
|
|
if(!t) continue;
|
|
|
|
material_manager->setAllMaterialFlags(t, mb);
|
|
|
|
} // for j<MATERIAL_MAX_TEXTURES
|
2009-12-05 10:17:32 -05:00
|
|
|
material_manager->setAllUntexturedMaterialFlags(mb);
|
2009-03-26 19:31:00 -04:00
|
|
|
} // for i<getMeshBufferCount()
|
|
|
|
} // setAllMaterialFlags
|
|
|
|
|
2009-03-23 19:50:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Converts the mesh into a water scene node.
|
|
|
|
* \param mesh The mesh which is converted into a water scene node.
|
|
|
|
* \param wave_height Height of the water waves.
|
|
|
|
* \param wave_speed Speed of the water waves.
|
|
|
|
* \param wave_length Lenght of a water wave.
|
|
|
|
*/
|
|
|
|
scene::ISceneNode* IrrDriver::addWaterNode(scene::IMesh *mesh,
|
|
|
|
float wave_height,
|
|
|
|
float wave_speed,
|
|
|
|
float wave_length)
|
|
|
|
{
|
|
|
|
return m_scene_manager->addWaterSurfaceSceneNode(mesh,
|
2009-05-09 20:55:46 -04:00
|
|
|
wave_height, wave_speed,
|
2009-03-23 19:50:50 -04:00
|
|
|
wave_length);
|
|
|
|
} // addWaterNode
|
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds a mesh that will be optimised using an oct tree.
|
|
|
|
* \param mesh Mesh to add.
|
|
|
|
*/
|
|
|
|
scene::ISceneNode *IrrDriver::addOctTree(scene::IMesh *mesh)
|
|
|
|
{
|
2010-01-04 22:38:35 -05:00
|
|
|
#if (IRRLICHT_VERSION_MAJOR == 1) && (IRRLICHT_VERSION_MINOR == 7)
|
|
|
|
return m_scene_manager->addOctreeSceneNode(mesh);
|
|
|
|
#else
|
2009-02-10 00:30:59 -05:00
|
|
|
return m_scene_manager->addOctTreeSceneNode(mesh);
|
2010-01-04 22:38:35 -05:00
|
|
|
#endif
|
2009-02-10 00:30:59 -05:00
|
|
|
} // addOctTree
|
|
|
|
|
2009-03-16 22:52:58 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds a particle scene node.
|
|
|
|
*/
|
|
|
|
scene::IParticleSystemSceneNode *IrrDriver::addParticleNode(bool default_emitter)
|
|
|
|
{
|
|
|
|
return m_scene_manager->addParticleSystemSceneNode(default_emitter);
|
|
|
|
} // addParticleNode
|
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds a static mesh to scene. This should be used for smaller objects,
|
|
|
|
* since the node is not optimised.
|
|
|
|
* \param mesh The mesh to add.
|
|
|
|
*/
|
2010-02-04 17:53:24 -05:00
|
|
|
scene::IMeshSceneNode *IrrDriver::addMesh(scene::IMesh *mesh)
|
2009-02-10 00:30:59 -05:00
|
|
|
{
|
|
|
|
return m_scene_manager->addMeshSceneNode(mesh);
|
|
|
|
} // addMesh
|
|
|
|
|
2009-03-23 19:50:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-12-28 14:37:59 -05:00
|
|
|
/** Adds a billboard node to scene.
|
|
|
|
*/
|
|
|
|
scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size, video::ITexture *texture, scene::ISceneNode* parent)
|
|
|
|
{
|
|
|
|
scene::IBillboardSceneNode* node = m_scene_manager->addBillboardSceneNode(parent, size);
|
|
|
|
assert(node->getMaterialCount() > 0);
|
|
|
|
node->setMaterialTexture(0, texture);
|
|
|
|
return node;
|
|
|
|
} // addMesh
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2009-12-05 21:05:45 -05:00
|
|
|
/** Creates a quad mesh buffer and adds it to the scene graph. (FIXME: wrong docs? I don't think it does)
|
2009-03-23 19:50:50 -04:00
|
|
|
*/
|
2009-07-16 20:22:58 -04:00
|
|
|
scene::IMesh *IrrDriver::createQuadMesh(const video::SMaterial *material,
|
|
|
|
bool create_one_quad)
|
2009-03-23 19:50:50 -04:00
|
|
|
{
|
|
|
|
scene::SMeshBuffer *buffer = new scene::SMeshBuffer();
|
2009-07-16 20:22:58 -04:00
|
|
|
if(create_one_quad)
|
|
|
|
{
|
|
|
|
video::S3DVertex v;
|
|
|
|
v.Pos = core::vector3df(0,0,0);
|
|
|
|
v.Normal = core::vector3df(1/sqrt(2.0f), 1/sqrt(2.0f), 0);
|
|
|
|
|
|
|
|
// Add the vertices
|
|
|
|
// ----------------
|
|
|
|
buffer->Vertices.push_back(v);
|
|
|
|
buffer->Vertices.push_back(v);
|
|
|
|
buffer->Vertices.push_back(v);
|
|
|
|
buffer->Vertices.push_back(v);
|
|
|
|
|
|
|
|
// Define the indices for the triangles
|
|
|
|
// ------------------------------------
|
|
|
|
buffer->Indices.push_back(0);
|
|
|
|
buffer->Indices.push_back(1);
|
|
|
|
buffer->Indices.push_back(2);
|
|
|
|
|
|
|
|
buffer->Indices.push_back(0);
|
|
|
|
buffer->Indices.push_back(2);
|
|
|
|
buffer->Indices.push_back(3);
|
|
|
|
}
|
2009-05-18 23:24:56 -04:00
|
|
|
if(material)
|
|
|
|
buffer->Material = *material;
|
2009-03-23 19:50:50 -04:00
|
|
|
SMesh *mesh = new SMesh();
|
|
|
|
mesh->addMeshBuffer(buffer);
|
|
|
|
mesh->recalculateBoundingBox();
|
|
|
|
buffer->drop();
|
|
|
|
return mesh;
|
|
|
|
} // createQuadMesh
|
|
|
|
|
2009-12-05 21:05:45 -05:00
|
|
|
/** Creates a quad mesh buffer
|
|
|
|
*/
|
|
|
|
scene::IMesh *IrrDriver::createTexturedQuadMesh(const video::SMaterial *material, const double w, const double h)
|
|
|
|
{
|
|
|
|
scene::SMeshBuffer *buffer = new scene::SMeshBuffer();
|
|
|
|
|
|
|
|
video::S3DVertex v1;
|
|
|
|
v1.Pos = core::vector3df(0,0,0);
|
|
|
|
v1.Normal = core::vector3df(1/sqrt(2.0f), 1/sqrt(2.0f), 0); // I hope normals are ok...
|
|
|
|
v1.TCoords = core::vector2d<f32>(0,1);
|
|
|
|
|
|
|
|
video::S3DVertex v2;
|
|
|
|
v2.Pos = core::vector3df(w,0,0);
|
|
|
|
v2.Normal = core::vector3df(1/sqrt(2.0f), 1/sqrt(2.0f), 0);
|
|
|
|
v2.TCoords = core::vector2d<f32>(1,1);
|
|
|
|
|
|
|
|
video::S3DVertex v3;
|
|
|
|
v3.Pos = core::vector3df(w,h,0);
|
|
|
|
v3.Normal = core::vector3df(1/sqrt(2.0f), 1/sqrt(2.0f), 0);
|
|
|
|
v3.TCoords = core::vector2d<f32>(1,0);
|
|
|
|
|
|
|
|
video::S3DVertex v4;
|
|
|
|
v4.Pos = core::vector3df(0,h,0);
|
|
|
|
v4.Normal = core::vector3df(1/sqrt(2.0f), 1/sqrt(2.0f), 0);
|
|
|
|
v4.TCoords = core::vector2d<f32>(0,0);
|
|
|
|
|
|
|
|
|
|
|
|
// Add the vertices
|
|
|
|
// ----------------
|
|
|
|
buffer->Vertices.push_back(v1);
|
|
|
|
buffer->Vertices.push_back(v2);
|
|
|
|
buffer->Vertices.push_back(v3);
|
|
|
|
buffer->Vertices.push_back(v4);
|
|
|
|
|
|
|
|
// Define the indices for the triangles
|
|
|
|
// ------------------------------------
|
|
|
|
buffer->Indices.push_back(0);
|
|
|
|
buffer->Indices.push_back(1);
|
|
|
|
buffer->Indices.push_back(2);
|
|
|
|
|
|
|
|
buffer->Indices.push_back(0);
|
|
|
|
buffer->Indices.push_back(2);
|
|
|
|
buffer->Indices.push_back(3);
|
|
|
|
|
|
|
|
if (material) buffer->Material = *material;
|
|
|
|
SMesh *mesh = new SMesh();
|
|
|
|
mesh->addMeshBuffer(buffer);
|
|
|
|
mesh->recalculateBoundingBox();
|
|
|
|
buffer->drop();
|
|
|
|
return mesh;
|
|
|
|
} // createQuadMesh
|
|
|
|
|
2009-03-11 01:10:56 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Removes a scene node from the scene.
|
|
|
|
* \param node The scene node to remove.
|
|
|
|
*/
|
|
|
|
void IrrDriver::removeNode(scene::ISceneNode *node)
|
|
|
|
{
|
|
|
|
node->remove();
|
|
|
|
} // removeMesh
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Removes a mesh from the mesh cache, freeing the memory.
|
|
|
|
* \param mesh The mesh to remove.
|
|
|
|
*/
|
|
|
|
void IrrDriver::removeMesh(scene::IMesh *mesh)
|
|
|
|
{
|
|
|
|
m_scene_manager->getMeshCache()->removeMesh(mesh);
|
|
|
|
} // removeMesh
|
2009-12-08 22:50:44 -05:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Removes a texture from irrlicht's texture cache.
|
|
|
|
* \param t The texture to remove.
|
|
|
|
*/
|
|
|
|
void IrrDriver::removeTexture(video::ITexture *t)
|
|
|
|
{
|
|
|
|
m_video_driver->removeTexture(t);
|
|
|
|
} // removeTexture
|
2009-03-11 01:10:56 -04:00
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds an animated mesh to the scene.
|
|
|
|
* \param mesh The animated mesh to add.
|
|
|
|
*/
|
2009-04-05 08:53:17 -04:00
|
|
|
scene::IAnimatedMeshSceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *mesh)
|
2009-02-10 00:30:59 -05:00
|
|
|
{
|
|
|
|
return m_scene_manager->addAnimatedMeshSceneNode(mesh);
|
|
|
|
} // addAnimatedMesh
|
|
|
|
|
2009-03-16 22:52:58 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds a sky dome. Documentation from irrlicht:
|
|
|
|
* A skydome is a large (half-) sphere with a panoramic texture on the inside
|
|
|
|
* and is drawn around the camera position.
|
|
|
|
* \param texture: Texture for the dome.
|
|
|
|
* \param horiRes: Number of vertices of a horizontal layer of the sphere.
|
|
|
|
* \param vertRes: Number of vertices of a vertical layer of the sphere.
|
2009-05-09 20:55:46 -04:00
|
|
|
* \param texturePercentage: How much of the height of the texture is used.
|
2009-03-16 22:52:58 -04:00
|
|
|
* Should be between 0 and 1.
|
2009-05-09 20:55:46 -04:00
|
|
|
* \param spherePercentage: How much of the sphere is drawn. Value should be
|
|
|
|
* between 0 and 2, where 1 is an exact half-sphere and 2 is a full
|
2009-03-16 22:52:58 -04:00
|
|
|
* sphere.
|
|
|
|
*/
|
2009-05-09 20:55:46 -04:00
|
|
|
scene::ISceneNode *IrrDriver::addSkyDome(const std::string &texture_name,
|
|
|
|
int hori_res, int vert_res,
|
|
|
|
float texture_percent,
|
2009-03-16 22:52:58 -04:00
|
|
|
float sphere_percent)
|
|
|
|
{
|
|
|
|
ITexture *texture = getTexture(texture_name);
|
|
|
|
return m_scene_manager->addSkyDomeSceneNode(texture, hori_res, vert_res,
|
2009-05-09 20:55:46 -04:00
|
|
|
texture_percent,
|
2009-03-16 22:52:58 -04:00
|
|
|
sphere_percent);
|
|
|
|
} // addSkyDome
|
|
|
|
|
2009-03-23 19:50:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds a skybox using. Irrlicht documentation:
|
2009-05-09 20:55:46 -04:00
|
|
|
* A skybox is a big cube with 6 textures on it and is drawn around the camera
|
2009-03-23 19:50:50 -04:00
|
|
|
* position.
|
|
|
|
* \param top: Texture for the top plane of the box.
|
|
|
|
* \param bottom: Texture for the bottom plane of the box.
|
|
|
|
* \param left: Texture for the left plane of the box.
|
|
|
|
* \param right: Texture for the right plane of the box.
|
|
|
|
* \param front: Texture for the front plane of the box.
|
|
|
|
* \param back: Texture for the back plane of the box.
|
|
|
|
*/
|
|
|
|
scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<std::string> &texture_names)
|
|
|
|
{
|
|
|
|
std::vector<video::ITexture*> t;
|
|
|
|
for(unsigned int i=0; i<texture_names.size(); i++)
|
|
|
|
{
|
|
|
|
t.push_back(getTexture(texture_names[i]));
|
|
|
|
}
|
|
|
|
return m_scene_manager->addSkyBoxSceneNode(t[0], t[1], t[2], t[3], t[4], t[5]);
|
|
|
|
} // addSkyBox
|
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Adds a camera to the scene.
|
|
|
|
*/
|
2009-11-23 00:20:05 -05:00
|
|
|
scene::ICameraSceneNode *IrrDriver::addCameraSceneNode()
|
2009-02-10 00:30:59 -05:00
|
|
|
{
|
|
|
|
return m_scene_manager->addCameraSceneNode();
|
2009-11-23 00:20:05 -05:00
|
|
|
} // addCameraSceneNode
|
|
|
|
|
2009-08-13 19:26:38 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Removes a camera. This can't be done with removeNode() since the camera
|
|
|
|
* can be marked as active, meaning a drop will not delete it. While this
|
|
|
|
* doesn't really cause a memory leak (the camera is removed the next time
|
|
|
|
* a camera is added), it's a bit cleaner and easier to check for memory
|
|
|
|
* leaks, since the scene root should now always be empty.
|
|
|
|
*/
|
2009-11-23 00:20:05 -05:00
|
|
|
void IrrDriver::removeCameraSceneNode(scene::ICameraSceneNode *camera)
|
2009-08-13 19:26:38 -04:00
|
|
|
{
|
|
|
|
if(camera==m_scene_manager->getActiveCamera())
|
|
|
|
m_scene_manager->setActiveCamera(NULL); // basically causes a drop
|
|
|
|
camera->remove();
|
2009-11-23 00:20:05 -05:00
|
|
|
} // removeCameraSceneNode
|
2009-08-13 19:26:38 -04:00
|
|
|
|
2009-03-11 01:10:56 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Loads a texture from a file and returns the texture object.
|
|
|
|
* \param filename File name of the texture to load.
|
|
|
|
*/
|
|
|
|
video::ITexture *IrrDriver::getTexture(const std::string &filename)
|
|
|
|
{
|
2010-01-07 19:23:31 -05:00
|
|
|
video::ITexture* out = m_scene_manager->getVideoDriver()->getTexture(filename.c_str());
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (out == NULL)
|
|
|
|
{
|
|
|
|
printf("Put a breakpoint at line %s:%i to debug!\n", __FILE__, __LINE__ );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return out;
|
2009-03-11 01:10:56 -04:00
|
|
|
} // getTexture
|
|
|
|
|
2009-03-15 21:45:49 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Sets the ambient light.
|
2009-05-09 20:55:46 -04:00
|
|
|
* \param light The colour of the light to set.
|
2009-03-15 21:45:49 -04:00
|
|
|
*/
|
|
|
|
void IrrDriver::setAmbientLight(const video::SColor &light)
|
|
|
|
{
|
|
|
|
m_scene_manager->setAmbientLight(light);
|
|
|
|
} // setAmbientLight
|
|
|
|
|
2009-07-12 07:54:21 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Renders the bullet debug view using glut.
|
|
|
|
*/
|
|
|
|
void IrrDriver::renderBulletDebugView()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_GLUT
|
|
|
|
// Use bullets debug drawer
|
|
|
|
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
|
|
|
|
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
|
|
|
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
2009-12-17 19:36:35 -05:00
|
|
|
/* light_position is NOT default value */
|
2009-07-12 07:54:21 -04:00
|
|
|
GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
|
|
|
|
GLfloat light_position1[] = { -1.0, -1.0, -1.0, 0.0 };
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
|
|
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
|
|
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
|
|
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
|
|
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_LIGHT1);
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
|
|
|
|
glClearColor(0.8f,0.8f,0.8f,0);
|
|
|
|
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
float f=2.0f;
|
|
|
|
glFrustum(-f, f, -f, f, 1.0, 1000.0);
|
|
|
|
|
2010-02-10 06:40:33 -05:00
|
|
|
World *world = RaceManager::getWorld();
|
|
|
|
const Kart *kart = world->getKart(world->getNumKarts()-1);
|
2009-08-02 19:18:10 -04:00
|
|
|
Vec3 xyz = kart->getXYZ();
|
|
|
|
// Compute the camera position 5 units behind and 4 units higher than the kart
|
|
|
|
Vec3 cam_pos= kart->getTrans()(Vec3(0, -5, 4));
|
2009-07-12 07:54:21 -04:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2009-08-02 19:18:10 -04:00
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
gluLookAt(cam_pos.getX(), cam_pos.getY(), cam_pos.getZ(),
|
|
|
|
xyz.getX(), xyz.getY(), xyz.getZ(),
|
|
|
|
0.0f, 0.0f, 1.0f );
|
2009-07-12 07:54:21 -04:00
|
|
|
|
2010-02-10 06:40:33 -05:00
|
|
|
for (unsigned int i = 0 ; i < world->getNumKarts(); ++i)
|
2009-07-12 07:54:21 -04:00
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
Kart *kart=world->getKart((int)i);
|
2009-07-12 07:54:21 -04:00
|
|
|
if(!kart->isEliminated()) kart->draw();
|
|
|
|
}
|
2010-02-10 06:40:33 -05:00
|
|
|
world->getPhysics()->draw();
|
2009-07-12 07:54:21 -04:00
|
|
|
#endif
|
|
|
|
} // renderBulletDebugView
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Displays the FPS on the screen.
|
|
|
|
*/
|
|
|
|
void IrrDriver::displayFPS()
|
|
|
|
{
|
2010-01-28 19:38:40 -05:00
|
|
|
// We will let pass some time to let things settle before trusting FPS counter
|
2010-01-28 21:03:45 -05:00
|
|
|
// even if we also ignore fps = 1, which tends to happen in first checks
|
|
|
|
#define NO_TRUST_COUNT 25
|
|
|
|
static int no_trust = NO_TRUST_COUNT;
|
2010-01-28 19:38:40 -05:00
|
|
|
|
2010-01-28 21:03:45 -05:00
|
|
|
if(no_trust) {
|
|
|
|
no_trust--;
|
2010-01-28 19:38:40 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-28 21:03:45 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getFont();
|
|
|
|
const int fps = m_device->getVideoDriver()->getFPS();
|
|
|
|
|
2009-07-12 16:47:01 -04:00
|
|
|
// Min and max info tracking, per mode, so user can check game vs menus
|
2009-09-06 14:45:38 -04:00
|
|
|
bool current_state = StateManager::get()->getGameState() == GUIEngine::GAME;
|
2009-07-12 16:47:01 -04:00
|
|
|
static bool prev_state = false;
|
|
|
|
static int min = 999; // Absurd values for start will print first time
|
|
|
|
static int max = 0; // but no big issue, maybe even "invisible"
|
|
|
|
|
|
|
|
// Reset limits if state changes
|
|
|
|
if (prev_state != current_state)
|
|
|
|
{
|
|
|
|
min = 999;
|
|
|
|
max = 0;
|
2010-01-28 21:03:45 -05:00
|
|
|
no_trust = NO_TRUST_COUNT;
|
2009-07-12 16:47:01 -04:00
|
|
|
prev_state = current_state;
|
|
|
|
}
|
|
|
|
|
2010-01-28 19:38:40 -05:00
|
|
|
if (min > fps && fps > 1) min = fps; // Start moments sometimes give useless 1
|
2009-07-12 16:47:01 -04:00
|
|
|
if (max < fps) max = fps;
|
|
|
|
|
2009-07-12 07:54:21 -04:00
|
|
|
static char buffer[32];
|
2009-07-12 16:47:01 -04:00
|
|
|
sprintf(buffer, "FPS : %i/%i/%i", min, fps, max);
|
2009-07-12 07:54:21 -04:00
|
|
|
|
|
|
|
core::stringw fpsString = buffer;
|
|
|
|
|
|
|
|
static video::SColor fpsColor = video::SColor(255, 255, 0, 0);
|
|
|
|
font->draw( fpsString.c_str(), core::rect< s32 >(0,0,600,200), fpsColor, true );
|
|
|
|
} // updateFPS
|
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Update, called once per frame.
|
|
|
|
* \param dt Time since last update
|
|
|
|
*/
|
|
|
|
void IrrDriver::update(float dt)
|
|
|
|
{
|
2010-01-02 11:28:55 -05:00
|
|
|
if (!m_device->run())
|
|
|
|
{
|
2010-02-03 16:47:36 -05:00
|
|
|
// FIXME: I have NO idea why, after performing resolution switch, the irrlicht device asks once to be deleted
|
|
|
|
if (m_res_switching) m_res_switching = false;
|
|
|
|
else main_loop->abort();
|
2010-01-02 11:28:55 -05:00
|
|
|
}
|
2009-06-24 19:01:45 -04:00
|
|
|
|
2010-01-31 18:08:23 -05:00
|
|
|
const bool inRace = race_manager->raceIsActive();
|
|
|
|
// With bullet debug view we have to clear the back buffer, but
|
|
|
|
// that's not necessary for non-debug
|
|
|
|
bool back_buffer_clear = inRace && UserConfigParams::m_bullet_debug;
|
|
|
|
m_device->getVideoDriver()->beginScene(back_buffer_clear,
|
|
|
|
true, video::SColor(255,100,101,140));
|
|
|
|
|
|
|
|
{ // Just to mark the begin/end scene block
|
2009-10-03 21:16:00 -04:00
|
|
|
GUIEngine::GameState state = StateManager::get()->getGameState();
|
|
|
|
if (state != GUIEngine::GAME)
|
2009-06-24 19:01:45 -04:00
|
|
|
{
|
2009-11-23 00:20:05 -05:00
|
|
|
// This code needs to go outside beginScene() / endScene() since
|
2009-07-12 07:54:21 -04:00
|
|
|
// the model view widget will do off-screen rendering there
|
|
|
|
const int updateAmount = GUIEngine::needsUpdate.size();
|
|
|
|
for(int n=0; n<updateAmount; n++)
|
|
|
|
{
|
|
|
|
GUIEngine::needsUpdate[n].update(dt);
|
|
|
|
}
|
2009-06-24 19:01:45 -04:00
|
|
|
}
|
2009-07-12 07:54:21 -04:00
|
|
|
|
2009-09-01 14:11:26 -04:00
|
|
|
if (inRace)
|
2009-04-29 10:48:18 -04:00
|
|
|
{
|
2010-01-31 18:08:23 -05:00
|
|
|
if (UserConfigParams::m_bullet_debug)
|
2009-10-03 21:16:00 -04:00
|
|
|
{
|
2009-08-02 19:18:10 -04:00
|
|
|
renderBulletDebugView();
|
2009-10-03 21:16:00 -04:00
|
|
|
}
|
2009-08-02 19:18:10 -04:00
|
|
|
else
|
|
|
|
{
|
2010-02-10 07:47:18 -05:00
|
|
|
World *world = RaceManager::getWorld();
|
|
|
|
RaceGUI *rg = world->getRaceGUI();
|
|
|
|
for(unsigned int i=0; i<world->getNumKarts(); i++)
|
2009-11-23 00:20:05 -05:00
|
|
|
{
|
2010-02-10 07:47:18 -05:00
|
|
|
Kart *kart=world->getKart(i);
|
|
|
|
if(kart->getCamera())
|
|
|
|
{
|
|
|
|
kart->activateCamera();
|
|
|
|
m_scene_manager->drawAll();
|
|
|
|
} // if kart->Camera
|
|
|
|
} // for i<world->getNumKarts()
|
2009-11-23 00:20:05 -05:00
|
|
|
// To draw the race gui we set the viewport back to the full
|
|
|
|
// screen.
|
|
|
|
m_video_driver->setViewPort(core::recti(0, 0,
|
|
|
|
UserConfigParams::m_width,
|
|
|
|
UserConfigParams::m_height));
|
2010-02-10 06:40:33 -05:00
|
|
|
for(unsigned int i=0; i<world->getNumKarts(); i++)
|
2009-11-23 00:20:05 -05:00
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
Kart *kart = world->getKart(i);
|
|
|
|
if(kart->getCamera())
|
|
|
|
rg->renderPlayerView(kart);
|
|
|
|
} // for i<getNumKarts
|
2009-11-23 00:20:05 -05:00
|
|
|
} // !bullet_debug
|
2009-04-29 10:48:18 -04:00
|
|
|
}
|
2009-11-23 00:20:05 -05:00
|
|
|
else
|
2009-10-03 21:16:00 -04:00
|
|
|
{
|
2009-10-15 18:11:02 -04:00
|
|
|
// render 3D stuff in cutscenes too
|
2009-10-03 21:16:00 -04:00
|
|
|
m_scene_manager->drawAll();
|
|
|
|
}
|
2009-09-01 14:11:26 -04:00
|
|
|
|
2010-01-31 18:08:23 -05:00
|
|
|
// The render and displayFPS calls interfere with bullet debug
|
|
|
|
// rendering, so they can not be called.
|
|
|
|
if(!inRace || !UserConfigParams::m_bullet_debug)
|
|
|
|
{
|
|
|
|
// Either render the gui, or the global elements of the race gui.
|
|
|
|
GUIEngine::render(dt);
|
2009-03-14 21:34:21 -04:00
|
|
|
|
2010-01-31 18:08:23 -05:00
|
|
|
// draw FPS if enabled
|
|
|
|
if ( UserConfigParams::m_display_fps ) displayFPS();
|
|
|
|
}
|
2009-07-12 07:54:21 -04:00
|
|
|
|
2010-01-31 18:08:23 -05:00
|
|
|
} // just to mark the begin/end scene block
|
2009-06-28 21:40:15 -04:00
|
|
|
m_device->getVideoDriver()->endScene();
|
2010-01-28 06:54:01 -05:00
|
|
|
// Enable this next print statement to get render information printed
|
|
|
|
// E.g. number of triangles rendered, culled etc.
|
|
|
|
//printRenderStats();
|
2009-02-10 00:30:59 -05:00
|
|
|
} // update
|
|
|
|
|
2009-02-03 19:31:40 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Irrlicht Event handler.
|
2009-02-28 19:46:47 -05:00
|
|
|
bool IrrDriver::OnEvent(const irr::SEvent &event)
|
|
|
|
{
|
2009-05-09 20:55:46 -04:00
|
|
|
switch (event.EventType)
|
2009-02-28 19:46:47 -05:00
|
|
|
{
|
|
|
|
case irr::EET_KEY_INPUT_EVENT: {
|
|
|
|
printf("key input event\n");
|
|
|
|
break;
|
|
|
|
} // keyboard
|
|
|
|
case irr::EET_GUI_EVENT: {
|
|
|
|
return false; }
|
|
|
|
case irr::EET_MOUSE_INPUT_EVENT: {
|
|
|
|
return false; }
|
|
|
|
case irr::EET_LOG_TEXT_EVENT:
|
|
|
|
{
|
|
|
|
// Ignore 'normal' messages
|
2009-03-11 01:10:56 -04:00
|
|
|
if(event.LogEvent.Level>0)
|
2009-02-28 19:46:47 -05:00
|
|
|
{
|
2009-05-09 20:55:46 -04:00
|
|
|
printf("Level %d: %s\n",
|
2009-02-28 19:46:47 -05:00
|
|
|
event.LogEvent.Level,event.LogEvent.Text);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
printf("Event: %d -> ",event.EventType);
|
|
|
|
return false;
|
|
|
|
} // switch
|
|
|
|
return false;
|
|
|
|
} // OnEvent
|
|
|
|
|
2009-02-03 19:31:40 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark RTT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Begins a rendering to a texture.
|
|
|
|
* \param dimension The size of the texture.
|
|
|
|
* \param name Name of the texture.
|
2009-09-08 08:50:52 -04:00
|
|
|
* \param dont_do_set_render_target This is a fix for the problem that 2d
|
|
|
|
* rendering doesn't work if setRenderTarget is called here, but 3d
|
|
|
|
* rendering doesn't work if it's not called here :(
|
2009-08-29 13:09:03 -04:00
|
|
|
*/
|
|
|
|
IrrDriver::RTTProvider::RTTProvider(const core::dimension2du &dimension,
|
2009-09-08 08:50:52 -04:00
|
|
|
const std::string &name)
|
2009-08-29 13:09:03 -04:00
|
|
|
{
|
|
|
|
m_video_driver = irr_driver->getVideoDriver();
|
|
|
|
|
|
|
|
m_render_target_texture = m_video_driver->addRenderTargetTexture(dimension,
|
|
|
|
name.c_str());
|
|
|
|
m_video_driver->setRenderTarget(m_render_target_texture);
|
|
|
|
|
|
|
|
m_rtt_main_node = NULL;
|
|
|
|
m_camera = NULL;
|
|
|
|
m_light = NULL;
|
2009-09-08 08:50:52 -04:00
|
|
|
} // RTTProvider
|
|
|
|
|
2009-08-29 13:09:03 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
IrrDriver::RTTProvider::~RTTProvider()
|
|
|
|
{
|
|
|
|
tearDownRTTScene();
|
2009-09-08 08:50:52 -04:00
|
|
|
} // ~RTTProvider
|
|
|
|
|
2009-08-29 13:09:03 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-08-29 13:23:00 -04:00
|
|
|
/** Sets up a given vector of meshes for render-to-texture. Ideal to embed a 3D
|
2009-08-29 15:59:27 -04:00
|
|
|
* object inside the GUI. If there are multiple meshes, the first mesh is considered
|
|
|
|
* to be the root, and all following meshes will have their locations relative to
|
|
|
|
* the location of the first mesh.
|
2009-08-29 13:09:03 -04:00
|
|
|
*/
|
|
|
|
void IrrDriver::RTTProvider::setupRTTScene(ptr_vector<scene::IMesh, REF>& mesh,
|
2009-12-30 14:41:59 -05:00
|
|
|
std::vector<Vec3>& mesh_location,
|
|
|
|
const std::vector<int>& model_frames)
|
|
|
|
{
|
|
|
|
if (model_frames[0] == -1)
|
|
|
|
{
|
|
|
|
scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(0), NULL);
|
|
|
|
node->setPosition( mesh_location[0].toIrrVector() );
|
|
|
|
m_rtt_main_node = node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(0), NULL);
|
|
|
|
node->setPosition( mesh_location[0].toIrrVector() );
|
|
|
|
node->setFrameLoop(model_frames[0], model_frames[0]);
|
|
|
|
node->setAnimationSpeed(0);
|
|
|
|
|
|
|
|
m_rtt_main_node = node;
|
|
|
|
//std::cout << "(((( set frame " << model_frames[0] << " ))))\n";
|
|
|
|
}
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2009-12-30 14:41:59 -05:00
|
|
|
assert(m_rtt_main_node != NULL);
|
|
|
|
assert(mesh.size() == (int)mesh_location.size());
|
|
|
|
assert(mesh.size() == (int)model_frames.size());
|
|
|
|
|
2009-08-29 13:09:03 -04:00
|
|
|
const int mesh_amount = mesh.size();
|
2009-08-29 15:59:27 -04:00
|
|
|
for (int n=1; n<mesh_amount; n++)
|
2009-08-29 13:09:03 -04:00
|
|
|
{
|
2009-12-30 14:41:59 -05:00
|
|
|
if (model_frames[n] == -1)
|
|
|
|
{
|
|
|
|
scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(n), m_rtt_main_node);
|
|
|
|
node->setPosition( mesh_location[n].toIrrVector() );
|
|
|
|
node->updateAbsolutePosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(n), m_rtt_main_node);
|
|
|
|
node->setPosition( mesh_location[n].toIrrVector() );
|
|
|
|
node->setFrameLoop(model_frames[n], model_frames[n]);
|
|
|
|
node->setAnimationSpeed(0);
|
|
|
|
node->updateAbsolutePosition();
|
|
|
|
//std::cout << "(((( set frame " << model_frames[n] << " ))))\n";
|
|
|
|
}
|
2009-08-29 13:09:03 -04:00
|
|
|
}
|
|
|
|
|
2009-08-29 13:23:00 -04:00
|
|
|
m_rtt_main_node->setScale( core::vector3df(35.0f, 35.0f, 35.0f) );
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
//vector3d< f32 > modelsize = mesh->getBoundingBox().getExtent();
|
|
|
|
//std::cout << "box size " << modelsize.X*50.0 << ", " << modelsize.Y*50.0 << ", " << modelsize.Z*50.0 << std::endl;
|
|
|
|
|
|
|
|
irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 120, 120, 120));
|
|
|
|
|
|
|
|
const core::vector3df &sun_pos = core::vector3df( 0, 200, 100.0f );
|
|
|
|
m_light = irr_driver->getSceneManager()->addLightSceneNode(NULL, sun_pos, video::SColorf(1.0f,1.0f,1.0f), 10000.0f /* radius */);
|
2009-10-25 20:03:23 -04:00
|
|
|
m_light->getLightData().DiffuseColor = irr::video::SColorf(0.5f, 0.5f, 0.5f, 0.5f);
|
2009-08-29 13:09:03 -04:00
|
|
|
m_light->getLightData().SpecularColor = irr::video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
m_rtt_main_node->setMaterialFlag(EMF_GOURAUD_SHADING , true);
|
|
|
|
m_rtt_main_node->setMaterialFlag(EMF_LIGHTING, true);
|
|
|
|
|
|
|
|
const int materials = m_rtt_main_node->getMaterialCount();
|
|
|
|
for (int n=0; n<materials; n++)
|
|
|
|
{
|
|
|
|
m_rtt_main_node->getMaterial(n).setFlag(EMF_LIGHTING, true);
|
|
|
|
|
2009-08-29 13:23:00 -04:00
|
|
|
m_rtt_main_node->getMaterial(n).Shininess = 100.0f; // set size of specular highlights
|
|
|
|
m_rtt_main_node->getMaterial(n).SpecularColor.set(255,50,50,50);
|
2009-08-29 13:09:03 -04:00
|
|
|
m_rtt_main_node->getMaterial(n).DiffuseColor.set(255,150,150,150);
|
|
|
|
|
|
|
|
m_rtt_main_node->getMaterial(n).setFlag(EMF_GOURAUD_SHADING , true);
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:36:35 -05:00
|
|
|
m_camera = irr_driver->getSceneManager()->addCameraSceneNode();
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2009-08-29 13:23:00 -04:00
|
|
|
m_camera->setPosition( core::vector3df(0.0, 20.0f, 70.0f) );
|
2009-08-29 13:09:03 -04:00
|
|
|
m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
|
|
|
|
m_camera->setTarget( core::vector3df(0, 10, 0.0f) );
|
2009-08-29 13:23:00 -04:00
|
|
|
m_camera->setFOV( DEGREE_TO_RAD*50.0f );
|
2009-08-29 13:09:03 -04:00
|
|
|
m_camera->updateAbsolutePosition();
|
2009-08-29 15:59:27 -04:00
|
|
|
|
|
|
|
// Detach the note from the scene so we can render it independently
|
|
|
|
m_rtt_main_node->setVisible(false);
|
|
|
|
m_light->setVisible(false);
|
2009-09-08 08:50:52 -04:00
|
|
|
} // setupRTTScene
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2009-09-08 08:50:52 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-08-29 13:09:03 -04:00
|
|
|
void IrrDriver::RTTProvider::tearDownRTTScene()
|
|
|
|
{
|
2009-08-29 15:59:27 -04:00
|
|
|
//if (m_rtt_main_node != NULL) m_rtt_main_node->drop();
|
|
|
|
if (m_rtt_main_node != NULL) m_rtt_main_node->remove();
|
|
|
|
if (m_light != NULL) m_light->remove();
|
|
|
|
if (m_camera != NULL) m_camera->remove();
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
m_rtt_main_node = NULL;
|
|
|
|
m_camera = NULL;
|
|
|
|
m_light = NULL;
|
2009-09-08 08:50:52 -04:00
|
|
|
} // tearDownRTTScene
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2009-09-08 08:50:52 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-08-29 13:09:03 -04:00
|
|
|
/**
|
|
|
|
* Performs the actual render-to-texture
|
|
|
|
* \param target The texture to render the meshes to.
|
|
|
|
* \param angle (Optional) heading for all meshes.
|
|
|
|
*/
|
2009-09-08 08:50:52 -04:00
|
|
|
ITexture* IrrDriver::RTTProvider::renderToTexture(float angle,
|
|
|
|
bool is_2d_render)
|
2009-08-29 13:09:03 -04:00
|
|
|
{
|
2009-09-08 08:50:52 -04:00
|
|
|
// Rendering a 2d only model (using direct opengl rendering)
|
|
|
|
// does not work if setRenderTarget is called here again.
|
|
|
|
// And rendering 3d only works if it is called here :(
|
|
|
|
if(!is_2d_render)
|
|
|
|
m_video_driver->setRenderTarget(m_render_target_texture);
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2009-08-29 15:59:27 -04:00
|
|
|
if (angle != -1 && m_rtt_main_node != NULL) m_rtt_main_node->setRotation( core::vector3df(0, angle, 0) );
|
|
|
|
|
|
|
|
if (m_rtt_main_node == NULL)
|
|
|
|
{
|
|
|
|
irr_driver->getSceneManager()->drawAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rtt_main_node->setVisible(true);
|
|
|
|
m_light->setVisible(true);
|
|
|
|
irr_driver->getSceneManager()->drawAll();
|
|
|
|
m_rtt_main_node->setVisible(false);
|
|
|
|
m_light->setVisible(false);
|
|
|
|
}
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
m_video_driver->setRenderTarget(0, false, false);
|
|
|
|
return m_render_target_texture;
|
|
|
|
}
|