glColor3f not working

I am having problems with my glColor3f not working :S Whenever I draw glutSolidSphere, it fails to colour it in the specific colour and just colours it in black. However other objects colour fine. It was working before but has stopped working for some reason

This is occuring within the draw mehod within my planet class:

	void Planet::draw()
	{
			
		glPushMatrix();
				
				glColor3f(r,g,b);
				glClearColor(1.0, 0.0, 1.0, 1.0);	//remove this when planet color3f bug is fixed.
				glTranslated(loop[(int)(ceil (speed))].x, loop[(int)(ceil (speed))].y, loop[(int)(ceil (speed))].z);
				glRotated(60, 0, 0, 1);
				glScalef(scale, scale, scale);
				glutSolidSphere(3.0, 20, 20);	
		glPopMatrix();

	}

here is where the method is being called:

void display() {
	
	
	
	glClear(GL_COLOR_BUFFER_BIT );
	glMatrixMode(GL_MODELVIEW); 
	glLoadIdentity(); // reset the matrix
	gluLookAt(cam.pos.x, cam.pos.y, cam.pos.z, 
		cam.lookAt.x, cam.lookAt.y, cam.lookAt.z, 
		cam.up.x, cam.up.y, cam.up.z);
	
	drawAxes();

	
	//Draw Player
	player.draw();

	// Draw planets
	for (int i = 0; i < planetNum; i++)
	{
		//This will draw planets and Planet HUD (shows planet name on their position)
		planet[i]->draw();
		glColor3f(255.0, 255.0, 255.0);
		stringstream ss;
		ss <<  planet[i]->getname() << endl;
		outputText(planet[i]->getPlanetPos().x, planet[i]->getPlanetPos().y, planet[i]->getPlanetPos().z, ss.str());

	} 
	
	glFlush();
	
}

What values do you pass to r, g, b? May be you are not passing them correctly?
have you tried passing a constant value, for example just modify this line



glColor3f(r,g,b);

to this



glColor3f(1,0,0);

and see if all planets turn red.

I had already tried this, no luck </3

There are a lot of meaningless statements in your code. Please consider reading chapter 2 from 7th revision of the Red Book, or some similar article about fundamentals of legacy OpenGL.Maybe answering to the following questing will help us to find where the problem is:1. What are the values of r,g and b variables?2. glClearColor() has no effect in your code. Do you know what’s the purpose of that command?

glClearColor(1.0, 0.0, 1.0, 1.0); //remove this when planet color3f bug is fixed.

  1. What color you think is set with glColor3f(255.0, 255.0, 255.0)? This is not a valid color. In fact, it is, but after clamping. The valid range for glColor*f is [0…1].4. Is there some missing code that you have deleted from the post as “not important”?

I was using glClearColor to set the background pink so I am able to view my planets. Without it, my background is black and I can’t see my planets (as they are black also). It was just there temporarily so I could view my planets while this problem exists.

R, G and B are unique values for each planet (there are 5 of them). The problem will not be that as I replaced them with “255,0,0” which should give me the colour red for every planet. This did not happen and they still stayed black.

glClearColor() does infact have an affect within my code as commenting it out caused my background black.

glColor3f(255.0, 255.0, 255.0) should give white.

I have not deleted anything from the post, just given both relevant methods.

[QUOTE=TimOgunmakin;1249801]I was using glClearColor to set the background pink so I am able to view my planets. Without it, my background is black and I can’t see my planets (as they are black also). It was just there temporarily so I could view my planets while this problem exists.[/QUOTE]glClearColor() affects next glClear(). This should be done once per frame, or even better in some PrepareScene() function (once per application execution).[QUOTE=TimOgunmakin;1249801]R, G and B are unique values for each planet (there are 5 of them). The problem will not be that as I replaced them with “255,0,0” which should give me the colour red for every planet. This did not happen and they still stayed black.[/QUOTE]Nope! glColor3f(1.0, 0.0, 0.0) is red! use glColor3ub if you want [0…255] segment.[QUOTE=TimOgunmakin;1249801]glClearColor() does infact have an affect within my code as commenting it out caused my background black. [/QUOTE]Move it before glClear(). In the first frame it does nothing, but remain in the subsequent frames hence the effect.[QUOTE=TimOgunmakin;1249801]glColor3f(255.0, 255.0, 255.0) should give white.[/QUOTE]Nope! glColor3f(1.0, 1.0, 1.0) is white.

Updated, same result.

draw method:

	void Planet::draw()
	{
			
		glPushMatrix();
				glColor3f(1.0,0.0,0.0);			
				glTranslated(loop[(int)(ceil (speed))].x, loop[(int)(ceil (speed))].y, loop[(int)(ceil (speed))].z);
				glRotated(60, 0, 0, 1);
				glScalef(scale, scale, scale);
				glutSolidSphere(3.0, 20, 20);	
		glPopMatrix();

	}

where it is being called:

void display() {
	
	
	
	glClear(GL_COLOR_BUFFER_BIT );
	glMatrixMode(GL_MODELVIEW); 
	glLoadIdentity(); // reset the matrix
	gluLookAt(cam.pos.x, cam.pos.y, cam.pos.z, 
		cam.lookAt.x, cam.lookAt.y, cam.lookAt.z, 
		cam.up.x, cam.up.y, cam.up.z);
	
	drawAxes();
	
	
	//Draw Player
	player.draw();

	// Draw planets
	for (int i = 0; i < planetNum; i++)
	{
		//This will draw planets and Planet HUD (shows planet name on their position)
		
		planet[i]->draw();
		glColor3f(1.0, 1.0, 1.0);
		stringstream ss;
		ss <<  planet[i]->getname() << endl;
		outputText(planet[i]->getPlanetPos().x, planet[i]->getPlanetPos().y, planet[i]->getPlanetPos().z, ss.str());

	} 
	
	glFlush();
	
}

There is not enough information here. Please post the complete thing otherwise we have no clue what you might be doing in some other part of code.
Would you mind setting up a simple code first to test if it works for rendering one simple sphere with solid color. Wrapping it up into a class should be the next step after you are certain it works for the basic case.