Jump to content

( LUA ) Looking for SetOrder() example


Alienhead
 Share

Recommended Posts

1 hour ago, Alienhead said:

this system is getting wiped in place of a new one? I

It's not. Just will be 3D camera instead of world and other things should stay like they are now afaik (and no SetRenderLayers will be needed for UI). Internally there will be bigger changes, but ideally it will affect only bugs (by fixing them indirectly) and not API beside CreateInterface

ui = CreateInterface(camera, font, frameSize)
  • Thanks 1
Link to comment
Share on other sites

SetOrder, GUI and Sprite with ordering example

local displays = GetDisplays()
local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR)
local world = CreateWorld()
local framebuffer = CreateFramebuffer(window)

local light = CreateBoxLight(world)
light:SetRotation(45, 35, 0)
light:SetRange(-10, 10)
light:SetColor(2)
local model = CreateBox(world)
model:SetColor(0, 0, 1)

local font = LoadFont("Fonts/arial.ttf")
local ui = CreateInterface(world, font, framebuffer.size)
ui:SetRenderLayers(2)
ui.background:SetColor(0.0, 0.0, 0.0, 0.0)
local sz = ui.background:ClientSize()
local sz = ui.background:ClientSize()
local button = CreateButton("Button", sz.x / 2 - 75, sz.y / 2 - 15, 150, 30, ui.background)

local uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC)
uiCamera:SetPosition(framebuffer.size.x * 0.5, framebuffer.size.y * 0.5, 0)
uiCamera:SetRenderLayers(2)
uiCamera:SetClearMode(CLEAR_DEPTH);
--higher number than other cameras means drawing later than other camera, by default 0 and order defined by creation order
uiCamera:SetOrder(1)

--100 width, 10 height
local sprite = CreateSprite(world, 100, 10)
sprite:SetColor(1, 0, 0)
--z/depth - to make appear behind GUI and correct order relativly other sprites
sprite:SetPosition(sz.x / 2, sz.y / 2, 0.99901)
--to display in 2D camera
sprite:SetRenderLayers(2)

local sprite2 = CreateSprite(world, 100, 10)
sprite2:SetColor(0, 1, 0)
--bigger depth means it will be behind first sprite
sprite2:SetPosition(sz.x / 2 + 50, sz.y / 2, 0.99902)
sprite2:SetRenderLayers(2)

local camera = CreateCamera(world)
camera:SetClearColor(0.125)
camera:SetPosition(0, 0, -4)

while not window:KeyDown(KEY_ESCAPE) do
    while (PeekEvent()) do
        local ev = WaitEvent()
        if (ev.id == EVENT_WINDOWCLOSE and ev.source == window) then
            return 0
        else
            ui:ProcessEvent(ev)
        end
    end
    model:Turn(0, 1, 0)
    world:Update()
    world:Render(framebuffer)
end

image.png

  • Thanks 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...