Jump to content

Splitscreen


Atmosaero
 Share

Go to solution Solved by Dreikblack,

Recommended Posts

  • Solution
13 hours ago, Atmosaero said:

Is it possible to set up two cameras to make a split screen in the game?

Yes, at least in Ultra, idk about Leadwerks. Made a simple example:

image.thumb.png.e5bf9e6c9172501c241d87b103568e2b.png

#include "UltraEngine.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, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

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

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

    auto sz = framebuffer->GetSize();

    //Create camera
    auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    camera->SetPosition(sz.x * 0.5f, sz.y * 0.5f, 0);
    camera->SetClearMode(CLEAR_DEPTH);

    auto leftSprite = CreateSprite(world, sz.x / 2, sz.y);
    auto rightSprite = CreateSprite(world, sz.x / 2, sz.y);
    rightSprite->SetPosition(sz.x / 2, 0);

    auto unlitShader = LoadShaderFamily("Shaders/Unlit.fam");
    auto leftMaterial = CreateMaterial();
    leftMaterial->SetShaderFamily(unlitShader);
    leftMaterial->SetTransparent(true);
    auto leftTextureBuffer = CreateTextureBuffer(sz.x / 2, sz.y);
    leftMaterial->SetTexture(leftTextureBuffer->GetColorAttachment());
    leftSprite->SetMaterial(leftMaterial);
    leftSprite->SetShadows(false);

    auto leftCamera = CreateCamera(world);
    leftCamera->SetFov(90);
    leftCamera->SetRenderTarget(leftTextureBuffer);
    leftCamera->SetMatrix(camera->matrix);

    auto rightMaterial = CreateMaterial();
    rightMaterial->SetShaderFamily(unlitShader);
    rightMaterial->SetTransparent(true);

    auto rightTextureBuffer = CreateTextureBuffer(sz.x / 2, sz.y);
    rightMaterial->SetTexture(rightTextureBuffer->GetColorAttachment());
    rightSprite->SetMaterial(rightMaterial);
    rightSprite->SetShadows(false);

    auto rightCamera = CreateCamera(world);
    rightCamera->SetFov(90);
    rightCamera->SetRenderTarget(rightTextureBuffer);

    //Create scenery
    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-10, 10);
    light->SetRotation(15, 15, 0);
    light->SetColor(2);


    auto box = CreateBox(world);

    auto cone = CreateCone(world);
    cone->SetPosition(1.25, 0, 0);
    cone->SetColor(0, 0, 1);

    auto sphere = CreateSphere(world);
    sphere->SetPosition(-1.25, 0, 0);
    sphere->SetColor(1, 0, 0);

    leftCamera->SetPosition(0, 0, -3);
    rightCamera->SetPosition(1, 0, -5);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

  • Like 3
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...