Jump to content
  • Advertisement
Sign in to follow this  
LGAB

OpenGL Color doesn't change

This topic is 3762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey people. This could be a really tiny problem, or a really weird bug somewhere. I'm simply trying to write text on a button in OpenGL, all works, except that when I want to change the color of the text when the mouse is over the button, it just doesn't work! I've tripple-checked that the mouseOver-routines work, it also works when I skip the shadow-text, it's as if I can't change color two times. This is just one variant, but now it's setting the color greyscale value to .8, unless the mouse is over it, then it becomes 1.0. Text remains .8 when the code looks like this. I'm baffled.. [help]
glColor4f(0,0,0,1);
drawText(Vector(centerx-1, centery-1),getCaption(),8);	// Text shadow

float tc = .8f;
if (mouseOver()) {tc = 1.0f;}
			
glColor4f(tc,tc,tc, 1.0f);
drawText(Vector(centerx, centery),getCaption(),8);	// Actual text

Share this post


Link to post
Share on other sites
Advertisement
Did you debug and stop at the second glColor4f call? Was tc = 1.0 then?

Could you post the drawText() code?

Share this post


Link to post
Share on other sites
Quote:
Original post by LGAB
it's as if I can't change color two times.

In order to draw the shadow, or the actual text, you make a pair of calls, one to glColor4f and one to drawText. Which of those is more likely to have a bug? [smile]

Share this post


Link to post
Share on other sites
having enabled GL_DEPTH_TEST w/ depth function set to GL_LESS might prevent the text shadow from being overwritten...

Share this post


Link to post
Share on other sites
Hello, you knights in shining armors :)

Lord_Evil: I did a cout << of the tc value as a debug, and indeed it changes as I do the mouse-over. Also, if I comment out the shadow, the color-change works sort of, except that when the mouse is outside, I get nothing, and when it's inside I get white text as expected.

I'm using this for drawing the text:
http://students.cs.byu.edu/~bfish/glfont.php

Here's the drawText routine, some stuff here is probably redundant or unnecessary. The glFontTextOut() routine comes from glFont (see link above).

void drawText(Vector p, string text, float scl)
{
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glFontBegin(&font);
glScalef(scl, scl, scl);
glFontTextOut(const_cast<char *>(text.c_str()), p.GetX()/scl, p.GetY()/scl, 0);
glFontEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

}

Share this post


Link to post
Share on other sites
So what is glFontBegin, glFontTextOut? These aren't GL functions so they shouldn't even have a gl in front. That makes it confusing.

Share this post


Link to post
Share on other sites
I agree.. but that comes from glFont, I wouldn't take the liberty to use gl as a prefix, but I didn't write that library. But it suited my needs so.. =) Here's what they do:

void glFontBegin (GLFONT *Font)
{
//Save pointer to font structure
if (Font->Char != NULL)
glFont = Font;
else
glFont = NULL;

//Bind to font texture
//glBindTexture(GL_TEXTURE_2D, Font->Tex);
}
//*********************************************************
void glFontEnd (void)
{
//Font no longer current
glFont = NULL;
}



Edit: I realized just now that I don't even need to call those every time since I'm not changing fonts. Oh well, doesn't fix my problem though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!