Jump to content

How do i create a UI buttons inside the 3d scene - Ultra engine early access


rdpobsss
 Share

Recommended Posts

  • 1 month later...

Probably he was talking about https://www.ultraengine.com/learn/CreateInterface?lang=cpp

Should 2nd example looks like that? 

image.thumb.png.1f07967cf0543dfa7731ad1a3ecda6d8.png

https://www.ultraengine.com/learn/CreateCamera?lang=cpp says there should be 2 cameras for scene and UI but i still having same pic with this code:

#include "UltraEngine.h"
#include "Components/CameraControls.hpp"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto world = CreateWorld();
    world->SetAmbientLight(0);
    auto framebuffer = CreateFramebuffer(window);

    auto plg = LoadPlugin("Plugins/FITextureLoader");
    auto model = LoadModel(world, "https://github.com/UltraEngine/Documentation/raw/master/Assets/Models/Characters/cyber_samurai.glb");

    //Create a camera    
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 1.4, -1);
    camera->SetFov(70);
    camera->AddPostEffect(LoadPostEffect("Shaders/PostEffects/FXAA.json"));

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-10, 10);
    light->SetArea(15, 15);
    light->SetRotation(45, 35, 0);
    light->SetColor(1.2);

    //Load a font
    auto font = LoadFont("Fonts/arial.ttf");

    //Create user interface
    auto ui = CreateInterface(world, font, framebuffer->GetSize());

    //Create widget
    iVec2 sz = ui->root->ClientSize();
    auto button = CreateButton("Button", sz.x / 2 - 75, sz.y / 2 - 15, 150, 30, ui->root);

    //Create camera
    auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);

    while (true)
    {
        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            switch (ev.id)
            {
            case EVENT_WINDOWCLOSE:
                if (ev.source == window)
                {
                    return 0;
                }
                break;
            default:
                ui->ProcessEvent(ev);
                break;
            }
        }

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

Some simple example with 3D scene and 2D UI above would help me a lot.

UPDATE: i fixed my problem with ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);

Apparently it was just a background that covered 3D scene.

Edited by Dreikblack
found solution for myself
Link to comment
Share on other sites

On 3/3/2023 at 6:36 AM, rdpobsss said:

It seems that I can't directly use the code from the documentation on how to create a button and I want to just make a pause button then pop up a panel that has a menu function in it, can someone help me with that? appreciate it.

If you are using Leadwerks, the default first-person shooter template includes a menu that appears when you press the escape key.

Leadwerks documentation is here:
https://leadwerks.com/learn

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...