Setting up a gradient Like Palette

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

Moderators: cheriff, TyRaNiD

Post Reply
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Setting up a gradient Like Palette

Post by ayatollah »

Hi

I am trying to setup a 32Bit Palette to use as Texture which generally works just fine using:

Code: Select all

		sceGuClutMode(GU_PSM_8888,0,0xff,0); // 32-bit palette
		sceGuClutLoad((256/8),clut256); // upload 32*8 entries (256)
		sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
now the (for me) tricky part.. I am trying to compute the Color Palette and I found varous sources on the net.. All of them deal with VGA Mode where it appears that one needs to call:

Code: Select all

    outp(0x3C8,col);   
    outp(0x3C9,R);   
    outp(0x3C9,G);   
    outp(0x3C9,B);
and this loop does the trick:

Code: Select all

    for &#40;x=1; x<=32; x++&#41; &#123;
        setrgb&#40;x, 0, 0, x*2-1&#41;;       /* Blue part */
        setrgb&#40;x+32, x*2-1, 0, 63&#41;;
        setrgb&#40;x+64, 63, x*2-1, 63&#41;;
        setrgb&#40;x+96, 63, 63, 63&#41;;
 
        setrgb&#40;x+128, 63, 63, 63&#41;;
        setrgb&#40;x+160, 63, 63, 63-&#40;x*2-1&#41;&#41;;
        setrgb&#40;x+192, 63, 63-&#40;x*2-1&#41;, 0&#41;;
        setrgb&#40;x+224, 63-&#40;x*2-1&#41;, 0, 0&#41;; /* Red part */

    &#125;
I found in the CLUT Sample of the SDK a Routine that does set up the Plaette like

Code: Select all

unsigned int* clut = &#40;unsigned int*&#41;&#40;&#40;&#40;unsigned int&#41;clut256&#41;|0x40000000&#41;;
		for &#40;i = 0; i < 256; ++i&#41;
		&#123;
			unsigned int j = &#40;i + offset&#41;&0xff;
			*&#40;clut++&#41; = &#40;j << 24&#41;|&#40;j << 16&#41;|&#40;j << 8&#41;|&#40;j&#41;;
		&#125;
Now if I use this, it gives me a GREYScale Palette only..
I tried to do:

Code: Select all

   for &#40;i=1; i<=32; i++&#41; 
	&#123;
        *clut+i		= &#40;0xff << 24&#41; | &#40;&#40;i*2-1&#41; << 16&#41; | &#40;0 << 8&#41; | 0;  	
        *clut+i+32	= &#40;0xff << 24&#41; | &#40;63 << 16&#41; | &#40;0 << 8&#41; | &#40;i*2-1&#41;;
        *clut+i+64	= &#40;0xff << 24&#41; | &#40;63 << 16&#41; | &#40;&#40;i*2-1&#41; << 8&#41; | 63;
        *clut+i+96	= &#40;0xff << 24&#41; | &#40;63 << 16&#41; | &#40;63 << 8&#41; | 63;

        *clut+i+128	= &#40;0xff << 24&#41; | &#40;63 << 16&#41; | &#40;63 << 8&#41; | 63;
        *clut+i+160	= &#40;0xff << 24&#41; | &#40;63-&#40;i*2-1&#41; << 16&#41; | &#40;63 << 8&#41; | 63;
        *clut+i+192	= &#40;0xff << 24&#41; | &#40;0 << 16&#41; | &#40;63-&#40;i*2-1&#41; << 8&#41; | 63;
        *clut+i+224	= &#40;0xff << 24&#41; | &#40;0 << 16&#41; | &#40;0 << 8&#41; | 63-&#40;i*2-1&#41;; */
	&#125;
 &#125;
but obviously that does not work. It gives the Error Message:

error: invalid lvalue in assignment

Anyhow.. I am really bad at pointers and not really sure how to get this done.. Is there anybody out that that can help me?? I am aware that this is a general C problem and the topic will most likely be closed but maybe somebody can shed some light ?!??!

THANK YOU SO MUCH!
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

look at the CLUT sample again. especialy this line:

Code: Select all

*&#40;clut++&#41; = &#40;j << 24&#41;|&#40;j << 16&#41;|&#40;j << 8&#41;|&#40;j&#41;;
then look at your code, here for example:

Code: Select all

*clut+i+32   = ...
if you still don't see it, try this ;)

Code: Select all

*&#40;clut+i+32&#41;   = ...
infj
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Post by ayatollah »

ouch... Thanx.. it works like a charm now !!!!
Post Reply