PDA

View Full Version : Alpha for 2D sprites



Levante
04-10-2010, 04:55 PM
Hi all,

I'm creating a 2D game in OpenGL, and I'm using the following texture loader to load up my textures:

http://members.iinet.net.au/~cleathley/openGL/TextureLoader.htm

Some of you may recognise it, and I hope so! Because whenever I try to display a loaded up texture, it just comes out as whatever colour I last set glColor4f() to.

I have a 24 bit bitmap loader that loads the textures and displays them fine, however I can't set an alpha value with that, so the backgrounds of my sprites show up, which isn't helpful :(

So, would anyone be able to either:

A) Explain how to fix the problem I'm having with Chris Leathley's texture loader.

Or B) Explain how I can make a single colour of a 24 bit bitmap that I've loaded up in OpenGL completely transparent (if it's even possible)

Any help is greatly appreciated :)

Rob

David_pb
04-11-2010, 03:59 AM
Hi,

I dont know the your code, so I can't say anything about A. But for B: You can copy the image data in a larger buffer and set the alpha values as you wish.

Some pseudocode:


imageData = your loaded rgb data

buffer = alloc(width * height * 4); // as in RGBA
ptr = buffer;
for ( int i = 0; i < width * height; i += 3 )
{
*ptr++ = imageData[i+0];
*ptr++ = imageData[i+1];
*ptr++ = iamgeData[i+2];
*ptr++ = 0; // thats your alpha value
}

// upload buffer etc...

Levante
04-11-2010, 07:16 AM
Thank you very much, it worked beautifully :) <3