Manually setting 4444 texture colours

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Manually setting 4444 texture colours

Post by AnonymousTipster »

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
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

The ABGR4444 format does not uses a palette. Try this:

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 |= &#40;rgba&#91;2&#93; << 4&#41; & 0x0f00;
        c |= &#40;rgba&#91;3&#93; << 8&#41; & 0xf000;
        return c;
&#125;

/* use it like this&#58; */
void convert_pixels &#40;unsigned long *rgba8888_pixels, unsigned short *abgr4444_pixels, int n_pixels&#41;
&#123;
        for &#40;i=0; i<n_pixels; i++&#41;
                abgr4444_pixels&#91;i&#93; = color_to_abgr4444&#40;rgba8888_pixels&#91;i&#93;&#41;;
&#125;
For other pixel formats similiar rules apply, you just need to modify the shift values and bitmasks appropriately.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

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.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

I'm having a little problem with this that I can't figure out. I'm using the code:

Code: Select all

void SetPixel2D&#40;int x, int y, int a, int r, int g, int b&#41;&#123;
unsigned char rgba&#91;4&#93;;
rgba&#91;0&#93; = r;
rgba&#91;1&#93; = g;
rgba&#91;2&#93; = b;
rgba&#91;3&#93; = a;
pixels&#91;&#40;y*512&#41;+x&#93; = color_to_abgr4444&#40;rgba&#41;;

&#125;
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?
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

do you flush the cache and emit a texture flush command? Alternatively you can write the texture in uncached memory.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

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.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

You need to flush the DCache after you completed the texture in RAM if you wrote it into a cached memory area.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

Ah, great thanks, I thought sceKernelDcacheWritebackAll(); worked in a different way, thanks for the help.
Post Reply