Jump to content

UI is broken on second screen


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

It happens after recreating window and UI on second screen, dragging app window and even if initially windows was created on 2nd display.

Depending on window resolution it looks differently on second screen - invisible or partly visible.

First screen:

image.thumb.png.11838df347ced88bc42a81f731dcae47.png

Second:

image.thumb.png.2a1db651306bf084b2aa60659913f0b7.png

#include "UltraEngine.h"

using namespace UltraEngine;

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;
shared_ptr<World> menuWold;
shared_ptr<Interface> ui;
shared_ptr<Camera> uiCamera;
shared_ptr<Widget> btn;
shared_ptr<Widget> btn2;
bool fullscreen = false;
int displayId = 0;

void initGui()
{
    auto default_font = LoadFont("Fonts\\arial.ttf");
    ui = CreateInterface(menuWold, default_font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);

    uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);

    btn = CreateButton("Change display", (float)framebuffer->GetSize().x / 2, framebuffer->GetSize().y / 2, 200, 200, ui->root);
    btn->SetFontScale(2.0f);

    btn2 = CreateButton("Fullscreen", (float)framebuffer->GetSize().x / 2, framebuffer->GetSize().y / 2 + 250, 120, 30, ui->root, BUTTON_CHECKBOX);
}

void changeDisplay()
{
    displayId = displayId == 0 ? 1 : 0;
    if (!fullscreen)
    {
        window = CreateWindow("Ultra Engine", 0, 0, 1000, 1000, GetDisplays()[displayId], WINDOW_DEFAULT);
    }
    else
    {
        window = CreateWindow("Ultra Engine", 0, 0, 1000, 1000, GetDisplays()[displayId], WINDOW_DEFAULT | WINDOW_FULLSCREEN);
    }
    framebuffer = CreateFramebuffer(window);
    initGui();
}

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 1000, 1000, displays[0], WINDOW_DEFAULT);

    //Create a world
    menuWold = CreateWorld();

    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);

    //Create light
    auto light = CreateBoxLight(menuWold);
    light->SetRange(-10, 10);
    light->SetRotation(15, 15, 0);
    light->SetColor(2);

    //Create camera
    auto camera = CreateCamera(menuWold);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -3);
    camera->SetFov(70);

    //Create scenery
    auto box = CreateBox(menuWold);

    initGui();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            if (ev.source == btn && ev.id == EVENT_WIDGETACTION)
            {
                changeDisplay();
            }
            if (ev.source == btn2 && ev.id == EVENT_WIDGETACTION)
            {
                fullscreen = !fullscreen;
            }
            ui->ProcessEvent(ev);
        }
        menuWold->Update();
        menuWold->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

  • 3 months later...
  • Solution

I tried it and the original code above worked on both screens with no issues.

Please let me know if this continues to be a problem in the future.

Flickering issues are also resolved.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...