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 

Coloring from black to fully transparent

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



Joined: 31 Dec 2005
Posts: 288

PostPosted: Wed Aug 23, 2006 10:04 pm    Post subject: Coloring from black to fully transparent Reply with quote

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:
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
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Aion



Joined: 24 Jul 2006
Posts: 40
Location: Montreal

PostPosted: Wed Aug 23, 2006 11:53 pm    Post subject: Reply with quote

That should do the job :

Code:

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

//Takes value between 0-16 for each channel, output 16bits color
#define ARGB4444(_A_,_R_,_G_,_B_)   (   ((u16)_A_&0x0F)<<12)   |   \
                           (   ((u16)_R_&0x0F)<<8)   |   \
                           (   ((u16)_G_&0x0F)<<4)      |   \
                           (   ((u16)_B_&0x0F)<<0)         )
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Thu Aug 24, 2006 12:16 am    Post subject: Reply with quote

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:
void fillScreenRect(Color color, int x0, int y0, int width, int height)
{
   if (!initialized) return;
   int skipX = PSP_LINE_SIZE - width;
   int x, y;
   Color* data = getVramDrawBuffer() + x0 + y0 * PSP_LINE_SIZE;
   for (y = 0; y < height; y++, data += skipX) {
      for (x = 0; x < width; x++, data++) *data = color;
   }
}

_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Thu Aug 24, 2006 8:57 am    Post subject: Reply with quote

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:
void FadeScreen(const int FadeInAlphaValue)
{
guStart();
sceGuDisable(GU_TEXTURE_2D);
CSVertex* vertices = (CSVertex*) sceGuGetMemory(2 * sizeof(CSVertex));
          vertices[0].color = GU_RGBA(0, 0, 0, FadeInAlphaValue);
          vertices[0].x = 0;
          vertices[0].y = 0;
          vertices[0].z = 0;
          vertices[1].color = GU_COLOR(0, 0, 0, FadeInAlphaValue);
          vertices[1].x = 480;
          vertices[1].y = 272;
          vertices[1].z = 0;
sceGuDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
sceGuEnable(GU_TEXTURE_2D);
sceGuFinish();
sceGuSync(0, 0);
}


Where CSVertex is:

Code:
typedef struct
{
   unsigned int color;
   short x, y, z;
} CSVertex;


Just pass the alpha value (0-255) to the function.
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Thu Aug 24, 2006 10:04 pm    Post subject: Reply with quote

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
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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