summaryrefslogtreecommitdiffstats
path: root/menu_demo/font.c
diff options
context:
space:
mode:
Diffstat (limited to 'menu_demo/font.c')
-rw-r--r--menu_demo/font.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/menu_demo/font.c b/menu_demo/font.c
new file mode 100644
index 0000000..620ec19
--- /dev/null
+++ b/menu_demo/font.c
@@ -0,0 +1,83 @@
+#ifdef G_OS_WIN32
+ #define WIN32_LEAN_AND_MEAN 1
+ #include <windows.h>
+#endif
+
+#include <GL/gl.h>
+
+#include "font.h"
+#include "bitmap.h"
+
+struct BitmapStruct g_sFont;
+
+int g_iWinWidth;
+int g_iWinHeight;
+
+GLuint base;
+
+void FontInit(int f_iWinWidth, int f_iWinHeight)
+{
+ float cx;
+ float cy;
+ int i = 0;
+
+ g_iWinWidth = f_iWinWidth;
+ g_iWinHeight = f_iWinHeight;
+
+ g_sFont = BitmapLoad("img/continuum_textured_alpha.bmp");
+
+ base = glGenLists(256);
+ glBindTexture(GL_TEXTURE_2D, g_sFont.m_iImageId);
+
+ for (i = 0; i < 256; i++)
+ {
+ cx = (float)(i % 16) / 16.0f;
+ cy = (float)(i / 16) / 16.0f;
+
+ glNewList(base + i, GL_COMPILE);
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2f(cx, 1 - cy);
+ glVertex2i(0, 0);
+ glTexCoord2f(cx + 0.0625f, 1 - cy);
+ glVertex2i(FONT_WIDTH, 0);
+ glTexCoord2f(cx, 1 - cy - 0.0625f);
+ glVertex2i(0, FONT_HEIGHT);
+ glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f);
+ glVertex2i(FONT_WIDTH, FONT_HEIGHT);
+ glEnd();
+
+ glTranslated(FONT_SPACING, 0, 0);
+ glEndList();
+ }
+
+} // BuildFont
+
+void FontDelete(GLvoid)
+{
+ glDeleteLists(base, 256);
+
+} // FontDelete
+
+void glPrint(GLint x, GLint y, char *string)
+{
+ glColor3d(0, 0, 0);
+ glBindTexture(GL_TEXTURE_2D, g_sFont.m_iImageId);
+ glDisable(GL_DEPTH_TEST);
+ glMatrixMode(GL_PROJECTION);
+
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(0, g_iWinWidth, g_iWinHeight, 0, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glTranslated(x, y, 0);
+ glListBase(base - 32);
+ glCallLists((GLsizei)strlen(string), GL_UNSIGNED_BYTE, string);
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+} // glPrint \ No newline at end of file