SpiderPig Posted December 27, 2022 Share Posted December 27, 2022 On a different note, I'm trying to setup a different world to render to a sprite but am getting nothing but a black sprite. I can get it to render when using just one world for everything, but not creating a new world. This is what I have so far. (I have a gui_camera setup and working on renderlayer_1) world = CreateWorld(); light = CreateDirectionalLight(world); render_target = CreateTextureBuffer(512, 512); camera = CreateCamera(world); camera->SetClearColor(1, 0, 0); camera->SetRenderTarget(render_target); camera->Move(0, 0, -5); material = CreateMaterial(); material->SetTexture(render_target->GetColorAttachment()); sprite = CreateSprite(sprite_world, 512, 512); sprite->SetRenderLayers(RENDERLAYER_1); sprite->SetMaterial(material); box = CreateBox(world); Link to comment Share on other sites More sharing options...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 1 hour ago, SpiderPig said: On a different note, I'm trying to setup a different world to render to a sprite but am getting nothing but a black sprite. I can get it to render when using just one world for everything, but not creating a new world. This is what I have so far. (I have a gui_camera setup and working on renderlayer_1) I couldn't get a sprite with a material to show at all on a different layer. CreateSprite() works fine, but using LoadSprite or changing it's material to anything causes it to go invisible. Example: #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, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create framebuffer auto framebuffer = CreateFramebuffer(window); //Create world auto world = CreateWorld(); //Create camera auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); camera->SetClearColor(0.125); //Create a ortho camera auto camera2D = CreateCamera(world, UltraEngine::PROJECTION_ORTHOGRAPHIC); camera2D->SetDepthPrepass(false); camera2D->SetClearMode(UltraEngine::CLEAR_DEPTH); camera2D->SetRenderLayers(UltraEngine::RENDERLAYER_7); camera2D->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0); //Create sprite auto sprite = LoadSprite(world, "https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Sprites/nightraider.dds"); sprite->SetPosition(0, 0); sprite->mesh->material->SetAlphaMask(true); // I should appear in the bottom left corner but I don't. sprite->SetRenderLayers(UltraEngine::RENDERLAYER_7); //Main loop while (window->Closed() == false and window->KeyHit(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } On 12/26/2022 at 7:05 AM, Josh said: You must add the following search header path to your existing projects: "$(UltraEnginePath)\Include\Libraries\zlib" I created a new project and I had to manually do this myself. Please update. The good news is that this works as expected now. #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, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create framebuffer auto framebuffer = CreateFramebuffer(window); //Create world auto world = CreateWorld(); //Create camera auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); camera->SetClearColor(0.5); //Create a ortho camera auto camera2D = CreateCamera(world, UltraEngine::PROJECTION_ORTHOGRAPHIC); camera2D->SetDepthPrepass(false); camera2D->SetClearMode(UltraEngine::CLEAR_DEPTH); camera2D->SetRenderLayers(UltraEngine::RENDERLAYER_7); camera2D->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0); // Create Text DropShadow; auto font = LoadFont("Fonts/arial.ttf"); auto text_dropshadow = CreateSprite(world, font, "Hello World!", 128); text_dropshadow->SetRenderLayers(UltraEngine::RENDERLAYER_7); // The Z position should push this back. text_dropshadow->SetPosition(4 + 2, 4 - 2, 1.0f); // Color me black text_dropshadow->SetColor(0.0f, 0.0f, 0.0f, 1.0f); // Create Text auto text = text_dropshadow->Instantiate(world)->As<UltraEngine::Sprite>(); text->SetPosition(4, 4, 0.0f); text->SetColor(1.0f, 1.0f, 1.0f, 1.0f); //Main loop while (window->Closed() == false and window->KeyHit(KEY_ESCAPE) == false) { static bool bSwap = false; if (window->KeyHit(KEY_SPACE)) { if (bSwap) { Print("Push drop shadow back!"); text_dropshadow->SetPosition(4 + 2, 4 - 2, 1.0f); text->SetPosition(4, 4, 0.0f); } else { Print("Bring drop shadow forward!"); text_dropshadow->SetPosition(4 + 2, 4 - 2, -1.0f); text->SetPosition(4, 4, 0.0f); } bSwap = !bSwap; } world->Update(); world->Render(framebuffer); } return 0; } 1 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...
SpiderPig Posted December 28, 2022 Share Posted December 28, 2022 7 hours ago, Josh said: Update Adjusted depth settings in transparency pass UTF-8 string conversion back to wide string no longer supported because it's unreliable I noticed since this update Josh did you don't have to call "SetDepthPrepass(false)". If you comment that out your example will work. Perhaps this isn't working as it should though? 1 Link to comment Share on other sites More sharing options...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 This example shows UI not updating properly or I'm doing it wrong. Either way, the list box stops working properly. Also, just want to bring up that the UI is still drawing ugly in 3D. This means I have to wait to work on game UI until this is fixed. #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, 1280, 720, 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); camera->SetViewport(200, 0, framebuffer->size.x - 200, framebuffer->size.y); auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); uiCamera->SetRenderLayers(RENDERLAYER_1); uiCamera->SetClearMode(CLEAR_DEPTH); uiCamera->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2); auto ui = CreateInterface(world, LoadFont("Fonts/arial.ttf"), iVec2(200, framebuffer->size.y)); ui->SetRenderLayers(RENDERLAYER_1); auto sz = ui->root->ClientSize(); auto listbox = CreateListBox(5, 5, sz.x - 10, 200, ui->root, LISTBOX_DEFAULT)->As<ListBox>(); auto tabber = CreateTabber(5, 205, sz.x - 10, sz.y - 205, ui->root)->As<Tabber>(); tabber->AddItem("Settings", true); tabber->AddItem("Output"); for (int i = 0; i < 100; i++) { listbox->AddItem("Item " + String(i)); } //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(0, 0, 1); //Entity component system auto actor = CreateActor(box); auto component = actor->AddComponent<Mover>(); component->rotation.y = 45; //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { if (PeekEvent()) { auto ev = WaitEvent(); ui->ProcessEvent(ev); switch (ev.id) { case UltraEngine::EVENT_WINDOWCLOSE: if (ev.source == window) exit(0); break; default: break; } } // Rebuild the window. if (window->KeyDown(KEY_SPACE)) { static bool bSwapped = false; framebuffer = NULL; window = NULL; if (!bSwapped) { // Make it a tad bigger window = CreateWindow("Ultra Engine", 0, 0, 1400, 800, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); framebuffer = CreateFramebuffer(window); } else { window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); framebuffer = CreateFramebuffer(window); } // Reposition the camera. uiCamera->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2); // Resize the ui (Am I doing this right??) ui->Redraw(0, 0, framebuffer->size.x, framebuffer->size.y); ui->UpdateLayout(); bSwapped = !bSwapped; } world->Update(); if (framebuffer) world->Render(framebuffer); } return 0; } 1 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...
SpiderPig Posted December 28, 2022 Share Posted December 28, 2022 Here's an example for my post earlier. Rendering to a texture doesn't work from a second world. Not sure if I've set it up correctly though or if it's supposed to work yet. I've tried updating the second world in the main loop as well as rendering to a second framebuffer but creating a second framebuffer will crash the program. If you uncomment the line below and use the first world the example works as expected. #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto world = CreateWorld(); auto framebuffer = CreateFramebuffer(window); auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetFov(70); camera->SetPosition(0, 2, -3); auto font = LoadFont("Fonts/arial.ttf"); auto ui = CreateInterface(world, font, framebuffer->size); ui->SetRenderLayers(RENDERLAYER_1); ui->root->SetColor(0, 0, 0, 0); auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); ui_cam->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2, 0); ui_cam->SetRenderLayers(RENDERLAYER_1); ui_cam->SetClearMode(CLEAR_DEPTH); auto world2 = CreateWorld(); //world2 = world; auto tex_buffer = CreateTextureBuffer(256, 256); auto cam2 = CreateCamera(world2); cam2->SetClearColor(1, 0, 0); cam2->SetRenderTarget(tex_buffer); cam2->Move(0, 0, -5); auto light2 = CreateDirectionalLight(world2); auto box2 = CreateBox(world2); auto mat = CreateMaterial(); mat->SetTexture(tex_buffer->GetColorAttachment()); auto sprite = CreateSprite(world, 256, 256); sprite->SetRenderLayers(RENDERLAYER_1); sprite->SetMaterial(mat); auto light = CreateDirectionalLight(world); light->SetRotation(35, 45, 0); light->SetRange(-10, 10); auto floor = CreateBox(world, 1000.0f, 0.1f, 1000.0f); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Link to comment Share on other sites More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 4 hours ago, SpiderPig said: I wonder if you should change SetRenderLayers() to SetRenderLayer()? Seeing as we're assigning the object to a specific layer it might make more sense. The render layers are a bitwise flag. You can assign multiple layers to the drawn object or the camera, and if they have a value in common then the camera draws that entity. 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 More sharing options...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 2 hours ago, SpiderPig said: I noticed since this update Josh did you don't have to call "SetDepthPrepass(false)". If you comment that out your example will work. Just found out my shadow text example breaks if SetDepthPrepass isn't set to false. The render layer I'm using is only meant for text so it's not a huge deal but something to note. 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...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 Also, speaking of layers, how would one blend 2 perspective cameras in one image. An example would be drawing a first-person view model on Layer 1 so it can have its own FOV settings and not be obstructed by anything. Here's what I tried. I expected the blue spin box to have a red cube being rendered on top of it, but I only see the red cube. #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, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create framebuffer auto framebuffer = CreateFramebuffer(window); //Create world auto world = CreateWorld(); //Create camera auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); 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(0, 0, 1); //Entity component system auto actor = CreateActor(box); auto component = actor->AddComponent<Mover>(); component->rotation.y = 45; //Create a view model camera auto cameraviewmodel = CreateCamera(world); cameraviewmodel->SetFov(70); cameraviewmodel->SetMatrix(camera->GetMatrix()); cameraviewmodel->SetClearMode(UltraEngine::CLEAR_DEPTH); cameraviewmodel->SetRenderLayers(UltraEngine::RENDERLAYER_1); auto viewmodel = CreateBox(world, 0.5f); viewmodel->SetRenderLayers(UltraEngine::RENDERLAYER_1); viewmodel->SetColor(1, 0, 0); viewmodel->Turn(45, 45, 0); // Although I'm further away, I should render on top! viewmodel->SetPosition(0, 0, 1); //Main loop while (window->Closed() == false and window->KeyHit(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } 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...
SpiderPig Posted December 28, 2022 Share Posted December 28, 2022 It seems to work if you create two perspective cameras. 2 Link to comment Share on other sites More sharing options...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 Oh wow, that parameter isn't supposed to be there. There wasn't supposed to be any 2D drawing at all. That's what I get for saying "Just one more thing" til midnight. I'll try removing it tomorrow. 1 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...
SpiderPig Posted December 28, 2022 Share Posted December 28, 2022 I was wondering if that was supposed to be there. Link to comment Share on other sites More sharing options...
SpiderPig Posted December 28, 2022 Share Posted December 28, 2022 @Josh I'm curious if the following is an acceptable way of setting a texture onto a panel. The texture is from a camera's render target and all seems to work well. I'd rather use the GUI instead of a sprite in this case as it's just easier. widget->blocks[0].texture = texture; Link to comment Share on other sites More sharing options...
SpiderPig Posted December 28, 2022 Share Posted December 28, 2022 With the GUI a transparent panel is cutting holes though it's parent. Also the same for text and sliders. This might be similar to what @reepblue was referring to earlier with SetDepthPrepass() not working as expected? #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto world = CreateWorld(); auto framebuffer = CreateFramebuffer(window); auto camera = CreateCamera(world); camera->SetClearColor(1,0,0); camera->SetFov(70); camera->SetPosition(0, 2, -3); auto font = LoadFont("Fonts/arial.ttf"); auto ui = CreateInterface(world, font, framebuffer->size); ui->SetRenderLayers(RENDERLAYER_1); ui->root->SetColor(0, 0, 0, 0); auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); ui_cam->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2, 0); ui_cam->SetRenderLayers(RENDERLAYER_1); ui_cam->SetClearMode(CLEAR_DEPTH); auto light = CreateDirectionalLight(world); light->SetRotation(35, 45, 0); light->SetRange(-10, 10); auto floor = CreateBox(world, 1000.0f, 0.1f, 1000.0f); auto back_panel = CreatePanel(10, 10, 250, 500, ui->root); auto top_panel = CreatePanel(10, 10, 100, 480, back_panel); top_panel->SetColor(1, 1, 1, 0); auto text = CreateLabel("Hello", 120, 10, 100, 20, back_panel); auto slider = CreateSlider(120, 40, 100, 20, back_panel); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Link to comment Share on other sites More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 Here is a simpler example that demonstrates the problem: #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, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create framebuffer auto framebuffer = CreateFramebuffer(window); //Create world auto world = CreateWorld(); //Create a ortho camera auto camera2D = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); camera2D->SetClearColor(0, 0, 1); camera2D->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0); //Create sprite auto sprite = CreateSprite(world, 400, 400); auto mtl = CreateMaterial(); sprite->SetMaterial(mtl); auto sprite2 = CreateSprite(world, 400, 400); sprite2->SetColor(1, 0, 0); sprite2->SetPosition(500, 0, 0); //Main loop while (window->Closed() == false and window->KeyHit(KEY_ESCAPE) == false) { camera2D->SetDepthPrepass(window->KeyDown(KEY_SPACE)); world->Update(); world->Render(framebuffer); } return 0; } 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 More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 Update Adjusted depth settings when early z-pass is disabled. 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 More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 10 hours ago, reepblue said: This example shows UI not updating properly or I'm doing it wrong. Either way, the list box stops working properly. You have too many events piling up in the queue faster than you are processing them. Change "if PeekEvent" to "while PeekEvent()". 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 More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 @SpiderPig This example reproduces your problem using a single camera... #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto world = CreateWorld(); auto framebuffer = CreateFramebuffer(window); auto font = LoadFont("Fonts/arial.ttf"); auto ui = CreateInterface(world, font, framebuffer->size); auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); ui_cam->SetClearColor(0, 1, 0); ui_cam->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0); ui_cam->SetDepthPrepass(true); auto text = CreateLabel("Hello", 120, 10, 100, 20, ui->root); auto slider = CreateSlider(120, 40, 100, 20, ui->root); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { while (PeekEvent()) { auto e = WaitEvent(); ui->ProcessEvent(e); } world->Update(); world->Render(framebuffer); } return 0; } 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 More sharing options...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 51 minutes ago, Josh said: You have too many events piling up in the queue faster than you are processing them. Change "if PeekEvent" to "while PeekEvent()". That's because I pulled @klepto2's example from the last page and I was making stupid mistakes because it was getting late. 🙃 I think the issue would can still happen even if that typo was corrected. I don't think independently resizing the UI isn't an event. I'll try it again tonight. 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...
klepto2 Posted December 28, 2022 Share Posted December 28, 2022 A small experiment to recreate an effect i used in my ocean for Leadwerks: This is uses a second camera with an attached postprocess effect which renders a distance and direction map from a topdown view. It consists of many passes but is still amazingly fast: Render everything but water in a texturebuffer where you store the texcoords for every pixel higher than the water level depending on the texture resolution: perform a JFA (https://www.shadertoy.com/view/WlGyR3) in multiple step sizes store the distance of each pixel to the shore You can see that this is not very accurate as i am currently only render a full cascade for the entire world. But you can get the idea behind it. Unfortunatly UltraEngine currently has no access to clipmaps which leads to the artifact you can see when the sphere is above water. But once clipmaps are reintroduced this should be a no-brainer to solve. 2 Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 Update Fixed bug where transparent objects were being drawn in the depth pre-pass, causing visual errors 11 hours ago, SpiderPig said: I'm curious if the following is an acceptable way of setting a texture onto a panel. The texture is from a camera's render target and all seems to work well. I'd rather use the GUI instead of a sprite in this case as it's just easier. Currently it's not really possible without using a pixmap, which would only work with image data in system memory, but it would probably not be too difficult to add an option for this, probably a Widget::SetTexture() method. 1 hour ago, klepto2 said: Unfortunatly UltraEngine currently has no access to clipmaps which leads to the artifact you can see when the sphere is above water. But once clipmaps are reintroduced this should be a no-brainer to solve. What do you propose? Something like Camera::SetClipPlane(const Plane& p, const int index)? 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 More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 @SpiderPig In this example, you never rendered world2, so it never gets drawn. This code will work, but I don't think the engine likes constantly switching back and forth between worlds. It would be much better to use render layers to control what gets drawn on which camera. There is also a Camera::SetRealtime method which can be used to draw a camera only once or intermittently. #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto world = CreateWorld(); auto framebuffer = CreateFramebuffer(window); auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetFov(70); camera->SetPosition(0, 2, -3); auto font = LoadFont("Fonts/arial.ttf"); auto ui = CreateInterface(world, font, framebuffer->size); ui->SetRenderLayers(RENDERLAYER_1); ui->root->SetColor(0, 0, 0, 0); auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); ui_cam->SetPosition(framebuffer->size.x / 2, framebuffer->size.y / 2, 0); ui_cam->SetRenderLayers(RENDERLAYER_1); ui_cam->SetClearMode(CLEAR_DEPTH); auto world2 = CreateWorld(); //world2 = world; auto tex_buffer = CreateTextureBuffer(256, 256); auto cam2 = CreateCamera(world2); cam2->SetClearColor(1, 0, 0); cam2->SetRenderTarget(tex_buffer); cam2->Move(0, 0, -5); auto light2 = CreateDirectionalLight(world2); auto box2 = CreateBox(world2); auto mat = CreateMaterial(); mat->SetTexture(tex_buffer->GetColorAttachment()); auto sprite = CreateSprite(world, 256, 256); sprite->SetRenderLayers(RENDERLAYER_1); sprite->SetMaterial(mat); auto light = CreateDirectionalLight(world); light->SetRotation(35, 45, 0); light->SetRange(-10, 10); auto floor = CreateBox(world, 1000.0f, 0.1f, 1000.0f); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { box2->Turn(0, 1, 0); world->Update(); world2->Render(framebuffer); world->Render(framebuffer); } return 0; } 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 More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 Also, you guys should use floating points when setting the 2D camera's position: camera2D->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0.0f); If you do integer division your position can be slightly off if the framebuffer happens to have an odd number for width or height. This WILL cause your sprites to not be pixel-perfect, and will cause blurry font rendering. 2 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 More sharing options...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 12 hours ago, reepblue said: Also, speaking of layers, how would one blend 2 perspective cameras in one image. An example would be drawing a first-person view model on Layer 1 so it can have its own FOV settings and not be obstructed by anything. You would never be able to do something like this with Leadwerks. 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 More sharing options...
reepblue Posted December 28, 2022 Share Posted December 28, 2022 11 minutes ago, Josh said: You would never be able to do something like this with Leadwerks. I think the only other engines that allow this is id tech and Source. I have yet to fix my example from last night but I'm looking forward getting an fps demo up and running soon. 🙂 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...
Josh Posted December 28, 2022 Author Share Posted December 28, 2022 This simple example shows fullscreen window resolution changes. It works but it will trigger a validation error in debug mode: #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_FULLSCREEN); //Create a world auto world = CreateWorld(); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create light auto light = CreateBoxLight(world); light->SetRange(-10, 10); light->SetRotation(15, 15, 0); light->SetColor(2); //Create camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 0, -3); camera->SetFov(70); //Create scenery auto box = CreateBox(world); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { if (window->KeyHit(KEY_SPACE)) { window = CreateWindow("Ultra Engine", 0, 0, 1920, 1080, displays[0], WINDOW_FULLSCREEN); framebuffer = CreateFramebuffer(window); } world->Update(); world->Render(framebuffer); } return 0; } 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 More sharing options...
Recommended Posts