views:

57

answers:

2
+1  Q: 

glBitmap questions

I'm working with a legacy piece of code in some stuff for work which uses glBitmap() calls to draw bitmap icons. My issue is that it's rather slow once you get to drawing about 1000 icons at once. It slows down to about a 1- to 2-second refresh rate, and I'd like to see if I can make it faster than that.

First I should probably describe how the current code works. The bitmap icons are 32x32 images with one bit per pixel, pre-loaded into memory. For each icon being drawn, the code does:

glNewList glRasterPos2f glBitmap glEndList

and then glCallList() is called on the display list. I know that calling glCallList() repeatedly like this for each icon can be really slow, but some overlying architecture in the code makes changing that pretty difficult.

Are there any other ways I can speed this up without rearchitecting the whole thing? I have pretty much free reign to do that kind of thing, but I have to be able to justify it to management. Would changing from glBitmap() to using something like texture-mapped quads be any faster? Can I stick multiple calls to glBitmap() in a single display list and just call glCallList() once for all of the icons?

I've done a bit of GL stuff in the past but it's been a while. I'm pretty rusty but I can figure most of it out.

+3  A: 

Textured quads all the way. I used that for rendering text (axis numbers for graphs) and got 60 FPS with several hundred digits on-screen, with Intel integrated video (a couple years ago, so it was GMA945 generation).

Put all the icon content into a single texture too, and just call glTexCoord to pick out the part you want, then you avoid switching textures.

BTW since your icons are monochrome (and for grayscale as well), store them in the texture's alpha channel and then you can choose the actual color when you output the quads.

Ben Voigt
Being fairly new to texture mapping, what do I pass to glTexImage2D? I can massage the input data into whatever format it needs to be in. It doesn't have to stay 1-bit-per-pixel.
timwoj
If 1 bit per pixel, use internalFormat = `GL_ALPHA`, type = `GL_BITMAP`. For 256-greyscale, use internalFormat = `GL_ALPHA8`, type = `GL_UNSIGNED_BYTE`. In both cases format = `GL_ALPHA`. I like to use PBM or PGM graphics files (can be created by Gimp, Photoshop, etc) because the data is already in the correct format to load with `glTexImage2D`, but you can use any format Windows supports and then call `GetDIBits` on the image to get the raw data to pass to OpenGL.
Ben Voigt
A: 

Agreed : use screen-aligned quads. Set up your modelview matrix to identity and your projection matric to gluOrtho(0,0, 800, 600, 1,-1). Draw your quads at (x,y,0). (beware of their orientation)

Never use display list, they are a nightmare to maintain for drivers developpers and may not be stable

Never use glBitmap or any other function that directly access the framebuffer (glGetPixels & co )

Calvin1602