From 366a458a6bf921dd081e27ee556cf5c1033755cf Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Thu, 22 Oct 2015 19:13:41 -0400 Subject: [PATCH 1/9] Remove a few unused files, see #2066 --- data/gui/challenges.stkgui | 20 -------------------- data/gui/enter_player_name_dialog.stkgui | 21 --------------------- 2 files changed, 41 deletions(-) delete mode 100644 data/gui/challenges.stkgui delete mode 100644 data/gui/enter_player_name_dialog.stkgui diff --git a/data/gui/challenges.stkgui b/data/gui/challenges.stkgui deleted file mode 100644 index 76fb5c19f..000000000 --- a/data/gui/challenges.stkgui +++ /dev/null @@ -1,20 +0,0 @@ - - - - -
- -
- - - - - - - - - - -
-
diff --git a/data/gui/enter_player_name_dialog.stkgui b/data/gui/enter_player_name_dialog.stkgui deleted file mode 100644 index 45176b442..000000000 --- a/data/gui/enter_player_name_dialog.stkgui +++ /dev/null @@ -1,21 +0,0 @@ - - -
- -
-
From f9f9b660d3898febe4478b1dd94bdcc19ba82607 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sun, 25 Oct 2015 21:21:05 -0400 Subject: [PATCH 2/9] Rename profiler marker to clarify what it measures --- src/modes/world.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index e73b1ac64..d79513c70 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -954,7 +954,7 @@ void World::update(float dt) m_physics->update(dt); } - PROFILER_PUSH_CPU_MARKER("World::update (AI)", 0x40, 0x7F, 0x00); + PROFILER_PUSH_CPU_MARKER("World::update (Kart::upate)", 0x40, 0x7F, 0x00); const int kart_amount = (int)m_karts.size(); for (int i = 0 ; i < kart_amount; ++i) { From af68319da7f6f7a730c67a7ba407598bae1d69a0 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sun, 25 Oct 2015 21:22:45 -0400 Subject: [PATCH 3/9] Add profiler marker to measure material handling in Kart::update --- src/karts/kart.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 2369fab4b..9187258a9 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1252,6 +1252,8 @@ void Kart::update(float dt) { m_body->getBroadphaseHandle()->m_collisionFilterGroup = old_group; } + + PROFILER_PUSH_CPU_MARKER("Kart::Update (material)", 0x60, 0x34, 0x7F); handleMaterialGFX(); const Material* material=m_terrain_info->getMaterial(); if (!material) // kart falling off the track @@ -1309,6 +1311,7 @@ void Kart::update(float dt) #endif } } // if there is material + PROFILER_POP_CPU_MARKER(); // Check if any item was hit. // check it if we're not in a network world, or if we're on the server (when network mode is on) From c5b8c3e3e9938fe31093be0994633863574adb21 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 27 Oct 2015 14:59:20 +1100 Subject: [PATCH 4/9] Try to improve performance for sfx (#2154). --- src/karts/kart.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 2369fab4b..8b3735d69 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1447,7 +1447,11 @@ void Kart::handleMaterialSFX(const Material *material) // In case that three sfx needed to be played (i.e. a previous is // playing, a current is playing, and a new terrain with sfx is // entered), the oldest (previous) sfx is stopped and deleted. - if(getLastMaterial()!=material) + + // FIXME: if there are already two sfx playing, don't add another + // one. This should reduce the performance impact when driving + // on the bridge in Cocoa. + if(getLastMaterial()!=material && !m_previous_terrain_sound) { // First stop any previously playing terrain sound // and remove it, so that m_previous_terrain_sound From 953c29089e6a7273dc08828fc565ef7be7a25deb Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Tue, 27 Oct 2015 18:33:54 -0400 Subject: [PATCH 5/9] Scripting : start adding features to control light objects --- src/scriptengine/script_track.cpp | 23 +++++++++++++++++++++++ src/tracks/track_object.hpp | 4 ++++ src/tracks/track_object_presentation.cpp | 12 +++++++++++- src/tracks/track_object_presentation.hpp | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index b909802fb..213b4bc12 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -213,6 +213,25 @@ namespace Scripting /** @} */ } + // ----------- Light Object methods ----------- + + namespace Light + { + /** + * @addtogroup Scripting_Light Light (script binding) + * Type returned by trackObject.getLight() + * @{ + */ + + void setEnergy(float energy, /** \cond DOXYGEN_IGNORE */void *memory /** \endcond */) + { + ((TrackObjectPresentationLight*)memory)->setEnergy(energy); + } + + /** @} */ + } + + // ----------- Sound Object methods ----------- namespace SoundEmitter @@ -289,6 +308,7 @@ namespace Scripting r = engine->RegisterObjectType("ParticleEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); r = engine->RegisterObjectType("SoundEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); r = engine->RegisterObjectType("Animator", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectType("Light", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); //r = engine->RegisterGlobalFunction("void disableTrackObject(const string &in)", asFUNCTION(disableTrackObject), asCALL_CDECL); assert(r >= 0); //r = engine->RegisterGlobalFunction("void enableTrackObject(const string &in)", asFUNCTION(enableTrackObject), asCALL_CDECL); assert(r >= 0); @@ -305,6 +325,7 @@ namespace Scripting // TrackObject r = engine->RegisterObjectMethod("TrackObject", "void setEnabled(bool status)", asMETHOD(::TrackObject, setEnabled), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "SoundEmitter@ getSoundEmitter()", asMETHOD(::TrackObject, getSoundEmitter), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Light@ getLight()", asMETHOD(::TrackObject, getLight), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "PhysicalObject@ getPhysics()", asMETHOD(::TrackObject, getPhysics), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "Mesh@ getMesh()", asMETHOD(::TrackObject, getMesh), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "ParticleEmitter@ getParticleEmitter()", asMETHOD(::TrackObject, getParticleEmitter), asCALL_THISCALL); assert(r >= 0); @@ -335,6 +356,8 @@ namespace Scripting r = engine->RegisterObjectMethod("SoundEmitter", "void playOnce()", asFUNCTION(SoundEmitter::playOnce), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("SoundEmitter", "void playLoop()", asFUNCTION(SoundEmitter::playLoop), asCALL_CDECL_OBJLAST); assert(r >= 0); + // Light + r = engine->RegisterObjectMethod("Light", "void setEnergy(float)", asFUNCTION(Light::setEnergy), asCALL_CDECL_OBJLAST); assert(r >= 0); // Curve based Animation //fails due to insufficient visibility to scripts TODO : Decide whether to fix visibility or introduce wrappers diff --git a/src/tracks/track_object.hpp b/src/tracks/track_object.hpp index 88e629080..0fe791cf5 100644 --- a/src/tracks/track_object.hpp +++ b/src/tracks/track_object.hpp @@ -197,6 +197,10 @@ public: * On the script side, the returned object is of type : @ref Scripting_SoundEmitter */ TrackObjectPresentationSound* getSoundEmitter(){ return getPresentation(); } + /** Should only be used on sound emitter track objects. + * On the script side, the returned object is of type : @ref Scripting_Light + */ + TrackObjectPresentationLight* getLight() { return getPresentation(); } // For angelscript. Needs to be named something different than getAnimator since it's overloaded. /** Should only be used on TrackObjects that use curve-based animation. * On the script side, the returned object is of type : @ref Scripting_Animator diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 0402d6875..409deaff9 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -25,6 +25,7 @@ #include "graphics/camera.hpp" #include "graphics/central_settings.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/light.hpp" #include "graphics/material_manager.hpp" #include "graphics/mesh_tools.hpp" #include "graphics/particle_emitter.hpp" @@ -972,7 +973,16 @@ TrackObjectPresentationLight::TrackObjectPresentationLight( TrackObjectPresentationLight::~TrackObjectPresentationLight() { } // ~TrackObjectPresentationLight - +// ---------------------------------------------------------------------------- +void TrackObjectPresentationLight::setEnergy(float energy) +{ + m_energy = energy; + LightNode* lnode = dynamic_cast(m_node); + if (lnode != NULL) + { + lnode->setEnergy(energy); + } +} // ---------------------------------------------------------------------------- TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger( const XMLNode& xml_node) diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index 151d31bbd..a6f7fbbca 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -359,6 +359,7 @@ public: TrackObjectPresentationLight(const XMLNode& xml_node, scene::ISceneNode* parent); virtual ~TrackObjectPresentationLight(); + void setEnergy(float energy); }; // TrackObjectPresentationLight // ============================================================================ From 66909086fd29948019fce6dba5686cc97322838a Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Tue, 27 Oct 2015 19:08:12 -0400 Subject: [PATCH 6/9] Scripting : allow smoothly animating lights --- src/scriptengine/script_track.cpp | 6 +++++ src/tracks/track_object_presentation.cpp | 28 ++++++++++++++++++++++++ src/tracks/track_object_presentation.hpp | 7 ++++++ 3 files changed, 41 insertions(+) diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index 213b4bc12..36821c080 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -228,6 +228,11 @@ namespace Scripting ((TrackObjectPresentationLight*)memory)->setEnergy(energy); } + void animateEnergy(float energy, float duration, /** \cond DOXYGEN_IGNORE */void *memory /** \endcond */) + { + ((TrackObjectPresentationLight*)memory)->setEnergy(energy, duration); + } + /** @} */ } @@ -358,6 +363,7 @@ namespace Scripting // Light r = engine->RegisterObjectMethod("Light", "void setEnergy(float)", asFUNCTION(Light::setEnergy), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("Light", "void animateEnergy(float, float)", asFUNCTION(Light::animateEnergy), asCALL_CDECL_OBJLAST); assert(r >= 0); // Curve based Animation //fails due to insufficient visibility to scripts TODO : Decide whether to fix visibility or introduce wrappers diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 409deaff9..6161f4e47 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -967,6 +967,11 @@ TrackObjectPresentationLight::TrackObjectPresentationLight( { m_node = NULL; // lights require shaders to work } + + m_energy_animation_from = 0.0f; + m_energy_animation_to = 0.0f; + m_energy_animation_total_duration = 0.0f; + m_energy_animation_remaining_duration = 0.0f; } // TrackObjectPresentationLight // ---------------------------------------------------------------------------- @@ -984,6 +989,29 @@ void TrackObjectPresentationLight::setEnergy(float energy) } } // ---------------------------------------------------------------------------- +void TrackObjectPresentationLight::setEnergy(float energy, float duration) +{ + m_energy_animation_from = m_energy; + m_energy_animation_to = energy; + m_energy_animation_total_duration = duration; + m_energy_animation_remaining_duration = duration; +} +// ---------------------------------------------------------------------------- +void TrackObjectPresentationLight::update(float dt) +{ + if (m_energy_animation_remaining_duration > 0.0f) + { + m_energy_animation_remaining_duration -= dt; + if (m_energy_animation_remaining_duration < 0.0f) + m_energy_animation_remaining_duration = 0.0f; + + float ratio = m_energy_animation_remaining_duration / m_energy_animation_total_duration; + + setEnergy(m_energy_animation_from + + (m_energy_animation_to - m_energy_animation_from)*(1.0f - ratio)); + } +} +// ---------------------------------------------------------------------------- TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger( const XMLNode& xml_node) : TrackObjectPresentation(xml_node) diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index a6f7fbbca..ca4ba2b0b 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -355,11 +355,18 @@ private: float m_distance; float m_energy; + float m_energy_animation_from; + float m_energy_animation_to; + float m_energy_animation_total_duration; + float m_energy_animation_remaining_duration; + public: TrackObjectPresentationLight(const XMLNode& xml_node, scene::ISceneNode* parent); virtual ~TrackObjectPresentationLight(); void setEnergy(float energy); + void setEnergy(float energy, float duration); + virtual void update(float dt) OVERRIDE; }; // TrackObjectPresentationLight // ============================================================================ From b9b2b538fad7b7a056cff8e2d275b0aa87429f2a Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 30 Oct 2015 18:08:02 +0800 Subject: [PATCH 7/9] Clean up freetype code 1. Remove all ifdef of freetype 2. Require freetype in CMake 3. Clean up declaration 4. Add leak check 5. Make script language display better in title --- CMakeLists.txt | 22 +- src/graphics/stk_text_billboard.cpp | 6 +- src/guiengine/engine.cpp | 106 +---- src/guiengine/engine.hpp | 8 - src/guiengine/ft_environment.cpp | 2 - src/guiengine/ft_environment.hpp | 5 + src/guiengine/glyph_page_creator.cpp | 6 - src/guiengine/glyph_page_creator.hpp | 13 +- src/guiengine/scalable_font.cpp | 531 +++-------------------- src/guiengine/scalable_font.hpp | 50 --- src/states_screens/options_screen_ui.cpp | 4 +- 11 files changed, 105 insertions(+), 648 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e67e802be..2d02a92bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,6 @@ if (NOT CMAKE_BUILD_TYPE) endif() option(USE_WIIUSE "Support for wiimote input devices" ON) -option(USE_FREETYPE "Use Freetype to render text" ON) option(USE_FRIBIDI "Support for right-to-left languages" ON) option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON) option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF) @@ -166,14 +165,12 @@ else() endif() # Freetype -if(USE_FREETYPE) - find_package(Freetype) - if(FREETYPE_FOUND) - include_directories(${FREETYPE_INCLUDE_DIRS}) - else() - message(FATAL_ERROR "Freetype not found. " - "Either install freetype or disable freetype rendering support with -DUSE_FREETYPE=0 ") - endif() +find_package(Freetype) +if(FREETYPE_FOUND) + include_directories(${FREETYPE_INCLUDE_DIRS}) +else() + message(FATAL_ERROR "Freetype not found. " + "Freetype is required to display characters in SuperTuxKart. ") endif() # Fribidi @@ -351,7 +348,7 @@ target_link_libraries(supertuxkart ${OGGVORBIS_LIBRARIES} ${OPENAL_LIBRARY} ${OPENGL_LIBRARIES} - ${FREETPYE_LIBRARIES} + ${FREETYPE_LIBRARIES} ) if(UNIX AND NOT APPLE) @@ -381,11 +378,6 @@ if(USE_FRIBIDI) add_definitions(-DENABLE_BIDI) endif() -if(USE_FREETYPE) - target_link_libraries(supertuxkart ${FREETYPE_LIBRARIES}) - add_definitions(-DENABLE_FREETYPE) -endif() - # Wiiuse # ------ if(USE_WIIUSE) diff --git a/src/graphics/stk_text_billboard.cpp b/src/graphics/stk_text_billboard.cpp index 3ab19cd7c..756ef1927 100644 --- a/src/graphics/stk_text_billboard.cpp +++ b/src/graphics/stk_text_billboard.cpp @@ -67,11 +67,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon font->doDraw(text, core::rect(0, 0, size.Width, size.Height), video::SColor(255,255,255,255), false, false, NULL, this); -#ifdef ENABLE_FREETYPE - const float scale = 0.03f; //Larger for ttf font as they are less bold -#else - const float scale = 0.018f; -#endif // ENABLE_FREETYPE + const float scale = 0.03f; //scene::SMesh* mesh = new scene::SMesh(); std::map buffers; diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index b4815da8c..bcf3fd5e8 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -688,10 +688,8 @@ namespace GUIEngine { IGUIEnvironment* g_env; Skin* g_skin = NULL; -#ifdef ENABLE_FREETYPE FTEnvironment* g_ft_env = NULL; GlyphPageCreator* g_gp_creator = NULL; -#endif // ENABLE_FREETYPE ScalableFont *g_font; ScalableFont *g_outline_font; ScalableFont *g_large_font; @@ -956,12 +954,10 @@ namespace GUIEngine //if (g_skin != NULL) delete g_skin; g_skin = NULL; -#ifdef ENABLE_FREETYPE g_ft_env->~FTEnvironment(); g_ft_env = NULL; g_gp_creator->~GlyphPageCreator(); g_gp_creator = NULL; -#endif // ENABLE_FREETYPE for (unsigned int i=0; isetMonospaceDigits(true); g_digit_font = digit_font; @@ -1081,16 +1071,16 @@ namespace GUIEngine sfont2->setKerningWidth(0); // Because the fallback font is much smaller than the title font: sfont2->m_fallback_font_scale = 2.0f; - sfont2->m_fallback_kerning_width = 5; + sfont2->m_fallback_kerning_width = 0; ScalableFont* sfont =new ScalableFont(g_env,T_NORMAL); sfont->setKerningHeight(0); - sfont->setScale(normal_text_scale); + sfont->setScale(1); g_font = sfont; Private::font_height = g_font->getDimension( L"X" ).Height; ScalableFont* sfont_larger = sfont->getHollowCopy(); - sfont_larger->setScale(normal_text_scale*1.4f); + sfont_larger->setScale(1.4f); sfont_larger->setKerningHeight(0); g_large_font = sfont_larger; @@ -1100,7 +1090,7 @@ namespace GUIEngine Private::large_font_height = g_large_font->getDimension( L"X" ).Height; ScalableFont* sfont_smaller = sfont->getHollowCopy(); - sfont_smaller->setScale(normal_text_scale*0.8f); + sfont_smaller->setScale(0.8f); sfont_smaller->setKerningHeight(0); g_small_font = sfont_smaller; @@ -1108,83 +1098,11 @@ namespace GUIEngine g_small_font->getDimension( L"X" ).Height; sfont2->m_fallback_font = sfont; - sfont2->setScale(title_text_scale); + sfont2->setScale(1); sfont2->m_black_border = true; g_title_font = sfont2; Private::title_font_height = g_title_font->getDimension( L"X" ).Height; -#else - // font size is resolution-dependent. - // normal text will range from 0.8, in 640x* resolutions (won't scale - // below that) to 1.0, in 1024x* resolutions, and linearly up - // normal text will range from 0.2, in 640x* resolutions (won't scale - // below that) to 0.4, in 1024x* resolutions, and linearly up - const int screen_width = irr_driver->getFrameSize().Width; - const int screen_height = irr_driver->getFrameSize().Height; - float scale = std::max(0, screen_width - 640)/564.0f; - - // attempt to compensate for small screens - if (screen_width < 1200) scale = std::max(0, screen_width - 640) / 750.0f; - if (screen_width < 900 || screen_height < 700) scale = std::min(scale, 0.05f); - - Log::info("GUIEngine", "scale: %f", scale); - - float normal_text_scale = 0.7f + 0.2f*scale; - float title_text_scale = 0.2f + 0.2f*scale; - - ScalableFont* sfont = - new ScalableFont(g_env, - file_manager->getAssetChecked(FileManager::FONT, - "StkFont.xml",true) ); - sfont->setScale(normal_text_scale); - sfont->setKerningHeight(-5); - g_font = sfont; - - ScalableFont* digit_font = - new ScalableFont(g_env, - file_manager->getAssetChecked(FileManager::FONT, - "BigDigitFont.xml",true)); - digit_font->lazyLoadTexture(0); // make sure the texture is loaded for this one - digit_font->setMonospaceDigits(true); - g_digit_font = digit_font; - - Private::font_height = g_font->getDimension( L"X" ).Height; - - ScalableFont* sfont_larger = sfont->getHollowCopy(); - sfont_larger->setScale(normal_text_scale*1.4f); - sfont_larger->setKerningHeight(-5); - g_large_font = sfont_larger; - - g_outline_font = sfont->getHollowCopy(); - g_outline_font->m_black_border = true; - - Private::large_font_height = g_large_font->getDimension( L"X" ).Height; - - ScalableFont* sfont_smaller = sfont->getHollowCopy(); - sfont_smaller->setScale(normal_text_scale*0.8f); - sfont_smaller->setKerningHeight(-5); - g_small_font = sfont_smaller; - - Private::small_font_height = - g_small_font->getDimension( L"X" ).Height; - - - ScalableFont* sfont2 = - new ScalableFont(g_env, - file_manager->getAssetChecked(FileManager::FONT, - "title_font.xml", - true) ); - sfont2->m_fallback_font = sfont; - // Because the fallback font is much smaller than the title font: - sfont2->m_fallback_font_scale = 4.0f; - sfont2->m_fallback_kerning_width = 15; - sfont2->setScale(title_text_scale); - sfont2->setKerningWidth(-18); - sfont2->m_black_border = true; - g_title_font = sfont2; - Private::title_font_height = - g_title_font->getDimension( L"X" ).Height; -#endif // ENABLE_FREETYPE if (g_font != NULL) g_skin->setFont(g_font); @@ -1202,15 +1120,13 @@ namespace GUIEngine void reloadHollowCopyFont(irr::gui::ScalableFont* sfont) { //Base on the init function above - float normal_text_scale = 1; - - sfont->setScale(normal_text_scale); - sfont->setKerningHeight(-5); + sfont->setScale(1); + sfont->setKerningHeight(0); Private::font_height = sfont->getDimension( L"X" ).Height; ScalableFont* sfont_larger = sfont->getHollowCopy(); - sfont_larger->setScale(normal_text_scale*1.4f); - sfont_larger->setKerningHeight(-5); + sfont_larger->setScale(1.4f); + sfont_larger->setKerningHeight(0); g_large_font = sfont_larger; g_outline_font = sfont->getHollowCopy(); @@ -1219,8 +1135,8 @@ namespace GUIEngine Private::large_font_height = g_large_font->getDimension( L"X" ).Height; ScalableFont* sfont_smaller = sfont->getHollowCopy(); - sfont_smaller->setScale(normal_text_scale*0.8f); - sfont_smaller->setKerningHeight(-5); + sfont_smaller->setScale(0.8f); + sfont_smaller->setKerningHeight(0); g_small_font = sfont_smaller; Private::small_font_height = g_small_font->getDimension( L"X" ).Height; diff --git a/src/guiengine/engine.hpp b/src/guiengine/engine.hpp index 2a182e643..8f68c8a98 100644 --- a/src/guiengine/engine.hpp +++ b/src/guiengine/engine.hpp @@ -39,10 +39,8 @@ namespace irr #include "utils/constants.hpp" #include "utils/ptr_vector.hpp" -#ifdef ENABLE_FREETYPE #include "guiengine/ft_environment.hpp" #include "guiengine/glyph_page_creator.hpp" -#endif // ENABLE_FREETYPE /** * \ingroup guiengine @@ -86,10 +84,8 @@ namespace GUIEngine { extern irr::gui::IGUIEnvironment* g_env; extern Skin* g_skin; -#ifdef ENABLE_FREETYPE extern FTEnvironment* g_ft_env; extern GlyphPageCreator* g_gp_creator; -#endif // ENABLE_FREETYPE extern irr::gui::ScalableFont* g_small_font; extern irr::gui::ScalableFont* g_font; extern irr::gui::ScalableFont* g_outline_font; @@ -181,7 +177,6 @@ namespace GUIEngine */ inline Skin* getSkin() { return Private::g_skin; } -#ifdef ENABLE_FREETYPE /** * \pre GUIEngine::init must have been called first * \return the freetype and library with face @@ -193,7 +188,6 @@ namespace GUIEngine * \return the glyph page creator, useful to create a glyph page from individual char */ inline GlyphPageCreator* getGlyphPageCreator() { return Private::g_gp_creator; } -#endif // ENABLE_FREETYPE Screen* getScreenNamed(const char* name); @@ -271,13 +265,11 @@ namespace GUIEngine */ void reloadSkin(); -#ifdef ENABLE_FREETYPE /** * \brief call when translation in user config was updated for freetype rendering STK */ void cleanHollowCopyFont(); void reloadHollowCopyFont(irr::gui::ScalableFont*); -#endif // ENABLE_FREETYPE } #endif diff --git a/src/guiengine/ft_environment.cpp b/src/guiengine/ft_environment.cpp index a80210238..82072bee0 100644 --- a/src/guiengine/ft_environment.cpp +++ b/src/guiengine/ft_environment.cpp @@ -15,7 +15,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifdef ENABLE_FREETYPE #include "guiengine/ft_environment.hpp" #include "guiengine/get_font_properties.hpp" #include "io/file_manager.hpp" @@ -98,4 +97,3 @@ FT_Library FTEnvironment::ft_lib = NULL; FT_Error FTEnvironment::ft_err = 0; } // guiengine -#endif // ENABLE_FREETYPE diff --git a/src/guiengine/ft_environment.hpp b/src/guiengine/ft_environment.hpp index 3d663a610..cea22930b 100644 --- a/src/guiengine/ft_environment.hpp +++ b/src/guiengine/ft_environment.hpp @@ -19,6 +19,8 @@ #include "guiengine/get_font_properties.hpp" #include FT_FREETYPE_H +#include "utils/leak_check.hpp" + /** * \ingroup guiengine */ @@ -30,6 +32,9 @@ namespace GUIEngine class FTEnvironment { public: + + LEAK_CHECK() + FTEnvironment(); ~FTEnvironment(); FT_Face ft_face[irr::gui::F_COUNT]; diff --git a/src/guiengine/glyph_page_creator.cpp b/src/guiengine/glyph_page_creator.cpp index 86f7fcf55..aeeadf3f8 100644 --- a/src/guiengine/glyph_page_creator.cpp +++ b/src/guiengine/glyph_page_creator.cpp @@ -21,7 +21,6 @@ // // http://irrlicht.suckerfreegames.com/ -#ifdef ENABLE_FREETYPE #include #include "guiengine/engine.hpp" @@ -151,9 +150,4 @@ bool GlyphPageCreator::insertGlyph(FT_Bitmap bits, core::rect& rect) return true; } -u32 GlyphPageCreator::used_width = 0; -u32 GlyphPageCreator::used_height = 0; -u32 GlyphPageCreator::temp_height = 0; - } // guiengine -#endif // ENABLE_FREETYPE diff --git a/src/guiengine/glyph_page_creator.hpp b/src/guiengine/glyph_page_creator.hpp index 393b43fd8..58a028987 100644 --- a/src/guiengine/glyph_page_creator.hpp +++ b/src/guiengine/glyph_page_creator.hpp @@ -21,6 +21,8 @@ #include FT_FREETYPE_H #include +#include "utils/leak_check.hpp" + using namespace irr; /** @@ -34,6 +36,9 @@ namespace GUIEngine class GlyphPageCreator { public: + + LEAK_CHECK() + GlyphPageCreator(); ~GlyphPageCreator(); @@ -51,7 +56,7 @@ namespace GUIEngine /** Reset position of glyph on the current glyph page. */ - static void clearGlyphPage(); + void clearGlyphPage(); /** Clear (fill it with transparent content) the current glyph page. */ @@ -87,9 +92,9 @@ namespace GUIEngine */ video::IImage* page; - static u32 temp_height; - static u32 used_width; - static u32 used_height; + u32 temp_height; + u32 used_width; + u32 used_height; }; } // guiengine diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index 3c5079e43..5ca3f0cfd 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -26,7 +26,6 @@ namespace gui { //! constructor -#ifdef ENABLE_FREETYPE ScalableFont::ScalableFont(IGUIEnvironment *env, TTFLoadingType type) : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) @@ -90,51 +89,6 @@ void ScalableFont::recreateFromLanguage() Log::fatal("ScalableFont", "Recreation of TTF font failed"); } } -#else -ScalableFont::ScalableFont(IGUIEnvironment *env, const std::string &filename) - : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), - MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) -{ -#ifdef _DEBUG - setDebugName("ScalableFont"); -#endif - - m_fallback_font = NULL; - m_fallback_kerning_width = 0; - m_fallback_font_scale = 1.0f; - m_scale = 1.0f; - m_is_hollow_copy = false; - m_black_border = false; - m_shadow = false; - m_mono_space_digits = false; - m_rtl = translations->isRTLLanguage(); - - if (Environment) - { - // don't grab environment, to avoid circular references - Driver = Environment->getVideoDriver(); - - SpriteBank = Environment->addEmptySpriteBank(io::path(filename.c_str())); - if (SpriteBank) - SpriteBank->grab(); - } - - if (Driver) - Driver->grab(); - - setInvisibleCharacters ( L" " ); - - io::IXMLReader* reader = file_manager->createXMLReader(filename.c_str()); - if (!load( reader )) - { - Log::fatal("ScalableFont", "Loading font failed"); - } - reader->drop(); - - assert(Areas.size() > 0); -} - -#endif // ENABLE_FREETYPE //! destructor ScalableFont::~ScalableFont() @@ -157,204 +111,6 @@ void ScalableFont::setShadow(const irr::video::SColor &col) m_shadow_color = col; } -#ifndef ENABLE_FREETYPE -void ScalableFont::doReadXmlFile(io::IXMLReader* xml) -{ - int trim_top = 0; - int trim_bottom = 0; - - while (xml->read()) - { - if (io::EXN_ELEMENT == xml->getNodeType()) - { - if (core::stringw(L"include") == xml->getNodeName()) - { - core::stringc filename = xml->getAttributeValue(L"file"); - /* - const wchar_t* iflangis = xml->getAttributeValue(L"iflanguage"); - - Log::info("ScalableFont", "langcode = %s", translations->getCurrentLanguageCode().c_str()); - - if (iflangis != NULL && - core::stringc(iflangis) != translations->getCurrentLanguageCode().c_str()) - { - continue; - } - */ - - io::IXMLReader* included = file_manager->createXMLReader( - file_manager->getAsset(FileManager::FONT, filename.c_str())); - if (included != NULL) - { - doReadXmlFile(included); - included->drop(); - } - } - else if (core::stringw(L"Texture") == xml->getNodeName()) - { - // add a texture - core::stringc filename = xml->getAttributeValue(L"filename"); - core::stringc fn = file_manager->getAsset(FileManager::FONT, - filename.c_str()).c_str(); - u32 i = (u32)xml->getAttributeValueAsInt(L"index"); - - float scale=1.0f; - if(xml->getAttributeValue(L"scale")) - { - scale = xml->getAttributeValueAsFloat(L"scale"); - //Log::info("ScalableFont", "scale = %f", scale); - } - - bool excludeFromMaxHeightCalculation = false; - if (xml->getAttributeValue(L"excludeFromMaxHeightCalculation")) - excludeFromMaxHeightCalculation = (core::stringc(xml->getAttributeValue(L"excludeFromMaxHeightCalculation")) == "true"); - - core::stringw alpha = xml->getAttributeValue(L"hasAlpha"); - - //Log::info("ScalableFont", "Adding font texture %s; alpha = %s", fn.c_str(), alpha.c_str()); - - - // make sure the sprite bank has enough textures in it - while (i+1 > SpriteBank->getTextureCount()) - { - SpriteBank->addTexture(NULL); - } - - TextureInfo info; - info.m_file_name = fn; - info.m_has_alpha = (alpha == core::stringw("true")); - info.m_scale = scale; - info.m_exclude_from_max_height_calculation = excludeFromMaxHeightCalculation; - - -#ifdef DEBUG - if (m_texture_files.find(i) != m_texture_files.end()) - { - Log::warn("ScalableFont", "Font conflict, two images have texture %i.", i); - } -#endif - - m_texture_files[i] = info; - } - else if (core::stringw(L"font") == xml->getNodeName()) - { - trim_top = (u32)xml->getAttributeValueAsInt(L"trim_top"); // returns 0 if no such attribute - trim_bottom = (u32)xml->getAttributeValueAsInt(L"trim_bottom"); - } - else if (core::stringw(L"c") == xml->getNodeName()) - { - // adding a character to this font - SFontArea a; - SGUISpriteFrame f; - SGUISprite s; - core::rect rectangle; - - a.underhang = xml->getAttributeValueAsInt(L"u"); - a.overhang = xml->getAttributeValueAsInt(L"o"); - a.spriteno = SpriteBank->getSprites().size(); - s32 texno = xml->getAttributeValueAsInt(L"i"); - - // parse rectangle - core::stringc rectstr = xml->getAttributeValue(L"r"); - wchar_t ch = xml->getAttributeValue(L"c")[0]; - - const c8 *c = rectstr.c_str(); - s32 val; - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.UpperLeftCorner.X = val; - while (*c == L' ' || *c == L',') c++; - - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.UpperLeftCorner.Y = val + trim_top; - while (*c == L' ' || *c == L',') c++; - - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.LowerRightCorner.X = val; - while (*c == L' ' || *c == L',') c++; - - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.LowerRightCorner.Y = val - trim_bottom; - - CharacterMap[ch] = Areas.size(); - - //Log::info("ScalableFont", "Inserting character '%d' with area %d", (int)ch, Areas.size()); - - // make frame - f.rectNumber = SpriteBank->getPositions().size(); - f.textureNumber = texno; - - // add frame to sprite - s.Frames.push_back(f); - s.frameTime = 0; - - // add rectangle to sprite bank - SpriteBank->getPositions().push_back(rectangle); - a.width = rectangle.getWidth(); - - // add sprite to sprite bank - SpriteBank->getSprites().push_back(s); - - // add character to font - Areas.push_back(a); - } - } - } - -} - -//! loads a font file from xml -bool ScalableFont::load(io::IXMLReader* xml) -{ - if (!SpriteBank) - { - Log::error("ScalableFont::load", "SpriteBank is NULL!!"); - return false; - } - - doReadXmlFile(xml); - - // set bad character - WrongCharacter = getAreaIDFromCharacter(L' ', NULL); - - setMaxHeight(); - - for(wchar_t c='0'; c<='9'; c++) - { - SFontArea a = getAreaFromCharacter(c, NULL); - if(a.overhang > m_max_digit_area.overhang ) m_max_digit_area.overhang = a.overhang; - if(a.underhang > m_max_digit_area.underhang) m_max_digit_area.underhang = a.underhang; - if(a.width > m_max_digit_area.width ) m_max_digit_area.width = a.width; - } - m_max_digit_area.overhang = 0;m_max_digit_area.underhang=0; - return true; -} -#endif // ENABLE_FREETYPE - -#ifdef ENABLE_FREETYPE //! loads a font from a TTF file bool ScalableFont::loadTTF() { @@ -376,12 +132,12 @@ bool ScalableFont::loadTTF() m_dpi = cur_prop.size; std::vector offset; - std::vector bx; + std::vector bearingx; std::vector advance; std::vector height; std::set::iterator it; - s32 current_maxheight = 0; + s32 curr_maxheight = 0; s32 t; u32 texno = 0; SpriteBank->addTexture(NULL); @@ -437,22 +193,22 @@ bool ScalableFont::loadTTF() Log::error("ScalableFont::loadTTF", "Can't load a single glyph."); // Store vertical offset on line. - s32 offset_on_line = (curr_face->glyph->metrics.height >> 6) - curr_face->glyph->bitmap_top; - offset.push_back(offset_on_line); + s32 curr_offset = (curr_face->glyph->metrics.height >> 6) - curr_face->glyph->bitmap_top; + offset.push_back(curr_offset); // This is to be used later. t = curr_face->glyph->metrics.height >> 6; height.push_back(t); - if (t > current_maxheight) - current_maxheight = t; + if (t > curr_maxheight) + curr_maxheight = t; // Store horizontal padding (bearingX). - s32 bX = curr_face->glyph->bitmap_left; - bx.push_back(bX); + s32 curr_bearingx = curr_face->glyph->bitmap_left; + bearingx.push_back(curr_bearingx); // Store total width on horizontal line. - s32 width = curr_face->glyph->advance.x >> 6; - advance.push_back(width); + s32 curr_advance = curr_face->glyph->advance.x >> 6; + advance.push_back(curr_advance); // Convert to an anti-aliased bitmap FT_Bitmap bits = slot->bitmap; @@ -538,7 +294,7 @@ bool ScalableFont::loadTTF() //Storing now SFontArea a; a.spriteno = n; - a.offsety = current_maxheight - height.at(n) + a.offsety = curr_maxheight - height.at(n) + offset.at(n); //Compute the correct offset as ttf texture image is cropped against the glyph fully. a.offsety_bt = -offset.at(n); //FIXME @@ -550,7 +306,7 @@ bool ScalableFont::loadTTF() if (!n) //Skip width-less characters a.bearingx = 0; else - a.bearingx = bx.at(n); + a.bearingx = bearingx.at(n); if (!n) //Skip width-less characters a.width = 0; else @@ -563,10 +319,10 @@ bool ScalableFont::loadTTF() //Reserve 10 for normal font new characters added, 40 for digit font to display separately //Consider fallback font (bold) too - MaxHeight = (int)((current_maxheight + (m_type == T_DIGIT ? 40 : 10) + + MaxHeight = (int)((curr_maxheight + (m_type == T_DIGIT ? 40 : 10) + (m_type == T_BOLD ? 20 : 0))*m_scale); - GlyphMaxHeight = current_maxheight; + GlyphMaxHeight = curr_maxheight; for(wchar_t c='0'; c<='9'; c++) { @@ -611,8 +367,8 @@ bool ScalableFont::lazyLoadChar() GUIEngine::GlyphPageCreator* gp_creator = GUIEngine::getGlyphPageCreator(); s32 height; - s32 bX; - s32 offset_on_line; + s32 bearingx; + s32 curr_offset; s32 width; u32 texno = SpriteBank->getTextureCount() - 1; std::set::iterator it; @@ -653,9 +409,9 @@ bool ScalableFont::lazyLoadChar() if (err) Log::error("ScalableFont::loadTTF", "Can't load a single glyph."); - offset_on_line = (curr_face->glyph->metrics.height >> 6) - curr_face->glyph->bitmap_top; + curr_offset = (curr_face->glyph->metrics.height >> 6) - curr_face->glyph->bitmap_top; height = curr_face->glyph->metrics.height >> 6; - bX = curr_face->glyph->bitmap_left; + bearingx = curr_face->glyph->bitmap_left; width = curr_face->glyph->advance.x >> 6; FT_Bitmap bits = slot->bitmap; CharacterMap[*it] = SpriteBank->getSprites().size(); @@ -686,9 +442,9 @@ bool ScalableFont::lazyLoadChar() SFontArea a; a.spriteno = SpriteBank->getSprites().size() - 1; - a.offsety = GlyphMaxHeight - height + offset_on_line; - a.offsety_bt = -offset_on_line; - a.bearingx = bX; + a.offsety = GlyphMaxHeight - height + curr_offset; + a.offsety_bt = -curr_offset; + a.bearingx = bearingx; a.width = width; Areas.push_back(a); } @@ -729,42 +485,12 @@ void ScalableFont::forceNewPage() gp_creator->createNewGlyphPage(); } -#endif // ENABLE_FREETYPE void ScalableFont::setScale(const float scale) { m_scale = scale; } -#ifndef ENABLE_FREETYPE -void ScalableFont::setMaxHeight() -{ - MaxHeight = 0; - s32 t; - - core::array< core::rect >& p = SpriteBank->getPositions(); - core::array< SGUISprite >& sprites = SpriteBank->getSprites(); - - for (u32 i=0; iMaxHeight) - MaxHeight = t; - } - - MaxHeight = (int)(MaxHeight*m_scale); -} -#endif // ENABLE_FREETYPE @@ -780,18 +506,6 @@ s32 ScalableFont::getKerningWidth(const wchar_t* thisLetter, const wchar_t* prev { s32 ret = GlobalKerningWidth; -#ifndef ENABLE_FREETYPE - if (thisLetter) - { - ret += Areas[getAreaIDFromCharacter(*thisLetter, NULL)].overhang; - - if (previousLetter) - { - ret += Areas[getAreaIDFromCharacter(*previousLetter, NULL)].underhang; - } - } -#endif // ENABLE_FREETYPE - return ret; } @@ -880,7 +594,6 @@ void ScalableFont::setInvisibleCharacters( const wchar_t *s ) //! returns the dimension of text core::dimension2d ScalableFont::getDimension(const wchar_t* text) const { -#ifdef ENABLE_FREETYPE GUIEngine::GlyphPageCreator* gp_creator = GUIEngine::getGlyphPageCreator(); if (m_type == T_NORMAL || T_BOLD) //lazy load char @@ -901,7 +614,6 @@ core::dimension2d ScalableFont::getDimension(const wchar_t* text) const Log::error("ScalableFont::lazyLoadChar", "Can't insert new char into glyph pages."); } } -#endif // ENABLE_FREETYPE assert(Areas.size() > 0); @@ -925,10 +637,6 @@ core::dimension2d ScalableFont::getDimension(const wchar_t* text) const bool fallback = false; const SFontArea &area = getAreaFromCharacter(*p, &fallback); -#ifndef ENABLE_FREETYPE - thisLine.Width += area.underhang; -#endif // ENABLE_FREETYPE - thisLine.Width += getCharWidth(area, fallback); } @@ -1015,7 +723,6 @@ void ScalableFont::doDraw(const core::stringw& text, core::array offsets(text_size); std::vector fallback(text_size); -#ifdef ENABLE_FREETYPE if (m_type == T_NORMAL || T_BOLD) //lazy load char, have to do this again { //because some text isn't drawn with getDimension for (u32 i = 0; i= spriteAmount)) continue; + if (indices[n] == -1) continue; + + const int texID = (fallback[n] ? + (*fallback_sprites)[spriteID].Frames[0].textureNumber : + sprites[spriteID].Frames[0].textureNumber); + + core::rect source = (fallback[n] ? + (*fallback_positions)[(*fallback_sprites)[spriteID].Frames[0].rectNumber] : + positions[sprites[spriteID].Frames[0].rectNumber]); + + core::dimension2d size = source.getSize(); + + float scale = (fallback[n] ? m_scale*m_fallback_font_scale : m_scale); + size.Width = (int)(size.Width * scale); + size.Height = (int)(size.Height * scale); + + core::rect dest(offsets[n], size); + + video::ITexture* texture = (fallback[n] ? + m_fallback_font->SpriteBank->getTexture(texID) : + SpriteBank->getTexture(texID) ); + + for (int x_delta=-2; x_delta<=2; x_delta++) + { + for (int y_delta=-2; y_delta<=2; y_delta++) + { + if (x_delta == 0 || y_delta == 0) continue; + draw2DImage(texture, + dest + core::position2d(x_delta, y_delta), + source, + clip, + black, true); + } + } + } + } + for (int n=0; nm_texture_files.find(texID))).second : - (*(m_texture_files.find(texID))).second - ); - float char_scale = info.m_scale; -#endif // ENABLE_FREETYPE - core::dimension2d size = source.getSize(); float scale = (fallback[n] ? m_scale*m_fallback_font_scale : m_scale); - size.Width = (int)(size.Width * scale * char_scale); - size.Height = (int)(size.Height * scale * char_scale); + size.Width = (int)(size.Width * scale); + size.Height = (int)(size.Height * scale); - // align vertically if character is smaller -#ifndef ENABLE_FREETYPE - int y_shift = (size.Height < MaxHeight*m_scale ? (int)((MaxHeight*m_scale - size.Height)/2.0f) : 0); - - core::rect dest(offsets[n] + core::position2di(0, y_shift), size); -#else core::rect dest(offsets[n], size); -#endif // ENABLE_FREETYPE video::ITexture* texture = (fallback[n] ? m_fallback_font->SpriteBank->getTexture(texID) : @@ -1176,54 +906,7 @@ void ScalableFont::doDraw(const core::stringw& text, GL32_draw2DRectangle(video::SColor(255, 255,0,0), dest,clip); #endif -#ifndef ENABLE_FREETYPE - if (texture == NULL) - { - // perform lazy loading - - if (fallback[n]) - { - m_fallback_font->lazyLoadTexture(texID); - texture = m_fallback_font->SpriteBank->getTexture(texID); - } - else - { - lazyLoadTexture(texID); - texture = SpriteBank->getTexture(texID); - } - - if (texture == NULL) - { - Log::warn("ScalableFont", "Character not found in current font"); - continue; // no such character - } - } -#endif // ENABLE_FREETYPE - - if (m_black_border && charCollector == NULL) - { - // draw black border - video::SColor black(color.getAlpha(),0,0,0); - - for (int x_delta=-2; x_delta<=2; x_delta++) - { - for (int y_delta=-2; y_delta<=2; y_delta++) - { - if (x_delta == 0 || y_delta == 0) continue; - draw2DImage(texture, - dest + core::position2d(x_delta, y_delta), - source, - clip, - black, true); - } - } - } - -#ifdef ENABLE_FREETYPE if (fallback[n] || m_type == T_BOLD) -#else - if (fallback[n]) -#endif // ENABLE_FREETYPE { // TODO: don't hardcode colors? video::SColor orange(color.getAlpha(), 255, 100, 0); @@ -1269,78 +952,10 @@ void ScalableFont::doDraw(const core::stringw& text, } -#ifndef ENABLE_FREETYPE -void ScalableFont::lazyLoadTexture(int texID) -{ - Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true); - - // load texture - assert(m_texture_files[texID].m_file_name.size() > 0); - - // Font textures can not be resized (besides the impact on quality in - // this case, the indices in the xml files would become wrong). - core::dimension2du old_max_size = Driver->getDriverAttributes() - .getAttributeAsDimension2d("MAX_TEXTURE_SIZE"); - Driver->getNonConstDriverAttributes().setAttribute("MAX_TEXTURE_SIZE", - core::dimension2du(0, 0)); - - SpriteBank->setTexture(texID, Driver->getTexture( m_texture_files[texID].m_file_name )); - Driver->getNonConstDriverAttributes().setAttribute("MAX_TEXTURE_SIZE", old_max_size); - - // set previous mip-map+filter state - //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap); - - // couldn't load texture, abort. - if (!SpriteBank->getTexture(texID)) - { - Log::error("ScalableFont::lazyLoadTexture", "Unable to load all textures in the font"); - _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; - return; - } - else - { - assert(m_texture_files[texID].m_file_name.size() > 0); - - // colorkey texture rather than alpha channel? - if (! m_texture_files[texID].m_has_alpha) - { - Driver->makeColorKeyTexture(SpriteBank->getTexture(texID), core::position2di(0,0)); - } - } -} -#endif // ENABLE_FREETYPE - int ScalableFont::getCharWidth(const SFontArea& area, const bool fallback) const { -#ifdef ENABLE_FREETYPE - const float char_scale = 1.0f; -#else - core::array< SGUISprite >& sprites = SpriteBank->getSprites(); - core::array< SGUISprite >* fallback_sprites = (m_fallback_font != NULL ? - &m_fallback_font->SpriteBank->getSprites() : - NULL); - - const int texID = (fallback ? - (*fallback_sprites)[area.spriteno].Frames[0].textureNumber : - sprites[area.spriteno].Frames[0].textureNumber); - - const TextureInfo& info = (fallback ? - (*(m_fallback_font->m_texture_files.find(texID))).second : - (*(m_texture_files.find(texID))).second - ); - assert(info.m_file_name.size() > 0); - const float char_scale = info.m_scale; -#endif // ENABLE_FREETYPE - - //Log::info("ScalableFont", "area.spriteno = %d, char_scale = %f", area.spriteno, char_scale); - -#ifdef ENABLE_FREETYPE - if (fallback) return (int)((area.width*m_fallback_font_scale + m_fallback_kerning_width) * m_scale * char_scale); - else return (int)((area.width + GlobalKerningWidth) * m_scale * char_scale); -#else - if (fallback) return (int)(((area.width + area.overhang)*m_fallback_font_scale + m_fallback_kerning_width) * m_scale * char_scale); - else return (int)((area.width + area.overhang + GlobalKerningWidth) * m_scale * char_scale); -#endif // ENABLE_FREETYPE + if (fallback) return (int)((area.width*m_fallback_font_scale + m_fallback_kerning_width) * m_scale); + else return (int)((area.width + GlobalKerningWidth) * m_scale); } @@ -1355,11 +970,7 @@ s32 ScalableFont::getCharacterFromPos(const wchar_t* text, s32 pixel_x) const bool use_fallback_font = false; const SFontArea &a = getAreaFromCharacter(text[idx], &use_fallback_font); -#ifdef ENABLE_FREETYPE x += getCharWidth(a, use_fallback_font) + GlobalKerningWidth; -#else - x += getCharWidth(a, use_fallback_font) + a.overhang + a.underhang + GlobalKerningWidth; -#endif // ENABLE_FREETYPE if (x >= pixel_x) return idx; diff --git a/src/guiengine/scalable_font.hpp b/src/guiengine/scalable_font.hpp index 09447fbde..24effc0a9 100644 --- a/src/guiengine/scalable_font.hpp +++ b/src/guiengine/scalable_font.hpp @@ -7,9 +7,7 @@ #include "utils/leak_check.hpp" -#ifdef ENABLE_FREETYPE #include "guiengine/get_font_properties.hpp" -#endif // ENABLE_FREETYPE #include "IrrCompileConfig.h" #include "IGUIFontBitmap.h" @@ -55,26 +53,6 @@ class ScalableFont : public IGUIFontBitmap bool m_mono_space_digits; irr::video::SColor m_shadow_color; -#ifndef ENABLE_FREETYPE - struct TextureInfo - { - irr::core::stringc m_file_name; - bool m_has_alpha; - float m_scale; - bool m_exclude_from_max_height_calculation; - - TextureInfo() - { - m_has_alpha = false; - m_scale = 1.0f; - } - }; - - std::map m_texture_files; - - void doReadXmlFile(io::IXMLReader* xml); -#endif // ENABLE_FREETYPE - bool m_is_hollow_copy; bool m_rtl; @@ -84,22 +62,16 @@ public: bool m_black_border; -#ifdef ENABLE_FREETYPE TTFLoadingType m_type; FontUse m_font_use; u32 m_dpi; -#endif // ENABLE_FREETYPE ScalableFont* m_fallback_font; float m_fallback_font_scale; int m_fallback_kerning_width; //! constructor -#ifdef ENABLE_FREETYPE ScalableFont(IGUIEnvironment* env, TTFLoadingType type); -#else - ScalableFont(IGUIEnvironment* env, const std::string &filename); -#endif // ENABLE_FREETYPE /** Creates a hollow copy of this font; i.e. the underlying font data is the *same* for * both fonts. The advantage of doing this is that you can change "view" parameters @@ -120,15 +92,8 @@ public: //! destructor virtual ~ScalableFont(); -#ifdef ENABLE_FREETYPE //! loads a font from a TTF file bool loadTTF(); -#else - //! loads a font from an XML file - bool load(io::IXMLReader* xml); - - void lazyLoadTexture(int texID); -#endif // ENABLE_FREETYPE //! draws an text and clips it to the specified rectangle if wanted virtual void draw(const core::stringw& text, const core::rect& position, @@ -180,7 +145,6 @@ public: void updateRTL(); -#ifdef ENABLE_FREETYPE //! re-create fonts when language is changed void recreateFromLanguage(); @@ -189,11 +153,9 @@ public: //! force create a new texture (glyph) page in a font void forceNewPage(); -#endif // ENABLE_FREETYPE private: -#ifdef ENABLE_FREETYPE struct SFontArea { SFontArea() : width(0), spriteno(0), offsety(0), offsety_bt(0), bearingx(0) {} @@ -203,16 +165,6 @@ private: s32 offsety_bt; s32 bearingx; }; -#else - struct SFontArea - { - SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {} - s32 underhang; - s32 overhang; - s32 width; - u32 spriteno; - }; -#endif // ENABLE_FREETYPE int getCharWidth(const SFontArea& area, const bool fallback) const; s32 getAreaIDFromCharacter(const wchar_t c, bool* fallback_font) const; @@ -229,10 +181,8 @@ private: u32 WrongCharacter; s32 MaxHeight; s32 GlobalKerningWidth, GlobalKerningHeight; -#ifdef ENABLE_FREETYPE s32 GlyphMaxHeight; video::ITexture* LastNormalPage; -#endif // ENABLE_FREETYPE core::stringw Invisible; }; diff --git a/src/states_screens/options_screen_ui.cpp b/src/states_screens/options_screen_ui.cpp index 62853fb77..c1077b451 100644 --- a/src/states_screens/options_screen_ui.cpp +++ b/src/states_screens/options_screen_ui.cpp @@ -330,13 +330,11 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con translations = new Translations(); -#ifdef ENABLE_FREETYPE - //Reload fonts for new translation when using freetype + //Reload fonts for new translation GUIEngine::cleanHollowCopyFont(); GUIEngine::getTitleFont()->recreateFromLanguage(); GUIEngine::getFont()->recreateFromLanguage(); GUIEngine::reloadHollowCopyFont(GUIEngine::getFont()); -#endif // ENABLE_FREETYPE GUIEngine::getStateManager()->hardResetAndGoToScreen(); From 41bd914f7c53ba0956db95fb556acf8de0fb3f02 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 31 Oct 2015 00:29:53 +0800 Subject: [PATCH 8/9] Fix typo --- cmake/FindFreetype.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/FindFreetype.cmake b/cmake/FindFreetype.cmake index 279b646e5..7d27a2102 100644 --- a/cmake/FindFreetype.cmake +++ b/cmake/FindFreetype.cmake @@ -11,15 +11,15 @@ if(WIN32) find_path(FREETYPE_INCLUDE_DIRS NAMES freetype/freetype.h PATHS "${PROJECT_SOURCE_DIR}/dependencies/include") - find_library(FREETPYE_LIBRARY NAMES freetype PATHS "${PROJECT_SOURCE_DIR}/dependencies/lib") + find_library(FREETYPE_LIBRARY NAMES freetype PATHS "${PROJECT_SOURCE_DIR}/dependencies/lib") set(FREETYPE_FOUND 1) - set(FREETPYE_LIBRARIES ${FREETPYE_LIBRARY}) + set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) elseif(APPLE) find_path(FREETYPE_INCLUDE_DIRS NAMES freetype/freetype.h PATHS "/Library/Frameworks/FreeType.Framework/Versions/2.4/unix/include") - find_library(FREETPYE_LIBRARY NAMES freetype PATHS "/Library/Frameworks/FreeType.Framework/Versions/2.4/") + find_library(FREETYPE_LIBRARY NAMES freetype PATHS "/Library/Frameworks/FreeType.Framework/Versions/2.4/") include_directories(/Library/Frameworks/FreeType.Framework/Versions/2.4/unix/include) set(FREETYPE_FOUND 1) - set(FREETPYE_LIBRARIES ${FREETPYE_LIBRARY}) + set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) elseif(UNIX) include(FindPkgConfig) pkg_check_modules(FREETYPE freetype2) From 8a288f05fff58f29d279256bf16f90a00765f0cc Mon Sep 17 00:00:00 2001 From: Deve Date: Sat, 31 Oct 2015 01:00:48 +0100 Subject: [PATCH 9/9] Implement lightning effect using shaders --- data/shaders/lightning.frag | 7 +++++++ src/graphics/post_processing.cpp | 30 ++++++++++++++++++++++++++++ src/graphics/post_processing.hpp | 1 + src/states_screens/race_gui_base.cpp | 15 +++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 data/shaders/lightning.frag diff --git a/data/shaders/lightning.frag b/data/shaders/lightning.frag new file mode 100644 index 000000000..66f68a51e --- /dev/null +++ b/data/shaders/lightning.frag @@ -0,0 +1,7 @@ +uniform vec3 intensity; +out vec4 FragColor; + +void main() +{ + FragColor = vec4(intensity, 1.0f); +} diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 6cdf969f6..6a3d0bdde 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -818,6 +818,24 @@ public: } // render }; // SunLightShader +// ============================================================================ +class LightningShader : public TextureShader +{ +public: + LightningShader() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert", + GL_FRAGMENT_SHADER, "lightning.frag"); + assignUniforms("intensity"); + } // LightningShader + // ------------------------------------------------------------------------ + void render(core::vector3df intensity) + { + drawFullScreenEffect(intensity); + } // render +}; // LightningShader + // ============================================================================ PostProcessing::PostProcessing(IVideoDriver* video_driver) @@ -1408,6 +1426,18 @@ void PostProcessing::applyMLAA() glDisable(GL_STENCIL_TEST); } // applyMLAA +// ---------------------------------------------------------------------------- +void PostProcessing::renderLightning(core::vector3df intensity) +{ + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + glBlendEquation(GL_FUNC_ADD); + + LightningShader::getInstance()->render(intensity); + + glDisable(GL_BLEND); +} + // ---------------------------------------------------------------------------- /** Render the post-processed scene */ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index 866f9d061..d1f423edf 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -105,6 +105,7 @@ public: void renderMotionBlur(unsigned cam, const FrameBuffer &in_fbo, FrameBuffer &out_fbo); void renderGlow(unsigned tex); + void renderLightning(core::vector3df intensity); /** Render the post-processed scene */ FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace); diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index 37d674b0f..ee38fba41 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -22,11 +22,13 @@ #include "audio/music_manager.hpp" #include "config/user_config.hpp" -#include "graphics/camera.hpp" #include "graphics/2dutils.hpp" +#include "graphics/camera.hpp" +#include "graphics/central_settings.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material.hpp" #include "graphics/material_manager.hpp" +#include "graphics/post_processing.hpp" #include "graphics/referee.hpp" #include "guiengine/scalable_font.hpp" #include "io/file_manager.hpp" @@ -410,6 +412,17 @@ void RaceGUIBase::preRenderCallback(const Camera *camera) // ---------------------------------------------------------------------------- void RaceGUIBase::renderPlayerView(const Camera *camera, float dt) { + if (CVS->isGLSL()) + { + if (m_lightning > 0.0f) + { + core::vector3df intensity = {0.7f * m_lightning, + 0.7f * m_lightning, + 0.7f * std::min(1.0f, m_lightning * 1.5f)}; + irr_driver->getPostProcessing()->renderLightning(intensity); + } + } + #if 0 const core::recti &viewport = camera->getViewport();