mirror of https://github.com/BOINC/boinc.git
Merge branch 'master' of ssh://isaac.ssl.berkeley.edu/boinc-v2
This commit is contained in:
commit
1859c7c82b
|
@ -26,7 +26,8 @@
|
||||||
// freetype2 library: http://www.freetype.org/
|
// freetype2 library: http://www.freetype.org/
|
||||||
|
|
||||||
// this should basically be a drop-in for the old boinc txf_* functions i.e.
|
// this should basically be a drop-in for the old boinc txf_* functions i.e.
|
||||||
// txf_load_fonts and txf_render_string, with extra options on the latter for rotating etc
|
// txf_load_fonts and txf_render_string,
|
||||||
|
// with extra options on the latter for rotating etc
|
||||||
|
|
||||||
// originally adapted by Carl Christensen
|
// originally adapted by Carl Christensen
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@
|
||||||
#include "filesys.h" // from boinc for file_exists
|
#include "filesys.h" // from boinc for file_exists
|
||||||
|
|
||||||
// I put in it's own namespace so call TTFont::ttf_load_fonts() etc
|
// I put in it's own namespace so call TTFont::ttf_load_fonts() etc
|
||||||
|
//
|
||||||
namespace TTFont {
|
namespace TTFont {
|
||||||
|
|
||||||
// The Liberation version 2.00.0 fonts referenced below are free
|
// The Liberation version 2.00.0 fonts referenced below are free
|
||||||
|
@ -53,6 +55,7 @@ namespace TTFont {
|
||||||
|
|
||||||
// you'll want to define a 2-d array of char as appropriate for your
|
// you'll want to define a 2-d array of char as appropriate for your
|
||||||
// truetype font filenames (path is set in the call to ttf_load_fonts)
|
// truetype font filenames (path is set in the call to ttf_load_fonts)
|
||||||
|
//
|
||||||
static const char *g_cstrFont[] = {
|
static const char *g_cstrFont[] = {
|
||||||
"LiberationSans-Regular.ttf", // 0, this is the default
|
"LiberationSans-Regular.ttf", // 0, this is the default
|
||||||
"LiberationSans-Bold.ttf", // 1
|
"LiberationSans-Bold.ttf", // 1
|
||||||
|
@ -74,14 +77,24 @@ static const char *g_cstrFont[] = {
|
||||||
FTFont* g_font[NUM_FONT];
|
FTFont* g_font[NUM_FONT];
|
||||||
int g_iFont = -1;
|
int g_iFont = -1;
|
||||||
|
|
||||||
// load fonts. call once.
|
// Load fonts. call once.
|
||||||
// pass in the font directory, and any special-scaling font name & size (e.g. if I want a huge typeface for Sans-Serif Regular then I pass in "LiberationSans-Regular.ttf", 3000)
|
// Pass in the font directory (normally the project directory:
|
||||||
void ttf_load_fonts(const char* dir, const char* strScaleFont, const int& iScaleFont) {
|
// APP_INIT_DATA::project_dir for BOINC apps),
|
||||||
static bool bInit = false; // flag so we don't call again, otherwise we'll have memory leaks each subsequent call to new FTTextureFont etc
|
// and any special-scaling font name & size
|
||||||
|
// (e.g. if I want a huge typeface for Sans-Serif Regular
|
||||||
|
// then I pass in "LiberationSans-Regular.ttf", 3000)
|
||||||
|
//
|
||||||
|
void ttf_load_fonts(
|
||||||
|
const char* dir, const char* strScaleFont, const int& iScaleFont
|
||||||
|
) {
|
||||||
|
static bool bInit = false;
|
||||||
|
// flag so we don't call again, otherwise we'll have memory leaks
|
||||||
|
// each subsequent call to new FTTextureFont etc
|
||||||
if (bInit) return; // we've already been here
|
if (bInit) return; // we've already been here
|
||||||
bInit = true; // we're in now!
|
bInit = true; // we're in now!
|
||||||
ttf_cleanup();
|
ttf_cleanup();
|
||||||
memset(g_font, 0x00, sizeof(FTFont*) * NUM_FONT); // initialize to null's for error checking later
|
memset(g_font, 0x00, sizeof(FTFont*) * NUM_FONT);
|
||||||
|
// initialize to null's for error checking later
|
||||||
char vpath[MAXPATHLEN];
|
char vpath[MAXPATHLEN];
|
||||||
g_iFont = -1;
|
g_iFont = -1;
|
||||||
for (unsigned int i=0 ; i < NUM_FONT; i++){
|
for (unsigned int i=0 ; i < NUM_FONT; i++){
|
||||||
|
@ -97,8 +110,7 @@ void ttf_load_fonts(const char* dir, const char* strScaleFont, const int& iScale
|
||||||
#endif
|
#endif
|
||||||
int iScale = 30;
|
int iScale = 30;
|
||||||
if (strScaleFont && !strcmp(strScaleFont, g_cstrFont[i])) iScale = iScaleFont;
|
if (strScaleFont && !strcmp(strScaleFont, g_cstrFont[i])) iScale = iScaleFont;
|
||||||
if(!g_font[i]->FaceSize(iScale))
|
if(!g_font[i]->FaceSize(iScale)) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to set size");
|
fprintf(stderr, "Failed to set size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,9 +130,9 @@ void ttf_load_fonts(const char* dir, const char* strScaleFont, const int& iScale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove our objects?
|
// remove our objects
|
||||||
void ttf_cleanup()
|
//
|
||||||
{
|
void ttf_cleanup() {
|
||||||
for (unsigned int i = 0; i < NUM_FONT; i++) {
|
for (unsigned int i = 0; i < NUM_FONT; i++) {
|
||||||
if (g_font[i]) {
|
if (g_font[i]) {
|
||||||
delete g_font[i];
|
delete g_font[i];
|
||||||
|
@ -143,8 +155,7 @@ void ttf_render_string(
|
||||||
const float& fRotY, // optional rotation vector for Y
|
const float& fRotY, // optional rotation vector for Y
|
||||||
const float& fRotZ, // optional rotation vector for Z
|
const float& fRotZ, // optional rotation vector for Z
|
||||||
const float& fRadius // circular radius to draw along
|
const float& fRadius // circular radius to draw along
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
// http://ftgl.sourceforge.net/docs/html/
|
// http://ftgl.sourceforge.net/docs/html/
|
||||||
|
|
||||||
// if requested font isn't available, find first one that is
|
// if requested font isn't available, find first one that is
|
||||||
|
|
16
api/ttfont.h
16
api/ttfont.h
|
@ -25,8 +25,9 @@
|
||||||
// ftgl library: http://sourceforge.net/projects/ftgl/files/FTGL%20Source/
|
// ftgl library: http://sourceforge.net/projects/ftgl/files/FTGL%20Source/
|
||||||
// freetype2 library: http://www.freetype.org/
|
// freetype2 library: http://www.freetype.org/
|
||||||
|
|
||||||
// this should basically be a drop-in for the old boinc txf_* functions i.e.
|
// this should basically be a drop-in for the old boinc txf_* functions,
|
||||||
// txf_load_font and txf_render_string, with extra options on the latter for rotating etc
|
// i.e. txf_load_font and txf_render_string,
|
||||||
|
// with extra options on the latter for rotating etc
|
||||||
|
|
||||||
// originally adapted by Carl Christensen
|
// originally adapted by Carl Christensen
|
||||||
|
|
||||||
|
@ -34,11 +35,16 @@
|
||||||
#ifndef _TTFONT_H_
|
#ifndef _TTFONT_H_
|
||||||
#define _TTFONT_H_
|
#define _TTFONT_H_
|
||||||
|
|
||||||
// I put in it's own namespace so call TTFont::ttf_load_fonts() etc
|
// I put in its own namespace so call TTFont::ttf_load_fonts() etc
|
||||||
|
|
||||||
namespace TTFont {
|
namespace TTFont {
|
||||||
extern int g_iFont;
|
extern int g_iFont;
|
||||||
|
|
||||||
extern void ttf_load_fonts(const char* dir = NULL, const char* strScaleFont = NULL, const int& iScaleFont =30);
|
extern void ttf_load_fonts(
|
||||||
|
const char* dir = NULL,
|
||||||
|
const char* strScaleFont = NULL,
|
||||||
|
const int& iScaleFont =30
|
||||||
|
);
|
||||||
|
|
||||||
extern void ttf_render_string(
|
extern void ttf_render_string(
|
||||||
const double& x,
|
const double& x,
|
||||||
|
@ -59,5 +65,3 @@ namespace TTFont {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif // inclusion
|
#endif // inclusion
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ void app_graphics_init() {
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
ttf_load_fonts(".");
|
ttf_load_fonts(strlen(uc_aid.project_dir)?uc_aid.project_dir:".");
|
||||||
|
|
||||||
boinc_resolve_filename("logo.jpg", path, sizeof(path));
|
boinc_resolve_filename("logo.jpg", path, sizeof(path));
|
||||||
logo.load_image_file(path);
|
logo.load_image_file(path);
|
||||||
|
|
Loading…
Reference in New Issue