1 / 14

Display Lists & Text

Display Lists & Text. Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 22, 2003. Review: Client-Server Model. Many operations in a computing environment, especially in a networked environment, are provided via a client-server model .

Download Presentation

Display Lists & Text

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Display Lists & Text Glenn G. ChappellCHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 22, 2003

  2. Review:Client-Server Model • Many operations in a computing environment, especially in a networked environment, are provided via a client-server model. • The server sits and waits for requests. • A client can request the server to provide services. • This model works well in a CG context. • Client: Application program. • Server: Graphics hardware (or low-level software). • The model affects optimization. • Assumption: client-server communication may be slow. CS 381

  3. Display Lists:Motivation • Many factors can slow down OpenGL rendering. • Scenes modeled in real time may require large computations. • *Function-call overhead. • *Slow client-server communication. • Slow rendering hardware. • In order to mitigate some of these effects (marked with *), OpenGL provides “display lists”. • In OpenGL-speak, these are often called “call lists”. CS 381

  4. Display Lists:What Are They? • A display list (or call list) is a way for an OpenGL implementation to store a sequence of OpenGL commands for later playback. • Application programmers need no knowledge of how display lists are stored. You simply tell OpenGL: Store these commands as a display list. • A display list can be compiled once and executed many times. • Display lists always reduce function-call overhead. • Since display lists may be stored on the graphics hardware, they may reduce client-server communication delays. CS 381

  5. Display Lists:Usage Overview • We compile a display list in four steps: • Allocate a “name” (actually an integer) for the list. (glGenLists). • Tell OpenGL that we are creating a display list (glNewList). • Make the OpenGL function calls that we want to store in the display list. • Tell OpenGL that we are finished creating the list (glEndList). • We can later execute the commands in the display list. • We use a display list by calling it (glCallList). • This tells OpenGL to execute all the commands stored in the list, just as if we made all those calls again, but generally a bit faster. CS 381

  6. Display Lists:Usage Details — Naming • An OpenGL display-list “name” is just a number. • But that number must be assigned by OpenGL. • Get a display-list name with glGenLists. • 1 parameter: # of list names to generate. • Return value: 1st list name generated, or 0 if error. • Put the name into a global int. • Check for errors! int my_list; // global // The following goes in function init, maybe? my_list = glGenLists(1); // Give me 1 list name if (my_list == 0) { cerr << "Could not make display-list" << endl; exit(1); // Error } CS 381

  7. Display Lists:Usage Details — Compilation • We compile a display list using glNewList. 2 parameters: • The list name. • Either GL_COMPILE or GL_COMPILE_AND_EXECUTE. • The latter is useful when making a display list in the display function. • Then give the OpenGL commands to be stored in the list. • Last, glEndList (no parameters). glNewList(my_list, GL_COMPILE); // Lots of OpenGL commands here // Indentation helps, as with glBegin/glEnd glEndList(); • You can do glBegin…glEnd inside the above, but do not do the above inside glBegin…glEnd. CS 381

  8. Display Lists:Usage Details — Execution • We execute a display list using glCallList. • 1 parameter: The list name. // The following goes in the display function! glCallList(my_list); • There is also glCallLists, for executing multiple display lists. CS 381

  9. EXAMPLE 1 • Modify intro2d.cpp to use a display list. • Modified the program so that the color was set and the square was drawn using a display list. • The display list was created in function init. • The display function was reduced to 3 lines: • Clear the viewport. • Execute the display list. • Flush. CS 381

  10. Text:Introduction • In CG, text comes in two varieties: • Raster/bitmap fonts. • Text described as an image. • Outline/stroke fonts. • Text described as a sequence of curves. • Both are available, in a limited form, in GLUT. • We will discuss bitmap text here. CS 381

  11. Text:Raster Position & Bitmaps [1/2] • When we make bitmap text, we are telling OpenGL to draw a raster image. • A raster image is drawn with the left-hand point on its baseline at the current raster position. • The OpenGL raster position is specified with glRasterPos*. • Coordinates passed via glRasterPos* pass through the same transformations as those passed via glVertex*. • However, glRasterPos* is not called between glBegin & glEnd. CS 381

  12. Text:Raster Position & Bitmaps [2/2] • Bitmap images are raster images with 1 bit per pixel. • They are intended specifically for rendering bitmap text. • OpenGL draws bitmap images with the primitive glBitmap. • This command includes an amount to move the raster position by. • We will use GLUT commands, not glBitmap, but it is important to remember that glBitmap is what GLUT calls. CS 381

  13. Text:Using GLUT Bitmap Fonts • We draw a character at the current raster position using glutBitmapCharacter. 2 parameters: • The GLUT font to use. • I use GLUT_BITMAP_9_BY_15. See doc’s for others. • The character to render. • The raster position is advanced by an appropriate amount. CS 381

  14. EXAMPLE 2 • See the program bmptext.cpp, which draws bitmap text using GLUT. • Source code is on the web page. CS 381

More Related