350 352














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




The width and height parameters specify the width and height of the bitmap. The bits parameter contains the bitmap you want to draw and is 32-bit aligned. The xorig and yorig parameters contain the center location of the bitmap. After the bitmap is drawn, the current raster position is moved by (xmove,ymove) pixels, and the raster position valid flag is left unchanged. The xmove and ymove parameters are normally used for bitmap fonts (described in the upcoming section) to advance to the next character “cell."


A Note About the Current Raster Position:  As stated earlier,
bitmaps will not be drawn if the raster position is outside the bitmap.
However, since the raster position valid flag is left unchanged after a
call to glBitmap, you can use glBitmap to position and draw bitmaps that
are partially clipped on the edge of the current viewport. For example,
hereƂs how to draw the smiley bitmap just to the left of the current
viewport:

glRasterPos2i(0, 0);
glBitmap(0, 0, 0.0, 0.0, -4.0, 0.0, NULL);
glBitmap(16, 16, 8.0, 8.0, 0.0, 0.0, smiley);

The NULL parameter in the first call to glBitmap simply specifies that there is no bitmap to draw. After the first call to glBitmap, the current raster position will be moved 4 pixels to the left (
4.0) before the real bitmap is drawn in the second call. This solution also applies to drawing pixmaps, explained later in this chapter.


Bitmap Fonts
One very important application of bitmaps is displaying character strings. Under ordinary circumstances, you would have to define a bitmap array for each character and then draw the bitmaps as necessary to display the string. Fortunately, the Microsoft Windows Win32 libraries provide a function called wglUseFontBitmaps to generate these bitmaps from font files loaded on your system.

To use the font bitmaps, OpenGL provides three functions: glGenLists, glListBase and glCallLists (described in Chapter 10). The glGenLists function generates a contiguous series of OpenGL display list IDs that will hold the character bitmaps created by wglUseFontBitmaps.

GLuint base;
HDC hdc;

base = glGenLists(96);
wglUseFontBitmaps(hdc, 32, 96, base);

This creates 96 character bitmaps from the current font starting at character 32, the ASCII code for the space character. The base variable contains the first display list bitmap in the fontin this case, character 32 (ASCII space). To display a string of characters using these bitmaps, you use a combination of glListBase and glCallLists:


char *s;

glListBase(base - 32);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);

The glListBase function sets the base display list ID. The glCallList and glCallLists functions will add this number to the display list ID(s) passed to them, effectively selecting the font you just defined. The glCallLists function calls a series of display lists based upon the array of characters (unsigned bytes) you pass in, which draws the character string.

Building a Simple Font Library
Certainly the wglCreateFontBitmaps function simplifies font creation, but you still have to do a lot just to output a character string. You can build a usable font library fairly easily, however. To start, youƂll need a font creation function (Listing 11-2).

Listing 11-2 The beginning of the FontCreateBitmaps function

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)
return (0);

The typeface argument is simply the name of the font, such as Courier or Helvetica, and specifies the style of character that you want. The height, weight, and italic arguments are passed directly to wglUseFontBitmaps and set the size and appearance of the characters.




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