Hi Everybody,
Here my problem. From the SuperBible (chapter 7) I have been trying to create and object that I could use to write 2D bitmap text on my Ortho. It doesn't work ???
Any ideas ? (Really appretiated)
#include "stdafx.h"
#include "OpenGL.h"
#include "OpenGLView.h"
#include <stdarg.h>
#include <string.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// Construction/Destruction
CPixFont::CPixFont(HDC Hdc, const char *Typeface, int Height, int Weight, DWORD Italic)
{
// Create display list for the fonts (256) bitmaps
base = glGenLists(256);
// Pass arguments to member variables.
italic = Italic;
hdc = Hdc;
height = Height;
weight = Weight;
typeface = Typeface;
// Create Font
FontCreate();
}
CPixFont::~CPixFont()
{
// Delete display list for the bitmaps
glDeleteLists(base, 256);
}
void CPixFont::GPrint(int align, const char *format, ...)
{
int strwidpix;
unsigned char *ptr; // pointer to string
va_list ap; // Argument pointer
// Sets arg_ptr to the first optional argument in the list.
va_start(ap, format);
// Write formatted output using a pointer to a list of arguments.
vsprintf((char *) s, format, ap);
// Reset argument pointer.
va_end(ap);
// Determine the string width in pixel
for (ptr = s, strwidpix = 0; *ptr; ptr ++)
strwidpix = strwidpix + widths[*ptr];
if (align < 0)
glBitmap(0, 0, 0, 0, -strwidpix, 0, NULL);
else if (align == 0)
glBitmap(0, 0, 0, 0, -strwidpix/2, 0, NULL);
// Draw using bitmap fonts.
FontPuts();
}
void CPixFont::FontPuts(void)
{
// Push the current list attributes
glPushAttrib(GL_LIST_BIT);
//
glListBase(base);
glCallLists(strlen((char *) s), GL_UNSIGNED_BYTE, s);
glPopAttrib();
}
void CPixFont::FontCreate(void)
{
int charset; // Character set code
HFONT fontid; //Windows font Id
// Choose character set
if (stricmp (typeface, "symbol" == 0)
charset = SYMBOL_CHARSET;
else
charset = ANSI_CHARSET;
// Load bitmap font
fontid = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE, charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, typeface);
// The SelectObject function selects an object into the specified
// device context. The new object replaces the previous object of the same type.
SelectObject(hdc, fontid);
// Create glBitmaps from fontid.
wglUseFontBitmaps(hdc, 0, 256, base);
// Collect the width information for the font and store it
// in the arrays.
GetCharWidth(hdc, 0, 255, widths);
}
Here my problem. From the SuperBible (chapter 7) I have been trying to create and object that I could use to write 2D bitmap text on my Ortho. It doesn't work ???
Any ideas ? (Really appretiated)
#include "stdafx.h"
#include "OpenGL.h"
#include "OpenGLView.h"
#include <stdarg.h>
#include <string.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// Construction/Destruction
CPixFont::CPixFont(HDC Hdc, const char *Typeface, int Height, int Weight, DWORD Italic)
{
// Create display list for the fonts (256) bitmaps
base = glGenLists(256);
// Pass arguments to member variables.
italic = Italic;
hdc = Hdc;
height = Height;
weight = Weight;
typeface = Typeface;
// Create Font
FontCreate();
}
CPixFont::~CPixFont()
{
// Delete display list for the bitmaps
glDeleteLists(base, 256);
}
void CPixFont::GPrint(int align, const char *format, ...)
{
int strwidpix;
unsigned char *ptr; // pointer to string
va_list ap; // Argument pointer
// Sets arg_ptr to the first optional argument in the list.
va_start(ap, format);
// Write formatted output using a pointer to a list of arguments.
vsprintf((char *) s, format, ap);
// Reset argument pointer.
va_end(ap);
// Determine the string width in pixel
for (ptr = s, strwidpix = 0; *ptr; ptr ++)
strwidpix = strwidpix + widths[*ptr];
if (align < 0)
glBitmap(0, 0, 0, 0, -strwidpix, 0, NULL);
else if (align == 0)
glBitmap(0, 0, 0, 0, -strwidpix/2, 0, NULL);
// Draw using bitmap fonts.
FontPuts();
}
void CPixFont::FontPuts(void)
{
// Push the current list attributes
glPushAttrib(GL_LIST_BIT);
//
glListBase(base);
glCallLists(strlen((char *) s), GL_UNSIGNED_BYTE, s);
glPopAttrib();
}
void CPixFont::FontCreate(void)
{
int charset; // Character set code
HFONT fontid; //Windows font Id
// Choose character set
if (stricmp (typeface, "symbol" == 0)
charset = SYMBOL_CHARSET;
else
charset = ANSI_CHARSET;
// Load bitmap font
fontid = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE, charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, typeface);
// The SelectObject function selects an object into the specified
// device context. The new object replaces the previous object of the same type.
SelectObject(hdc, fontid);
// Create glBitmaps from fontid.
wglUseFontBitmaps(hdc, 0, 256, base);
// Collect the width information for the font and store it
// in the arrays.
GetCharWidth(hdc, 0, 255, widths);
}