Atmosaero Posted Friday at 05:36 PM Share Posted Friday at 05:36 PM Is it possible to set up two cameras to make a split screen in the game? Quote Link to comment Share on other sites More sharing options...
Solution Dreikblack Posted Saturday at 06:50 AM Solution Share Posted Saturday at 06:50 AM 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: #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; } 3 Quote Link to comment Share on other sites More sharing options...
reepblue Posted Saturday at 04:26 PM Share Posted Saturday at 04:26 PM Oh wow, I knew this was possible but thanks for the example. I hope more couch co-op games are made because of this post. 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
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.