opengl (openTK)
-
Using OpenTK in devStudio 15 and windows forms on my dell desktop. When I render a color (eg red = 255, 0, 0, 255), and read the results back it is about, but not quite half of the written value, eg 127, 0, 0, 127.
private void GetHitMap()
{
// copy hitmap from screen
IntPtr unmanagedPointer = Marshal.AllocHGlobal(_hitMap.Length);
GL.ReadBuffer(ReadBufferMode.Back);
GL.ReadPixels(0, 0, renderCanvas.Width, renderCanvas.Height, PixelFormat.Rgba, PixelType.Byte, unmanagedPointer);
Marshal.Copy(unmanagedPointer, _hitMap, 0, _hitMap.Length);
Marshal.FreeHGlobal(unmanagedPointer);
}On a laptop, running the same code, same extremely simple shaders, but different gpu, the red is sometime red on the screen, and sometimes 'half red' and the values I read back are sometimes not exactly half, Using a framebuffer in opengl instead of Marshalling gives the same results. All other colors and using r,g,b or any combination gives the same result. I was planning to use 'designated colors' to identify objects, similar to a shadow map, but the colors are not consistent. Is this a known or expected behavior? Is it fixable? Running out of things to look for.
-
Using OpenTK in devStudio 15 and windows forms on my dell desktop. When I render a color (eg red = 255, 0, 0, 255), and read the results back it is about, but not quite half of the written value, eg 127, 0, 0, 127.
private void GetHitMap()
{
// copy hitmap from screen
IntPtr unmanagedPointer = Marshal.AllocHGlobal(_hitMap.Length);
GL.ReadBuffer(ReadBufferMode.Back);
GL.ReadPixels(0, 0, renderCanvas.Width, renderCanvas.Height, PixelFormat.Rgba, PixelType.Byte, unmanagedPointer);
Marshal.Copy(unmanagedPointer, _hitMap, 0, _hitMap.Length);
Marshal.FreeHGlobal(unmanagedPointer);
}On a laptop, running the same code, same extremely simple shaders, but different gpu, the red is sometime red on the screen, and sometimes 'half red' and the values I read back are sometimes not exactly half, Using a framebuffer in opengl instead of Marshalling gives the same results. All other colors and using r,g,b or any combination gives the same result. I was planning to use 'designated colors' to identify objects, similar to a shadow map, but the colors are not consistent. Is this a known or expected behavior? Is it fixable? Running out of things to look for.
-
Try pixel type unsigned byte.
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
Using unsigned byte in the GL code works much better. Thanks for the suggestion. Still have to verify on the laptop if this solves all or only some of the issues. I also tried copying to a bitmap :
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(bounds2.Location, Point.Empty, bounds2.Size);
}which returns the 'right' values from 0..255.
-
Using unsigned byte in the GL code works much better. Thanks for the suggestion. Still have to verify on the laptop if this solves all or only some of the issues. I also tried copying to a bitmap :
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(bounds2.Location, Point.Empty, bounds2.Size);
}which returns the 'right' values from 0..255.