GLART week 8: Text

Assigment: Add text to any of the previous homework assignments. Reading: Redbook pages 255-277 "Chapter 7: Display Lists" Examples: GLART_8_text.java -- flat text drawn over a scene GLART_8_textInSpace.java -- text drawn in a 3D scene Requires font_tahoma.png and GLImage.java Images: Illuminated Manuscript, Giotto and Bosch Resources: Bitmap Font Builder -- creates texture images of character sets NOTES: ================================================================= OpenGL does not have any font or text capabilities built-in, but there are several ways to create text, including building geometry from font shapes, or drawing images of letters. This second method is simple and works well in most situations so we'll explore it here. The idea is to draw an image of a letter textured onto a quad. That's not so complex by itself, but the problem becomes more substantial when you consider that there are 26 letters in the alphabet, plus upper and lower case, and then there are numbers, punctuation, etc. Fortunately with some clever use of texture coordinates and display lists, we can create a character set and draw any text string we want with minimal effort. We'll need a texture image (font_tahoma.png) that contains a full character set arranged in order by ascii value. The buildFont() function creates a set of quads, each textured with one character from the character set image. The textured quads are rendered into a set of display lists, so that we can later draw any character just by calling its display list. The glPrint() function draws text by matching each character in a text string with the correct display list, then running callList() to draw that character. glPrint() calls setOrthoOn() to set the projection mode to ortho, and disables the depth test so text draws on top of other geometry. We don't need any new functions to use text in OpenGL, but there are some settings that affect how text will appear: texture - be sure to glEnable(GL_TEXTURE_2D) light - disable lighting (glDisable(GL_LIGHTING)), to insure that the text color is even across the screen. With lighting on, some or all of the text may appear shadowed. blend - enable blending so the background of the text will be transparent. glEnable(GL_BLEND) glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)