forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Manually setting 4444 texture colours

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Sat Aug 27, 2005 9:15 pm    Post subject: Manually setting 4444 texture colours Reply with quote

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
View user's profile Send private message
holger



Joined: 18 Aug 2005
Posts: 204

PostPosted: Sat Aug 27, 2005 10:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Sat Aug 27, 2005 11:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Sun Aug 28, 2005 8:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
holger



Joined: 18 Aug 2005
Posts: 204

PostPosted: Sun Aug 28, 2005 10:44 pm    Post subject: Reply with quote

do you flush the cache and emit a texture flush command? Alternatively you can write the texture in uncached memory.
Back to top
View user's profile Send private message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Mon Aug 29, 2005 12:05 am    Post subject: Reply with quote

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
View user's profile Send private message
holger



Joined: 18 Aug 2005
Posts: 204

PostPosted: Mon Aug 29, 2005 1:45 am    Post subject: Reply with quote

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
View user's profile Send private message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Mon Aug 29, 2005 1:59 am    Post subject: Reply with quote

Ah, great thanks, I thought sceKernelDcacheWritebackAll(); worked in a different way, thanks for the help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group