| View previous topic :: View next topic |
| Author |
Message |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Sat Aug 27, 2005 9:15 pm Post subject: Manually setting 4444 texture colours |
|
|
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 |
|
| Back to top |
|
 |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Sat Aug 27, 2005 10:45 pm Post subject: |
|
|
The ABGR4444 format does not uses a palette. Try this:
| Code: |
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]);
}
|
For other pixel formats similiar rules apply, you just need to modify the shift values and bitmasks appropriately. |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Sat Aug 27, 2005 11:14 pm Post subject: |
|
|
| Excellent, thanks a lot, it's working perfectly now, although the engine is chugging a bit, having to draw a fully lit 3D world and a 2D layer, but i'll try and get it sorted before release. |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Sun Aug 28, 2005 8:33 pm Post subject: |
|
|
I'm having a little problem with this that I can't figure out. I'm using the code:
| Code: | 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);
} | 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? |
|
| Back to top |
|
 |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Sun Aug 28, 2005 10:44 pm Post subject: |
|
|
| do you flush the cache and emit a texture flush command? Alternatively you can write the texture in uncached memory. |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Mon Aug 29, 2005 12:05 am Post subject: |
|
|
| I assume you mean sceGuTexFlush();, but where does it go? It doesn't seem to change anything using it before or after the pixel data is copied to the texture. |
|
| Back to top |
|
 |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Mon Aug 29, 2005 1:45 am Post subject: |
|
|
| You need to flush the DCache after you completed the texture in RAM if you wrote it into a cached memory area. |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Mon Aug 29, 2005 1:59 am Post subject: |
|
|
| Ah, great thanks, I thought sceKernelDcacheWritebackAll(); worked in a different way, thanks for the help. |
|
| Back to top |
|
 |
|