The hardware accelerates drawing rectangles that have their vertical and horizontal edges parallel to those of the window. The OpenGL glRect() call--as opposed to IRIS GL rect()--specifies rectangles, but depending on the matrix transformations they may not be screen-aligned. If the matrices are such that the rectangle drawn by glRect() is screen-aligned, OpenGL detects that and uses the accelerated mode for screen-aligned rectangles.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,xsize,0,ysize);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_FLAT);
You also have to use a glVertex2fv() call to specify 2D vertices.
glEnable(GL_TEXTURE_2D);
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
In addition, follow these guidelines:
Note that the above fast path does not work when stencil is enabled and when depth buffering and alpha testing are both on.
Note: Avoid using depth buffering whenever possible, because the fill rates for depth buffering are much slower. In particular, avoid using depth-buffered lines, as they are especially slow. The depth buffer is as large as the window, so use the smallest possible window to minimize the amount of memory allocated to the depth buffer. The same applies for stencil buffers.
Format | Type |
---|---|
GL_RGBA | GL_UNSIGNED_BYTE |
GL_ABGR_EXT | GL_UNSIGNED_BYTE |
GL_COLOR_INDEX | GL_UNSIGNED_BYTE |
GL_COLOR_INDEX | GL_UNSIGNED_SHORT |
Note that GL_ABGR_EXT provides better performance than GL_RGBA on Indigo Entry systems but not on Indy or Indigo2 XL where the two perform about the same.
Here are some additional guidelines for optimizing pixel operations:
When you scroll something, such as a teleprompter text scroll or an EKG display, use glCopyPixels() to shift the part of the window in the scrolling direction, and draw only the area that's newly exposed.
This is much faster than completely redrawing each frame.