glBitmap or glDraw/ReadPixels

Hi there,

I’m writing an app that requires to draw symbols (triangles, circles, etc), the size of these symbols is given on pixels, and may or not be filled, so no matter how close/far or what view the user is at, the symbols stay the same, I may have to draw an average of 10,000 of them, what should I use ?, I think my options are glBitmap or glDrawPixels, I have read that glBitmap is slower, but what I like about it is that zeros do not affect background, which is what I need, if I do it with glDrawPixels, I think I may have to do glReadPixels for the background on every symbol… any suggestions ?

Many thanks in advance.

glBitmap and glDrawPixels will both be slower than a textured quad.
If pixel operations like that are enough, you can store your symbols in one big texture atlas and use texture coordinates to select each of the symbols while using simple nearest fitering.
This way you can render all 10000 symbols with a single bind texture call and a single(!) draw call (use vertex arrays).
Redrawing 10000 of those textured quads per frame isn’t too hard for current graphics hardware.
Drawing pixel aligned quads just needs the correct matrix setup. Use glOrtho or gluOrtho2D and set the projection matrix to the corners of your viewport. Load identity into the modelview matrix and then the quads’ vertices are on full numbers.
Having the symbols in textures also allows for some other options like transparency, and rotation(!).

many thanks for your reply!

I agree I should use textured quads, and what you say sounds very good, however I would need to make a lot of combinations in that big texture, so I was thinking if I could do the texture in the fly (in memory, no loading files) and then draw it, is that possible ?, I think it should, also, how can I draw a masked textured quad ?, I mean, I would like that one special color on the texture (perhaps black color) be used as transparent, so when draw, the background is preserved.

I don’t know what you mean with “combinations”.
How many different symbols do you have and how big are they?

I mean if there are 10,000 differnt symbols and each is just 1616 pixel, a texture edge would be sqrt(1616*10000) = 1600 long. A single texture could hold that on a modern graphics board.

You can generate the input data to the glTexImage2D however you like. glTexImage2D will just try to copy whatever you throw at it.

You can and should use the alpha channel inside an RGBA texture to define transparency.
You can either use a paint program to generate the alpha mask for you or do it yourself during loading if you find a unique color which shoul be transparent, set its alpha to 0.0 (GLubyte 0x00) or 1.0 (GLubyte 0xFF).

Then search for glAlphaFunc and GL_ALPHA_TEST in the OpenGL spec which explains how to keep texels from generating fragments depending on their alpha values.

by combinations I mean that symbols have parameters, like shape type, size, filled or hollow, etc…
defintely I’ll do them on the fly, since glTexImage2D just takes what you give, pehaps the user may create its own symbol so no practical use of the texture file…

about the masked texture, I don’t know about the alpha test, I’m still newbie at GL, I havce to study it, I was reading on Nehe tutorial # 20, which is about masked textures that you can do it with blending… for your texture, you need to have its mask which is a black and white image, black where the solid part is and white for trasnparent, first you set glBlendFunc( GL_DST_COLOR, GL_ZERO ); and draw the masked texture on a quad, then set glBlendFunc( GL_ONE, GL_ONE ); and draw the original texture, looks fine to me, but then I’ll have to find a way for generating the texture mask on the fly as well… does the alpha test do the same at the end next to this blend approach??, what do you suggest me ?

btw, I already tried glBitmap, not too bad at all, though the graphic operations (rotate, pan) slow down… but at least does not dies… maybe becasuse I use a display list… so, next to this way, is the texture quad much more faster ?, how much ?

the other pro I see on glBitmap is that I specify the origin of the symbol in 3D world, which is what I want, if I do on an ortho2D view with texture quad I might have to convert every point to screen coords right ?

ok, many thanks again for taking the time to reply.