00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #ifndef GLPRINTF_H
00029 #define GLPRINTF_H
00030
00031 #if _WIN32
00032 # include <windows.h>
00033 #endif
00034
00035 #ifdef __APPLE__
00036 # include <OpenGL/gl.h>
00037 # include <GLUT/glut.h>
00038 #else
00039 # include <GL/gl.h>
00040 # include <GL/glut.h>
00041 #endif
00042
00043 #include <cstring>
00044 #include <cstdarg>
00045 #include <cstdio>
00046
00047 #if _WIN32
00048 # pragma warning(disable:4996)
00049 #endif
00050
00062 void glPrintf(const char* msg, ...)
00063 {
00064 static GLuint fontBase = 0;
00065 if(!glIsList(fontBase))
00066 {
00067 fontBase = glGenLists(127);
00068 for(unsigned int i=0; i!=127; ++i)
00069 {
00070
00071 glNewList(fontBase + i, GL_COMPILE);
00072 glutBitmapCharacter(GLUT_BITMAP_8_BY_13, i);
00073 glEndList();
00074 }
00075 }
00076
00077
00078 char str[256];
00079 va_list arg;
00080 va_start(arg, msg);
00081 vsnprintf(str, 256, msg, arg);
00082 va_end(arg);
00083
00084
00085 glRasterPos3f(0,0,0);
00086 glListBase(fontBase);
00087 glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
00088 }
00089
00090 #if _WIN32
00091 # pragma warning(default:4996)
00092 #endif
00093
00094
00095 #endif
00096