Forum

hud translucent

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

Moderator: InsideQC Admins

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

allmost forgot

Code: Select all
/*==========
Sbar_DrawPic
==========*/
void Sbar_DrawPic (int x, int y, qpic_t *pic)
{
#ifdef GLQUAKE
   Draw_Pic (x, y + vid.height, pic, r_hudalpha.value);
#else
   Draw_TransPic (x, y + vid.height, pic);
#endif
}


where r_hudalpha.value sets the alpha

and

Code: Select all
/*=====================================================
Sbar_DrawCharacter - Draws one solid graphics character
=====================================================*/
void Sbar_DrawCharacter (int x, int y, int num)
{
#ifdef GLQUAKE
   Draw_Character (x+4, y + vid.height, num, r_hudalpha.value);
#else
   Draw_Character (x+4, y + vid.height, num, 1.0);
#endif
}

/*=============
Sbar_DrawString
=============*/
void Sbar_DrawString (int x, int y, char *str)
{
   if (cl.gametype == GAME_DEATHMATCH)
      Draw_String (x , y+ vid.height, str, r_hudalpha.value);
   else
      Draw_String (x , y+ vid.height, str, r_hudalpha.value);
}


might be a few more places you need to change

and the other draw functions now with an alpha component

Code: Select all
/*================
Draw_Character
Draws one 8*8 graphics character with 0 being transparent.
It can be clipped to the top of the screen to allow the console to be smoothly scrolled off.
================*/
void Draw_Character (int x, int y, int num, float alpha)
{
   byte         *dest;
   byte         *source;
   unsigned short   *pusdest;
   int            drawline;   
   int            row, col;
   float         frow, fcol, size;
   int            TEXT_SIZE;

   if (gl_textdouble.value == 1)
      TEXT_SIZE = 16;
   else
      TEXT_SIZE = 8;

   if (num == 32)
      return;      // space

   num &= 255;
   
   if (y <= -TEXT_SIZE)
      return;         // totally off screen

   row = num>>4;
   col = num&15;

   frow = row*0.0625;
   fcol = col*0.0625;
   size = 0.0625;

   glEnable (GL_BLEND);
   glColor4f (1,1,1,alpha);
   
   GL_Bind (char_texture);
   glBegin (GL_QUADS);
   glTexCoord2f (fcol, frow);
   glVertex2f (x, y);
   glTexCoord2f (fcol + size, frow);
   glVertex2f (x + TEXT_SIZE, y);
   glTexCoord2f (fcol + size, frow + size);
   glVertex2f (x + TEXT_SIZE, y + TEXT_SIZE);
   glTexCoord2f (fcol, frow + size);
   glVertex2f (x, y + TEXT_SIZE);
   glEnd ();
   glDisable(GL_BLEND);
}

/*================
Draw_String
================*/
void Draw_String (int xh, int y, char *str, float alpha)
{
   char *text = str;
   int x = 0, j = 0;

   for (x=0 ; x < strlen(str) ; x++)
   {
      if (text[x] == '&')
      {
         if (text[x + 1] == 'c')
         {
            x += 2;
            glColor3f((float) (text[x] - '0') / 9,
                    (float)  (text[x + 1] - '0') / 9,
                    (float)  (text[x + 2] - '0') / 9);
            x += 4;
         }
         else if (text[x + 1] == 'r')
         {
            glColor3f(1, 1, 1);
            x += 3;
         }
      }
      Draw_Character (xh + j, y, text[x], alpha);
      if (gl_textdouble.value == 1)
         j=j+16;
      else
         j=j+8;
   }
}
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby Mexicouger » Sun Oct 03, 2010 9:42 pm

I took The Drawpic Function and made it into this:

Code: Select all
/*
=============
Sbar_DrawPic
=============
*/
void Sbar_DrawAlphaPic (int x, int y, qpic_t *pic, float alpha)
{
  if(kurok)
     Draw_Pic (x /* + ((vid.width - 320)>>1)*/, y + (vid.height-SBAR_HEIGHT), pic);
  else
  {
   if (cl.gametype == GAME_DEATHMATCH)
      Draw_Pic (x /* + ((vid.width - 320)>>1)*/, y +

(vid.height-SBAR_HEIGHT), pic);
   else
      Draw_Pic (x + ((vid.width - 320)>>1), y + (vid.height-SBAR_HEIGHT), pic);
  }
}


Is that right?

But when I when to do this:
Code: Select all
   if (cl_plasmanade.value == 1)
   {
   plas = Draw_CachePic ("gfx/plasmanade.lmp");
   Sbar_DrawAlphaPic ( (710-plas->width)/2, 55, plas, 0.5 );
   }


The graphic didn't even show up on the screen. What happened?
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Baker » Mon Oct 04, 2010 12:50 am

You weren't having the function call Draw_AlphaPic, which means you weren't doing anything different. Draw_AlphaPic is what draws less than solid.

Use this Sbar_DrawAlphaPic which I believe will work without any modification for your purposes.

Code: Select all
/*
=============
Sbar_DrawAlphaPic
Alpha = 1 :  full alpha which is fully solid
Alpha = 0.5 ... 50% transparency
Alpha = 0.25 ... 75% transparency
Alpha = 0 ... invisible .. not drawn essentially
This function calls Draw_AlphaPic in video_hardware_draw.cpp (PSP)/gl_draw.c (GLQuake)
instead of Draw_Pic (Draw_Pic draws fully solid images).  Draw_AlphaPic offers an extra field "alpha"
which can draw fully solid or with transparency/translucency or whatever you like to call it.
=============
*/
void Sbar_DrawAlphaPic (int x, int y, qpic_t *pic, float alpha)
{
  if(kurok)
  {
     Draw_AlphaPic (x /* + ((vid.width - 320)>>1)*/, y + (vid.height-SBAR_HEIGHT), pic, alpha);
  else
  {
   if (cl.gametype == GAME_DEATHMATCH)
      Draw_AlphaPic (x /* + ((vid.width - 320)>>1)*/, y +

(vid.height-SBAR_HEIGHT), pic, alpha);
   else
      Draw_AlphaPic (x + ((vid.width - 320)>>1), y + (vid.height-SBAR_HEIGHT), pic, alpha);
  }
}
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 » Mon Oct 04, 2010 1:19 am

Problem: Draw_AlphaPic

It Doesn't know the function or something...

if function 'Sbar_DrawAlphaPic'
warning: implicit declaration of function 'Draw_AlphaPic'

At the bottom:

undefined reference to 'Draw_AlphaPic'
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Baker » Mon Oct 04, 2010 1:39 am

Open video_hardware_draw.cpp

You'll see this ...

Code: Select all
/*
=============
Draw_AlphaPic
=============
*/
static void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
{


Kill the static!

Static makes it so it cannot be access outside the file. sbar.c is a different file. So just remove the static out of the above, save it and attempt recompile again.
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 » Mon Oct 04, 2010 1:50 am

Still have the same Problem:
Code: Select all
function 'Sbar_DrawAlphaPic'
warning: implicit declaration of function 'Draw_AlphaPic'

At the bottom:

undefined reference to 'Draw_AlphaPic'


That is still stopping it from compiling. I have the function set and everything, And i also redid the brackets on the Sbar_DrawAlphaPic, because It gave me problems:

Code: Select all
/*
=============
Sbar_DrawAlphaPic
Alpha = 1 :  full alpha which is fully solid
Alpha = 0.5 ... 50% transparency
Alpha = 0.25 ... 75% transparency
Alpha = 0 ... invisible .. not drawn essentially
This function calls Draw_AlphaPic in video_hardware_draw.cpp (PSP)/gl_draw.c (GLQuake)
instead of Draw_Pic (Draw_Pic draws fully solid images).  Draw_AlphaPic offers an extra field "alpha"
which can draw fully solid or with transparency/translucency or whatever you like to call it.
=============
*/
void Sbar_DrawAlphaPic (int x, int y, qpic_t *pic, float alpha)
{
  if(kurok)
     Draw_AlphaPic (x /* + ((vid.width - 320)>>1)*/, y + (vid.height-SBAR_HEIGHT), pic, alpha);
  else
  {
   if (cl.gametype == GAME_DEATHMATCH)
      Draw_AlphaPic (x /* + ((vid.width - 320)>>1)*/, y +

(vid.height-SBAR_HEIGHT), pic, alpha);
   else
      Draw_AlphaPic (x + ((vid.width - 320)>>1), y + (vid.height-SBAR_HEIGHT), pic, alpha);
  }
}
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby revelator » Mon Oct 04, 2010 6:07 am

you also need to change the definition in the headers so it matches the new one :)
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby Baker » Mon Oct 04, 2010 10:53 am

Mexicouger ... do this ...

[quote="Baker"]You weren't having the function call Draw_AlphaPic, which means you weren't doing anything different. Draw_AlphaPic is what draws less than solid.

Use this Sbar_DrawAlphaPic which I believe will work without any modification for your purposes.

Code: Select all
/*
=============
Sbar_DrawAlphaPic
Alpha = 1 :  full alpha which is fully solid
Alpha = 0.5 ... 50% transparency
Alpha = 0.25 ... 75% transparency
Alpha = 0 ... invisible .. not drawn essentially
This function calls Draw_AlphaPic in video_hardware_draw.cpp (PSP)/gl_draw.c (GLQuake)
instead of Draw_Pic (Draw_Pic draws fully solid images).  Draw_AlphaPic offers an extra field "alpha"
which can draw fully solid or with transparency/translucency or whatever you like to call it.
=============
*/
void Sbar_DrawAlphaPic (int x, int y, qpic_t *pic, float alpha)
{
  void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha); // <--add this to declare the function prototype and it should work even with gcc
  if(kurok)
  {
     Draw_AlphaPic (x /* + ((vid.width - 320)>>1)*/, y + (vid.height-SBAR_HEIGHT), pic, alpha);
  else
  {
   if (cl.gametype == GAME_DEATHMATCH)
      Draw_AlphaPic (x /* + ((vid.width - 320)>>1)*/, y +

(vid.height-SBAR_HEIGHT), pic, alpha);
   else
      Draw_AlphaPic (x + ((vid.width - 320)>>1), y + (vid.height-SBAR_HEIGHT), pic, alpha);
  }
}


Notice the function prototype thrown in there. That'll make it work. gcc has different compiler warnings than, say, Microsoft Visual Studio which would have accepted and compiled my previous example (after removing the static from video_hardware_draw.cpp) but gcc is far more anal retentive.
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 » Mon Oct 04, 2010 12:55 pm

And it Still Doesn't work. I have the same exact Problem I have had this entire time.

Code: Select all
Undefined  reference to 'Draw_AlphaPic'

collect2: ID returned 1 to exit status.


I am compiling with cygwin.

I killed static.
I put Sbar_DrawAlphaPic code.

Still gets error. Can comeone test this in cygwin? There has to be something wrong. I am using a fresh Kurok engine source.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby revelator » Mon Oct 04, 2010 1:21 pm

edit: taken care off.
Last edited by revelator on Mon Oct 04, 2010 1:39 pm, edited 1 time in total.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby revelator » Mon Oct 04, 2010 1:37 pm

add this to video_hardware_draw.cpp

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);

   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);
}


and it should magically work :)

i noticed baker allready taken care of the external by defining it inside the sbar function.

disregard my post above this.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby Mexicouger » Mon Oct 04, 2010 1:47 pm

Still, Same problem... This is starting to make me mad :evil:
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby revelator » Mon Oct 04, 2010 7:51 pm

hmm thats strange then is the source file video_draw_hardware.cpp included in the build settings ? i might have to take a look else but im moving atm so might take a lil before i can.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby Baker » Mon Oct 04, 2010 8:35 pm

Mexicouger wrote:And it Still Doesn't work. I have the same exact Problem I have had this entire time.


I'll add this to the base Kurok engine and compile here in a few hours (6 hours from now) ... if Reckless or yourself or someone else doesn't do it before that.
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 » Mon Oct 04, 2010 10:44 pm

Alright thanks Baker :)

And when you find the problem, Can you tell me? I am very curious to squish that bug
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

PreviousNext

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest