Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various newbie questions / wishlist for demo #4144

Closed
dgm3333 opened this issue May 16, 2021 · 2 comments
Closed

various newbie questions / wishlist for demo #4144

dgm3333 opened this issue May 16, 2021 · 2 comments

Comments

@dgm3333
Copy link

dgm3333 commented May 16, 2021

I'm just starting out and although I LOVE imgui_demo there are a few things it I haven't been able to figure out from it.
I'm using win10, VS, and c++17
My Q are:

  1. In my win32 app I was able to draw text to the window from the middle of a function by holding the hdc open.
    It crashes when I call ImGui::Render() without an ImGui::End() first, but because I'm in the middle of a function I don't want to.
    And currently when I exit the function it also clears the window of any text I had placed there (win32 only did it when you repainted)
    Am I forced to run a totally separate rendering thread from the function thread, and keep a vector to store the text I want painted to the window and just keep painting it back in during the render cycle. This seems incredibly inefficient when I just want the window left alone (but I can't just totally bypass the rendering code or any other windows will also be affected)? Or is there a window specific ImGui::RenderFreeze()?
    I would REALLY like to see a demo of how to do this well in imgui_demo (and also a live progress bar in the same vein - I'm currently using one from here: Progress Indicators (spinner + loading bar) #1901)

  2. Is there an "im_gui" way of separating the color from the alpha. I have the following, but it seems like something which should be part of the library? I've also attached my header in case it's any use - but you'll have to rename from .txt to .h
    colours.txt

// in colours.h
#define RGB2FLOAT(r,g,b) (float)r/255.0f, (float)g/255.0f, (float)b/255.0f
#define CF_ghostwhite    RGB2FLOAT(248,   248,   255)
//...

// in colourscheme code
colors[ImGuiCol_ChildBg] = ImVec4(CF_black, 0.00f);
colors[ImGuiCol_HeaderActive] = ImVec4(CF_steelblue, 1.00f);
colors[ImGuiCol_SeparatorActive] = ImVec4(CF_dodgerblue2, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(CF_darkgoldenrod2, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(CF_lightgoldenrod1, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(CF_grey70, 0.70f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(CF_grey20, 0.35f);

Also why isn't there the setting for the main background colour in the colourscheme?
Instead the example has it defined in the "main" routine to be called later in the render code
ImVec4 clear_color = ImVec4(CF_white, 1.00f);

There are some other things I would like in imgui_demo (or maybe I just haven't found them)

  1. A button to open/close the windows console eg
static bool consoleVisible = true;
if (ImGui::Button("Console")) {
    if (consoleVisible) {
        ShowWindow(GetConsoleWindow(), SW_HIDE);
        std::cout << "Console Now Hidden\n";
    }
    else {
        ShowWindow(GetConsoleWindow(), SW_RESTORE);
        std::cout << "Console Restored\n";
    }
    consoleVisible = !consoleVisible;
}
  1. Examples of quickly selecting different point sizes for the font. I set up my own map of pointers to each io.Fonts member so I can quickly select it (eg ImGui::PushFont(font[SMALL_HEADER]), ImGui::PushFont(font[PT_16]), etc) although before that I was interating over them so that's another option:-
bool setFontSize(ImGuiIO& io, uint16_t size) {
    if (ImGui::GetFontSize() == size)
        return false;
    //ImGui::GetFont()
    ImFontAtlas* atlas = io.Fonts;
    for (int i = 0; i < atlas->Fonts.Size; i++) {
        ImFont* font = atlas->Fonts[i];
        if (font->FontSize == size) {
            ImGui::PushFont(font);
        }
    }
    return true;
}
  1. A working example of loading an image/texture from file
    I eventually found this: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
    But it took me a little while to realise it wasn't working in my module because the example didn't mention you need to reference the backend (obvious now but not as a total newbie)
    #include <GL/gl3w.h>
    And why couldn't stb_image.h just be included in the Dear im_gui distribution?

Thanks
David

@ocornut
Copy link
Owner

ocornut commented May 16, 2021

Hello David,

Thanks for your feedback.

I LOVE [....]

Being a "newbie" doesn't allow you to ignore requested issue template and guidelines. By doing so you are hogging our attention and consuming our finite amount of energy. Please be considerate of that. Several your questions are missing the information carefully requested and explained in #2261. Please consider opening one issue for each distinct question and making sure to fill the requested issue template.

How do you change the background colour of the primary application - it seems to be locked to olive green? [....] Also why isn't there the setting for the main background colour in the colourscheme?

If you study the examples app you'll see it is part of the clear color that the examples app are using to clear the framebuffer. It is not the scope of dear imgui to handle or care about that (it would be incorrect to even do so since dear imgui is designed to be overlayed over existing apps running graphics).

It crashes when I call ImGui::Render() without an ImGui::End() first,

Hard to understand your paragraph and won't read/answer it without a more detailed explanation (again, see #2261).

Is there an "im_gui" way of separating the color from the alpha. I

Has nothing to do with dear imgui. ImVec4 are 4 float components feel free to create your own macros if you think it makes thing more readable this way.

A button to open/close the windows console eg

That's OS specific and has nothing to do with the purpose of Dear ImGui.

Examples of quickly selecting different point sizes for the font

You answered your own question with the code. We currently won't promote using that until dear imgui has a better scheme for automatically allowing fonts of any sizes. Also the demo only relies on the fixed-size bitmap font embedded in code so difficult for demo to rely on extra fonts from file system.

A working example of loading an image/texture from file
I eventually found this: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples

As stated in that WIKI entry it's not really an Dear ImGui question, we are covering it since it's a frequently asked thing but it's not our job to provide a fancy 3d/graphics engine.

And why couldn't stb_image.h just be included in the Dear im_gui distribution?

Because it's not the purpose of dear imgui.

@ocornut ocornut closed this as completed May 16, 2021
@PathogenDavid
Copy link
Contributor

In my win32 app I was able to draw text to the window from the middle of a function by holding the hdc open.

This seems incredibly inefficient when I just want the window left alone (but I can't just totally bypass the rendering code or any other windows will also be affected)?

Keep in mind that GDI (the portion of the Win32 API you're referring to) is literally as old as Windows its self. It was designed for an era where hardware-accelerated rendering did not exist and computers were slow as dirt. Modern graphics APIs can be used that way, but in practice it is not very common to see them that way in game-like applications (which is arguably what Dear ImGui focuses on and excels at.) You should generally not be applying expectations or usage patterns from GDI to anything modern.

There are various issues/pull requests about modifying Dear ImGui to avoid re-rendering when nothing has changed (#2749 #3124 #4076 #4133), but even then they're still re-rendering the entire screen rather than any sort of dirty rectangle rendering strategy. If you're making a game, you really probably shouldn't be thinking about anything beyond vsync anyway because games tend to inherently need the entire screen redrawn most of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants