glColor not working, random color appearing

Started by
2 comments, last by Brother Bob 12 years, 5 months ago
Hello

There's something wrong in my code somewhere but for any number of primitives that I draw, despite calling glClearColor and then picking a color with glColor3f, the colors that appear are completely random...

So in my Rendering class I cycle through all the objects and call their drawing methods, for primitives they would look like:

inline void PrimitiveDrawer::drawWireframePrism(Vector3 pos, float radius, Vector3 col){

glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glColor3f(col.x, col.y, col.z);

glLineWidth(3);
glBegin (GL_LINE_LOOP);
...
glEnd()


But no matter what color i select I always get different ones... The interesting think is that all primitive lines I draw with this method assume the color of the models that they bound (they are meant to be bounding volumes for meshes)... Could it have to do with the model loaders I am using?

This is affecting every shape (outside the ones around the models), where every GL_LINE assumes the same colour (green for some reason), including the glutBitMapCharacter that I am trying to draw... That's the main think that bothers me as I'd like to pick the colour for the text drawing, currently I am doing:


void renderBitmapString(float x, float y, void *font,char *string)
{

char *c;
glRasterPos2f(x, y);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}

void drawText(char text[20], float x, float y){
glPushMatrix();
setOrthographicProjection();
glLoadIdentity();
glClearColor( 0, 0, 0, 0 );
glColor4f(0, 0, 1, 1);
renderBitmapString(x, y,(void *)font, text);
resetPerspectiveProjection();
glPopMatrix();
}

But the text comes up green instead of blue?
Advertisement
Why do you bring up and call glClearColor in the middle of everything? Unless you haver a different clear color as well, in which case something is really broken, then it really has nothing to do with your problem.

I suggest you strip down your program to a very minimum by removing everything that doesn't have anything do to with replicating the problem, and then you post a complete program here.But before that, check so that you don't leave states enabled where you don't need them, like lighting and texturing.
it was indeed GL_LIGHTING.... It needed to be disabled before rendering lines or text! I somehow thought that glClearColor was necessary for resetting the color before a new one was enabled....seems like I'm wrong, should i just remove it from everywhere?
glClearColor sets the color that is filled into the frame buffer when you call glClear, so you probably don't want it anywhere except at the beginning where you define your background color.

This topic is closed to new replies.

Advertisement