Draw_string with alpha
Moderator: InsideQC Admins
16 posts
• Page 1 of 2 • 1, 2
Draw_string with alpha
Okay, this may look silly to more experienced OpenGL coders, so my apologies for asking silly questions
. 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:
What am I doing wrong here ?
- 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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
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. :)
ps: glGetError() is your friend. :)
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Re: Draw_string with alpha
The fixed version would look something like this:
Also check your Draw_CharacterQuad function and make sure there's nothing happening in there that shouldn't be.
- 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
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
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.
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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
ceriux wrote:if you get it working you should post up a pic of it working.
see thru text in hl always annoyed me.
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.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

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

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 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.
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
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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
16 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest


