Coloring from black to fully transparent

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

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Coloring from black to fully transparent

Post by Ghoti »

Hi folks,

I want to make a fading thingy that fades from black to transparent.

for this i use the rectangle to screen function (from graphics.c from the yelarb tutorials):

Code: Select all

extern void fillScreenRect(Color color, int x0, int y0, int width, int height);
the color however is not in ABGR, it is in some other format that is only 1 large number. I know that there is some kind of conversion to alter the alpha channels of the color. I have seen in some other posts that they use (i guess) bitshifting. however i don't really know what it is and how i can use it for this problem. The examples i could find only work the other way around. they work from that colorcode to AGBR and i need the other way.

can someone help me out?

greets ghoti
Aion
Posts: 40
Joined: Mon Jul 24, 2006 10:58 pm
Location: Montreal

Post by Aion »

That should do the job :

Code: Select all

//Takes value between 0-255 for each channel, output 32bits color
#define ARGB8888&#40;_A_,_R_,_G_,_B_&#41;	&#40;	&#40;&#40;u32&#41;_A_&0xFF&#41;<<24&#41;	|	\
									&#40;			&#40;&#40;u32&#41;_R_&0xFF&#41;<<16&#41;	|	\
									&#40;			&#40;&#40;u32&#41;_G_&0xFF&#41;<<8&#41;		|	\
									&#40;		&#40;&#40;u32&#41;_B_&0xFF&#41;<<0&#41;			&#41;

//Takes value between 0-16 for each channel, output 16bits color
#define ARGB4444&#40;_A_,_R_,_G_,_B_&#41;	&#40;	&#40;&#40;u16&#41;_A_&0x0F&#41;<<12&#41;	|	\
									&#40;	&#40;&#40;u16&#41;_R_&0x0F&#41;<<8&#41;	|	\
									&#40;	&#40;&#40;u16&#41;_G_&0x0F&#41;<<4&#41;		|	\
									&#40;	&#40;&#40;u16&#41;_B_&0x0F&#41;<<0&#41;			&#41;
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi,

thanks for that code the code probebky works but only the color work with me. I guess it is this function which can't handle alpha channels:

Code: Select all

void fillScreenRect&#40;Color color, int x0, int y0, int width, int height&#41;
&#123;
	if &#40;!initialized&#41; return;
	int skipX = PSP_LINE_SIZE - width;
	int x, y;
	Color* data = getVramDrawBuffer&#40;&#41; + x0 + y0 * PSP_LINE_SIZE;
	for &#40;y = 0; y < height; y++, data += skipX&#41; &#123;
		for &#40;x = 0; x < width; x++, data++&#41; *data = color;
	&#125;
&#125;
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

What I'd do is draw a black quad over the screen and then alter then the alpha value of it.

This should work with the graphics.c stuff:

Code: Select all

void FadeScreen&#40;const int FadeInAlphaValue&#41;
&#123;
guStart&#40;&#41;;
sceGuDisable&#40;GU_TEXTURE_2D&#41;;
CSVertex* vertices = &#40;CSVertex*&#41; sceGuGetMemory&#40;2 * sizeof&#40;CSVertex&#41;&#41;;
          vertices&#91;0&#93;.color = GU_RGBA&#40;0, 0, 0, FadeInAlphaValue&#41;;
          vertices&#91;0&#93;.x = 0;
          vertices&#91;0&#93;.y = 0;
          vertices&#91;0&#93;.z = 0;
          vertices&#91;1&#93;.color = GU_COLOR&#40;0, 0, 0, FadeInAlphaValue&#41;;
          vertices&#91;1&#93;.x = 480;
          vertices&#91;1&#93;.y = 272;
          vertices&#91;1&#93;.z = 0;
sceGuDrawArray&#40;GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices&#41;;
sceGuEnable&#40;GU_TEXTURE_2D&#41;;
sceGuFinish&#40;&#41;;
sceGuSync&#40;0, 0&#41;;
&#125;
Where CSVertex is:

Code: Select all

typedef struct
&#123;
	unsigned int color;
	short x, y, z;
&#125; CSVertex;
Just pass the alpha value (0-255) to the function.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi, i will try that one. My own solution was to create an image and then replace the pixels every loop with a less alpha value but filling the whole picture slows it down alot, now it is only for transition between screen so interaction or anitmation is not neccesary so the slowing doesn't show to the user but i guess this methode is alot quicker i will try this one thanks
Post Reply