Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

beginning opengl game programming 2004 phần 9 pps
MIỄN PHÍ
Số trang
26
Kích thước
570.2 KB
Định dạng
PDF
Lượt xem
829

beginning opengl game programming 2004 phần 9 pps

Nội dung xem thử

Mô tả chi tiết

setting up the bitmap font for use with Windows through the wglUseFontBitmaps() func￾tion, the CreateBitmapFont() method returns the base ID for the character display list.

Next is the RenderFont() method, which displays a string of text using the selected bitmap

font at a specified raster position:

void CGfxOpenGL::RenderFont(int xPos, int yPos, unsigned int base, char *str)

{

if ((base == 0) || (!str))

return;

glRasterPos2i(xPos, yPos);

glPushAttrib(GL_LIST_BIT);

glListBase(base - 32);

glCallLists((int)strlen(str), GL_UNSIGNED_BYTE, str);

glPopAttrib();

}

The RenderFont() method is very simple in that it verifies the base ID and string it receives

before setting the raster position and rendering the text display list. Finally, we have the

ReleaseFont() method, which simply cleans up the font display list:

void CGfxOpenGL::ReleaseFont(unsigned int base)

{

if (base != 0)

glDeleteLists(base, 96);

}

The rest of the code uses these functions to display the screenshot shown in Figure 11.1.

The example is set up in orthographic projection. We recommend orthographic projec￾tion when rendering with bitmap fonts because it enables you to specify the raster posi￾tion coordinates in window coordinates, and you don’t need to worry about the

perspective projection affecting the raster position.

That’s all for bitmap fonts! Let’s look at another technique for putting text on the screen:

outline fonts.

Outline Fonts

Outline fonts are very similar to the bitmap fonts we just discussed, but they are much

more fun to play around with! Outline fonts define characters in a font as a series of lines

and curves, which means they can be scaled up and down without a loss in quality. With

Outline Fonts 253

11 BOGL_GP CH11 3/1/04 10:06 AM Page 253

TLFeBOOK

OpenGL, you can move outline font text around the screen in 3D, give the font text some

thickness, and essentially turn any font on the current system into a 3D font with all the

functionality of other 3D objects.

To use outline fonts, you first need to declare an array of 256 GLYPHMETRICSFLOAT variables,

which hold information about the placement and orientation of a glyph in a character

cell. The GLYPHMETRICSFLOAT structure is a special structure created specifically for using text

with OpenGL. It is defined as:

typedef struct _GLYPHMETRICSFLOAT { // gmf

FLOAT gmfBlackBoxX;

FLOAT gmfBlackBoxY;

POINTFLOAT gmfptGlyphOrigin;

FLOAT gmfCellIncX;

FLOAT gmfCellIncY;

} GLYPHMETRICSFLOAT;

You’ll pass the GLYPHMETRICSFLOAT variable you create to the wglUseFontOutlines() function.

This function creates a set of display lists, one for each glyph of the current outline font,

which you can use to render text to the screen. This function is defined as:

BOOL wglUseFontOutlines(

HDC hdc, // device context of the outline font

DWORD first, // first glyph to be turned into a display list

DWORD count, // number of glyphs to be turned into display lists

DWORD listBase, // specifies the starting display list

FLOAT deviation, // specifies the maximum chordal deviation from the

// true outlines

FLOAT extrusion, // extrusion value in the negative-z direction

int format, // specifies line segments or polygons in display lists

LPGLYPHMETRICSFLOAT lpgmf // address of buffer to receive glyph metric data

);

Creation of the outline font is essentially the same as the bitmap font with the addition of

these two items. For instance, compare the CreateBitmapFont() function we showed earlier

with this CreateOutlineFont() function:

unsigned int CreateOutlineFont(char *fontName, int fontSize, float depth)

{

HFONT hFont; // windows font

unsigned int base;

base = glGenLists(256); // create storage for 256 characters

if (stricmp(fontName, “symbol”) == 0)

254 Chapter 11 ■ Displaying Text

11 BOGL_GP CH11 3/1/04 10:06 AM Page 254

TLFeBOOK

Tải ngay đi em, còn do dự, trời tối mất!