Forum

PSP Engines: Alpha 2D Pics

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

PSP Engines: Alpha 2D Pics

Postby Baker » Fri Dec 31, 2010 6:53 pm

The ability to render translucent 2D textures via alpha in Kurok PSP is broke --- this is referring to the HUD, console, etc. Actually it isn't actually broke, it was reworked by MDave to save memory specifically for Kurok's virtually all black console by reusing a small texture over and over again.

Either way, the function name is misleading and isn't useful for anything except the Kurok HUD.

There is a part 2 to this: I want the ability to render masked 2D textures with alpha and that isn't supported in the source either.

Here are solutions to #1 and #2

#1: Render 2D graphics (sbar.c, console, whatever) with alpha

Open video_hardware_draw.cpp --- this is the equivalent of gl_draw.c in GLQuake --- and replace the entire function with this one.

Code: Select all
/*
=============
Draw_AlphaPic
=============
*/
void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
{
   if (alpha != 1.0f)
   {
      sceGuTexFunc(GU_TFX_DECAL, GU_TCC_RGBA);
   }

   glpic_t         *gl;

#if 0
   if (scrap_dirty)
      Scrap_Upload ();
#endif
   gl = (glpic_t *)pic->data;
   GL_Bind (gl->index);

   struct vertex
   {
      short         u, v;
      short         x, y, z;
   };

    vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * 2));

   vertices[0].u      = 0;
    vertices[0].v      = 0;
    vertices[0].x      = x;
    vertices[0].y      = y;
    vertices[0].z      = 0;

   const gltexture_t& glt = gltextures[gl->index];
    vertices[1].u      = glt.original_width;
    vertices[1].v      = glt.original_height;
    vertices[1].x      = x + pic->width;
    vertices[1].y      = y + pic->height;
    vertices[1].z      = 0;

    sceGuColor(GU_RGBA(0xff, 0xff, 0xff, static_cast<unsigned int>(alpha * 255.0f)));
    sceGuDrawArray(
      GU_SPRITES,
      GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D,
      2, 0, vertices);

   if (alpha != 1.0f)
   {
      sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
   }
}


#2 and the solution for drawing transparency masked 2D textures with alpha

Code: Select all
/*
=============
Draw_AlphaTransPic
=============
*/
void Draw_AlphaTransPic (int x, int y, qpic_t *pic, float alpha)
{
   if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||
       (unsigned)(y + pic->height) > vid.height)
   {
      Sys_Error ("Draw_TransPic: bad coordinates");
   }

   if (alpha != 1.0f)
   {   // filter

      sceGuEnable(GU_BLEND);
      sceGuDisable(GU_FOG);

      sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0xFFFFFFFF);
      sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGB);
   }

   glpic_t         *gl;

#if 0
   if (scrap_dirty)
      Scrap_Upload ();
#endif
   gl = (glpic_t *)pic->data;
   GL_Bind (gl->index);

   struct vertex
   {
      short         u, v;
      short         x, y, z;
   };

   vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * 2));

   vertices[0].u      = 0;
   vertices[0].v      = 0;
   vertices[0].x      = x;
   vertices[0].y      = y;
   vertices[0].z      = 0;

   const gltexture_t& glt = gltextures[gl->index];
   vertices[1].u      = glt.original_width;
   vertices[1].v      = glt.original_height;
   vertices[1].x      = x + pic->width;
   vertices[1].y      = y + pic->height;
   vertices[1].z      = 0;

   sceGuColor(GU_RGBA(0xff, 0xff, 0xff, static_cast<unsigned int>(alpha * 255.0f)));
   sceGuDrawArray(
      GU_SPRITES,
      GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D,
      2, 0, vertices);

   if (alpha != 1.0f)
   {
      sceGuDisable(GU_BLEND);
      sceGuEnable(GU_FOG);
      sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);

      sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
   }
}


Now last a small footnote: since to me it is important to retain full Kurok backwards compatibility I actually did keep MDave's code. I just renamed the function and only call it if the Kurok mod is being run.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Mexicouger » Fri Dec 31, 2010 7:04 pm

:D
Thanks again baker ;)
Improving our engines so much. Making game Quality better. I think I learn Alot by this and Comparing Kurok engine code to yours And DQuake
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Jukki » Fri Dec 31, 2010 11:11 pm

do the pinky parts be transparent?
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby Mexicouger » Fri Dec 31, 2010 11:16 pm

Jukki wrote:do the pinky parts be transparent?


If you use method 2, yes
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Jukki » Sat Jan 22, 2011 4:57 pm

idk why. I apply this but it makes the game act wierd. every pinky that should be (used transparent one) is black :/
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby Mexicouger » Sat Jan 22, 2011 7:39 pm

Jukki wrote:idk why. I apply this but it makes the game act wierd. every pinky that should be (used transparent one) is black :/


Well for me, Every image and text that had no alpha parameters, had black around it. But the actual images that had Alpha applied to it were just fine
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest