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

Wont render outside not inside #16

Open
GamebP opened this issue Sep 29, 2024 · 19 comments
Open

Wont render outside not inside #16

GamebP opened this issue Sep 29, 2024 · 19 comments

Comments

@GamebP
Copy link

GamebP commented Sep 29, 2024

I still have the same issue like last time from #7 . Maybe I need to change somere specific.
Changing NOTIFY_RENDER_OUTSIDE_MAIN_WINDOW to true it will not show it outside
But changing it to false will show in the menu

image

@GamebP
Copy link
Author

GamebP commented Sep 29, 2024

image

@GamebP
Copy link
Author

GamebP commented Sep 29, 2024

image

@OlegSirenko
Copy link

What branch of ImGui are you using? What backend is used for your app?

@GamebP
Copy link
Author

GamebP commented Oct 1, 2024

Yesterday I changed to recent updated ImGui Docking.ocornut/imgui@7937732

@TyomaVader
Copy link
Owner

Could this be caused by an old DirectX version ?

@GamebP
Copy link
Author

GamebP commented Oct 1, 2024

How to know witch one I am using?

@GamebP
Copy link
Author

GamebP commented Oct 1, 2024

@TyomaVader I think you still have the viewing perms to my private project on my side. Maybe I don't know....

@TyomaVader
Copy link
Owner

@TyomaVader I think you still have the viewing perms to my private project on my side. Maybe I don't know....

You're using DirectX 9 right now, it's pretty outdated, try upgrading to 11 or 12 from the Dear ImGui examples and check if this solves the issue

@GamebP
Copy link
Author

GamebP commented Oct 1, 2024

Isnt d3d11 gonna break my project?

@TyomaVader
Copy link
Owner

Isnt d3d11 gonna break my project?

I don't think you're using any DirectX 9 specific functions, so updating ImGui backend and main.cpp files should be enough

@GamebP
Copy link
Author

GamebP commented Oct 2, 2024

I'll try later

@GamebP
Copy link
Author

GamebP commented Oct 2, 2024

idk,
image

@OlegSirenko
Copy link

Maybe try other backend like SDL? It's also not clear what code are you using for showing notifications. Are you enabled docking flag of ImGui?

io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;         // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;       // Enable Multi-Viewport / Platform Windows

@GamebP
Copy link
Author

GamebP commented Oct 3, 2024

i am currently using d3d9

@GamebP
Copy link
Author

GamebP commented Oct 3, 2024

doing this in d3d9, will be same

io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;

It show's a movable black imgui not the one i want to be moved from:

void gui::CreateHWindow(const char* windowName) noexcept
{
    windowClass.cbSize = sizeof(WNDCLASSEX);
    windowClass.style = CS_CLASSDC;
    windowClass.lpfnWndProc = WindowProcess;
    windowClass.cbClsExtra = 0;
    windowClass.cbWndExtra = 0;
    windowClass.hInstance = GetModuleHandleA(0);
    windowClass.hIcon = 0;
    windowClass.hCursor = 0;
    windowClass.hbrBackground = 0;
    windowClass.lpszMenuName = 0;
    windowClass.lpszClassName = "class001";
    windowClass.hIconSm = 0;

    RegisterClassEx(&windowClass);

    window = CreateWindowEx(
        0,
        "class001",
        windowName,
        WS_POPUP,
        100,
        100,
        WIDTH,
        HEIGHT,
        0,
        0,
        windowClass.hInstance,
        0
    );

    ShowWindow(window, SW_SHOWDEFAULT);
    UpdateWindow(window);
}

Here are some defines:

bool gui::CreateDevice() noexcept
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    if (!d3d)
        return false;

    ZeroMemory(&presentParameters, sizeof(presentParameters));

    presentParameters.Windowed = TRUE;
    presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
    presentParameters.BackBufferFormat = D3DFMT_UNKNOWN;
    presentParameters.EnableAutoDepthStencil = TRUE;
    presentParameters.AutoDepthStencilFormat = D3DFMT_D16;
    presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

    if (d3d->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        window,
        D3DCREATE_HARDWARE_VERTEXPROCESSING,
        &presentParameters,
        &device) < 0)
        return false;

    return true;
}
void gui::CreateImGui() noexcept
{
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();

    // Enable multi-viewport support
    io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
    io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;

// ...
static const ImWchar icons_Ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; // Icons
static ImWchar emoji_ranges[] =     { 0x1, 0x1FFFF, 0 }; // Emojis

cfg.OversampleH = cfg.OversampleV = 1;
cfg.MergeMode = true;
cfg.PixelSnapH = true;
cfg.GlyphMinAdvanceX = iconFontSize;
cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;

io.Fonts->AddFontFromFileTTF("Resources\\Fonts\\Emoji.ttf", 18.0f, &cfg, emoji_ranges); // Emojis 
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, iconFontSize, &cfg, icons_Ranges); // Icons
io.Fonts->Build();
// ...
    ImGui_ImplDX9_Init(device);
#pragma once
#include <d3d9.h>

namespace gui
{
    constexpr int WIDTH = 500;
    constexpr int HEIGHT = 300;

    // when this changes, exit threads and close menu :)
    inline bool isRunning = true;

    // winapi window vars
    inline HWND window = nullptr;
    inline WNDCLASSEX windowClass = { };

    // points for window movement
    inline POINTS position = { };

    // direct x state vars
    inline PDIRECT3D9 d3d = nullptr;
    inline LPDIRECT3DDEVICE9 device = nullptr;
    inline D3DPRESENT_PARAMETERS presentParameters = { };

    // Handle window creation & destruction
    void CreateHWindow(const char* windowName) noexcept;
    void DestroyHWindow() noexcept;

    // Handle device creation & destruction
    bool CreateDevice() noexcept;
    void ResetDevice() noexcept;
    void DestroyDevice() noexcept;

    // Handle ImGui creation & destruction
    void CreateImGui() noexcept;
    void DestroyImGui() noexcept;

    // Begin and end rendering
    void BeginRender() noexcept;
    void EndRender() noexcept;

    // Render GUI elements
    void Render() noexcept;
}
void gui::Render() noexcept
{
// Loads the imgui data
if (ImGui::Begin(
    TitleName_Show.c_str(),
    &isRunning,
    ImGuiWindowFlags_NoResize |
    ImGuiWindowFlags_NoSavedSettings |
    ImGuiWindowFlags_NoCollapse |
    ImGuiWindowFlags_NoMove
))
{
// ...
void gui::BeginRender() noexcept
{
    MSG message;
    while (PeekMessage(&message, 0, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&message);
        DispatchMessage(&message);

        if (message.message == WM_QUIT)
        {
            isRunning = !isRunning;
            return;
        }
    }

    ImGui_ImplDX9_NewFrame();
    ImGui_ImplWin32_NewFrame();
    ImGui::NewFrame();
}
void gui::EndRender() noexcept
{
    ImGui::EndFrame(); // End ImGui frame

    // Clear the device and set render state
    device->SetRenderState(D3DRS_ZENABLE, FALSE);
    device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
    device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0, 0, 0, 255), 1.0f, 0);

    // Begin the scene
    if (device->BeginScene() >= 0)
    {
        ImGui::Render(); // Render ImGui data
        ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); // Draw ImGui elements
        device->EndScene(); // End the scene
    }

    // Present the back buffer to the screen
    const auto result = device->Present(0, 0, 0, 0);

    // Check for lost device
    if (result == D3DERR_DEVICELOST && device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
        ResetDevice();
}

@GamebP
Copy link
Author

GamebP commented Oct 3, 2024

CreateHWindow creates and is only movable not the imgui menu
image

@OlegSirenko
Copy link

I do not really understand where is your problem. It is looks like this is not the ImGuiNotify trouble.

@GamebP
Copy link
Author

GamebP commented Oct 4, 2024

its the d3d9 window creation issue 🤷

@GamebP
Copy link
Author

GamebP commented Oct 4, 2024

I'm no expert in ImGui but somehow could fix it. @TyomaVader Can help me a little?

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