#include <stdio.h>
#include <string.h>
#include "gamefontgl.h"
#include <GL/gl.h>
#include <GL/glut.h>
#include <il/il.h>
#include <il/ilu.h>
#include <il/ilut.h>
const int c_Width = 800, c_Height = 600;
const char *c_displayMode = "800x600:16@60";
int main( int argc, char **argv )
{
glutInitWindowPosition ( 0, 0 ) ;
glutInitWindowSize( c_Width, c_Height );
glutInit( &argc, argv ) ;
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ;
if ((argc==2) && (!strcmp(argv[1], "-fullscreen"))) {
glutGameModeString( c_displayMode );
glutEnterGameMode();
} else {
glutCreateWindow( "Font Test/Demo" ) ;
}
// initilize IL
ilInit();
glClearColor( 0.5, 0.5, 1, 1.0 );
glutDisplayFunc( cbDisplay ) ;
glDisable(GL_DEPTH_TEST );
glutMainLoop () ;
return 0;
}
|
void cbDisplay()
{
static bool initialized = false;
static unsigned int fontId, texFont;
static int count = 0;
if (!initialized) {
ilutRenderer( ILUT_OPENGL );
// Load the font image
ilGenImages( 1, &ilutFontId );
ilBindImage( ilutFontId );
if (!ilLoadImage( "fatmarker512.png" )) {
printf("Loading image failed\n");
}
texFont = ilutGLBindTexImage();
|
// Create a font by passing in an opengl texture id fontId = gfCreateFont( texFont ); |
// A .finfo file contains the metrics for a font. These
// are generated by the Fontpack utility.
gfLoadFontMetrics( fontId, "fatmarker512.finfo");
printf("font has %d chars\n",
gfGetFontMetric( fontId, GF_FONT_NUMCHARS ) );
|
gfEnableFont( fontId, 64 );
initialized = true;
}
|
// Clear the screen
glClear( GL_COLOR_BUFFER_BIT );
|
// Now draw some text on top.
// Use gfBeginText(), gfDrawString() and gfEndText() to draw text.
glColor3f( 1.0, 1.0, 1.0 );
gfEnableFont( fontId, 64 );
gfBeginText();
glTranslated( 300, 100, 0 );
gfDrawString("Hello World!\nWhats up?" );
gfEndText();
|
glutSwapBuffers();
}
|