Atmosaero Posted November 29 Share Posted November 29 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 November 30 Solution Share Posted November 30 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; } 4 1 Quote Link to comment Share on other sites More sharing options...
reepblue Posted November 30 Share Posted November 30 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...
Charrua Posted December 5 Share Posted December 5 hi, another way is using buffers.. create some buffers... //in my case camCount is 5 if (camCount>1) for (int i = 0; i < camCount; i++) { buffs[i] = Buffer::Create(context->GetWidth() / camCount, context->GetHeight()); } main loop: world->Update(); for (int i = 0; i < camCount; i++) { buffs[i]->Enable(); .. do whatever you need with the buffer, draw for example, move camera etc. world->Render(); buffs[i]->Disable(); context->sync(); a viede with 3 buffers, me a kinect and the ilusion of "looking through a window" the center one. Quote Paren el mundo!, me quiero bajar. 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.