# OpenGL Color doesn't change

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

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

float tc = .8f;
if (mouseOver()) {tc = 1.0f;}

glColor4f(tc,tc,tc, 1.0f);
drawText(Vector(centerx, centery),getCaption(),8);	// Actual text



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

Could you post the drawText() code?

##### Share on other sites
Quote:
 Original post by LGABit'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 on other sites
having enabled GL_DEPTH_TEST w/ depth function set to GL_LESS might prevent the text shadow from being overwritten...

##### 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 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 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015825
×