Display Lists - PowerPoint PPT Presentation

About This Presentation
Title:

Display Lists

Description:

We compile a display list in four steps: Allocate a 'name' (actually an integer) for the list. ... EXAMPLE 2. See the program bmptext.cpp, which draws bitmap ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 15
Provided by: glenngc
Learn more at: https://www.cs.uaf.edu
Category:
Tags: compile | display | lists

less

Transcript and Presenter's Notes

Title: Display Lists


1
Display Lists Text
  • Glenn G. ChappellCHAPPELLG_at_member.ams.org
  • U. of Alaska Fairbanks
  • CS 381 Lecture Notes
  • Monday, September 22, 2003

2
ReviewClient-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.

3
Display ListsMotivation
  • 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.

4
Display ListsWhat 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.

5
Display ListsUsage 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.

6
Display ListsUsage 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 ltlt "Could not make display-list" ltlt endl
  • exit(1) // Error

7
Display ListsUsage 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 glBeginglEnd inside the above, but do
    not do the above inside glBeginglEnd.

8
Display ListsUsage 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.

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.

10
TextIntroduction
  • 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.

11
TextRaster 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.

12
TextRaster 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.

13
TextUsing 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 docs for others.
  • The character to render.
  • The raster position is advanced by an appropriate
    amount.

14
EXAMPLE 2
  • See the program bmptext.cpp, which draws bitmap
    text using GLUT.
  • Source code is on the web page.
Write a Comment
User Comments (0)
About PowerShow.com