Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

glColor not working, random color appearing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 neo187   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 November 2011 - 09:55 AM

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?

Ad:

#2 Brother Bob   Moderators   -  Reputation: 4633

Like
1Likes
Like

Posted 21 November 2011 - 10:18 AM

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.

#3 neo187   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 November 2011 - 11:16 AM

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?

#4 Brother Bob   Moderators   -  Reputation: 4633

Like
1Likes
Like

Posted 21 November 2011 - 11:45 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS