Text Picking

I am drawing text using the OpenGL bitmaps(glBitmap) on to the drawing area created using X-Motif. I want to pick that text using the mouse as like any other geometric objects. So, please give me the coding details using OpenGL.

OpenGL has the selection buffer and that can be used for picking. You need to determine the dimensions of the glBitmap to be drawn and render a invisible primitive in the exact location.

Or better yet, just use textured primitives for your text and use those for the selection buffer as well.

V-man

Hi,
Thanks alot,
But , how to find the dimensions of a bitmap character.So that , I can draw a rectangle around that bitmap , then I can pick.
Please , give me an idea.
Thank you
Sadhu

The glBitmap will be a raster operation, so you know for certain which pixels are gone get rendered to.

You need to know the current raster position. Its also best for this case to use a ortho projection, and to have ortho be the size of your screen.

glOrtho(0, width, 0, height, -1.0, 1.0);

Now call
glRaster2i(rasterX, rasterY);

The primitive can be
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(rasterX, rasterY);
glVertex2f(rasterX, rasterY+height_of_glBitmap);
glVertex2f(rasterX+width_of_glBitmap, rasterY);
glVertex2f(rasterX+width_of_glBitmap, rasterY+height_of_glBitmap);
glEnd();

I hope this is correct. You can do a test and see. Also, there are the rasterization rules of opengl that may effect the exact pixels that get rendered too (something about a tiny offset needed in glVertex calls - 0.375 I think)

PS: cross your fingers!
V-man

That may need to be

glBegin(GL_TRIANGLE_STRIP);
glVertex2f(rasterX, rasterY);
glVertex2f(rasterX, rasterY-height_of_glBitmap);
glVertex2f(rasterX+width_of_glBitmap, rasterY);
glVertex2f(rasterX+width_of_glBitmap, rasterY-height_of_glBitmap);
glEnd();

V-man

Hi V-man,
thank you very much.

Regards.
sadhu