Skip to content

Commit 302a5e0

Browse files
committed
font glyph packing finished
* 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 Commented out outline strokes currently, will enable them after further testing.
1 parent 12e367b commit 302a5e0

26 files changed

+699
-251
lines changed

Diff for: examples/cpu/bubblechart.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ int main(void)
7777
* it can be used for rendering text */
7878
fg::Font fnt;
7979
#ifdef OS_WIN
80-
fnt.loadSystemFont("Calibri", 32);
80+
fnt.loadSystemFont("Calibri");
8181
#else
82-
fnt.loadSystemFont("Vera", 32);
82+
fnt.loadSystemFont("Vera");
8383
#endif
8484
wnd.setFont(&fnt);
8585

Diff for: examples/cpu/fractal.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ int main(void)
4242
* it can be used for rendering text */
4343
fg::Font fnt;
4444
#ifdef OS_WIN
45-
fnt.loadSystemFont("Calibri", 32);
45+
fnt.loadSystemFont("Calibri");
4646
#else
47-
fnt.loadSystemFont("Vera", 32);
47+
fnt.loadSystemFont("Vera");
4848
#endif
4949
wnd.setFont(&fnt);
5050

Diff for: examples/cpu/histogram.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ int main(void)
5959
* it can be used for rendering text */
6060
fg::Font fnt;
6161
#ifdef OS_WIN
62-
fnt.loadSystemFont("Calibri", 32);
62+
fnt.loadSystemFont("Calibri");
6363
#else
64-
fnt.loadSystemFont("Vera", 32);
64+
fnt.loadSystemFont("Vera");
6565
#endif
6666
wnd.setFont(&fnt);
6767

Diff for: examples/cpu/plot3.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ int main(void)
4949
* it can be used for rendering text */
5050
fg::Font fnt;
5151
#ifdef OS_WIN
52-
fnt.loadSystemFont("Calibri", 32);
52+
fnt.loadSystemFont("Calibri");
5353
#else
54-
fnt.loadSystemFont("Vera", 32);
54+
fnt.loadSystemFont("Vera");
5555
#endif
5656
wnd.setFont(&fnt);
5757

Diff for: examples/cpu/plotting.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ int main(void)
5555
* it can be used for rendering text */
5656
fg::Font fnt;
5757
#ifdef OS_WIN
58-
fnt.loadSystemFont("Calibri", 32);
58+
fnt.loadSystemFont("Calibri");
5959
#else
60-
fnt.loadSystemFont("Vera", 32);
60+
fnt.loadSystemFont("Vera");
6161
#endif
6262
wnd.setFont(&fnt);
6363

Diff for: examples/cpu/surface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ int main(void)
5353
* it can be used for rendering text */
5454
fg::Font fnt;
5555
#ifdef OS_WIN
56-
fnt.loadSystemFont("Calibri", 32);
56+
fnt.loadSystemFont("Calibri");
5757
#else
58-
fnt.loadSystemFont("Vera", 32);
58+
fnt.loadSystemFont("Vera");
5959
#endif
6060
wnd.setFont(&fnt);
6161

Diff for: examples/cuda/fractal.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ int main(void)
2626
* it can be used for rendering text */
2727
fg::Font fnt;
2828
#ifdef OS_WIN
29-
fnt.loadSystemFont("Calibri", 32);
29+
fnt.loadSystemFont("Calibri");
3030
#else
31-
fnt.loadSystemFont("Vera", 32);
31+
fnt.loadSystemFont("Vera");
3232
#endif
3333
wnd.setFont(&fnt);
3434

Diff for: examples/cuda/histogram.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ int main(void)
7878
* it can be used for rendering text */
7979
fg::Font fnt;
8080
#ifdef OS_WIN
81-
fnt.loadSystemFont("Calibri", 32);
81+
fnt.loadSystemFont("Calibri");
8282
#else
83-
fnt.loadSystemFont("Vera", 32);
83+
fnt.loadSystemFont("Vera");
8484
#endif
8585
wnd.setFont(&fnt);
8686

Diff for: examples/cuda/plot3.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ int main(void)
4141
* it can be used for rendering text */
4242
fg::Font fnt;
4343
#ifdef OS_WIN
44-
fnt.loadSystemFont("Calibri", 32);
44+
fnt.loadSystemFont("Calibri");
4545
#else
46-
fnt.loadSystemFont("Vera", 32);
46+
fnt.loadSystemFont("Vera");
4747
#endif
4848
wnd.setFont(&fnt);
4949

Diff for: examples/cuda/plotting.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ int main(void)
3535
* it can be used for rendering text */
3636
fg::Font fnt;
3737
#ifdef OS_WIN
38-
fnt.loadSystemFont("Calibri", 32);
38+
fnt.loadSystemFont("Calibri");
3939
#else
40-
fnt.loadSystemFont("Vera", 32);
40+
fnt.loadSystemFont("Vera");
4141
#endif
4242
wnd.setFont(&fnt);
4343

Diff for: examples/cuda/surface.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ int main(void)
3535
* it can be used for rendering text */
3636
fg::Font fnt;
3737
#ifdef OS_WIN
38-
fnt.loadSystemFont("Calibri", 32);
38+
fnt.loadSystemFont("Calibri");
3939
#else
40-
fnt.loadSystemFont("Vera", 32);
40+
fnt.loadSystemFont("Vera");
4141
#endif
4242
wnd.setFont(&fnt);
4343

Diff for: examples/opencl/fractal.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ int main(void)
118118
* it can be used for rendering text */
119119
fg::Font fnt;
120120
#ifdef OS_WIN
121-
fnt.loadSystemFont("Calibri", 32);
121+
fnt.loadSystemFont("Calibri");
122122
#else
123-
fnt.loadSystemFont("Vera", 32);
123+
fnt.loadSystemFont("Vera");
124124
#endif
125125
wnd.setFont(&fnt);
126126

Diff for: examples/opencl/histogram.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ int main(void)
213213
* it can be used for rendering text */
214214
fg::Font fnt;
215215
#ifdef OS_WIN
216-
fnt.loadSystemFont("Calibri", 32);
216+
fnt.loadSystemFont("Calibri");
217217
#else
218-
fnt.loadSystemFont("Vera", 32);
218+
fnt.loadSystemFont("Vera");
219219
#endif
220220
wnd.setFont(&fnt);
221221

Diff for: examples/opencl/plot3.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ int main(void)
8787
* it can be used for rendering text */
8888
fg::Font fnt;
8989
#ifdef OS_WIN
90-
fnt.loadSystemFont("Calibri", 32);
90+
fnt.loadSystemFont("Calibri");
9191
#else
92-
fnt.loadSystemFont("Vera", 32);
92+
fnt.loadSystemFont("Vera");
9393
#endif
9494
wnd.setFont(&fnt);
9595

Diff for: examples/opencl/plotting.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ int main(void)
9090
* it can be used for rendering text */
9191
fg::Font fnt;
9292
#ifdef OS_WIN
93-
fnt.loadSystemFont("Calibri", 32);
93+
fnt.loadSystemFont("Calibri");
9494
#else
95-
fnt.loadSystemFont("Vera", 32);
95+
fnt.loadSystemFont("Vera");
9696
#endif
9797
wnd.setFont(&fnt);
9898

Diff for: examples/opencl/surface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ int main(void)
9393
* it can be used for rendering text */
9494
fg::Font fnt;
9595
#ifdef OS_WIN
96-
fnt.loadSystemFont("Calibri", 32);
96+
fnt.loadSystemFont("Calibri");
9797
#else
98-
fnt.loadSystemFont("Vera", 32);
98+
fnt.loadSystemFont("Vera");
9999
#endif
100100
wnd.setFont(&fnt);
101101

Diff for: include/fg/defines.h

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ enum ErrorCode {
9292
* */
9393
FG_ERR_NOT_SUPPORTED = 5001, ///< Feature not supported
9494
FG_ERR_NOT_CONFIGURED = 5002, ///< Library configuration mismatch
95+
/*
96+
* Font config related error codes
97+
* '6**'
98+
* */
99+
FG_ERR_FONTCONFIG_ERROR = 6001, ///< Fontconfig related error
95100
/*
96101
* other error codes
97102
* match the following pattern

Diff for: include/fg/font.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,15 @@ class Font {
4949
Load a given font file
5050
5151
\param[in] pFile True Type Font file path
52-
\param[in] pFontSize the size of the font glyphs that will be created
5352
*/
54-
FGAPI void loadFont(const char* const pFile, int pFontSize);
53+
FGAPI void loadFontFile(const char* const pFile);
5554

5655
/**
5756
Load a system font based on the name
5857
5958
\param[in] pName True Type Font name
60-
\param[in] pFontSize the size of the font glyphs that will be created
6159
*/
62-
FGAPI void loadSystemFont(const char* const pName, int pFontSize);
60+
FGAPI void loadSystemFont(const char* const pName);
6361

6462
/**
6563
Get handle for internal implementation of Font object

Diff for: src/chart.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
using namespace std;
3434
typedef std::vector<std::string>::const_iterator StringIter;
3535

36-
static const int CHART2D_FONT_SIZE = 15;
36+
static const int CHART2D_FONT_SIZE = 16;
3737

3838
const std::shared_ptr<internal::font_impl>& getChartFont()
3939
{
@@ -42,9 +42,9 @@ const std::shared_ptr<internal::font_impl>& getChartFont()
4242

4343
std::call_once(flag, []() {
4444
#if defined(OS_WIN)
45-
mChartFont.loadSystemFont("Calibri", 32);
45+
mChartFont.loadSystemFont("Calibri");
4646
#else
47-
mChartFont.loadSystemFont("Vera", 32);
47+
mChartFont.loadSystemFont("Vera");
4848
#endif
4949
});
5050

@@ -98,7 +98,7 @@ void AbstractChart::renderTickLabels(
9898
* text center with tick mark position */
9999
if(pCoordsOffset < mTickCount) {
100100
// offset for y axis labels
101-
pos[0] -= (CHART2D_FONT_SIZE*it->length()/2.0f+mTickSize/2);
101+
pos[0] -= (CHART2D_FONT_SIZE*it->length()/2.0f+mTickSize);
102102
}else if(pCoordsOffset >= mTickCount && pCoordsOffset < 2*mTickCount) {
103103
// offset for x axis labels
104104
pos[0] -= (CHART2D_FONT_SIZE*it->length()/4.0f);
@@ -430,7 +430,7 @@ void chart2d_impl::render(const int pWindowId,
430430
/* render chart axes titles */
431431
if (!mYTitle.empty()) {
432432
glm::vec4 res = trans * glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f);
433-
pos[0] = 2;
433+
pos[0] = 4;
434434
pos[1] = h*(res.y+1.0f)/2.0f;
435435
fonter->render(pWindowId, pos, WHITE, mYTitle.c_str(), CHART2D_FONT_SIZE, true);
436436
}

Diff for: src/common.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ GLuint initShaders(const char* pVertShaderSrc, const char* pFragShaderSrc)
158158
return shaderProgram;
159159
}
160160

161-
int nextP2(const int pValue)
162-
{
163-
return int(std::pow(2, (std::ceil(std::log2(pValue)))));
164-
}
165-
166161
float clampTo01(const float pValue)
167162
{
168163
return (pValue < 0.0f ? 0.0f : (pValue>1.0f ? 1.0f : pValue));

Diff for: src/common.hpp

-7
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ GLuint createBuffer(GLenum pTarget, size_t pSize, const T* pPtr, GLenum pUsage)
8686
return retVal;
8787
}
8888

89-
/* compute the next power of two after given integer
90-
*
91-
* @pValue is the value whose next power of two is to be computed
92-
*/
93-
int nextP2(const int pValue);
94-
9589
#ifdef OS_WIN
9690
/* Get the paths to font files in Windows system directory
9791
*
@@ -134,7 +128,6 @@ std::ostream& operator<<(std::ostream&, const glm::mat4&);
134128
glm::vec3 trackballPoint(const float pX, const float pY,
135129
const float pWidth, const float pHeight);
136130

137-
138131
namespace internal
139132
{
140133

0 commit comments

Comments
 (0)