Jump to content
  • Advertisement
Sign in to follow this  
Joseph T

OpenGL Possible trouble with glColor

This topic is 3659 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

I'm supposed to be implementing rudimentary phong shading in a render of a model for my graphics class. We're doing everything by hand; we're reading in the polygonal information and rendering them pixel by pixel not using the polygon primitive. We're given the normals of the vertices along with their coordinates; we interpolate between edges of a polygon to determine the world coordinates and the coordinates of the normal for each pixel. The problem is that my shading isn't smooth; it's a harsher gradient. It does get shaded depending on where I place a light, but there are stripes. Stepping through my code I test the color of each pixel to see if it's actually getting changed in my equation, and it is. But usually by a very small amount, I'm glColorf and the color values usually are incremented in the thousandths place, if not the millionths. Would my problem be that the colors aren't changing enough to be reflected by OpenGL? As I said the color of each pixel is changing, yet there are hard gradient stripes when it renders.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Joseph T
the color values usually are incremented in the thousandths place, if not the millionths.
In 32bit color mode, there are only 256 possible values for each of R, G and B (so 256*256*256 total colours).
This means the smallest possible change that you can express is 1/256.0.

If for some reason you are using openGL in 16bit color mode, then you're even worse off!
IIRC Red/Blue get 5 bits each (32 possible values) and Green gets 6 bits (64 possible values) - so that's 32*32*64 total colours.


The choice between 16 and 32 bit color is made when you initialize your OpenGL context and create the window, are you familiar with this section of the code?

Quote:
Original post by Joseph T
As I said the color of each pixel is changing, yet there are hard gradient stripes when it renders.
From what I can tell, you're talking about banding. Can you check out the picture on that wikipedia link and tell us if that is the kind of effect you're seeing?

Share this post


Link to post
Share on other sites
No, honestly I'm not. And I am aware that for the integer variant of glColor that there are 0-255 colors available, and I suspected that a similar constraint applied to the floats. Just did a check: 1/256 ~ 0.004, which I think that my color values are changing enough to reflect a ~0.004 change, at least every two pixels.

And no, I'm not familiar with that section of code; we haven't even really been taught OpenGL yet. It's mostly been the mathematics behind graphics. If you could give me a hand with that I'd really appreciate it.

Edit: Yes, that's pretty much what I have. Mine is roughly the 8-bit gradient, dithered.

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!