Jump to content

Dreikblack

Members
  • Posts

    341
  • Joined

  • Last visited

Posts posted by Dreikblack

  1. Steam beta branch.

    When i first time create widgets it's works. But when i destroy them and create new ones in a same vector they are invisible.

    It worked several months ago. Need that for an inventory gui.

    image.png.15e6d527c2b602e89d3ec7c3994af9d9.pngimage.png.ef5393a41bd06f3638e38a8ef077ec5c.png

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    class ContainerWidget : public Panel
    {
        vector<shared_ptr<Widget>> btns;
    
    protected:
    
        virtual bool Initialize(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent)
        {
            btns.resize(4);
            return Widget::Initialize(text, x, y, width, height, parent, style);
        }
    
    public:
    
        void initBtns() {
            clearBtns();
            for (int i = 0; i < btns.size(); i++)
            {
                btns[i] = CreateButton("Btn", i * 50 + 10, 0, 20, 20, Self()->As<Widget>());
            }
        }
    
        void clearBtns() {
            for (int i = 0; i < btns.size(); i++)
            {
                if (btns[i])
                {
                    btns[i]->SetParent(nullptr);
                    btns[i] = nullptr;
                }
            }
        }
    
        static shared_ptr<ContainerWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent)
        {
            struct Struct : public ContainerWidget {
            };
            auto instance = std::make_shared<Struct>();
            instance->Initialize(x, y, width, height, parent);
            instance->SetColor(0.5, 0.5, 0.5, 1, WIDGETCOLOR_BACKGROUND);
            instance->initBtns();
            return instance;
        }
    
    };
    
    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<ContainerWidget> container;
    
    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);
        container = ContainerWidget::create(10, 50, 200, 50, ui->root);
        btn = CreateButton("Reinit buttons", 10, 10, 150, 20, ui->root);
    }
    
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        window = CreateWindow("Ultra Engine", 0, 0, 300, 300, 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);
    
        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)
                {
                    container->initBtns();
                }
                ui->ProcessEvent(ev);
            }
            menuWold->Update();
            menuWold->Render(framebuffer);
        }
        return 0;
    }

     

    • Thanks 1
  2. Looks like a component of new entity that was created by entity->Instantiate() has a pointer to original entity.

    Several months it worked fine. Maybe something went wrong when public entity pointer was replaced by GetEntity() method.

    Steam beta branch.

    image.thumb.png.a1a7d2ab275a1b0e324c93c81b4b43b1.png

    #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", 0, 0, 1200, 800, 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);
    
        //Create a light
        auto light = CreateBoxLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        //Create a box
        auto box = CreateBox(world);
        box->SetPosition(1, 1, 1);
    
        auto component = box->AddComponent<Mover>();
        component->rotationspeed.y = 45;
    
        auto newBox = box->Instantiate(world, true, true);
        newBox->SetPosition(2, 2, 2);
    
        auto componentTest = newBox->GetComponent<Mover>();
    
        Print("first box pos x:");
        Print(box->GetPosition().x);
        Print(component->GetEntity()->GetPosition().x);
        Print("second box pos x:");
        Print(newBox->GetPosition().x);
        Print(componentTest->GetEntity()->GetPosition().x);
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer, false);
        }
        return 0;
    }

     

    • Thanks 1
  3. Does not work anymore in latest dev beta branch:

    #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", 0, 0, 1200, 800, 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);
    
        //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(1, 0, 0);
        auto outlineBox = CreateBox(world);
        outlineBox->SetColor(0, 1, 0);
    
        auto material = CreateMaterial();
        auto unlitShader = LoadShaderFamily("Shaders/Unlit.fam");
        material->SetShaderFamily(unlitShader);
        outlineBox->SetMaterial(material);
    
        //Create a box2 
        auto box2 = CreateBox(world);
        box2->SetColor(1, 0, 0);
        auto outlineBox2 = CreateBox(world);
        outlineBox2->SetColor(0, 0, 1);
    
        auto material2 = CreateMaterial();
        auto unlitShader2 = LoadShaderFamily("Shaders/Unlit.fam");
        material2->SetShaderFamily(unlitShader);
        outlineBox2->SetMaterial(material);
    
        outlineBox2->SetPosition(2, 0, 0);
        box2->SetPosition(2, 0, 0);
    
        //Entity component system
        auto component = box->AddComponent<Mover>();
        component->rotationspeed.y = 45;
    
        auto outlineComponent = outlineBox->AddComponent<Mover>();
        outlineComponent->rotationspeed.y = 45;
    
        auto component2 = box2->AddComponent<Mover>();
        component2->rotationspeed.y = 45;
    
        auto outlineComponent2 = outlineBox2->AddComponent<Mover>();
        outlineComponent2->rotationspeed.y = 45;
    
        //------------------------------------------------------------------------------------  
        //------------------------------------------------------------------------------------  
    
        //Render to texture
        outlineBox->SetRenderLayers(2);
        outlineBox2->SetRenderLayers(2);
    
        auto cam2 = CreateCamera(world);
        cam2->SetClearColor(0, 0, 0, 0);
        cam2->SetRenderLayers(2);
        cam2->SetFov(camera->GetFov());
        cam2->SetMatrix(camera->matrix);
        cam2->AddPostEffect(LoadPostEffect("Shaders/Outline.fx"));
    
        auto sz = framebuffer->GetSize();
        auto texbuffer = CreateTextureBuffer(sz.x, sz.y);
        cam2->SetRenderTarget(texbuffer);
    
        ////Display overlay
        auto sprite = CreateSprite(world, sz.x, sz.y);
        sprite->SetRenderLayers(4);
        auto mtl = CreateMaterial();
        sprite->SetMaterial(mtl);
        mtl->SetTransparent(true);
        mtl->SetTexture(texbuffer->GetColorAttachment());
        auto cam3 = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        cam3->SetClearMode(CLEAR_DEPTH);
        cam3->SetRenderLayers(4);
        cam3->SetPosition(sz.x * 0.5f, sz.y * 0.5f, 0);
    
    
        //------------------------------------------------------------------------------------  
        //------------------------------------------------------------------------------------  
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer, false);
        }
        return 0;
    }
    #version 450
    #extension GL_GOOGLE_include_directive : enable
    #extension GL_ARB_separate_shader_objects : enable
    #extension GL_EXT_multiview : enable
    
    #include "../Base/PushConstants.glsl"
    #include "../Base/CameraInfo.glsl"
    #include "../Base/TextureArrays.glsl"
    #include "../Utilities/Dither.glsl"
    
    layout(location = 0) in vec2 texCoords;
    layout(location = 0) out vec4 outColor;
    
    void main()
    {
        outColor = texture(texture2DSampler[PostEffectTextureID1], texCoords.xy);
        outColor.a = 0.0f;
        
        float depth = texture(texture2DSampler[PostEffectTextureID0], texCoords.xy).r;
    
        //Handle selected objects
        if (depth < 1.0f)
        {
            const int m = 4;
            vec2 pixelsize = 1.0f / BufferSize;
            for (int x = -m; x <= m; ++x)
            {
                for (int y = -m; y <= m; ++y)
                {
                    if (x == 0 && y == 0) continue;
                    float neighbor = texture(texture2DSampler[PostEffectTextureID0], texCoords.xy + pixelsize * vec2(x, y)).r;
                    if (neighbor == 1.0f)
                    {
                        outColor = texture(texture2DSampler[PostEffectTextureID1], texCoords.xy);
                        return;
                    }
                }
            }
        }
    }

    image.thumb.png.85d3a1ecd4fbe54de65c4af786667e5b.png

  4. 3 hours ago, Meric said:

    But why is such a good engine designed to make mostly singleplayer 3d First-Person Shooter games?

    You can make game in any genre with Ultra. I'm working on turn based tactic game for example:

    It's currently on pause because i have to wait for release in Steam to be able to buy it and continue development. Had access when it had subscription system and i bought it for few months with payment for Quake Sacrifice league :lol:

     

    • Like 2
  5. Debug mode has no such problem but TransformPoint in same code in release mode don't returns true when it should.

    A model becomes yellow when it goes through a box in debug( i.e. TransformPoint() returns true).

    #include "UltraEngine.h"
    #include "Components/Mover.hpp"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    
        //Create a framebuffer
        auto framebuffer = CreateFramebuffer(window);
    
        //Create a world
        auto world = CreateWorld();
    
        //Create a camera    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.8);
        camera->Turn(35, 0, 0);
        camera->Move(0, 0, -2);
        camera->SetDebugPhysicsMode(true);
    
        //Create light
        auto light = CreateBoxLight(world);
        light->SetRange(-20, 20);
        light->SetArea(20, 20);
        light->SetRotation(35, 35, 0);
    
        auto unlitMaterial = CreateMaterial();
        auto unlitShader = LoadShaderFamily("Shaders/Unlit.json");
        unlitMaterial->SetShaderFamily(unlitShader);
    
        int width = 2, height = 1, length = 3;
        auto model = CreateModel(world);
        auto mesh = model->AddMesh();
    
        mesh->AddVertex(0, 0, 0); //S
        mesh->AddVertex(-width * 0.5, -height * 0.5, length);//NW
        mesh->AddVertex(width * 0.5, -height * 0.5, length);//NE
    
        mesh->AddPrimitive(2, 1, 0);//S , NW, NE
    
        mesh->AddVertex(-width * 0.5, height * 0.5, length);//NW h
        mesh->AddVertex(width * 0.5, height * 0.5, length);//NE h
    
        mesh->AddPrimitive(0, 3, 4);//S , NW h, NE h
    
        mesh->AddPrimitive(0, 1, 3);//left
    
        mesh->AddPrimitive(4, 3, 1); //"face"
        mesh->AddPrimitive(2, 4, 1); //"face"
    
    
        mesh->AddPrimitive(0, 4, 2); //"right"
    
        auto& mat = unlitMaterial;
        mat->SetTransparent(true);
        model->SetMaterial(mat);
        model->SetColor(0.5f, 0.8f, 0, 0.25f);
        model->SetPosition(0, 0, 0);
    
        auto collider = CreateConvexHullCollider(mesh);
        model->SetCollider(collider);
    
        Vec3 targetPos(2, 0, 0);
        auto box = CreateBox(world, 0.1f);
        box->SetPosition(targetPos);
    
        auto component = model->AddComponent<Mover>();
        component->rotationspeed.y = 45;
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            auto newTargetPos = TransformPoint(targetPos, Mat4(), model->GetMatrix());
            bool isInside = model->GetCollider()->IntersectsPoint(newTargetPos);
            if (isInside)
            {
                model->SetColor(1, 1, 0, 1);
            }
            else {
                model->SetColor(1, 0, 0, 1);
            }
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  6. For some reason usual widgets don't change icon at all so had to create little custom widget with AddBlock();

    #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> panel;
    shared_ptr<Widget> btn;
    
    bool isFirst = true;
    
    class TestWidget : public Widget
    {
    protected:
        virtual void Draw(const int x, const int y, const int width, const int height)
        {
            blocks.clear();
            int blockId = AddBlock(pixmap, iVec2(0), Vec4(1));
        }
    
    public:
        static shared_ptr<TestWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, const int style = 0)
        {
            struct Struct : public TestWidget {
            };
            auto instance = std::make_shared<Struct>();
            instance->Initialize("", x, y, width, height, parent, style);
            return instance;
        }
    };
    
    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);
    
        panel = TestWidget::create(10, 50, 64, 64, ui->root);
        auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
        panel->SetIcon(icon);
        btn = CreateButton("Change an icon", 10, 10, 150, 20, ui->root);
    }
    
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        window = CreateWindow("Ultra Engine", 0, 0, 200, 200, 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);
    
        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)
                {
                    isFirst = !isFirst;
                    if (isFirst)
                    {
                        auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
                        //panel->SetPixmap(icon->Rasterize(1));
                        panel->SetIcon(icon);
                    }
                    else
                    {
                        auto icon2 = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/new.svg");
                        //panel->SetPixmap(icon2->Rasterize(1));
                        panel->SetIcon(icon2);
                    }
                }
                ui->ProcessEvent(ev);
            }
            menuWold->Update();
            menuWold->Render(framebuffer);
        }
        return 0;
    }

     

  7. Is that possible to use Quake font from Quake pak in Ultra? Found "conchars" file without format in gfx.wad but have no idea what can i do with that,

    I have a strong feeling of seeing something like that long time ago but can't find it.

    Currently i'm using quake-like font from the internet but in game it looks much better and supports few languages in rerelease version. I think it's the only Quake thing left that i'm not using from the Quake pak archive.

  8. I made a controls manager where i'm trying reproduce system from this article but based on Ultra keys events (and no editing for action hotkeys yet)

    ControlsManager.h:

    #pragma once
    
    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    using json = nlohmann::json;
    
    enum ACTION_TYPE
    {
        ACTION_CAMERA_MOVE_FORWARD,
        ACTION_CAMERA_MOVE_BACKWARD,
        ACTION_CAMERA_MOVE_LEFT,
        ACTION_CAMERA_MOVE_RIGHT,
        ACTION_CAMERA_ROTATE_LEFT,
        ACTION_CAMERA_ROTATE_RIGHT,
        ACTION_CONFIRM,
        ACTION_WEAPON_FIRE,
        ACTION_WEAPON_SPECIAL,
        ACTION_WEAPON_OVERWATCH,
        ACTION_UNIT_SWITCH_NEXT,
        ACTION_UNIT_SWITCH_PREVIOUS,
        ACTION_INVENTORY,
        ACTION_COUNT
    };
    
    class ControlsManager : public Object
    {
    protected:
    	ControlsManager();
    	void init();
    	WString configPath;
    	json configData;
        map<KeyCode, bool> keysDown;
        map<KeyCode, bool> keysUp;
        map<ACTION_TYPE, vector<KeyCode>> actionsMap;
    public:
    	ControlsManager(ControlsManager const&) = delete;
    	ControlsManager& operator=(ControlsManager const&) = delete;
    	static std::shared_ptr<ControlsManager> getInstance();
        void saveConfig();
        void setAction(ACTION_TYPE action, vector<KeyCode> keys);
        void setDefaultKeys();
        void clearActionUp();
        void pollEvents(Event event);
    	bool isActionKeyDown(ACTION_TYPE action);
        bool isActionKeyUp(ACTION_TYPE action); 	
    };

    ControlsManager.cpp:

    #include "UltraEngine.h"
    #include "ControlsManager.h"
    //#include "SettingsManager.h"
    
    ControlsManager::ControlsManager()
    {
    	init();
    }
    
    struct StructControlsManager : public ControlsManager {
    };
    
    void ControlsManager::init() {
    	configPath = AppDir() + "/Saves/Config/Controls.json";
    	setDefaultKeys();
    	try
    	{
    		//configData = SettingsManager::getJson(configPath);
    	}
    	catch (const std::invalid_argument& e)
    	{
    		configData = json();
    	}
    }
    
    std::shared_ptr<ControlsManager> ControlsManager::getInstance()
    {
    	static std::shared_ptr<ControlsManager> instance = std::make_shared<StructControlsManager>();
    	return instance;
    }
    
    void ControlsManager::saveConfig()
    {
    	auto stream = WriteFile(configPath);
    	stream->WriteString(configData.dump());
    	stream->Close();
    }
    
    void ControlsManager::setAction(ACTION_TYPE action, vector<KeyCode> keys)
    {
    	actionsMap[action] = keys;
    }
    
    void ControlsManager::setDefaultKeys()
    {
    	setAction(ACTION_CAMERA_MOVE_FORWARD, { KEY_W, KEY_UP });
    	setAction(ACTION_CAMERA_MOVE_BACKWARD, { KEY_S, KEY_DOWN });
    	setAction(ACTION_CAMERA_MOVE_LEFT, { KEY_A, KEY_LEFT });
    	setAction(ACTION_CAMERA_MOVE_RIGHT, { KEY_D, KEY_RIGHT });
    	setAction(ACTION_CAMERA_ROTATE_LEFT, { KEY_Q });
    	setAction(ACTION_CAMERA_ROTATE_RIGHT, { KEY_E });
    	setAction(ACTION_CONFIRM, { KEY_SPACE });
    	setAction(ACTION_WEAPON_FIRE, { KEY_F });
    	setAction(ACTION_WEAPON_SPECIAL, { KEY_T });
    	setAction(ACTION_WEAPON_OVERWATCH, { KEY_Y });
    	setAction(ACTION_UNIT_SWITCH_NEXT, { KEY_TAB });
    	setAction(ACTION_UNIT_SWITCH_PREVIOUS, { KEY_SHIFT });
    	setAction(ACTION_INVENTORY, { KEY_I });
    }
    
    
    void ControlsManager::clearActionUp()
    {
    	for (auto& keyUp : keysUp)
    	{
    		keyUp.second = false;
    	}
    }
    
    void ControlsManager::pollEvents(Event event)
    {
    	switch (event.id)
    	{
    	case EVENT_KEYDOWN:
    	{
    		keysDown[static_cast<KeyCode>(event.data)] = true;
    		keysUp[static_cast<KeyCode>(event.data)] = false;
    		break;
    	}
    	case EVENT_KEYUP:
    	{
    		keysUp[static_cast<KeyCode>(event.data)] = true;
    		keysDown[static_cast<KeyCode>(event.data)] = false;
    		break;
    	}
    	}
    }
    
    bool ControlsManager::isActionKeyDown(ACTION_TYPE action)
    {
    	if (actionsMap[action].empty()) return false;
    	for (auto& key : actionsMap[action])
    	{
    		if (keysDown[key]) return true;
    	}
    	return false;
    }
    
    bool ControlsManager::isActionKeyUp(ACTION_TYPE action)
    {
    	if (actionsMap[action].empty()) return false;
    	for (auto& key : actionsMap[action])
    	{
    		if (keysUp[key]) return true;
    	}
    	return false;
    }

    Game loop (without few parts):

      while (window->Closed() == false)
        {
            controlsManager->clearActionUp();
            while (PeekEvent())
            {
                const Event ev = WaitEvent();
                switch (ev.id)
                {   
                default:
                    controlsManager->pollEvents(ev);
                 	ui->ProcessEvent(ev);
                    break;
                }
            }
            gameWorld->Update();
            gameWorld->Render(framebuffer);
        }

    Use case:

    auto controlsManager = ControlsManager::getInstance();
    if (controlsManager->isActionKeyDown(ACTION_CAMERA_MOVE_LEFT)) entity->Move(-speed * 2, 0, 0);
    if (controlsManager->isActionKeyDown(ACTION_CAMERA_MOVE_RIGHT)) entity->Move(speed * 2, 0, 0);
    • Like 1
    • Thanks 1
  9. Initially i tried to reproduced bug when while changing an icon it was blinking with purple but in test example first icons stays.

    #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> panel;
    shared_ptr<Widget> btn;
    
    bool isFirst = true;
    
    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);
    
        panel = CreatePanel(10, 50, 64, 64, ui->root, PANEL_DEFAULT);
        auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
        panel->SetIcon(icon);
        btn = CreateButton("Change an icon", 10, 10, 150, 20, ui->root);
    }
    
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        window = CreateWindow("Ultra Engine", 0, 0, 200, 200, 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);
    
        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)
                {
                    isFirst = !isFirst;
                    if (isFirst)
                    {
                        auto icon = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
                        panel->SetIcon(icon);
                    }
                    else
                    {
                        auto icon2 = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/new.svg");
                        panel->SetIcon(icon2);
                    }
                }
                ui->ProcessEvent(ev);
            }
            menuWold->Update();
            menuWold->Render(framebuffer);
        }
        return 0;
    }

     

×
×
  • Create New...