flopoloco's picture

Byte VS Unsigned Byte

I had vertex buffer object for color information setup like this.

byte[] dataColor = {
			255,   0,   0,
			255, 255,   0,
			  0, 255,   0,
			  0, 255,   0,
			  0,   0, 255,
			255,   0,   0
		};
GL.GenBuffers(1, out bufferColor);
			GL.BindBuffer(BufferTarget.ArrayBuffer, bufferColor);
			GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(dataColor.Length * sizeof(byte)),
			              dataColor, BufferUsageHint.StaticDraw);

For initializing the color information I had this

GL.EnableClientState(EnableCap.ColorArray);
			GL.BindBuffer(BufferTarget.ArrayBuffer, bufferColor);
			GL.ColorPointer(3, ColorPointerType.Byte, 0, 0);

But the result was a pitch black 3D object, after experimentation I had to change this line to display colored 3D object.
GL.ColorPointer(3, ColorPointerType.UnsignedByte, 0, 0);

What is the difference between ColorPointerType.Byte and ColorPointerType.UnsignedByte?

Thanks! :)


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
treplogle's picture

ColorPointerType.Byte is signed and C# byte is unsigned.

OpenGL
ColorPointerType.Byte = signed byte = -128 to 127
ColorPointerType.UnsignedByte = unsigned byte = 0 to 255

C#
byte = unsigned byte = 0 to 255
sbyte = signed byte = -128 to 127

flopoloco's picture

Oh, thanks. :)