Forum

hud translucent

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

Moderator: InsideQC Admins

hud translucent

Postby Hazematman » Mon Aug 02, 2010 5:56 pm

does standard glquake have support for translucent textures for the hud?

if so, how would I make it draw a translucent picture?

if not, does anyone know how to add it and could try to help me with it?
User avatar
Hazematman
 
Posts: 54
Joined: Thu Jul 15, 2010 1:58 am
Location: Canada

Postby Baker » Tue Aug 03, 2010 1:47 am

Yes it does.

Something like Draw_AlphaPic and if it doesn't, you can easily make one by turning on whatever r_wateralpha does on, presumably, the PSP.

In OpenGL, it something like GLBlendEnable and glColor4f (might be slightly off, not looking @ the engine code). I can't remember the PSPGU equivalent.
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 Sajt » Tue Aug 03, 2010 4:32 am

Draw_TransPic draws images with TRANSPARENT pixels (palette index 255). But "translucent" means fadey-alpha. I don't think GLQuake supports that out of the box.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby r00k » Tue Aug 03, 2010 6:07 am

Code: Select all
void Sbar_DrawPicAlpha (int x, int y, mpic_t *pic)
{   
   Draw_AlphaPic (x + sbar_xofs, y + (vid.height-SBAR_HEIGHT), pic, scr_sbaralpha.value);
}


Code: Select all
/*
=============
Draw_AlphaPic
=============
*/
void Draw_AlphaPic (int x, int y, mpic_t *pic, float alpha)
{
   if (scrap_dirty)
      Scrap_Upload ();

   glDisable(GL_ALPHA_TEST);
   glEnable (GL_BLEND);
   glCullFace (GL_FRONT);
   glColor4f (1, 1, 1, alpha);
   GL_Bind (pic->texnum);
   
   glBegin (GL_QUADS);
   glTexCoord2f (pic->sl, pic->tl);
   glVertex2f (x, y);
   glTexCoord2f (pic->sh, pic->tl);
   glVertex2f (x+pic->width, y);
   glTexCoord2f (pic->sh, pic->th);
   glVertex2f (x+pic->width, y+pic->height);
   glTexCoord2f (pic->sl, pic->th);
   glVertex2f (x, y+pic->height);
   glEnd ();

   glColor3f (1, 1, 1);
   glEnable(GL_ALPHA_TEST);
   glDisable (GL_BLEND);
}
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Sajt » Tue Aug 03, 2010 6:54 am

I stand corrected. I've never spent much time in the GLQuake source but I should have looked before I posted.

Anyway, it's still not clear what the original poster wanted. Constant alpha over the whole image (Draw_AlphaPic) or an image with an alpha channel... Probably the former. I'll go now...
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby Baker » Tue Aug 03, 2010 8:04 am

I wasn't 100% sure it was in GLQuake for sure either, then again I think I recall one version having a translucent console or something?

Since it is in GLQuake, PSP engines have equivalent, of course:

Code: Select all
/*
=============
Draw_AlphaPic
=============
*/
static 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);

   const gltexture_t& glt = gltextures[gl->index];

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

   int start, end;
   int slice = 32;

   // blit maximizing the use of the texture-cache

   for (start = 0, end = glt.original_width; start < end; start += slice, x += slice)
   {
        vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * 2));
        int width = (start + slice) < end ? slice : end-start;

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

        vertices[1].u      = start + width;//glt.original_width;
        vertices[1].v      = glt.original_height;
        vertices[1].x      = x + width;//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);
}
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 r00k » Thu Aug 05, 2010 6:51 am

draw_alpha pic available but i dont think glQuake used it for the sbar.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Sajt » Thu Aug 05, 2010 7:38 am

Probably only for the conback.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby leileilol » Thu Aug 05, 2010 8:40 am

Sajt wrote:Probably only for the conback.

indeed since the conback fades.

FUN FACT: the rage pro is stupid with alphas and TRIES TO SOFTWARE RENDER THEM WITHIN THE 3D BUFFER, maybe that's why it's hardly used.
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby Mexicouger » Sat Oct 02, 2010 10:35 am

Where the heck is Sbar_DrawPicAlpha located? Which file? I did a complete search in psp Kurok, and I fail to find it using textpad5/.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby revelator » Sun Oct 03, 2010 12:39 pm

normally in gl_draw.c allthough i dunno about the psp source.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby mh » Sun Oct 03, 2010 6:44 pm

You've got the name wrong - it's Draw_AlphaPic.

Another fun fact: GLQuake's Draw_AlphaPic is actually broken and won't draw with alpha at all on most (all?) modern 3D cards.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Baker » Sun Oct 03, 2010 7:11 pm

You will have to copy Sbar_DrawPic and make your own Sbar_DrawAlphaPic.

It is a trivial change, just add one more field called alpha to the end of the function declaration (i.e. float alpha).

Then in Sbar_DrawAlphaPic make it use Draw_AlphaPic if the alpha value is less than 1.

if (alpha < 1)
Draw_AlphaPic (...., alpha);
else
Draw_Pic (....);

Post back if you need help, unfortunately these next several days I may only be around 15 minutes twice per day but any other engine coder can help you with this because it is a very basic modification.
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 revelator » Sun Oct 03, 2010 7:30 pm

yup i actually think its somewhere in the old qsg tutorial archives it was mentioned first time :) translucent hud something...
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby revelator » Sun Oct 03, 2010 7:44 pm

found it.

/*=============
Draw_Pic
=============*/
void Draw_Pic (int x, int y, qpic_t *pic, float alpha)
{
byte *dest, *source;
unsigned short *pusdest;
int v, u;
glpic_t *gl;

if (scrap_dirty)
Scrap_Upload ();

gl = (glpic_t *)pic->data;

glEnable (GL_BLEND);
glColor4f (1,1,1,alpha);

GL_Bind (gl->texnum);
glBegin (GL_QUADS);
glTexCoord2f (gl->sl, gl->tl);
glVertex2f (x, y);
glTexCoord2f (gl->sh, gl->tl);
glVertex2f (x+pic->width, y);
glTexCoord2f (gl->sh, gl->th);
glVertex2f (x+pic->width, y+pic->height);
glTexCoord2f (gl->sl, gl->th);
glVertex2f (x, y+pic->height);
glEnd ();

glColor4f (1,1,1,1);
glDisable (GL_BLEND);
}[/code]
Last edited by revelator on Sun Oct 03, 2010 7:51 pm, edited 1 time in total.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Next

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest