glDrawPixels with a xbm image

Hi, I’m having some problems trying to draw a bitmap to screen. This is probably really stupid, but I’m really new to OpenGL and I wasn’t even able to google for an appropiate answer to my problems.

I’m trying to draw a xbm image containing a simple font to screen. I just want the simplest and smaller way of using a pixelated font. I made a simplified version of the image just to test the drawing functions:

#define pong_font_width 4
#define pong_font_height 4
static unsigned char pong_font_bits[] = {
   0x09, 0x00, 0x00, 0x01 };

That should draw to something like


Where “X” is black and “_” is white.
The closer I got to properly rendering the image was with glBitmap, but
the result is inverted vertically, and glPixelZoom doesn’t make any effect in making the image bigger or inverting it.

glRasterPos2f((MI_WIDTH(mi)-pong_font_width*8)/2, MI_HEIGHT(mi)*8/10);
glBitmap( pong_font_width, pong_font_height,
          0, 0, 0, 0,
          pong_font_bits );

The proper method if I want to be in control of the zoom factor is probably glDrawPixels, but I can’t find the combination of parameters to properly render it.

This code renders nothing, and the closer I got to something useful was drawing some multicolor random garbage (I don’t remember with wich parameters).

glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

static unsigned char colors[] = { 0x01, 0x00, 0x00, 0x00 };

glRasterPos2f( (MI_WIDTH(mi)-pong_font_width*8)/2, MI_HEIGHT(mi)*8/10 );
glPixelZoom( 8.0, 8.0 );
glDrawPixels( pong_font_width,
              pong_font_bits2 );

Could anybody help me out? I’m pretty sure I’m not understanding some basic concept about OpenGL rendering here.

bitmaps, pixelzoom, etc are completely outdated, not on the fast path.
It is way better to use textured quads instead. Much easier to scale rotate etc.

Even making a texture with glTexImage2D I needa similar kind of parameters. I tried some combinations but I only managed rubbish in the texture.

In every single tutorial I’ve found they use RGB values for the textures, but here I’m trying to use directly my xbm data. Is this possible (and if it is, what would the internal format, format and pixel data type be?), or should I just transform my XBM B&W bitmap data into RGB data and stop bitching?

Indeed, converting bitmap BW to RGB is easy and common :slight_smile:

If the texture memory usage becomes too high, you can use 1-channel textures :
GL_LUMINANCE8 as internal format and GL_LUMINANCE as format, GL_UNSIGNED_BYTE as type, ans send only monochrome values 0-255.

But I never used it myself.

Thanks a lot, I was trying to use GL_COLOR_INDEX and GL_BITMAP to directly use the data without processing, without any luck, but the GL_LUMINANCE method works fine and it’s easy to implement :slight_smile:

GL_COLOR_INDEX and GL_BITMAP are really outdated too :wink: