NogginBops / ImGui.NET_OpenTK_Sample

A sample project showing an ImGui (using ImGui.NET) renderer for OpenTK in C#
106 stars 27 forks source link

Corrupt Display #6

Closed jbracey2004 closed 4 years ago

jbracey2004 commented 4 years ago

When I run the sample, it comes up like this: ImGui Sample!_ OpenGL Version_ 3 3 0 - Build 25 20 100 6576 5_27_2020 6_34_55 PM Any idea what's going on here?

NogginBops commented 4 years ago

Hi, sorry for delayed response.

Can you tell me what OS, .NET version, and GPU you are using?

If you have some more time, would you be able to send a RenderDoc capture so I can look into what I going on? https://renderdoc.org/docs/how/how_capture_frame.html After you have the captured frame you can just save the capture to a file and send it to me.

jbracey2004 commented 4 years ago

Here are a couple of snapshots I took

Snapshots_202006021815.zip

This is on Windows 10 Home 10.0.19041, Visual Studio 2019, .NET Framework Version 4.7.2, Rendering with the Intel UHD 620, OpenGL 3.3

NogginBops commented 4 years ago

Thanks a lot for the captures!

Just pushed a fix. If you can test this issue with the latest commit that would be great.

jbracey2004 commented 4 years ago

Hey. Sorry for the late reply. Thanks for the update version. I tested the new version, and found that the GUI initially displays correctly. I ran into a new issue. When I mouse over one of the menus, the entire GUI disappears. I attempted to get the capture via RenderDoc, but I could not get RenderDoc to start the program. Then I fell asleep. I will attempt to get that capture of this occuring later today.

NogginBops commented 4 years ago

@jbracey2004 I just created a opengl3.3 branch that actually adhers to the functions available in 3.3 (it used a few 4.5 features). So I think the issue should be solved in that branch.

Would much appreciate if you could test and see if the issue is fixed. 🙂 (If you could test both the master and the opengl3.3 branch that would be fantastic)

jbracey2004 commented 4 years ago

I was able to get the sample on the master branch to work correctly by having the buffers deleted before recreating them when resizing. Below is the corrected code:

uint totalVBSize = (uint)(draw_data.TotalVtxCount * Unsafe.SizeOf<ImDrawVert>());
if (totalVBSize > _vertexBufferSize)
{
    int newSize = (int)Math.Max(_vertexBufferSize * 1.5f, totalVBSize);
    GL.DeleteBuffer(_vertexBuffer);
    Util.CreateVertexBuffer("ImGui", out _vertexBuffer);
    GL.NamedBufferData(_vertexBuffer, newSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
    GL.VertexArrayVertexBuffer(_vertexArray, 0, _vertexBuffer, IntPtr.Zero, Unsafe.SizeOf<ImDrawVert>());
    _vertexBufferSize = newSize;
    Console.WriteLine($"Resized vertex buffer to new size {_vertexBufferSize}");
}
uint totalIBSize = (uint)(draw_data.TotalIdxCount * sizeof(ushort));
if (totalIBSize > _indexBufferSize)
{
    int newSize = (int)Math.Max(_indexBufferSize * 1.5f, totalIBSize);
    GL.DeleteBuffer(_indexBuffer);
    Util.CreateElementBuffer("ImGui", out _indexBuffer);
    GL.NamedBufferData(_indexBuffer, newSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
    GL.VertexArrayElementBuffer(_vertexArray, _indexBuffer);
    _indexBufferSize = newSize;
    Console.WriteLine($"Resized index buffer to new size {_indexBufferSize}");
}

Also note, I also have a forked version that uses the old-fashioned glBuffer calls instead of the glNamedBuffer calls. It seems to be able to resize buffers without having to delete and recreate them.

Also, I have tested the app on the opengl3.3 branch. That one works too.

NogginBops commented 4 years ago

@jbracey2004 I thought I would let you know that I just discovered a problem with the projection matrix that is used, and it's making the text blurry. When creating the projection matrix the call should look like this:

Matrix4 mvp = Matrix4.CreateOrthographicOffCenter(
                0.0f,
                io.DisplaySize.X,
                io.DisplaySize.Y,
                0.0f,
                -1.0f,
                1.0f);

The change is that the first argument is changed from -1.0 to 0.0.