Jump to content

ULTRAPP Kit


Robert_d1968
 Share

Recommended Posts

The OpenGL example code doesn't work out of the box in the documentation. You'll probably get this kind of result ...

tnDc4OC.thumb.png.1e77e8da3d7051caaea99717dd7049d6.png

I'd recommend adjusting to this ...

#include "UltraEngine.h"

#include <GL/GL.h>
#pragma comment (lib, "opengl32.lib")

using namespace UltraEngine;

bool ResizeViewport(const Event& ev, shared_ptr<Object> extra)
{
    if (ev.id == EVENT_WINDOWSIZE)
    {
        auto window = ev.source->As<Window>();
        iVec2 sz = window->ClientSize();
        auto subwindow = extra->As<Window>();
        subwindow->SetShape(200, 8, sz.x - 200 - 8, sz.y - 16);
    }
    return true;
}

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

    //Create a window
    auto window = CreateWindow("OpenGL Example", 0, 0, 800, 600, displays[0], WINDOW_TITLEBAR | WINDOW_RESIZABLE);

    //Create user interface
    auto ui = CreateInterface(window);
    iVec2 sz = ui->root->ClientSize();
    auto treeview = CreateTreeView(8, 8, 200 - 16, sz.y - 16, ui->root);
    treeview->SetLayout(1, 0, 1, 1);
    treeview->root->AddNode("Object 1");
    treeview->root->AddNode("Object 2");
    treeview->root->AddNode("Object 3");

    //Create viewport window
    auto subwindow = CreateWindow("", 200, 8, sz.x - 200 - 8, sz.y - 16, window, WINDOW_EMBEDDED);

    //Adjust the viewport size when main window resized
    ListenEvent(EVENT_WINDOWSIZE, window, ResizeViewport, subwindow);

    //Initialize OpenGL context    
    HWND hwnd = (HWND)(subwindow->GetHandle());
    HDC hdc = GetDC(hwnd);

    PIXELFORMATDESCRIPTOR pfd =
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    // Flags
        PFD_TYPE_RGBA,        // The kind of framebuffer. RGBA or palette.
        32,                   // Colordepth of the framebuffer.
        0, 0, 0, 0, 0, 0,
        0,
        0,
        0,
        0, 0, 0, 0,
        24,                   // Number of bits for the depthbuffer
        8,                    // Number of bits for the stencilbuffer
        0,                    // Number of Aux buffers in the framebuffer.
        PFD_MAIN_PLANE,
        0,
        0, 0, 0
    };
   
    int format = ChoosePixelFormat(hdc, &pfd);

    if (SetPixelFormat(hdc, format, &pfd) == 0) RuntimeError("SetPixelFormat() failed.");

    HGLRC glcontext = wglCreateContext(hdc);

    if (glcontext == NULL) RuntimeError("wglCreateContext() failed.");

    wglMakeCurrent(hdc, glcontext);

    while (true)
    {
        //Check for events
        const Event ev = WaitEvent();
        switch (ev.id)
        {
        case EVENT_WINDOWPAINT:
            if (ev.source == subwindow)
            {
                iVec2 sz = subwindow->ClientSize();
                glViewport(0, 0, sz.x, sz.y);
                glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                SwapBuffers(hdc);
            }
            break;
        case EVENT_WINDOWCLOSE:
            if (ev.source == window) return 0;
            break;
        }
    }

    return 0;
}

The issues I found in the code example were GetHandle returns a void * so a cast to HWND was required to get the window handle. Also the format parameter for SetPixelFormat was hard-coded to a value of 1. According to MS documentation it is best practice to get the available match of pixel format for the device context by calling ChoosePixelFormat.

And the enum in the code example for the creation of subwindow was WINDOW_CHILD, this isn't included in the current build of UAK (maybe in beta, I have no idea ?) so I used WINDOW_EMBEDDED instead.

bZ0F9il.thumb.png.ef1fc4bbaa2c6f3641642d5c91063e04.png

I also changed what window calls ClientSize in the render loop, subwindow now calls ClientSize instead of window which results in the correct size being handed to the viewport.

ItAx0Z0.thumb.png.e366879f584f9bc1a14af7c2440cba65.png

  • Thanks 2
Link to comment
Share on other sites

Can't wait to dive into this more when I have more time, its very promising (way cooler than IMGUI or any other GUI library I've come across). Although for the sake of cleanliness it would be great to have redundant includes and dependencies removed from the source.

I've been trying to link and include UAK in my own project (as opposed to using the launcher to generate a project for me) and it is a nightmare having to go through and remove the excess stuff that isn't used, I've spent a good few hours perusing around various header files removing includes myself. This may be just me and everyone else is ok with this but I like to setup my projects myself as I have complete control over my build configurations, what includes and dependencies I use, as well as general control over my project structure.

  • Like 1
Link to comment
Share on other sites

I gotta say though man, fantastic work! Such a clean API.

Your definitely right about the resizing too, this ****s rapid! My window is resizing before I even click it, that's how quick it is, lightening speed! ?

And the DPI scaling mwah! I'll for sure be using this as a frontend solution for my University major project and any other desktop applications I create. I've already been recommending it to my fellow programmer pals.

  • Like 2
Link to comment
Share on other sites

I am adding some additional information here . See "Adding to an Existing Project":
https://www.ultraengine.com/learn/CPP/Introduction

I guess this won't work with LE4 unless a 32-bit build is created, which I was not planning but maybe we can add that.

  • Like 1
  • Thanks 1

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

1 hour ago, SlipperyBrick said:

Where can I buy UAK? I want to get my mate a copy but can't find it on Steam (I purchased when backing it on kickstarter)

EDIT: Just noticed the store button, I'm an idiot ?

Steam keys were sent out to backers.

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

I also tried out the OpenGL on two computers both computers were Alienware's None would display a thing in the box for the 

Display to be drawn in..  On my alienware it has the gforce 880M video card, it works great with lead werks.

But I see, that Windows 10 seems to have problems with AMD graphics drivers and I did notice alot of AMD stuff in that program.

 

Robert

Edited by Robert_d1968
a misspelled word to correct
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...