dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
753 stars 300 forks source link

Drawing text clears pixels set by DrawPixels #140

Open wzydhek opened 6 years ago

wzydhek commented 6 years ago

I am having a problem using DrawPixels and Drawing text on the same "surface".

I have an OpenGLControl set up to show "static", randomly set pixels shown using DrawPixels in the OpenGLDraw event. If I have DrawFPS set to true, OR if I use DrawText in the same method handler, all the "static" pixels disappear and the text is shown instead. Am I doing something wrong? Is there another way to handle this? Is this behavior by design?

I have included my method below. It shows "static" properly if DrawFPS is set to false. If set to true OR if I uncomment the DrawText, there is no "static", just the drawn text and/or the FPS.

` private void openGLControl_OpenGLDraw(object sender, RenderEventArgs args) { RGBType[] pixels = new RGBType[640 * 480]; GCHandle handle = GCHandle.Alloc(pixels, GCHandleType.Pinned); Random rndm = new Random(); try { IntPtr ptr = handle.AddrOfPinnedObject();

           OpenGL gl = openGLControl.OpenGL;

           gl.ClearColor(0, 0, 0, 0);
           gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);

           for (int i = 0; i < 640 * 480; i++)
           {
                   byte temp = (byte)rndm.Next(255);

                   pixels[i].r = temp;
                   pixels[i].g = temp;
                   pixels[i].b = temp;
           }

           gl.DrawPixels(640, 480, OpenGL.GL_RGB, OpenGL.GL_BYTE, ptr);

           int x = rndm.Next(580);
           int y = rndm.Next(470);
           //gl.DrawText(x, y, 1.0f, 1.0f, 1.0f, "Arial", 12.0f, " Signal Mising! Press F9");
    }
    finally
    {
            if (handle.IsAllocated)
                    handle.Free();
    }

} `