Diuc38's picture

Color picking

Hello,

I'm trying to make a color picking function with OpenGl in 2D.

I've done this just before :
GL.Disable(EnableCap.Texture2D);
GL.Disable(EnableCap.Fog);
GL.Disable(EnableCap.Lighting);

I'm using this code inside a MouseMove function where e.X and e.Y are my mouse position...

int[] viewport = new int[4];
GL.GetInteger(GetPName.Viewport, viewport);
int[] pixel = new int[3];

try
{
GL.ReadPixels(e.X, viewport[3] - e.Y, viewport[2], viewport[3], PixelFormat.RgbInteger, PixelType.Int, pixel);
}
catch
{ }

When I run the program, it's return always :
pixel[0] = 0
pixel[1] = 0
pixel[2] = 0 wathever my mouse position...

I think i missed something, but what ?
Is my code correct or something missing ?

Thanks for you help,

Diuc38


Comments

Comment viewing options

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

Hello,

I think I found my answer.
Here's my code and works :

int[] viewport = new int[4];
GL.GetInteger(GetPName.Viewport, viewport);
byte[] pixel = null;
IntPtr p = new IntPtr();
try
{
GL.ReadPixels(Position.X, viewport[3] - Position.Y, 1, 1, PixelFormat.Rgb, PixelType.UnsignedByte, ref p);
pixel = BitConverter.GetBytes(p.ToInt32());
}
catch
{ }

Bye, bye