summaryrefslogtreecommitdiffstats
path: root/matchblox/common/font.c
diff options
context:
space:
mode:
Diffstat (limited to 'matchblox/common/font.c')
-rw-r--r--matchblox/common/font.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/matchblox/common/font.c b/matchblox/common/font.c
new file mode 100644
index 0000000..0332174
--- /dev/null
+++ b/matchblox/common/font.c
@@ -0,0 +1,90 @@
+#ifdef G_OS_WIN32
+ #define WIN32_LEAN_AND_MEAN 1
+ #include <windows.h>
+#else
+ #define FALSE 0
+ #define TRUE !FALSE
+#endif
+
+#include <GL/gl.h>
+#include <string.h>
+
+#include "font.h"
+#include "bitmap.h"
+
+struct BitmapStruct g_sFont;
+
+int g_iWinWidth;
+int g_iWinHeight;
+
+GLuint g_iBase;
+
+
+void FontInit(int f_iWinWidth, int f_iWinHeight)
+{
+ float cx;
+ float cy;
+ int l_iImageId;
+ int i = 0;
+
+ float x = (float)(1.0f/FONT_XCHAR);
+
+ g_iWinWidth = f_iWinWidth;
+ g_iWinHeight = f_iWinHeight;
+
+ g_sFont = BitmapLoad("img/continuum_textured_alpha.bmp");
+ l_iImageId = g_sFont.m_iImageId;
+
+ g_iBase = glGenLists(FONT_COUNT);
+ glBindTexture(GL_TEXTURE_2D, l_iImageId);
+
+ for (i = 0; i < FONT_COUNT; i++)
+ {
+ cx = (float)(i % 16) / 16.0f;
+ cy = (float)(i / 16) / 16.0f;
+
+ glNewList(g_iBase + i, GL_COMPILE);
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2f(cx, 1 - cy); glVertex2i(0, 0);
+ glTexCoord2f(cx + x, 1 - cy); glVertex2i(FONT_WIDTH, 0);
+ glTexCoord2f(cx, 1 - cy - x); glVertex2i(0, FONT_HEIGHT);
+ glTexCoord2f(cx + x, 1 - cy - x); glVertex2i(FONT_WIDTH, FONT_HEIGHT);
+ glEnd();
+
+ glTranslated(FONT_SPACING, 0, 0);
+ glEndList();
+ }
+
+} // BuildFont
+
+
+void FontDelete(void)
+{
+ glDeleteLists(g_iBase, FONT_COUNT);
+
+} // FontDelete
+
+
+void glPrint(GLint x, GLint y, char *string, struct ColorStruct f_sColor)
+{
+ glColor3d(f_sColor.m_dRed, f_sColor.m_dGreen, f_sColor.m_dBlue);
+ 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(g_iBase - 32);
+ glCallLists((GLsizei)strlen(string), GL_UNSIGNED_BYTE, string);
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+} // glPrint