views:

605

answers:

1

Is it possible to pump monochrome (graphical data with 1 bit image depth) texture into OpenGL?

I'm currently using this:

glTexImage2D( GL_TEXTURE_2D, 0, 1, game->width, game->height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, game->culture[game->phase] );

I'm pumping it with square array of 8 bit unsigned integers in GL_LUMINANCE mode (one 8 bit channel represents brightness of all 3 channels and full alpha), but it is IMO vastly ineffective, because the onlu values in the array are 0x00 and 0xFF.

Can I (and how) use simple one-bit per pixel array of booleans instead somehow? The excessive array size slows down any other operations on the array :(

+2  A: 

The smallest uncompressed texture-format for luminance images uses 8 bits per pixel.

However, 1 bit per pixel images can be compressed without loss to the S3TC or DXT format. This will still not be 1 bit per pixel but somewhere between 2 and 3 bits.

If you really need 1 bit per pixel you can do so with a little trick. Load 8 1 bit per pixel textures as one 8 bit Alpha-only texture (image 1 gets loaded into bit 1, image 2 into bit 2 and so on). Once you've done that you can "address" each of the sub-textures using the alpha-test feature and a bit of texture environment programming to turn alpha into a color.

This will of only work if you have 8 1 bit per pixel textures and tricky to get right though.

Nils Pipenbrinck
The 8 textures trick sounds interesting, but it is not really what I am looking for. I'm using the OpenGL to visualize data from my application, so such trick would slow down standard operation on the array (not speaking of programming complications).
CommanderZ