Lesser color textures / images

BlitzMax Forums/OpenGL Module/Lesser color textures / images

Shagwana(Posted 2005) [#1]
Is it possible to have a 2 color image (aka 1bit per pixel) or maybe even a 256 color image (aka byte per pixel) stored on the graphics card thats then used for drawing in either 16bit and 32bit?. Net result would be some images could take up less room in gfx memory.

If so, anyone got pointers on how to make that happen in BlitzMax ?


ImaginaryHuman(Posted 2005) [#2]
Look at OpenGL `Bitmaps`, which are 1-bit, usually used for text characters but you could use them for other objects.

Some graphics cards support the `index mode` buffers, mine don't and I'm guessing that isn't very widespread since most people have 16/32-bit color these days. Index mode was basically like planar/chunky graphics 256-color modes.

Somehow 256 colors are possible, since if I set my desktop to 256 colors and draw stuff in OpenGL it dithers down to 256 colors. But internally it's still 32bit RGBA.

Um .... you could have one image which handles each color component separately, then you could effectively store three images in one actual images. One is stored in the Red component, one in Green and one in Blue. You can then specify which components of the color buffer you write to. Would at least let you draw reg, green, or blue images ;-D ... or maybe with some use of Blending you can get it to convert that one color component into three?

Internally though all the Images are 32bit in the same format, I don't *think* you can have different format Images, like you can with Pixmaps. You could store less data in a pixmap but it'd be converted to 32bit when you transfer it.


ImaginaryHuman(Posted 2005) [#3]
Taking a look at more OpenGL documentation, I see that you can actually use glTexImage2D with a variety of internal formats and a variety of formats for the pixel data that is uploaded to the gfx card. Max2D creates textures in RGBA format, but there are many other options. I am trying to experiment with these at the moment (e.g. having a texture which is just GL_ALPHA only). Apparently you can have 4-bit components (e.g. GL_RGBA4), which would be less color resolution, um .. 12bit color? 4096 colors (like original Ham6 on the Amiga!)

For example...

"The number of color components in the texture. Must be 1, 2, 3, or 4, or one of the following symbolic constants: GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16, GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, GL_RGBA8, GL_RGB10_A2, GL_RGBA12, or GL_RGBA16. "

taken from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_16jo.asp


Shagwana(Posted 2005) [#4]
Did you get anywhere with this AngelDaniel ?


ImaginaryHuman(Posted 2005) [#5]
No, I wasn't trying to get anywhere with it.

You can have the graphics card store whatever format you want for your data. You can have it store 16-bit color using the codewords with a 4 on the end, such as GL_RGBA4. You can also specify that the alpha buffer will only be 1-bit using the codewords which have _A1 at the end, such as GL_RGB5_A1 would give you 5-bits per color component for color and 1 bit per pixel for an alpha buffer/mask.

If your graphics card cannot support the exact mode you request it will default to using whatever is nearest.

BlitzMax isn't set up to support 256-color indexed color displays - for example the command glEnable(GL_LOGIC_OP) which works on the indexed backbuffer is not even defined as a valid command. So there is no indexed color support. You can use GL_LUMINENCE if you want grayscale images.


Sonic(Posted 2008) [#6]
Hi, sorry to revive this one, but I was just wondering about the same issue.

I'm doing an animation-heavy but low colour game. Is there any way for me to use / modify the LoadImage / LoadAnimImage commands and ensure the GPU is storing textures internally at a lower bitrate? Ideally I'd have a .png24->GL_RGBA5 converter built into my load function (to use half less VRAM) - but would Blitz 'take over' and force conversion to 32bit when uploading to the GPU?


ImaginaryHuman(Posted 2008) [#7]
If you use Max2D to upload to video ram as `Images` it will convert it to 24-bit color probably. You will have to write your own OpenGL code requesting that the data be stored in a given format, and it will only work if your graphics card/driver supports that format for textures. But it is possible.