
Color picking
Posted Monday, 12 March, 2012 - 20:36 by Diuc38 inHello,
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
Re: Color picking
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