Jump to content

world->Render prevent render if it was before main loop


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

Look at 123 line loadingWorld->Render(framebuffer);

I was doing similar thing to show loading screen when main menu was loading

image.thumb.png.a8cad2d4671f76a1bcaa9e857841529f.png

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

using namespace UltraEngine;


shared_ptr<World> gameWorld;
shared_ptr<Interface> gameUi;

shared_ptr<World> loadingWorld;
shared_ptr<Interface> loadingUi;
shared_ptr<Camera> loadingCamera;


shared_ptr<Camera> uiCamera;
shared_ptr<Map> gameScene;

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;

shared_ptr<Widget> menuPanel;
bool isMenuOn = false;
bool isMainMenuOn = true;

bool resumeGameButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    menuPanel->SetHidden(true);
    isMenuOn = false;
    return true;

}

bool mainMenuButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    isMainMenuOn = true;
    return true;
}


bool newGameButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    isMainMenuOn = false;
    return true;
}

bool exitButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    exit(0);
    return true;
}

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

    // Create user interface
    gameUi = CreateInterface(gameWorld, font, framebuffer->GetSize());
    gameUi->SetRenderLayers(2);
    gameUi->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);

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

    int menuWidth = 200;
    int menuHeight = 200;
    int indent = 25;

    menuPanel = CreatePanel(framebuffer->size.x * 0.5 - menuWidth / 2, framebuffer->size.y * 0.5 - menuHeight / 2, menuWidth, menuHeight, gameUi->root);
    menuPanel->SetColor(0.2, 0.2, 0.2, 1);
    menuPanel->SetLayout(1, 1, 1, 1);
    menuPanel->SetHidden(true);

    int buttonWidth = menuWidth - indent * 2;
    int buttonHeight = 50;
    int posIter = 0;
    int buttonY = indent + posIter * (buttonHeight + indent);
    auto resumeButton = CreateButton("Resume", indent, buttonY, buttonWidth, buttonHeight, menuPanel);
    ListenEvent(EVENT_WIDGETACTION, resumeButton, resumeGameButtonCallback);
    posIter = posIter + 1;
    buttonY = indent + posIter * (buttonHeight + indent);
    auto mainMenuButton = CreateButton("Main Menu", indent, buttonY, buttonWidth, buttonHeight, menuPanel);
    ListenEvent(EVENT_WIDGETACTION, mainMenuButton, mainMenuButtonCallback);
}

int main(int argc, const char* argv[])
{
    RegisterComponents();
    //Load FreeImage plugin (optional)
    auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
    //Get the displays
    auto displays = GetDisplays();
    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);
    //Create a world
    auto world = CreateWorld();

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

    // LOADING
    loadingWorld = CreateWorld();
    loadingUi = CreateInterface(loadingWorld, font, framebuffer->GetSize());
    loadingUi->SetRenderLayers(2);
    loadingUi->root->SetColor(0.5f, 0.5f, 0.5f, 1.0f);
    float labelHeight = float(framebuffer->GetSize().y) * 0.2f;
    int centerX = float(framebuffer->GetSize().x) * 0.5f;
    int centerY = float(framebuffer->GetSize().y) * 0.5f;
    auto loadingLabel = CreateLabel("LOADING...", float(framebuffer->GetSize().x) * 0.05f, centerY - labelHeight * 0.5f, float(framebuffer->GetSize().x) * 0.95f, labelHeight, loadingUi->root, LABEL_CENTER | LABEL_MIDDLE);
    float fonstScale = labelHeight / 14.0f;
    loadingLabel->SetFontScale(fonstScale * 0.5f);
    loadingCamera = CreateCamera(loadingWorld, PROJECTION_ORTHOGRAPHIC);
    loadingCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);
    loadingCamera->SetRenderLayers(2);
    loadingCamera->SetClearMode(CLEAR_DEPTH);
    //CAUSES AN ISSUE
    loadingWorld->Render(framebuffer);

    //Create user interface
    auto ui = CreateInterface(world, font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(0.2f, 0.2f, 0.2f, 1.0f);

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

    auto newGameButton = CreateButton("New game", 200, 125, 200, 50, ui->root);
    ListenEvent(EVENT_WIDGETACTION, newGameButton, newGameButtonCallback);

    auto exitButton = CreateButton("Exit", 200, 200, 200, 50, ui->root);
    ListenEvent(EVENT_WIDGETACTION, exitButton, exitButtonCallback);

    gameWorld = CreateWorld();
    gameWorld->RecordStats();
    WString mapName = "Maps/start.ultra";
    gameScene = LoadMap(gameWorld, mapName);
    guiInit();

    shared_ptr<World> currentWorld = world;
    shared_ptr<Interface> currentUI = ui;

    while (window->Closed() == false)
    {
        if (isMainMenuOn) currentWorld = world; else currentWorld = gameWorld;
        if (isMainMenuOn) currentUI = ui; else currentUI = gameUi;

        if (window->KeyDown(KEY_ESCAPE) == true)
        {
            menuPanel->SetHidden(false);
            isMenuOn = true;
            window->SetMousePosition(framebuffer->size.x * 0.5, framebuffer->size.y * 0.5);
        }
        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            switch (ev.id)
            {
            case EVENT_WINDOWCLOSE:
                if (ev.source == window)
                {
                    exit(0);
                    break;
                }
                break;
            case EVENT_STARTRENDERER:
                if (ev.data == 0)
                {
                    Print("Error: Renderer failed to initialize.");
                    Notify("Renderer failed to initialize.", "Error", true);
                    return 0;
                }
                break;
            default:
                currentUI->ProcessEvent(ev);
                break;
            }
        }
        currentWorld->Update();
        currentWorld->Render(framebuffer);
    }
    return 0;
}

 

  • Thanks 1
Link to comment
Share on other sites

I believe this is fixed in the build that will go out today. Please let me know if it doesn't work, or mark this as the solution if it does.

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

You should get rid of the call to LoadColorScheme, since that file is not included in the report, and it's not necessary.

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

For some reason your code is causing SetPixelFormat to fail in the context creation code. I don't have an explanation yet.

You can add this code to your event evaluation to check if the renderer fails to initialize. It's a good idea to have this anyways because it will show the user if their GPU is unsupported:

            case EVENT_STARTRENDERER:
                if (ev.data == 0)
                {
                    Print("Error: Renderer failed to initialize.");
                    Notify("Renderer failed to initialize.", "Error", true);
                    return 0;
                }
                break;

 

  • Upvote 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

I can sometimes make this issue appear, and sometimes it does not.

I think what's going on is the WM_CREATE must be processed before the OpenGL context is created. A call to WaitEvent() or maybe just PeekEvent() before your first call to world::Render() will probably solve this problem:

    //CAUSES AN ISSUE
    WaitEvent();
    loadingWorld->Render(framebuffer);

 

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 just checked and during the first render there are no cameras being used.

I get a black screen until the program switched over to the main menu.

I cannot find any cameras being created in loadingWorld.

I think you want this:

    // LOADING
    loadingWorld = CreateWorld();
    loadingUi = CreateInterface(loadingWorld, font, framebuffer->GetSize());
    loadingUi->SetRenderLayers(2);
    loadingUi->root->SetColor(0.5f, 0.5f, 0.5f, 1.0f);
    float labelHeight = float(framebuffer->GetSize().y) * 0.2f;
    int centerX = float(framebuffer->GetSize().x) * 0.5f;
    int centerY = float(framebuffer->GetSize().y) * 0.5f;
    auto loadingLabel = CreateLabel("LOADING...", float(framebuffer->GetSize().x) * 0.05f, centerY - labelHeight * 0.5f, float(framebuffer->GetSize().x) * 0.95f, labelHeight, loadingUi->root, LABEL_CENTER | LABEL_MIDDLE);
    float fonstScale = labelHeight / 14.0f;
    loadingLabel->SetFontScale(fonstScale * 0.5f);
    loadingCamera = CreateCamera(loadingWorld, PROJECTION_ORTHOGRAPHIC);
    loadingCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);
    loadingCamera->SetRenderLayers(2);
    loadingCamera->SetClearMode(CLEAR_DEPTH);
    //CAUSES AN ISSUE
    loadingWorld->Render(framebuffer);

 

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

Yeah, camera supposed to be in loading world, just a typo from copy pasting ig. Still "Renderer failed to initialize". I wonder if it can be related to few screens somehow since idk what else can it be if it works for you on amd and nvidia cards,

Link to comment
Share on other sites

Another world render before a loop causing a problem

#include "UltraEngine.h"

using namespace UltraEngine;

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

    //Create window
    auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create world
    auto world = CreateWorld();

    auto world2 = CreateWorld();

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

    //Create a camera
    auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    camera->SetClearColor(0.125);

    world2->Render(framebuffer);

    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        while (PeekEvent())
        {
            auto ev = WaitEvent();
            if (ev.id == EVENT_STARTRENDERER)
            {
                if (ev.data == 0)
                {
                    Print("Renderer failed to start");
                    Notify("Renderer failed to initialize.", "Error", true);
                    return 0;
                }
            }
        }
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

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