Josh Posted August 19, 2022 Share Posted August 19, 2022 This code shows how to set up a GUI with 3D graphics. This requires an update I will upload today: #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); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 0.1, -1); auto specmap = LoadTexture("Materials/Environment/Storm/specular.dds"); auto diffmap = LoadTexture("Materials/Environment/Storm/diffuse.dds"); world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND); world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR); world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE); auto mtl = CreateMaterial(); mtl->SetRoughness(0.25); mtl->SetMetalness(0.5); auto ball = CreateSphere(world,0.5,32); ball->SetMaterial(mtl); camera->Point(ball); auto cam2d = CreateCamera(world); cam2d->SetProjectionMode(PROJECTION_ORTHOGRAPHIC); cam2d->SetRange(-1, 1); cam2d->SetRenderLayers(RENDERLAYER_1); cam2d->SetClearMode(CLEAR_DEPTH); cam2d->SetPosition(float(framebuffer->size.x)*0.5f, float(framebuffer->size.y)*0.5f); const int SIDEPANELWIDTH = 200; auto ui = CreateInterface(world, framebuffer->size); ui->background->SetShape(0, 0, SIDEPANELWIDTH, ui->background->size.y); ui->background->SetLayout(1, 0, 1, 1); ui->SetRenderLayers(RENDERLAYER_1); int x = 10, y = 10; CreateLabel("Rougness:", x, y, ui->background->size.x - 2 * x, 30, ui->background); y += 40; auto roughnessslider = CreateSlider(x, y, ui->background->size.x - 2 * x, 30, ui->background, SLIDER_HORIZONTAL | SLIDER_TRACKBAR); roughnessslider->SetLayout(1, 1, 1, 0); roughnessslider->SetRange(0, 10); roughnessslider->SetValue(0); y += 40; CreateLabel("Metallic:", x, y, ui->background->size.x - 2 * x, 30, ui->background); y += 40; auto metallicslider = CreateSlider(x, y, ui->background->size.x - 2 * x, 30, ui->background, SLIDER_HORIZONTAL | SLIDER_TRACKBAR); metallicslider->SetRange(0, 10); metallicslider->SetValue(0); metallicslider->SetLayout(1, 1, 1, 0); y += 40; ui->SetScale(displays[0]->scale); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { while (PeekEvent()) { const auto& e = WaitEvent(); switch (e.id) { //Pass these events to the GUI: case EVENT_MOUSEWHEEL: case EVENT_MOUSEDOWN: case EVENT_MOUSEUP: case EVENT_MOUSEMOVE: case EVENT_KEYDOWN: case EVENT_KEYUP: case EVENT_KEYREPEAT: case EVENT_KEYCHAR: ui->ProcessEvent(e); break; //Response to GUI events: case EVENT_WIDGETACTION: if (e.source == roughnessslider) { mtl->SetRoughness(float(e.data) * 0.1f); } else if (e.source == metallicslider) { mtl->SetMetalness(float(e.data) * 0.1f); } break; } } //camera->UpdateControls(window); world->Update(); world->Render(framebuffer); } return 0; } Here is the result: 1 1 Quote 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 August 19, 2022 Author Share Posted August 19, 2022 Okay, the update is available now and this example works. I noticed the project was not showing as requiring an update, even though new shaders were downloaded. There may be an issue with the time stamps on zip-extracted files, so you may need to uninstall and reinstall the SDK before the project will show that it is outdated. 1 Quote 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 August 19, 2022 Share Posted August 19, 2022 Thanks. Going to have a ton of fun this weekend! 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.