Jump to content
  • Advertisement
Sign in to follow this  
Omelas0469

OpenGL glColor3d(1.0,1.0,0.0) won't make my circle yellow!

This topic is 3611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm trying to code Pacman in C++ using the openGL library for the graphics. When I try to draw a yellow circle to represent Pacman, the circle is an olive color even though I do glColor3d(1.0,1.0,0.0); All my program does right now is print out the map (which is basically 20x20 quads with texture) and the olive circle. The tiles appear as expected but Pacman is olive... I'm guessing this might be a lighting issue... I haven't used openGL in a while so I don't want to use more complicated lighting than I have to since this is not primarily a graphics project. I tried just adding the line glEnable(GL_LIGHTING) but this made everything disappear... Any ideas how I can make my Pacman yellow instead of olive? Here's the code I'm using to print my (olive) Pacman:
void drawPacman()
{
	glLoadIdentity();
	glPushMatrix();
	glTranslatef(1.5,1.5,0.0);
	glColor3d(1.0,1.0,0.0);
	double x1 = 0.0;
    double y1 = 0.0;
	double radius = 0.5;
	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(x1, y1);
	for(double angle = 0.0; angle <360; ++angle)
	glVertex2f(x1 + sin(angle) * radius, y1 + cos(angle) * radius);
	glEnd();
	glPopMatrix();
}
Thanks, Omelas P.S. I'm not racist or anything, it's just that pacman is classically a yellow color...

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by zacaj
You might try moving the glColor into the begin/end calls


Yeah and try to use glColor3f(1.0f,1.0f,0.0f);

Share this post


Link to post
Share on other sites
That does sound like a lighting issue, as in some normals are scaled wrong or something. Try turning on GL_NORMALIZE before you draw anything.

glEnable(GL_NORMALIZE);

Share this post


Link to post
Share on other sites
It's a 2d game though. I did glDisable(GL_DEPTH_TEST). I didn't define any normals. Besides, if it's just a circle, should that not be an issue?

Share this post


Link to post
Share on other sites
Quote:
Original post by zacaj
You might try moving the glColor into the begin/end calls


State Machine ??. Leave the glColor where it is no need to change it from place.

Share this post


Link to post
Share on other sites
Arghhhhh... I figured it out. I just added glDisable(GL_TEXTURE_2D);
I don't understand why this fix it though. Can someone please enlighten me?

Thanks for the help everyone.

Omelas

Share this post


Link to post
Share on other sites
I had the same problem about a month ago...


Thing is, when you draw something while GL_TEXTURE_2D is enabled, OpenGL will draw a textured polygon, whenever you use or don't use glTex2f to map the texture. The map's texture is still bound, so OpenGL will use that texture, and since there were no calls to glTex2f, OpenGL will assume all vertexes are mapped to (0,0) on the texture(Or to the last call to glTex2f. Never bothered to check that out, and it doesn't really matter). So, OpenGL will take the color of point (0,0) of your map texture, combine it with the color you sent with glColor3d, and draw the entire shape olive.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!