diff --git a/examples/00-helloworld/helloworld.cpp b/examples/00-helloworld/helloworld.cpp index 263105ae8..f0661436d 100644 --- a/examples/00-helloworld/helloworld.cpp +++ b/examples/00-helloworld/helloworld.cpp @@ -3,12 +3,12 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "processevents.h" int _main_(int /*_argc*/, char** /*_argv*/) { diff --git a/examples/01-cubes/cubes.cpp b/examples/01-cubes/cubes.cpp index a205b43a1..4a7f4a395 100644 --- a/examples/01-cubes/cubes.cpp +++ b/examples/01-cubes/cubes.cpp @@ -3,14 +3,14 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" #include #include diff --git a/examples/02-metaballs/metaballs.cpp b/examples/02-metaballs/metaballs.cpp index ec0700d7a..217abe5bf 100644 --- a/examples/02-metaballs/metaballs.cpp +++ b/examples/02-metaballs/metaballs.cpp @@ -3,14 +3,14 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" #include #include diff --git a/examples/03-raymarch/raymarch.cpp b/examples/03-raymarch/raymarch.cpp index 23d498328..92c35c455 100644 --- a/examples/03-raymarch/raymarch.cpp +++ b/examples/03-raymarch/raymarch.cpp @@ -3,14 +3,14 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" #include #include diff --git a/examples/04-mesh/mesh.cpp b/examples/04-mesh/mesh.cpp index edb92bb6d..a4ee84ad9 100644 --- a/examples/04-mesh/mesh.cpp +++ b/examples/04-mesh/mesh.cpp @@ -3,15 +3,15 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" #include #include diff --git a/examples/05-instancing/instancing.cpp b/examples/05-instancing/instancing.cpp index 120f32b9f..fdec886fb 100644 --- a/examples/05-instancing/instancing.cpp +++ b/examples/05-instancing/instancing.cpp @@ -3,14 +3,14 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" #include #include diff --git a/examples/06-bump/bump.cpp b/examples/06-bump/bump.cpp index 5c7cef24b..3880fc807 100644 --- a/examples/06-bump/bump.cpp +++ b/examples/06-bump/bump.cpp @@ -3,15 +3,15 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" #include #include diff --git a/examples/07-callback/callback.cpp b/examples/07-callback/callback.cpp index 7493dfd4a..0739da96e 100644 --- a/examples/07-callback/callback.cpp +++ b/examples/07-callback/callback.cpp @@ -3,15 +3,15 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include #include -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/aviwriter.h" +#include "dbg.h" +#include "fpumath.h" +#include "aviwriter.h" #include #include diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index 23034a9c1..06ce0f3d9 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -3,16 +3,16 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" -#include "../common/packrect.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" +#include "packrect.h" #include #include diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index e5db5a4e2..8922e8e93 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -3,17 +3,17 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" -#include "../common/imgui/imgui.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" +#include "imgui/imgui.h" #include #include diff --git a/examples/10-font/font.cpp b/examples/10-font/font.cpp index 9f97dabe0..c9f98d5ab 100644 --- a/examples/10-font/font.cpp +++ b/examples/10-font/font.cpp @@ -3,19 +3,19 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" -#include "../common/font/font_manager.h" -#include "../common/font/text_buffer_manager.h" +#include "font/font_manager.h" +#include "font/text_buffer_manager.h" #include #include diff --git a/examples/11-fontsdf/fontsdf.cpp b/examples/11-fontsdf/fontsdf.cpp index 6028fd8be..0fa1c99d1 100644 --- a/examples/11-fontsdf/fontsdf.cpp +++ b/examples/11-fontsdf/fontsdf.cpp @@ -3,18 +3,18 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" -#include "../common/font/font_manager.h" -#include "../common/font/text_metrics.h" -#include "../common/font/text_buffer_manager.h" -#include "../common/imgui/imgui.h" +#include "font/font_manager.h" +#include "font/text_metrics.h" +#include "font/text_buffer_manager.h" +#include "imgui/imgui.h" #include #include @@ -112,13 +112,13 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Create a distance field font. FontHandle base_distance_font = fontManager->createFontByPixelSize(font_tt, 0, 48, FONT_TYPE_DISTANCE); - + // Create a scaled down version of the same font (without adding anything to the atlas). FontHandle scaled_font = fontManager->createScaledFontToPixelSize(base_distance_font, 14); - - TextLineMetrics metrics(fontManager, scaled_font); + + TextLineMetrics metrics(fontManager->getFontInfo(scaled_font) ); uint32_t lineCount = metrics.getLineCount(bigText); - + float visibleLineCount = 20.0f; const char* textBegin = 0; @@ -129,7 +129,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) textBufferManager->setTextColor(scrollableBuffer, 0xFFFFFFFF); textBufferManager->appendText(scrollableBuffer, scaled_font, textBegin, textEnd); - + MouseState mouseState; int32_t scrollArea = 0; while (!processEvents(width, height, debug, reset, &mouseState) ) @@ -145,22 +145,22 @@ int _main_(int /*_argc*/, char** /*_argv*/) const int guiPanelWidth = 250; const int guiPanelHeight = 200; - + imguiBeginScrollArea("Text Area", width - guiPanelWidth - 10, 10, guiPanelWidth, guiPanelHeight, &scrollArea); imguiSeparatorLine(); - + static float textScroll = 0.0f; static float textRotation = 0.0f; static float textScale = 1.0f; static float textSize = 14.0f; - - bool recomputeVisibleText = false; + + bool recomputeVisibleText = false; recomputeVisibleText |= imguiSlider("Number of lines", &visibleLineCount, 1.0f, 177.0f , 1.0f); if(imguiSlider("Font size", &textSize, 6.0f, 64.0f , 1.0f)) { fontManager->destroyFont(scaled_font); scaled_font = fontManager->createScaledFontToPixelSize(base_distance_font, (uint32_t) textSize); - metrics = TextLineMetrics (fontManager, scaled_font); + metrics = TextLineMetrics(fontManager->getFontInfo(scaled_font) ); recomputeVisibleText = true; } @@ -174,9 +174,9 @@ int _main_(int /*_argc*/, char** /*_argv*/) metrics.getSubText(bigText,(uint32_t)textScroll, (uint32_t)(textScroll+visibleLineCount), textBegin, textEnd); textBufferManager->appendText(scrollableBuffer, scaled_font, textBegin, textEnd); } - + imguiEndScrollArea(); - + imguiEndFrame(); // Set view 0 default viewport. @@ -209,10 +209,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Setup a top-left ortho matrix for screen space drawing. mtxOrtho(proj, centering, width + centering, height + centering, centering, -1.0f, 1.0f); - + // Set view and projection matrix for view 0. bgfx::setViewTransform(0, view, proj); - + //very crude approximation :( float textAreaWidth = 0.5f * 66.0f * fontManager->getFontInfo(scaled_font).maxAdvanceWidth; @@ -220,7 +220,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) float textCenterMat[16]; float textScaleMat[16]; float screenCenterMat[16]; - + mtxRotateZ(textRotMat, textRotation); mtxTranslate(textCenterMat, -(textAreaWidth * 0.5f), (-visibleLineCount)*metrics.getLineHeight()*0.5f, 0); mtxScale(textScaleMat, textScale, textScale, 1.0f); @@ -229,16 +229,16 @@ int _main_(int /*_argc*/, char** /*_argv*/) //first translate to text center, then scale, then rotate float tmpMat[16]; mtxMul(tmpMat, textCenterMat, textRotMat); - + float tmpMat2[16]; mtxMul(tmpMat2, tmpMat, textScaleMat); - + float tmpMat3[16]; mtxMul(tmpMat3, tmpMat2, screenCenterMat); // Set model matrix for rendering. bgfx::setTransform(tmpMat3); - + // Draw your text. textBufferManager->submitTextBuffer(scrollableBuffer, 0); diff --git a/examples/12-lod/lod.cpp b/examples/12-lod/lod.cpp index 44ba41691..eb4765ae2 100644 --- a/examples/12-lod/lod.cpp +++ b/examples/12-lod/lod.cpp @@ -3,16 +3,16 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include "../common/common.h" +#include "common.h" #include #include #include -#include "../common/entry.h" -#include "../common/dbg.h" -#include "../common/math.h" -#include "../common/processevents.h" -#include "../common/imgui/imgui.h" +#include "entry.h" +#include "dbg.h" +#include "fpumath.h" +#include "processevents.h" +#include "imgui/imgui.h" #include #include diff --git a/examples/common/font/text_metrics.cpp b/examples/common/font/text_metrics.cpp index 03a134406..93ace94c2 100644 --- a/examples/common/font/text_metrics.cpp +++ b/examples/common/font/text_metrics.cpp @@ -1,7 +1,7 @@ /* - * Copyright 2013 Jeremie Roy. All rights reserved. - * License: http://www.opensource.org/licenses/BSD-2-Clause - */ +* Copyright 2013 Jeremie Roy. All rights reserved. +* License: http://www.opensource.org/licenses/BSD-2-Clause +*/ #include // wcslen @@ -22,7 +22,7 @@ void TextMetrics::appendText(FontHandle _fontHandle, const char* _string) { GlyphInfo glyph; const FontInfo& font = m_fontManager->getFontInfo(_fontHandle); - + if (font.lineGap > m_lineGap) { m_lineGap = font.lineGap; @@ -37,7 +37,7 @@ void TextMetrics::appendText(FontHandle _fontHandle, const char* _string) CodePoint codepoint = 0; uint32_t state = 0; - + for (; *_string; ++_string) { if (!utf8_decode(&state, (uint32_t*)&codepoint, *_string) ) @@ -52,7 +52,8 @@ void TextMetrics::appendText(FontHandle _fontHandle, const char* _string) m_x = 0; break; } - //TODO handle kerning + + m_x += glyph.advance_x; if(m_x > m_width) { @@ -73,7 +74,7 @@ void TextMetrics::appendText(FontHandle _fontHandle, const wchar_t* _string) { GlyphInfo glyph; const FontInfo& font = m_fontManager->getFontInfo(_fontHandle); - + if (font.lineGap > m_lineGap) { m_lineGap = font.lineGap; @@ -113,10 +114,9 @@ void TextMetrics::appendText(FontHandle _fontHandle, const wchar_t* _string) } } -TextLineMetrics::TextLineMetrics(FontManager* _fontManager, FontHandle _fontHandle) +TextLineMetrics::TextLineMetrics(const FontInfo& _fontInfo) { - const FontInfo& font = _fontManager->getFontInfo(_fontHandle); - m_lineHeight = font.ascender - font.descender + font.lineGap; + m_lineHeight = _fontInfo.ascender - _fontInfo.descender + _fontInfo.lineGap; } uint32_t TextLineMetrics::getLineCount(const char* _string) const @@ -177,8 +177,8 @@ void TextLineMetrics::getSubText(const char* _string, uint32_t _firstLine, uint3 BX_CHECK(state == UTF8_ACCEPT, "The string is not well-formed"); _begin = _string; - - while((*_string) && (currentLine < _lastLine) ) + + while ( (*_string) && (currentLine < _lastLine) ) { for (; *_string; ++_string) { @@ -281,7 +281,7 @@ void TextLineMetrics::getVisibleText(const wchar_t* _string, float _top, float _ { // y is bottom of a text line float y = m_lineHeight; - + const wchar_t* _textEnd = _string + wcslen(_string); while (y < _top) diff --git a/examples/common/font/text_metrics.h b/examples/common/font/text_metrics.h index 31c44d16b..34f39aab1 100644 --- a/examples/common/font/text_metrics.h +++ b/examples/common/font/text_metrics.h @@ -1,7 +1,7 @@ /* - * Copyright 2013 Jeremie Roy. All rights reserved. - * License: http://www.opensource.org/licenses/BSD-2-Clause - */ +* Copyright 2013 Jeremie Roy. All rights reserved. +* License: http://www.opensource.org/licenses/BSD-2-Clause +*/ #ifndef __TEXT_METRICS_H__ #define __TEXT_METRICS_H__ @@ -12,13 +12,13 @@ class TextMetrics { public: TextMetrics(FontManager* _fontManager); - + /// Append an ASCII/utf-8 string to the metrics helper. void appendText(FontHandle _fontHandle, const char* _string); /// Append a wide char string to the metrics helper. void appendText(FontHandle _fontHandle, const wchar_t* _string); - + /// Return the width of the measured text. float getWidth() const { return m_width; } @@ -38,8 +38,8 @@ private: class TextLineMetrics { public: - TextLineMetrics(FontManager* _fontManager, FontHandle _fontHandle); - + TextLineMetrics(const FontInfo& _fontInfo); + /// Return the height of a line of text using the given font. float getLineHeight() const { return m_lineHeight; } @@ -48,7 +48,7 @@ public: /// Return the number of text line in the given text. uint32_t getLineCount(const wchar_t* _string) const; - + /// Return the first and last character visible in the [_firstLine, _lastLine] range. void getSubText(const char* _string, uint32_t _firstLine, uint32_t _lastLine, const char*& _begin, const char*& _end); @@ -62,7 +62,6 @@ public: void getVisibleText(const wchar_t* _string, float _top, float _bottom, const wchar_t*& _begin, const wchar_t*& _end); private: - FontManager* m_fontManager; float m_lineHeight; }; diff --git a/examples/common/math.h b/examples/common/fpumath.h similarity index 100% rename from examples/common/math.h rename to examples/common/fpumath.h diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 91f1d00d7..70adb180d 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -29,7 +29,7 @@ #include #include "imgui.h" -#include "../math.h" +#include "../fpumath.h" #include "vs_imgui_color.bin.h" #include "fs_imgui_color.bin.h" diff --git a/premake/premake4.lua b/premake/premake4.lua index 5053a62d0..a1e567506 100644 --- a/premake/premake4.lua +++ b/premake/premake4.lua @@ -47,6 +47,7 @@ function exampleProject(_name, _uuid) BX_DIR .. "include", BGFX_DIR .. "include", BGFX_DIR .. "3rdparty", + BGFX_DIR .. "examples/common", } files {