Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. opengl (openTK)

opengl (openTK)

Scheduled Pinned Locked Moved Graphics
winformsgraphicsgame-devquestion
4 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dspdad010
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • D dspdad010

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try pixel type unsigned byte.

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      D 1 Reply Last reply
      0
      • L Lost User

        Try pixel type unsigned byte.

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        D Offline
        D Offline
        dspdad010
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • D dspdad010

          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.

          J Offline
          J Offline
          jon 80
          wrote on last edited by
          #4

          How well does .NET graphics library including all latest plug-ins meet the original theories outlined by Christer Ericson (Morgan Kaufmann series)?

          Jon

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups