Skip to content

Commit

Permalink
font glyph packing finished
Browse files Browse the repository at this point in the history
* Removed font size parameter from loadFont functions
* Font class loads a range of font sizes a prior
* Characters have an outline to enable easy reading
* Updated examples to reflect the change related to loadFont functions
* Added a new FontAtlas class that creates the single texture that
  has all the glphs for all font sizes and characters

WIP: glyphs that are narrow in width are having hallow effects making
the text look wobbly. Debuggin this issue now. Apart from that, text
rendering seems to be back to original state after glyph packing is
implemented.
  • Loading branch information
9prady9 committed Feb 8, 2016
1 parent 12e367b commit 811b4d7
Show file tree
Hide file tree
Showing 26 changed files with 699 additions and 251 deletions.
4 changes: 2 additions & 2 deletions examples/cpu/bubblechart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/fractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/plot3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/fractal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/histogram.cu
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/plot3.cu
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/plotting.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/surface.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/fractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/plot3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
5 changes: 5 additions & 0 deletions include/fg/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ enum ErrorCode {
* */
FG_ERR_NOT_SUPPORTED = 5001, ///< Feature not supported
FG_ERR_NOT_CONFIGURED = 5002, ///< Library configuration mismatch
/*
* Font config related error codes
* '6**'
* */
FG_ERR_FONTCONFIG_ERROR = 6001, ///< Fontconfig related error
/*
* other error codes
* match the following pattern
Expand Down
6 changes: 2 additions & 4 deletions include/fg/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ class Font {
Load a given font file
\param[in] pFile True Type Font file path
\param[in] pFontSize the size of the font glyphs that will be created
*/
FGAPI void loadFont(const char* const pFile, int pFontSize);
FGAPI void loadFontFile(const char* const pFile);

/**
Load a system font based on the name
\param[in] pName True Type Font name
\param[in] pFontSize the size of the font glyphs that will be created
*/
FGAPI void loadSystemFont(const char* const pName, int pFontSize);
FGAPI void loadSystemFont(const char* const pName);

/**
Get handle for internal implementation of Font object
Expand Down
10 changes: 5 additions & 5 deletions src/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
using namespace std;
typedef std::vector<std::string>::const_iterator StringIter;

static const int CHART2D_FONT_SIZE = 15;
static const int CHART2D_FONT_SIZE = 16;

const std::shared_ptr<internal::font_impl>& getChartFont()
{
Expand All @@ -42,9 +42,9 @@ const std::shared_ptr<internal::font_impl>& getChartFont()

std::call_once(flag, []() {
#if defined(OS_WIN)
mChartFont.loadSystemFont("Calibri", 32);
mChartFont.loadSystemFont("Calibri");
#else
mChartFont.loadSystemFont("Vera", 32);
mChartFont.loadSystemFont("Vera");
#endif
});

Expand Down Expand Up @@ -98,7 +98,7 @@ void AbstractChart::renderTickLabels(
* text center with tick mark position */
if(pCoordsOffset < mTickCount) {
// offset for y axis labels
pos[0] -= (CHART2D_FONT_SIZE*it->length()/2.0f+mTickSize/2);
pos[0] -= (CHART2D_FONT_SIZE*it->length()/2.0f+mTickSize);
}else if(pCoordsOffset >= mTickCount && pCoordsOffset < 2*mTickCount) {
// offset for x axis labels
pos[0] -= (CHART2D_FONT_SIZE*it->length()/4.0f);
Expand Down Expand Up @@ -430,7 +430,7 @@ void chart2d_impl::render(const int pWindowId,
/* render chart axes titles */
if (!mYTitle.empty()) {
glm::vec4 res = trans * glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f);
pos[0] = 2;
pos[0] = 4;
pos[1] = h*(res.y+1.0f)/2.0f;
fonter->render(pWindowId, pos, WHITE, mYTitle.c_str(), CHART2D_FONT_SIZE, true);
}
Expand Down
5 changes: 0 additions & 5 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ GLuint initShaders(const char* pVertShaderSrc, const char* pFragShaderSrc)
return shaderProgram;
}

int nextP2(const int pValue)
{
return int(std::pow(2, (std::ceil(std::log2(pValue)))));
}

float clampTo01(const float pValue)
{
return (pValue < 0.0f ? 0.0f : (pValue>1.0f ? 1.0f : pValue));
Expand Down
7 changes: 0 additions & 7 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ GLuint createBuffer(GLenum pTarget, size_t pSize, const T* pPtr, GLenum pUsage)
return retVal;
}

/* compute the next power of two after given integer
*
* @pValue is the value whose next power of two is to be computed
*/
int nextP2(const int pValue);

#ifdef OS_WIN
/* Get the paths to font files in Windows system directory
*
Expand Down Expand Up @@ -134,7 +128,6 @@ std::ostream& operator<<(std::ostream&, const glm::mat4&);
glm::vec3 trackballPoint(const float pX, const float pY,
const float pWidth, const float pHeight);


namespace internal
{

Expand Down
Loading

0 comments on commit 811b4d7

Please sign in to comment.