#define MAX_STRING 1024
GLuint SmallFont, /* Small raster font */
SymbolFont, /*symbol font*/
MediumFont, /* Medium raster font */
LargeFont; /* Large raster font */
GLuint FontCreateBitmaps(HDC hdc, char *typeface, int height,
int weight, DWORD italic);
GLuint FontCreateOutlines(HDC hdc, char *typeface, int height,
int weight, DWORD italic);
void FontDelete(GLuint font);
void FontPrintf(GLuint font, char *format, ...);
void FontPuts(GLuint font, char *s);
GLuint
FontCreateBitmaps(HDC hdc, /* I - Device Context */
char *typeface, /* I - Font specification */
int height, /* I - Font height/size in pixels */
int weight, /* I - Weight of font (bold, etc) */
DWORD italic) /* I - Text is italic */
{
GLuint base; /* Base display list for font */
HFONT font; /* Windows font ID */
//if ((base = glGenLists(96)) == 0)
if ((base = glGenLists(224)) == 0)
return (0);
if (stricmp(typeface, "symbol") == 0)
font = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
SYMBOL_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
DEFAULT_PITCH, typeface);
else
font = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
DEFAULT_PITCH, typeface);
/*font = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
UNICODE_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
DEFAULT_PITCH, typeface);
*/
SelectObject(hdc, font);
//wglUseFontBitmaps(hdc, 32, 96, base);
wglUseFontBitmaps(hdc, 32, 224, base);
return (base);
}
/*
* 'FontDelete()' - Delete the OpenGL display lists used for a font.
*/
void
FontDelete(GLuint font) /* I - Font to delete */
{
if (font == 0)
return;
// glDeleteLists(font, 96);
glDeleteLists(font, 224);
}
/*
* 'FontPuts()' - Display a string using the specified font.
*/
void
FontPuts(GLuint font, /* I - Font to use */
char *s) /* I - String to display */
{
if (font == 0)
return;
if (s == NULL)
return;
glPushAttrib(GL_LIST_BIT);
glListBase(font - 32);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);
glPopAttrib();
}
/*
* 'FontPrintf()' - Display a formatted string using the specified font.
*/
void
FontPrintf(GLuint font, /* I - Font to use */
char *format, /* I - printf() style format string */
...) /* I - Other arguments as necessary */
{
va_list ap; /* Argument pointer */
char s[MAX_STRING + 1]; /* Output string */
if (format == NULL)
return;
va_start(ap, format);
vsprintf(s, format, ap);
va_end(ap);
FontPuts(font, s);
}
//finnally to draw the text inside your function
{
SmallFont = FontCreateBitmaps(m_hDC, "Courier", 12, FW_BOLD, 0);
double x=10;
double y=20;
double z=15;
glRasterPos3d(x , y, z);
FontPuts(SmallFont, "-x");
}
#define MAX_STRING 1024
GLuint SmallFont, /* Small raster font */
SymbolFont, /*symbol font*/
MediumFont, /* Medium raster font */
LargeFont; /* Large raster font */
GLuint FontCreateBitmaps(HDC hdc, char *typeface, int height,
int weight, DWORD italic);
GLuint FontCreateOutlines(HDC hdc, char *typeface, int height,
int weight, DWORD italic);
void FontDelete(GLuint font);
void FontPrintf(GLuint font, char *format, ...);
void FontPuts(GLuint font, char *s);
GLuint
FontCreateBitmaps(HDC hdc, /* I - Device Context */
char *typeface, /* I - Font specification */
int height, /* I - Font height/size in pixels */
int weight, /* I - Weight of font (bold, etc) */
DWORD italic) /* I - Text is italic */
{
GLuint base; /* Base display list for font */
HFONT font; /* Windows font ID */
//if ((base = glGenLists(96)) == 0)
if ((base = glGenLists(224)) == 0)
return (0);
if (stricmp(typeface, "symbol") == 0)
font = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
SYMBOL_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
DEFAULT_PITCH, typeface);
else
font = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
DEFAULT_PITCH, typeface);
/*font = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
UNICODE_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
DEFAULT_PITCH, typeface);
*/
SelectObject(hdc, font);
//wglUseFontBitmaps(hdc, 32, 96, base);
wglUseFontBitmaps(hdc, 32, 224, base);
return (base);
}
/*
* 'FontDelete()' - Delete the OpenGL display lists used for a font.
*/
void
FontDelete(GLuint font) /* I - Font to delete */
{
if (font == 0)
return;
// glDeleteLists(font, 96);
glDeleteLists(font, 224);
}
/*
* 'FontPuts()' - Display a string using the specified font.
*/
void
FontPuts(GLuint font, /* I - Font to use */
char *s) /* I - String to display */
{
if (font == 0)
return;
if (s == NULL)
return;
glPushAttrib(GL_LIST_BIT);
glListBase(font - 32);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);
glPopAttrib();
}
/*
* 'FontPrintf()' - Display a formatted string using the specified font.
*/
void
FontPrintf(GLuint font, /* I - Font to use */
char *format, /* I - printf() style format string */
...) /* I - Other arguments as necessary */
{
va_list ap; /* Argument pointer */
char s[MAX_STRING + 1]; /* Output string */
if (format == NULL)
return;
va_start(ap, format);
vsprintf(s, format, ap);
va_end(ap);
FontPuts(font, s);
}
//finnally to draw the text inside your function
{
SmallFont = FontCreateBitmaps(m_hDC, "Courier", 12, FW_BOLD, 0);
double x=10;
double y=20;
double z=15;
glRasterPos3d(x , y, z);
FontPuts(SmallFont, "-x");
}
To copy to clipboard, switch view to plain text mode
Bookmarks