I would like to know if its possible to run through a texture stored in an AUX_RGBImageRec type, to access the single pixels of it.
I want to add some kind of color-keying to my textures through setting pixels with a special color-value to an 0-alpha-value.
since aux is no longer documented in .net 2k3, and since i have never personally used this structure (or aux for that matter), i make no guarantess about the following code.
assuming you have successfully loaded your image with auxDIBImageLoad, you can plow through the bits with this:
unsigned char* data = image->data;
for( int y = 0; y < image->sizeY; y++ )
{
for( int x = 0; x < image->sizeX; x++ )
{
// get or set here
unsigned char red = data[0];
unsigned char green = data[1];
unsigned char blue = data[2];
// advance to next rgb triple
// !!! assumes packed rgb
data += 3;
}
}
Sorry for double-posting, just wanted to say that it worked great. I got it after a while
Thank you for your help.
However I’ve another question
I want to make it possible to load non-squared textures like 140x60 pixels, instead of 128x128… I think it works when I load the .bmp and copy it to a 128x128 texture, and the fill-up the empty parts with black. I think it should be no problem to code, however here are to questions:
How can I check the nearest square-size to the size of the bitmap… eg, how can I tell my code that a 256x256 pixel-texture should be created when there’s a 210x280 pixel bitmap?
How can I set the texture-coordinates to a QUAD that it gets only textured with the part of the texture that is filled?
If you want to know why I need it: I’m coding a 2D-engine with OpenGL, and I want that I can load free-sized bitmaps
I set up the orthographic mode, so one coordinate-unit is 1 pixel.
using this approach you also eat up less texture memory for your textures (generally).
there are some limitations (no GL_REPEAT texture mode for one)…
if you decide to use power of two textures you can adapt the code below to find the nearest power of two given the native resolution of the image
int nextPow2(int i)
{
//get to the nearest power of two dimension
//less than i.
int pow2 = 2;
while(pow2 < i)
pow2 *= 2;
//deterimine if we scale up or down now:
//find the power of two which is closest to
//native size
if(abs(i-pow2) < abs(i-(pow2*2)))
return pow2
return pow2*2;
}