Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object for bitmap fonts using OpenGL

Status
Not open for further replies.

vanleurth

Programmer
Sep 1, 2001
156
US
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, &quot;symbol&quot;) == 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);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top