Forum

Draw_string with alpha

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

Moderator: InsideQC Admins

Draw_string with alpha

Postby frag.machine » Mon Jan 31, 2011 1:47 am

Okay, this may look silly to more experienced OpenGL coders, so my apologies for asking silly questions :D. Anyway, I wasted a good amount of time trying to figure this out alone but got no luck. I am trying to modify the Draw_String () to accept an alpha value, but so far this is simply ignored and the string is drawn solid like regular Draw_String. Here's my code:
Code: Select all
extern      gltexture_t *char_texture;
void MyDrawString (int x, int y, char *str, float f)
{
   if (y <= -8)
      return;         // totally off screen

   if (f > 0.0f)
   {
      GL_Bind (char_texture);
      glBegin (GL_QUADS);
      if (f < 1.0f)
      {
         glEnable (GL_BLEND);
         glColor4f (1,1,1,f);
         glDisable (GL_ALPHA_TEST);
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      }

      while (*str)
      {
         if (*str != 32) //don't waste verts on spaces
            Draw_CharacterQuad (x, y, *str);
         str++;
         x += 8;
      }

      if (f < 1.0f)
      {
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
         glEnable (GL_ALPHA_TEST);
         glDisable (GL_BLEND);
         glColor4f (1,1,1,1);
      }

      glEnd ();
   }
}


What am I doing wrong here ?
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Sajt » Mon Jan 31, 2011 3:12 am

Is the blendmode set properly?

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
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 Spike » Mon Jan 31, 2011 10:33 am

opengl doesn't permit you to change lots of state between glBegin and glEnd. Logically the only things you're allowed to change there restricted to actual vertex attributes (colour/texcoords/position). What you're definitely not able to change is blend modes.

ps: glGetError() is your friend. :)
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Draw_string with alpha

Postby mh » Mon Jan 31, 2011 11:01 am

The fixed version would look something like this:
Code: Select all
extern      gltexture_t *char_texture;
void MyDrawString (int x, int y, char *str, float f)
{
   if (y <= -8)
      return;         // totally off screen

   if (f > 0.0f)
   {
      GL_Bind (char_texture);

      if (f < 1.0f)
      {
         glEnable (GL_BLEND);
         glColor4f (1,1,1,f);
         glDisable (GL_ALPHA_TEST);
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      }

      glBegin (GL_QUADS);

      while (*str)
      {
         if (*str != 32) //don't waste verts on spaces
            Draw_CharacterQuad (x, y, *str);
         str++;
         x += 8;
      }

      glEnd ();

      if (f < 1.0f)
      {
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
         glEnable (GL_ALPHA_TEST);
         glDisable (GL_BLEND);
         glColor4f (1,1,1,1);
      }
   }
}

Also check your Draw_CharacterQuad function and make sure there's nothing happening in there that shouldn't be.
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 frag.machine » Mon Jan 31, 2011 11:37 pm

Heh, not mine, it's FitzQuake code I'm just messing around.

Draw_CharacterQuad has no state changes, IIRC it's only feeding vertexes to the pipeline. Thanks for the tips guys, I'll try this later.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby ceriux » Mon Jan 31, 2011 11:49 pm

if you get it working you should post up a pic of it working.

see thru text in hl always annoyed me.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby frag.machine » Tue Feb 01, 2011 12:04 am

ceriux wrote:if you get it working you should post up a pic of it working.

see thru text in hl always annoyed me.

Image

For the record, it was indeed just a case of moving the glBegin() and glEnd() so the state changes now happens out of the block delimited by them. It's much easier when you know what you're doing. :D Thanks again for the help, guys.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby ceriux » Tue Feb 01, 2011 1:09 am

way better than half-lifes =D looks great!
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby frag.machine » Tue Feb 01, 2011 2:06 am

Image
Some experiments with the "hud" command idea... :twisted:
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Baker » Tue Feb 01, 2011 2:40 am

Looks really nice. All of it. :D
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 » Tue Feb 01, 2011 5:21 am

Could be used to interpolate the hud face animation, or fading of centerprint messages etc..

I used the alpha channel once apon a time when making this gif Image
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Sajt » Tue Feb 01, 2011 6:25 am

What's up with the row of messed up pixels above the quakeguy heads on that last screenshot?
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 frag.machine » Tue Feb 01, 2011 10:27 pm

No idea yet :? . I used the regular engine functions to load and draw it (Draw_PicFromWad() and Draw_Pic() ).
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Tue Feb 01, 2011 11:34 pm

glquake writes into the wad data after the first time its loaded.
those pixels that you can see, those are integers. :)
its actually a glpic_t that you can see.
the second time its loaded, the image data comes from the wad again, but this time it already has the glpic_t corruption from last time around.
that's what those messed up pixels are.
the actual renderer is fine, its just the image loader/wad code at fault. it would work fine with a lmp. Or you could find the existing image instead and reuse it.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby frag.machine » Wed Feb 02, 2011 9:56 pm

hmm, that's make sense. Thanks for the info Spike, I'll think about some clean way to deal with this later.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Next

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest