Hi, With bibltoteki OpenTK draw a map of the city. I need to know the color of the pixel under the cursor (RGB) and displayed in Label each channel of RGB?
I think the Picking Example supplied with OpenTK does exactly what you need.
Specifically, you want the Byte4 struct and the GL.ReadPixels() call on line 255.
Posted Monday, 7 June, 2010 - 07:10 by Hortus Longus
Have a look at the function reference and you will see:
Parameters:
x Specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels.
width Specify the dimensions of the pixel rectangle. width and height of one correspond to a single pixel.
format Specifies the format of the pixel data. The following symbolic values are accepted: GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA.
type Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV.
data Returns the pixel data.
If you need to read more than a single pixel, allocate an array large enough to hold your pixels. If you need to read pixels in a different format (e.g. float instead of byte), change the definition of the Rgba struct and specify the correct PixelType.
Comments
Re: Сolor of the pixel
I think the Picking Example supplied with OpenTK does exactly what you need.
Specifically, you want the Byte4 struct and the GL.ReadPixels() call on line 255.
Re: Сolor of the pixel
? - I do not know what to write and how to allocate RGB
Color foncolor = GL.ReadPixels(e.X, e.Y,glControl1.Width,glControl1.Height, ? , ?);
Re: Сolor of the pixel
Have a look at the function reference and you will see:
Parameters: x Specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels. width Specify the dimensions of the pixel rectangle. width and height of one correspond to a single pixel. format Specifies the format of the pixel data. The following symbolic values are accepted: GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA. type Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV. data Returns the pixel data.Re: Сolor of the pixel
To read a single pixel:
If you need to read more than a single pixel, allocate an array large enough to hold your pixels. If you need to read pixels in a different format (e.g. float instead of byte), change the definition of the Rgba struct and specify the correct
PixelType.