Alex
Alex

Reputation: 561

glColor not working, random color appearing

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?

Upvotes: 0

Views: 2305

Answers (1)

datenwolf
datenwolf

Reputation: 162317

glClearColor has nothing to do with glColor. glClearColor sets the color used with a call of glClear(GL_COLOR_BUFFER_BIT) to clear the framebuffer with.

Colors from other objects drawn sounds to me, that you forget to disable texturing. Add a glDiable(GL_TEXTURE_2D); after you're done drawing textured stuff.

Upvotes: 6

Related Questions