PDA

View Full Version : Silly question on glColor


LongJumper
2003.10.24, 11:24 PM
Pardon me for being stupid, but for some reason I never do this glColor 'ing correctly. It's a hard problem to describe, but basically whenver I make a call to glColor to change the color of, let's say some text, it draws the text in that color, and all the things drawn after it in the same color. If I call glColor4f(1,1,1,1) after I draw the object with color, then it too turns white... I have no idea if this makes sense, I hope it does :)

skyhawk
2003.10.24, 11:28 PM
OpenGL is a state machine, that is exactly how it should act.

OneSadCookie
2003.10.25, 12:46 AM
Originally posted by LongJumper
If I call glColor4f(1,1,1,1) after I draw the object with color, then it too turns white...

That's not how it's supposed to work... but I suspect that's not actually what you're doing or it's not actually what's happening :p

LongJumper
2003.10.25, 03:23 AM
Well I assume it has to do something with how I push/pop matrices and such. if I make a call to glcolor inside a pushmatrix will effect everything else? i don't really understand those either :)

Bachus
2003.10.25, 03:25 AM
Could you post some code?

It should be:

glColor3f(1.0f, 0.0f, 0.0f); // or glColor4f()
// Draw text
glColor3f(1.0f, 1.0f, 1.0f);
// Draw whatever

Josh
2003.10.25, 04:13 AM
I don't think it has anything to do with pushing and popping matrices.

m_e_my_self
2003.10.25, 02:17 PM
glColor3f(1.0f,1.0f,1.0f);
//draw = white
glPushAttrib( GL_COLOR_BUFFER_BIT |GL_CURRENT_BIT );
glColor3f(0.0f,0.0f,0.0f);
//draw = black
glPopAttrib();
//back to the previous color=white

LongJumper
2003.10.25, 05:35 PM
Here is the update function that deals with drawing:
aglSetCurrentContext (*(engine->GetAGLContext()));
aglUpdateContext(*(engine->GetAGLContext()));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cam->Render();

//if(!engine->IsPaused())
// world->Animate();
world->Draw(cam);

//Draw windows and controls
windowIterator = engine->GetXWindows();
while(windowIterator != NULL)
{
windowIterator->Draw();
windowIterator = windowIterator->next;
}

engine->ShowFrameRate();
//Swap double buffer
aglSwapBuffers(*(engine->GetAGLContext()));

Here is windowIterator->Draw
void XWindow::Draw()
{
if(hidden)
return;

XControl* contList = controlList;

glPushMatrix();
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,appearance.texID);
glTranslatef(0,0,-1); //Always this.

if(trans)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA);
}
glFrontFace(GL_CW);
glBegin(GL_QUADS);
glTexCoord2f(0,1);
glVertex3f(x,y,0);

glTexCoord2f(1,1);
glVertex3f(x+width,y,0);

glTexCoord2f(1,0);
glVertex3f(x+width,y-height,0);

glTexCoord2f(0,0);
glVertex3f(x,y-height,0);

glEnd();

while(contList)
{
contList->Draw();
contList = contList->next;
}
glFrontFace(GL_CCW);
glDisable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);
if(width < .4) //small window)
TextEngine::UseSmall();
else
TextEngine::UseLarge();
double titleLocation[2] = { x + width/2.0 -
TextEngine::FindLength(title)/2.0f ,
y - TextEngine::FindHeight() };
TextEngine::SetColor(.2,.2,.5);
TextEngine::DrawText(title,titleLocation);
glDisable(GL_BLEND);
glPopMatrix();
}
There is no calls to glColor inside the XControl's draw method.
Here is TextEngine::DrawText
void TextEngine::DrawText(char* string, double* point)
{
glPushMatrix();
glLoadIdentity();
glRasterPos3d(point[0],point[1],-1);
glColor3f(TextEngine::color[0],
TextEngine::color[1],
TextEngine::color[2]);
DrawCStringGL(string,
!usingLarge?(TextEngine::smallText):(TextEngine::l argeText));
glPopMatrix();
}

The code like this draws everything with a blue tint. When I add a glColor3f(1,1,1); after the DrawCStringGL, everythign draws white...

Mars_999
2003.10.25, 10:46 PM
Here is what I use try this

void CFont::DrawText(const char *text, float x, float y, float z)
{
glLoadIdentity();
glColor3f(1.0f, 0.0f, 0.0f);

glRasterPos3f(x, y, z);

if(text == NULL)
return;

glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
glColor3f(1.0f, 1.0f, 1.0f);
}

m_e_my_self
2003.10.26, 05:45 AM
Originally posted by LongJumper

Here is TextEngine::DrawText
[CODE]void TextEngine::DrawText(char* string, double* point)
{
glPushMatrix();
glLoadIdentity();
glRasterPos3d(point[0],point[1],-1);
glColor3f(TextEngine::color[0],
TextEngine::color[1],
TextEngine::color[2]);
DrawCStringGL(string,
!usingLarge?(TextEngine::smallText):(TextEngine::l argeText));
glPopMatrix();
}

Using what I said, make it
void TextEngine::DrawText(char* string, double* point)
{
glPushMatrix();
glLoadIdentity();
glPushAttrib( GL_COLOR_BUFFER_BIT |GL_CURRENT_BIT );
glRasterPos3d(point[0],point[1],-1);
glColor3f(TextEngine::color[0],
TextEngine::color[1],
TextEngine::color[2]);
DrawCStringGL(string,
!usingLarge?(TextEngine::smallText):(TextEngine::l argeText));
glPopAttrib();
glPopMatrix();
}