0

I'm making a text renderer that uses FreeType 2 and legacy OpenGL. Problem is, FreeType 2's coordinate system has (0, 0) in the top left corner while OpenGL's coordinate system is Cartesian. This means I have to flip the bitmap. I expected glScalef to work with glBitmap but it has no effect. Can anyone tell me if it's possible to flip a bitmap vertically with glScalef, or if it is not possible, point me to some other source that can flip a bitmap upside down (Preferably efficiently as possible)?

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1.0, -1.0, 1.0)
glBitmap(size_x, size_y, 0, 0, xadd, yadd, (GLubyte *) bitmap);
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982

1 Answers1

0

The function you are looking for is glPixelZoom.

Pixel zoom factors are not limited to positive values. Negative zoom factors reflect the resulting image about the current raster position.

It definitely will have the desired effect on glDrawPixels. There's a note in glBitmap saying that it acts like glDrawPixels but I cannot find any explicit statement on whether glPixelZoom applies to glBitmap or not, so YMMV.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • I tested it and nothing happened... does it work with glBitmap or only glDrawPixels? I've heard that glDrawPixels is pretty inefficient and would like to avoid that if possible. – testaccoun0987 Sep 07 '20 at 23:17
  • `glBitmap` said "The bitmap image is interpreted like image data for the glDrawPixels command, with width and height corresponding to the width and height arguments of that command, and with type set to GL_BITMAP and format set to GL_COLOR_INDEX. Modes specified using glPixelStore affect the interpretation of bitmap image data; modes specified using glPixelTransfer do not." so I was hoping that it indeed meant it was treated like glDrawPixels data. – Ben Voigt Sep 08 '20 at 19:31
  • If by `glDrawPixels` you are referring to https://stackoverflow.com/a/8777965/103167 then yes he's right, and the same caution applies to `glBitmap`. Textures are just better although more complicated to set up. – Ben Voigt Sep 08 '20 at 19:32
  • Thanks, I'll go figure out how to use textures since they seem to be more flexible than ```glBitmap```. – testaccoun0987 Sep 08 '20 at 22:04