From ba37e1cf415420c403d68e750e42fcd4b5ec1838 Mon Sep 17 00:00:00 2001 From: Angaros Date: Mon, 18 Nov 2024 11:15:02 +0100 Subject: [PATCH] buffer screenshot working + update gitignore for screenshot/.png --- .gitignore | 1 + scene_screenshot_buffer.lua | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 36ec8b5..23f3fd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /resources_compiled /_bin /assetc-ubuntu-x64-2.3.0 +screenshots/.png diff --git a/scene_screenshot_buffer.lua b/scene_screenshot_buffer.lua index b021cb7..2f7a5b0 100644 --- a/scene_screenshot_buffer.lua +++ b/scene_screenshot_buffer.lua @@ -7,26 +7,28 @@ hg.InputInit() hg.WindowSystemInit() res_x, res_y = 1024, 1024 -win = hg.RenderInit('Screenshot Buffer', res_x, res_y, hg.RF_VSync | hg.RF_MSAA4X) +win = hg.RenderInit('Frame Buffer Screenshot', res_x, res_y, hg.RF_VSync | hg.RF_MSAA4X) -hg.AddAssetsFolder("resources_compiled") pipeline = hg.CreateForwardPipeline() local res = hg.PipelineResources() -scene = hg.Scene() -hg.LoadSceneFromAssets("car_engine/engine.scn", scene, res, hg.GetForwardPipelineInfo()) +hg.AddAssetsFolder("resources_compiled") local tex_size = 1024 -local picture = hg.Picture(tex_size, tex_size, hg.PF_RGBA32F) +local picture = hg.Picture(tex_size, tex_size, hg.PF_RGBA32) local frame_buffer = hg.CreateFrameBuffer(tex_size, tex_size, hg.TF_RGBA8, hg.TF_D24, 4, 'framebuffer') local tex_color = hg.GetColorTexture(frame_buffer) local tex_color_ref = res:AddTexture("tex_rb", tex_color) local tex_readback = hg.CreateTexture(tex_size, tex_size, "readback", hg.TF_ReadBack | hg.TF_BlitDestination, hg.TF_RGBA8) +scene = hg.Scene() +ret = hg.LoadSceneFromAssets("car_engine/engine.scn", scene, res, hg.GetForwardPipelineInfo()) + +assert(ret) + local state = "none" --- main loop local frame = 0 local view_id = 0 @@ -57,16 +59,16 @@ while not hg.ReadKeyboard():Key(hg.K_Escape) and hg.IsWindowOpen(win) do scene:Update(dt) - view_id = 0 + view_id = 0 view_id = hg.SubmitSceneToPipeline(view_id, scene, hg.IntRect(0, 0, res_x, res_y), true, pipeline, res, frame_buffer.handle) - --view_id = hg.SubmitSceneToPipeline(view_id, scene, hg.IntRect(0, 0, res_x, res_y), true, pipeline, res) - -- hg.SetViewPerspective(view_id, 0, 0, res_x, res_y, hg.TranslationMat4(hg.Vec3(0, 0, -1.8))) + hg.SetViewPerspective(view_id, 0, 0, res_x, res_y, hg.TranslationMat4(hg.Vec3(0, 0, -1.8))) + + val_uniforms = {hg.MakeUniformSetValue('color', hg.Vec4(1, 1, 1, 1))} + tex_uniforms = {hg.MakeUniformSetTexture('s_tex', tex_color, 0)} - -- val_uniforms = {hg.MakeUniformSetValue('color', hg.Vec4(1, 1, 1, 1))} - -- tex_uniforms = {hg.MakeUniformSetTexture('s_tex', tex_color, 0)} + hg.DrawModel(view_id, plane_mdl, plane_prg, val_uniforms, tex_uniforms, hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(-math.pi/2,0, 0))) - -- hg.DrawModel(view_id, plane_mdl, plane_prg, val_uniforms, tex_uniforms, hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(-math.pi/2,0, 0))) frame = hg.Frame() hg.UpdateWindow(win) end