Code Monkey home page Code Monkey logo

Comments (9)

ocornut avatar ocornut commented on May 12, 2024

Have you tried offsetting your orthogonal projection matrix by half a pixel instead?

I'm looking at the 0.375 trick and will add it as a suggestion in the comments.

from imgui.

lightbits avatar lightbits commented on May 12, 2024

Ok. Without any changes to the library code, offsetting my projection matrix by half a pixel (0.375)
does work too. Offsetting by 0.5 doesn't work on my hardware though.

from imgui.

ocornut avatar ocornut commented on May 12, 2024

I have added the following comment (or variants) in four places:

  • In the header of imgui.cpp in the 'getting started' section.
  • In the OpenGL and DirectX sample, above the render function.
  • In the README file that is shown on the web page in the 'FAQ' section.

"
if text or lines are blurry when integrating ImGui in your engine:
- try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f
- in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
"

I believe it should solve the problem for other users. What do you think?

from imgui.

ocornut avatar ocornut commented on May 12, 2024

I actually noticed some blurry line in one of the engine I am testing on. It looks like the code could be:

// Align to be pixel perfect
pos.x = (float)(int)pos.x;
pos.y = (float)(int)pos.y;

And single pixel horizontal/vertical lines are sometimes misplaced. I am working on this now but it is a bit tricky testing on 5 codebase/renderers.

from imgui.

lightbits avatar lightbits commented on May 12, 2024

Yeah I got some blurry lines on graph lines and column lines, to mention a few.

But I fixed it somehow, see screenshot below.
What I do is:

  • Fix blurry lines with vtx_write->pos.xy = (float)(int)(vtx_write->pos.xy + 0.375f); in ImDrawList::AddVtx
  • Use orthographic projection without offset
  • Set PixelCenterOffset to 0.0
  • Do gl_Position = projection * vec4(round(position), 0.0, 1.0); in GLSL shader.

The last line could be done without shaders by rounding all vertices before submitting them. I'm sure this will break on some other machine though.
screenshot

from imgui.

ocornut avatar ocornut commented on May 12, 2024

lightbits: could you disable "no border" in Window Options and post a screenshot of the output using your renderer? thanks. it's pretty messy here.

from imgui.

lightbits avatar lightbits commented on May 12, 2024

Sure, with same setup as I described above:
borders

from imgui.

ocornut avatar ocornut commented on May 12, 2024

I'm having a hard time getting those rectangle outline to be perfect on all sort of renderers, with super sampling etc enabled. (they are rendered using 2 triangles per line, not using line primitives so I can merge draw calls)
I've got a sort of working formula on my 5 test suites here but I don't quite understand the reasonning behind it, which is a sign that it's probably not correct.

I think I will obsolete the "bordered" mode anyway because it is just ugly, but it is a convenient way to test the correctness of pixel accurate drawing so I am keeping it while I'm fixing those things.

from imgui.

ocornut avatar ocornut commented on May 12, 2024

I have committed the code that you tested following our twitter exchange. I think the library should support renderer using multisampling better now. Unfortunately I broke some of the settings for previous users so they may have to change PixelCenterOffset or their projection matrix after updating.

To make sure it is working for you could you confirm that you can continue user ImGui with a vanilla copy of the code? (with only changes applied to user-side code)

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.