Possible trouble with glColor

Started by
1 comment, last by Joseph T 15 years, 6 months ago
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.
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?
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.

This topic is closed to new replies.

Advertisement