glColor not working, random color appearing

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?

From the code you have posted I can’t see why the color3f command is not setting the colours for you. One possibility is you using a shader to render the wireframes?

However,

glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );

Won’t do what you think. This is just setting the background renderbuffer/glWindow buffer colour next time you call glClear.
It has nothing to do with the object you are drawing.

Thank you. The issue was actually the lighting. I did not know I had to disable lighting after trying to draw lines or text, doing so has indeed resolved the issue!

Thanks for the explanation of glClearColor, I chucked it everywhere in my code thinking that it was necessary everytime I needed to draw using a new color…