Why does this code draw colors with double value?

BlitzMax Forums/BlitzMax OpenGL Programming/Why does this code draw colors with double value?

I cannot figure out why this OpenGL code turns all glColor() calls into double their value. If I do glColor4b($80,$80,$80,$80) i get white pixels drawn. If I do $04,$04,$04,$04 I get $08 pixels draws. Everything gets doubled. I cannot understand why. What am I doing wrong or missing?

Local TestPixel:Int=$0		'Initialize as if black $00000000
Local TestPixel2:Int=$0	'Initialize as if black $00000000
			'Try
				glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE)		
				glColor4b($80,$80,$80,$80)			
				
				glBegin(GL_QUADS)		'Draw two quads in the left corners
					glVertex2i(0,0)
					glVertex2i(0,2)
					glVertex2i(2,2)
					glVertex2i(2,0)	'Draw the first quad, anticlockwise
					glVertex2i(0,GameClientHeight-2)
					glVertex2i(0,GameClientHeight)
					glVertex2i(2,GameClientHeight)
					glVertex2i(2,GameClientHeight-2)		'Draw the second quad, anticlockwise
				glEnd()
				glFinish()		'Make sure all rendering is totally finished before we test
				glReadPixels(0,0,1,1,GL_RGBA,GL_UNSIGNED_BYTE,Varptr(TestPixel))		'Get first pixel, all components
				glReadPixels(0,GameClientHeight-1,1,1,GL_RGBA,GL_UNSIGNED_BYTE,Varptr(TestPixel2))		'Get second pixel, all components
Print "TestPixel: "+Hex$(TestPixel)
Print "TestPixel2: "+Hex$(TestPixel2)
EnablePolledInput
Flip
WaitKey

Any ideas/suggestions greatly appreciated. I know it's not the reading of the pixel that is in error. It's the actual drawing of it.

This seems to be entirely a problem with glColor4b(). glColor4f(0.5,0.5,0.5,0.5) does draw mid-grey.

Just got to understand why.

This would explain it:

"Signed integer color components, when specified, are linearly mapped to floating-point values such that the most positive representable value maps to 1.0, and the most negative representable value maps to -1.0. (Note that this mapping does not convert 0 precisely to 0.0.) Floating-point values are mapped directly."

So this means that glColor3b or glColor4b are actually SIGNED bytes, so if you say $80, it maps that as 1.0, which is same as $FF because the highest value can only be $7F.

What you have to use to do normal unsigned byte hex values, ie glColor3ub or glColor4ub (ub for unsigned byte). Good to know. I think I used `b` in some other test programs without realising it!