Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot understand gl raster position

Tags:

opengl

I still cannot understand the "raster position" when I use OpenGL to draw fonts even after reading the Red book. What is raster position? What's the difference between the glrasterpos2f and glvertex2f? What is GL_CURRENT_RASTER_POSITION? Why I must use this API to draw a font? I'll be appreciated if anyone can illustrate this.

like image 711
Yan Li Avatar asked Nov 17 '25 10:11

Yan Li


1 Answers

Older versions of OpenGL have a number of "raster" operations, that perform pixel manipulations directly on the framebuffer's pixel raster, without going through the whole primitive setup.

The raster position is the position in window coordinates at which the next raster operation will start from. For example glDrawPixels will just overdraw a portion of the framebuffer, with the raster position defining the lower left corner where the replacing pixel data will be placed. Similar to that glBitmap allows to replace pixels' values with the glColor and in the same step advance the raster position.

When setting the raster position with glRasterPos, the coordinate passed to this call are subjected to the same transformation pipeline as vertex coordinates, to produce the window coordinate raster position. Important only the raster position is transformed, the actual raster operations happen in "pixel space" and are not transformed. Also if the coordinate passed to glRasterPos happens to be clipped, the following raster operations will become No-Ops.

If you want to set the raster pos in window coordinates directly, you can use glWindowPos for that.

Why I must use this API to draw a font?

It is trivial to draw bitmap fonts using glBitmap and hence it used to be a very popular method for font drawing. Hence, in case you're using raster ops to draw a font you must set the raster position.

However in modern versions of OpenGL (version 3 and beyond) all raster ops have been removed. This also means, that you must use a different method to draw text in modern versions of OpenGL.

like image 68
datenwolf Avatar answered Nov 19 '25 08:11

datenwolf