Ok, now I'm stumped again.
I get no errors from the BuildFont() function, but there is nothing being displayed. I have removed some of the error checking code to make it easier to read, but wglUseFontBitmaps() does not return false, and the SelectObject() function returns the font properly now.
Posted is the full CText class and the calls to the class:
#ifndef __GL_TEXT_H_#define __GL_TEXT_H_#include <windows.h>#include <stdio.h>#include <stdarg.h>#include <gl/gl.h>#include <gl/glu.h>#include <gl/glaux.h>class CText{public: CText(); CText(HDC hdc); ~CText(); GLvoid Print(float x, float y, const char *fmt, ...);protected: GLvoid BuildFont(GLvoid); GLvoid KillFont(GLvoid); HDC m_hDC; GLuint m_base;};#endif
#include "text.hpp"CText::CText(){ }CText::CText(HDC hdc) : m_hDC(hdc){ BuildFont(); }CText::~CText(){ KillFont();}GLvoid CText::BuildFont(GLvoid) { HFONT font; HFONT oldfont; m_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(m_hDC, font); wglUseFontBitmaps(m_hDC, 32, 96,m_base); SelectObject(m_hDC, oldfont); DeleteObject(font); }GLvoid CText::KillFont(GLvoid) { glDeleteLists(m_base, 96); }GLvoid CText::Print(float x, float y, const char *fmt, ...) { char text[256]; va_list ap; int len; if (fmt == NULL) return; va_start(ap, fmt); len = _vscprintf(fmt, ap) + 1; if(len > 256) return; vsprintf_s(text,len,fmt, ap); va_end(ap); glRasterPos2f(x, y); glPushAttrib(GL_LIST_BIT); glListBase(m_base - 32); glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); glPopAttrib(); }
Declared global:
In my initialisation where ghdc is a global, working, HDC:
TextPrinter = CText(ghdc);
And finally the actual call: I do not tranformations, all matrices are loaded with identity matrices
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glColor3f(0.1, 0.3, 0.9);TextPrinter.Print(0.0, 0.0, "Hello Milla!"); SwapBuffers(ghdc);
Again, is this something obvious I'm missing or what? any help appreciated