diedir Posted October 28, 2023 Share Posted October 28, 2023 Hello, me again.. i try to position a sprite created for head up display over a scene, but can't move the display where i want here the code i used : --Get the displays local displays = GetDisplays() --Create window local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1]) --Create framebuffer local framebuffer = CreateFramebuffer(window) --Create world local world = CreateWorld() --env map local specmap = LoadTexture("./Materials/Environment/Default/specular.dds") local diffmap = LoadTexture("./Materials/Environment/Default/diffuse.dds") world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND) world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR) world:SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE) --[[load map local mapname = "Maps/scene1.ultra" local cl = CommandLine() if type(cl["map"]) == "string" then mapname = cl["map"] end local scene = LoadMap(world, mapname) --]] --Create light local light = CreateBoxLight(world) light:SetRange(-10, 10) light:SetArea(15, 15) light:SetRotation(45, 35, 0) light:SetColor(2) --Load a font local font = LoadFont("Fonts/arial.ttf") local fontsize = 36 -- Create sprite local sprite = CreateSprite(world, font,"HEY YOU !",fontsize) sprite:SetColor(1, 1, 1, 1) sprite:SetPosition(0,-50, 0) -- Create a camera local camera = CreateCamera(world,PROJECTION_PERSPECTIVE) camera:SetClearColor(0.125) camera:SetPosition(0, 5, 0) --Create second camera local cam2 = CreateCamera(world,PROJECTION_ORTHOGRAPHIC) cam2:SetPosition(0, 0, 0) cam2:SetClearMode(CLEAR_DEPTH) --Camera controls to look around require 'Components/Player/CameraControls' camera:AddComponent(CameraControls) --main loop while not window:KeyDown(KEY_ESCAPE) do world:Update() world:Render(framebuffer) end Thank you for helping Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 Link to comment Share on other sites More sharing options...
reepblue Posted October 28, 2023 Share Posted October 28, 2023 You're not setting your cam2 or your sprite to a new render layer. Not much of a Lua user, but try this. --Get the displays local displays = GetDisplays() --Create window local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1]) --Create framebuffer local framebuffer = CreateFramebuffer(window) --Create world local world = CreateWorld() --env map local specmap = LoadTexture("./Materials/Environment/Default/specular.dds") local diffmap = LoadTexture("./Materials/Environment/Default/diffuse.dds") world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND) world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR) world:SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE) --[[load map local mapname = "Maps/scene1.ultra" local cl = CommandLine() if type(cl["map"]) == "string" then mapname = cl["map"] end local scene = LoadMap(world, mapname) --]] --Create light local light = CreateBoxLight(world) light:SetRange(-10, 10) light:SetArea(15, 15) light:SetRotation(45, 35, 0) light:SetColor(2) --Load a font local font = LoadFont("Fonts/arial.ttf") local fontsize = 36 -- Create a camera local camera = CreateCamera(world,PROJECTION_PERSPECTIVE) camera:SetClearColor(0.125) camera:SetPosition(0, 5, 0) --Create second camera local cam2 = CreateCamera(world,PROJECTION_ORTHOGRAPHIC) cam2:SetPosition(0, 0, 0) cam2:SetClearMode(CLEAR_DEPTH) cam2:SetRenderLayers(1) -- Create sprite local sprite = CreateSprite(world, font,"HEY YOU !",fontsize) sprite:SetColor(1, 1, 1, 1) sprite:SetPosition(0, 0, 0) sprite:SetRenderLayers(1) --Camera controls to look around require 'Components/Player/CameraControls' camera:AddComponent(CameraControls) --main loop while not window:KeyDown(KEY_ESCAPE) do world:Update() world:Render(framebuffer) end This should spawn the sprite in the center of the screen. 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...
diedir Posted October 28, 2023 Author Share Posted October 28, 2023 Well thank you for your time but the sprite was already in the center of the window, the problem is that i can't place it where i wanted (eg: at top left or top right... etc) still searching Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 Link to comment Share on other sites More sharing options...
reepblue Posted October 28, 2023 Share Posted October 28, 2023 Move the camera to the bottom edge of the framebuffer. 0,0 should be the top left of the screen. Then you can use the size of the framebuffer to position the sprite wherever you want like if you were using the Interface class. local size = framebuffer:GetSize() cam2:SetPosition(size.x * 0.5, size.y * 0.5f) 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...
Solution diedir Posted October 28, 2023 Author Solution Share Posted October 28, 2023 Ok i got it, simply by positionning the sprite in 2D coords like -400,300 x negative on the left side, x positve on the right and y positive on top side and negative in the bottom 0,0 is the center of the window thank you Reepblue Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 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.