Giter VIP home page Giter VIP logo

Comments (6)

rune-scape avatar rune-scape commented on May 20, 2024

I'll submit a pull request

I'll also add a function to ImGuiIntegration::Context to get the atlas texture:
GL::Texture2D &getAtlasTexture();

from magnum-integration.

rune-scape avatar rune-scape commented on May 20, 2024

I should explain what I'm doing too, probably helpful (maybe good for documentation?).

Big picture I'm trying to use color emojis, and do it seamlessly. I should be able to put an emoji in a raw string literal and pass it to ImGui::Text() and it renders a color emoji.

I'm very close.
I can create a custom glyph with a codepoint in the atlas and it renders(yay!), but I need:

  • Access to the texture in memory after ImFontAtlas::Build()
    or
  • Access to the GL::Texture2D after it is sucked into the GPU memory

Preferably the latter, because this library makes GL texture stuff not painful!

from magnum-integration.

rune-scape avatar rune-scape commented on May 20, 2024

The first option is not possible becuase ImGuiIntegration::Context::relayout() both calls ImFontAtlas::Build() and creates a texture out of that, so none of my code can edit the built (and in CPU memory) texture data

from magnum-integration.

mosra avatar mosra commented on May 20, 2024

Hi again!

Apologies if I'm misunderstanding what you want to do (not using ImGui that much myself, definitely not on the advanced level you're on, haha) -- so you are able to add extraneous glyphs together with their position in the atlas to ImGui, but it doesn't let you upload the data for it, and thus you need to do that manually by accessing the texture after, right?

Adding a texture() getter is a no-brainer, not sure why that was not done already. I'm not sure what exactly would io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(&_texture)); do, but maybe it simplifies the render to not need this branching here?

auto userTexture = static_cast<GL::Texture2D*>(pcmd->TextureId);
_shader.bindTexture(userTexture ? *userTexture : _texture);

none of my code can edit the built

did you try calling io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &pixelSize) on your side after you have all fonts set up and before calling relayout()? It should cause the texture to be built slightly earlier, but then you'd somehow need to reset the IsLoaded() flag so relayout() knows it needs to repopulate the GPU texture ... and I don't know if/how is that possible. Adding some sort of callback or splitting relayout() into two parts to make the access possible would be overcomplicating things for everyone else I'm afraid :/ So this texture access is probably the best way to go about it.

maybe good for documentation?

Definitely! If you open a PR, would be great to expand the Context docs with this -- useful for lots of other users :) Thanks in advance.

(Please note I'm going to be without an access to a computer for the whole next week, so won't be able to do any merging or reviewing until I get back.)

from magnum-integration.

rune-scape avatar rune-scape commented on May 20, 2024

Howdy,

Yes, ImFontAtlas::AddCustomRectFontGlyph lets me specify a Rect to pack into the atlas and map it to a codepoint.

https://github.com/ocornut/imgui/blob/ebe79bbed00a13fd4455f04131b63d49c28ebd5d/imgui.cpp#L230-L234
That is from release v1.69 which is what I think magnum-integration v2019.01 was tested against?
(I am using the unicode branch, which is v1.75 wip)
The comment from the above link says This will be passed back to your via the renderer.
So I tested simplifying that ternary statement and it works! (obviously doesn't work without TexID being set)
And the tests pass on my machine too.

I agree that splitting relayout would be weird, but what about optionally delaying repopulating the GPU texture until newframe? Im not sure. This isn't the issue i'm trying to solve, i'm just spitballing.

Cool! I'll try to write a snippet or two.

from magnum-integration.

mosra avatar mosra commented on May 20, 2024

Fixed by #61, thank you!

from magnum-integration.

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.