I am trying to get a 2D layer to go over my game for the HUD and other things, I've setup the 512x512 texture exactly like the sample, but I need to know what sort of unsigned short will control the 4444 colour palette properly. Is it in the format 0xffffff? or do you need to use a bit-shifting macro? What I would like to know is if I want to set one of the pixels to colour ARGB 255,100,200,100 , how would I do that using the 4444 palette?
Thanks
Manually setting 4444 texture colours
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
The ABGR4444 format does not uses a palette. Try this:
For other pixel formats similiar rules apply, you just need to modify the shift values and bitmasks appropriately.
Code: Select all
static inline
unsigned short color_to_abgr4444 (unsigned char rgba [4])
{
unsigned short c;
c = rgba[0] >> 4;
c |= rgba[1] & 0x00f0;
c |= (rgba[2] << 4) & 0x0f00;
c |= (rgba[3] << 8) & 0xf000;
return c;
}
/* use it like this: */
void convert_pixels (unsigned long *rgba8888_pixels, unsigned short *abgr4444_pixels, int n_pixels)
{
for (i=0; i<n_pixels; i++)
abgr4444_pixels[i] = color_to_abgr4444(rgba8888_pixels[i]);
}
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
I'm having a little problem with this that I can't figure out. I'm using the code:
to set each pixel, which should work, but sometimes the texture doesn't get set, so some of the pixels remain unchanged. Some of these 'missing' pixels flicker on and off. Weird. Any ideas?
Code: Select all
void SetPixel2D(int x, int y, int a, int r, int g, int b){
unsigned char rgba[4];
rgba[0] = r;
rgba[1] = g;
rgba[2] = b;
rgba[3] = a;
pixels[(y*512)+x] = color_to_abgr4444(rgba);
}
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am