I was learning to display fonts in my program, but when I tried it, it didn't work that easily. The problem is that when I load the textures, fonts don't appear on the screen, and when I dont load the textures, fonts work well. At first, I load some textures to memory at the beginning of the program, like this:
data = (unsigned char*) malloc(128*128*3*sizeof(unsigned char));
if(!data) return 0;
glGenTextures(1, &tekstuuri);
glBindTexture(GL_TEXTURE_2D, tekstuuri);
// Load .raw texture
tiedosto = fopen("tekstuuri.raw", "rb");
if(!tiedosto) return 0;
fread(data, 3, 128*128, tiedosto);
fclose(tiedosto);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
As you can see, I use .raw textures. And the code/function that makes the problem is glTexImage2D(....); I found that out by myself. The functions that deal with the fonts: (About the same code, as Nehe's tutorial 13)
void CreateFontti(void)
{
HFONT font;
HFONT oldfont;
base = glGenLists(96);
font = CreateFont(-24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Courier New");
oldfont = (HFONT)SelectObject(hdc, font);
wglUseFontBitmaps(hdc, 32, 96, base);
SelectObject(hdc, oldfont);
DeleteObject(font);
}
void glPrint(char *text)
{
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
void KillFont(void)
{
glDeleteLists(base, 96);
}
The question: How to make this working, with .raw textures?