Drawing a simple rectangle as raster font background


I would like to draw a simple rectangle, say 200 x 50 pixels (as background to a raster font generated with wglUseFontBitmaps).

Is there a smarter way to do it than to use glBitmap and a gigantic array of one:s?

(I guess using glBegin(GL_QUADS) or something similar won’t work for me as I want to specify the size of this rectangle in pixels, whereas GL_QUADS wants me to specify all vertexes of the rectangle).

// David

if you use glOrtho(0, window_width, 0, window_height, -1., 1.), all values that you pass to glVertex() will be pixel units.

Thanks for your help, but the position of the rectangle should be somewhere in the scene (and affected by rotations etc), so I can’t use glOrtho to change the projection matrix.

The effect is somewhat like a speech bubble or an explanatory text related to an object.

// David

You can convert the 3D object space coordinates to 2D screencoordinates with gluProject:

// Coordinates in 2D:
GLdouble winX, winY, winZ;
// Project object coord to window coordinate
if (gluProject(x, y, z, modelMatrix, projMatrix, viewport, &winX, &winY, &winZ))
MyDrawStringFunction(s, winX, winY, winZ, txtCol, bckCol);