Add help and font size indicator to FTGLDemo, courtesy of Bzflag's developer jwmelto.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/demo/FTGLDemo.cpp b/demo/FTGLDemo.cpp
index ff26435..a84cd2c 100644
--- a/demo/FTGLDemo.cpp
+++ b/demo/FTGLDemo.cpp
@@ -30,6 +30,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <iostream>
+#include <sstream>
#if defined HAVE_GL_GLUT_H
# include <GL/glut.h>
@@ -79,7 +81,8 @@ const float OY = 170;
//wchar_t myString[16] = { 0x6FB3, 0x9580};
char myString[4096];
-static FTFont* fonts[7];
+static int const FTGL_NUM_FONTS = 7;
+static FTFont* fonts[FTGL_NUM_FONTS];
static FTPixmapFont* infoFont;
static float textures[][48] =
@@ -144,7 +147,7 @@ void setUpFonts(const char* file)
fonts[FTGL_TEXTURE] = new FTTextureFont(file);
fonts[FTGL_BUFFER] = new FTBufferFont(file);
- for(int x = 0; x < 7; ++x)
+ for(int x = 0; x < FTGL_NUM_FONTS; ++x)
{
if(fonts[x]->Error())
{
@@ -353,7 +356,9 @@ void renderFontInfo()
}
glRasterPos2f(20.0f , 20.0f + infoFont->LineHeight());
- infoFont->Render(fontfile);
+ std::stringstream tmpbuf;
+ tmpbuf << fontfile << " size: " << fonts[current_font]->FaceSize();
+ infoFont->Render(tmpbuf.str().c_str());
// If the current layout is a SimpleLayout, output the alignemnt mode
if(layouts[currentLayout]
@@ -595,10 +600,10 @@ void parseSpecialKey(int key, int x, int y)
switch (key)
{
case GLUT_KEY_UP:
- current_font = (current_font + 1) % 7;
+ current_font = (current_font + 1) % FTGL_NUM_FONTS;
break;
case GLUT_KEY_DOWN:
- current_font = (current_font + 6) % 7;
+ current_font = (current_font + FTGL_NUM_FONTS - 1) % FTGL_NUM_FONTS;
break;
case GLUT_KEY_PAGE_UP:
currentLayout = (currentLayout + 1) % NumLayouts;
@@ -698,6 +703,23 @@ int main(int argc, char *argv[])
exit(1);
}
+ std::cout
+ << "The following interactive commands are available:" << std::endl
+ << "\tTAB: change the alignment of the text" << std::endl
+ << "\tENTER: toggle interactive mode" << std::endl
+ << std::endl
+ << "\tARROW-UP: cycle the font type up" << std::endl
+ << "\tARROW-DOWN: cycle the font type down" << std::endl
+ << "\tARROW-LEFT: decrease the font size" << std::endl
+ << "\tARROW-RIGHT: increase the font size" << std::endl
+ << std::endl
+ << "\tPAGE-UP: cycle the layout up" << std::endl
+ << "\tPAGE-DOWN: cycle the layout down" << std::endl
+ << "\tHOME: decrease line length" << std::endl
+ << "\tEND: increase line length" << std::endl
+ << std::endl
+ << "\tESC: quit" << std::endl;
+
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE);
glutInitWindowPosition(50, 50);