summaryrefslogtreecommitdiffstats
path: root/menu_demo/font.c
blob: e3773a58bea235731e65d450c0bba2696a3cc0dc (plain)
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
81
82
83
84
85
86
87
#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 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(void)
{
	glDeleteLists(base, 256);

} // 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(base - 32);
	    glCallLists((GLsizei)strlen(string), GL_UNSIGNED_BYTE, string);
	    glMatrixMode(GL_PROJECTION);
	  glPopMatrix();
	  glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

} // glPrint