2

How can I change the font color in FTGL?

genpfault
  • 51,148
  • 11
  • 85
  • 139
MsrButterfly
  • 1,599
  • 2
  • 10
  • 17
  • More information is necessary... FTGL can render vector fonts, raster fonts (deprecated) or texture fonts. The general idea, however, is that the font is monochrome (it may have shades of grey, but no color) and you will change the color by multiplying it by something else. – Andon M. Coleman Nov 27 '13 at 20:19

2 Answers2

2

Simply use a glColor call before asking the font to render; you may need to disable lighting depending on your situation. Here's an example for C++:

FTFont *myfont= new FTBufferFont("myfontfile.ttf");

glPushAttrib(GL_ALL_ATTRIB_BITS);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);

glColor4d(1.0, 0.0, 0.0, 1.0);
myfont->Render("Hello world");

glPopAttrib();
Riot
  • 15,723
  • 4
  • 60
  • 67
  • This is not working. 'glColor4d' was not declared in this scope. – Raghuram Vadapalli Jan 26 '16 at 04:10
  • @Achilles-96 glColor is a basic opengl function. You will need to include the opengl header - I doubt that anything else in the code will work without it. See https://www.opengl.org/sdk/docs/man2/xhtml/glColor.xml – Riot Jan 26 '16 at 15:25
0

This worked for me:

FTGLPixmapFont font("Myfont.ttf");

glPushAttrib(GL_ALL_ATTRIB_BITS);

glPixelTransferf(GL_RED_BIAS, red - 1);
glPixelTransferf(GL_GREEN_BIAS, green - 1);
glPixelTransferf(GL_BLUE_BIAS, blue - 1);

font.Render(str, -1, FTPoint(x, y));

glPopAttrib();

You can add another line for GL_ALPHA_BIAS if you want your text to be transparent.

いちにち
  • 417
  • 6
  • 16