Jump to content

New Framebuffer keeps initial one's size.


reepblue
 Share

Go to solution Solved by Josh,

Recommended Posts

Running through old samples we were testing during the beta and noticed that this example doesn't have the framebuffer fill the window anymore after it's been "resized".

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

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

    //Create a window
    auto window = CreateWindow("Ultra Engine - Normal", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

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

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 0, -3);
    camera->SetViewport(200, 0, framebuffer->size.x - 200, framebuffer->size.y);

    auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);
    uiCamera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
    auto ui = CreateInterface(world, LoadFont("Fonts/arial.ttf"), iVec2(200, framebuffer->size.y));
    ui->SetRenderLayers(2);

    auto sz = ui->root->ClientSize();
    auto listbox = CreateListBox(5, 5, sz.x - 10, 200, ui->root, LISTBOX_DEFAULT)->As<ListBox>();
    auto tabber = CreateTabber(5, 205, sz.x - 10, sz.y - 205, ui->root)->As<Tabber>();
    tabber->AddItem("Settings", true);
    tabber->AddItem("Output");
    tabber->SetLayout(1, 0, 1, 1);

    for (int i = 0; i < 100; i++)
    {
        listbox->AddItem("Item " + String(i));
    }

    //Create a light
    auto light = CreateBoxLight(world);
    light->SetRotation(35, 45, 0);
    light->SetRange(-10, 10);

    //Create a box
    auto box = CreateBox(world);
    box->SetColor(0, 0, 1);

    //Entity component system
    auto actor = CreateActor(box);
    auto component = actor->AddComponent<Mover>();
    component->rotation.y = 45;

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        while (PeekEvent())
        {
            auto ev = WaitEvent();
            ui->ProcessEvent(ev);

            switch (ev.id)
            {
            case UltraEngine::EVENT_WINDOWCLOSE:
                if (ev.source == window) exit(0);
                break;

            default:
                break;
            }
        }

        // Rebuild the window.
        if (window->KeyDown(KEY_SPACE))
        {
            static bool bSwapped = false;
            framebuffer = NULL;
            window = NULL;

            if (!bSwapped)
            {
                // Make it a tad bigger
                window = CreateWindow("Ultra Engine - Resized", 0, 0, 1400, 800, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
                framebuffer = CreateFramebuffer(window);
            }
            else
            {
                window = CreateWindow("Ultra Engine - Normal", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
                framebuffer = CreateFramebuffer(window);
            }

            // Reposition the camera.
            uiCamera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);

            //Resize the interface
            ui->SetSize(iVec2(200, framebuffer->size.y));

            bSwapped = !bSwapped;
        }

        world->Update();
        if (framebuffer) world->Render(framebuffer);
    }
    return 0;
}

image.thumb.png.00856ff6ef0c22651ece6ec8e43a446a.png

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • Solution
camera->SetViewport(200, 0, framebuffer->size.x - 200, framebuffer->size.y);

If you call that code again after the new framebuffer is created, it works perfectly. :D 

Batman Facepalm GIF by WE tv

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...