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
Color doesn't change
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]
Did you debug and stop at the second glColor4f call? Was tc = 1.0 then?
Could you post the drawText() code?
Could you post the drawText() code?
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]
having enabled GL_DEPTH_TEST w/ depth function set to GL_LESS might prevent the text shadow from being overwritten...
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).
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);}
So what is glFontBegin, glFontTextOut? These aren't GL functions so they shouldn't even have a gl in front. That makes it confusing.
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:
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement