Open GL Super Bible:Raster Graphics in OpenGL
To access the contents, click the chapter and section titles.
Open GL Super Bible
(Publisher: Macmillan Computer Publishing)
Author(s): Waite group Press
ISBN: 1571690735
Publication Date: 08/01/96
Previous
Table of Contents
Next
Before you create the font bitmaps, you need to decide on a character set. Normally youłll use the ANSI or UNICODE character sets. The ANSI character set (ANSI_CHARSET) provides the standard 7-bit ASCII character set. To support international characters and diacritical marks, use the UNICODE character set instead (UNICODE_CHARSET). Some fonts use special character sets. The Symbol font, for example, provides Greek letters and many scientific symbols.
For this simple implementation, we will set the character set to ANSI_CHARSET for normal fonts, and SYMBOL_FONTSET for the Symbol font. See Listing 11-3.
Listing 11-3 Continuation of the FontCreateBitmaps function
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);
SelectObject(hdc, font);
wglUseFontBitmaps(hdc, 32, 96, base);
return (base);
}
If you need to use international characters, change the “normal" character set to UNICODE_CHARSET, and define 224 characters (256 minus 32), as shown here:
else
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, 224, base);
To complement FontCreateBitmaps youłll need a font deletion function (Listing 11-4). Here the glDeleteLists function simply deletes the specified display lists, in this case our font bitmaps. As with the FontCreateBitmaps function, to make this function work with international character sets you need to change the number of display lists from 96 to 224.
Listing 11-4 FontDelete function
void
FontDelete(GLuint font) /* I - Font to delete */
{
if (font == 0)
return;
glDeleteLists(font, 96);
}
Finally, to make drawing character strings easier, you can make put-string and printf-string functions. FontPuts (Listing 11-5) uses the glPushAttrib and glPopAttrib functions to save and restore the current display list base ID. If you forget to do this, you might inadvertently affect your other drawing code that uses display lists!
Listing 11-5 FontPuts function
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();
}
A Note About glCallLists and Strings: It is important to remember that glCallLists and the font functions presented here do not handle control characters such as tab and newline. If you include control characters in the string you display, other display lists may be called that affect your final output. This behavior can be controlled by parsing the incoming string prior to using glCallLists. Newline and tab functionality can be simulated using the glBitmap technique outlined in the previous note, “A Note About the Current Raster Position," along with a call to glGetIntegerv (described in Chapter 14).
The FontPrintf function (Listing 11-6) uses the <stdarg.h> header file to manage the variable number of arguments needed for vsprintf, which formats the string to be drawn.
Listing 11-6 FontPrintf function
#define MAX_STRING 1024
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); /* Start variable argument processing */
vsprintf(s, format, ap); /* Format the text into our output string */
va_end(ap); /* End variable argument processing */
FontPuts(font, s);
}
The complete code for FontCreate, FontDelete, FontPuts, and FontPrintf can be found in the CH11\FONT.C file. Prototypes are in the CH11\FONT.H file on the source code CD-ROM.
Pixmaps: Bitmaps with Color
Images with more than two colors are usually called pixmaps (short for pixel maps) and are used as background images or textures (covered in Chapter 12). In OpenGL, pixmaps are generally either 8-bit color index images or 24-bit RGB images.
Previous
Table of Contents
Next
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
351 354352 353354 356przeglad;mody,kategoria,352Dz U 2000 nr 29 poz 354 Tekst aktu350 35203 (352)349 352 j425pxv7fxhj4hqs7eplgh7th52blr5sya3fhqq352,21,artykul354 (2)344 352więcej podobnych podstron