PDA

View Full Version : glDrawPixels with a xbm image



RazZziel
11-20-2008, 03:33 PM
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


X__X
____
____
X___

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);
glEnable(GL_COLOR_TABLE);

static unsigned char colors[] = { 0x01, 0x00, 0x00, 0x00 };
glColorTable(GL_COLOR_TABLE, GL_RGB8, 1, GL_RGB, GL_UNSIGNED_BYTE, colors);

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_height,
GL_COLOR_INDEX,
GL_BITMAP,
pong_font_bits2 );

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

ZbuffeR
11-20-2008, 04:49 PM
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.

RazZziel
11-22-2008, 05:52 PM
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?

ZbuffeR
11-23-2008, 04:40 AM
Indeed, converting bitmap BW to RGB is easy and common :)

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.

RazZziel
11-23-2008, 03:02 PM
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 :)

ZbuffeR
11-23-2008, 03:11 PM
GL_COLOR_INDEX and GL_BITMAP are really outdated too ;)