Jump to content

Stretched window


Alienhead
 Share

Recommended Posts

The camera drawing system is flexible enough you can do this without any special feature to support it.

  1. Render to a 1920x1080 texture buffer.
  2. Apply the texture to a material on a sprite that is placed in front of a camera with orthogonal projection.
  3. Take victory lap because you just won.

This is exactly the steps any built-in window scaling feature would do, but you have exact control over it.

If you wanted to get even fancier, it would be completely possible to render any GUI or HUD after this, with no downsampling, so those elements would be crisp and clear on top of the lower-res 3D render.

The Interface class has a SetScale command which can be used to scale up the size of a GUI to match the window display scale setting.

  • Like 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

  • 3 weeks later...

Here's an example:
 

--Load FreeImage plugin (optional)
local fiplugin = LoadPlugin("Plugins/FITextureLoader")

--Get the displays
local displays = GetDisplays()

--Create a window
local window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[1].scale, 720 * displays[1].scale, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR)

--Create a framebuffer
local framebuffer = CreateFramebuffer(window)

--Create a world
local world = CreateWorld()

local cam = CreateCamera(world)
cam:AddComponent(CameraControls)
cam:SetPosition(0,1,-1)
--cam:SetFov(70)

local sz = Vec2(framebuffer.size.x * 0.25, framebuffer.size.y * 0.25)
local texbuffer = CreateTextureBuffer(sz.x, sz.y)
cam:SetRenderTarget(texbuffer)
local cam2 = CreateCamera(world, PROJECTION_ORTHOGRAPHIC)
cam2:SetRenderLayers(2)
local sprite = CreateSprite(world, framebuffer.size.x, framebuffer.size.y)
local mtl = CreateMaterial()
local fam = LoadShaderFamily("Shaders/Unlit.fam")
local tex = texbuffer:GetColorAttachment(1)
mtl:SetTexture(tex)
mtl:SetShaderFamily(fam)
sprite:SetMaterial(mtl)
sprite:SetRenderLayers(2)
cam2:SetPosition(framebuffer.size.x * 0.5, framebuffer.size.y * 0.5, 0)

--Load a map
local mapname = "Maps/start.ultra"
local cl = CommandLine()
if type(cl["map"]) == "string" then mapname = cl["map"] end
local scene = LoadMap(world, mapname)

while window:KeyDown(KEY_ESCAPE) == false and window:Closed() == false do

    --Update the world
    world:Update()

    --Render the world to the framebuffer
    world:Render(framebuffer)

end

 

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

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...