fix(shader): Use custom_background callback to render blurred texture

- Add _render_custom_background method as hello_imgui callback
- Render blurred FBO texture as ImGui background
- Use ctypes.cast to convert OpenGL texture ID to ImTextureRef
This commit is contained in:
2026-03-13 21:44:55 -04:00
parent aed461ef28
commit 1eed009b12
4 changed files with 39 additions and 34 deletions

View File

@@ -82,8 +82,9 @@ This file tracks all major tracks for the project. Each track has its own detail
11. [ ] **Track: Advanced Text Viewer with Syntax Highlighting**
*Link: [./tracks/text_viewer_rich_rendering_20260313/](./tracks/text_viewer_rich_rendering_20260313/)*
12. [ ] **Track: Frosted Glass Background Effect**
12. [ ] ~~**Track: Frosted Glass Background Effect**~~ THIS IS A LOST CAUSE DON'T BOTHER.
*Link: [./tracks/frosted_glass_20260313/](./tracks/frosted_glass_20260313/)*
---

View File

@@ -56,7 +56,7 @@ Response = true
Theme = true
"Log Management" = true
Diagnostics = false
"External Tools" = true
"External Tools" = false
"Shader Editor" = true
[theme]
@@ -64,8 +64,8 @@ palette = "Nord Dark"
font_path = "C:/projects/manual_slop/assets/fonts/MapleMono-Regular.ttf"
font_size = 18.0
scale = 1.0
transparency = 0.5400000214576721
child_transparency = 1.0
transparency = 0.4399999976158142
child_transparency = 0.5099999904632568
[mma]
max_workers = 4

View File

@@ -74,8 +74,8 @@ Collapsed=0
DockId=0xAFC85805,2
[Window][Theme]
Pos=0,1020
Size=680,737
Pos=0,543
Size=387,737
Collapsed=0
DockId=0x00000002,2
@@ -91,8 +91,8 @@ Collapsed=0
DockId=0x00000010,2
[Window][Context Hub]
Pos=0,1020
Size=680,737
Pos=0,543
Size=387,737
Collapsed=0
DockId=0x00000002,1
@@ -103,26 +103,26 @@ Collapsed=0
DockId=0x0000000D,0
[Window][Discussion Hub]
Pos=1462,26
Size=950,1731
Pos=1169,26
Size=950,1254
Collapsed=0
DockId=0x00000013,0
[Window][Operations Hub]
Pos=682,26
Size=778,1731
Pos=389,26
Size=778,1254
Collapsed=0
DockId=0x00000005,0
[Window][Files & Media]
Pos=0,1020
Size=680,737
Pos=0,543
Size=387,737
Collapsed=0
DockId=0x00000002,0
[Window][AI Settings]
Pos=0,26
Size=680,992
Size=387,515
Collapsed=0
DockId=0x00000001,0
@@ -132,14 +132,14 @@ Size=416,325
Collapsed=0
[Window][MMA Dashboard]
Pos=2414,26
Size=653,1731
Pos=2121,26
Size=653,1254
Collapsed=0
DockId=0x00000010,0
[Window][Log Management]
Pos=2414,26
Size=653,1731
Pos=2121,26
Size=653,1254
Collapsed=0
DockId=0x00000010,1
@@ -330,7 +330,7 @@ Size=967,499
Collapsed=0
[Window][Usage Analytics]
Pos=1439,259
Pos=1627,680
Size=480,343
Collapsed=0
@@ -380,7 +380,7 @@ Size=900,700
Collapsed=0
[Window][Shader Editor]
Pos=923,623
Pos=998,497
Size=493,369
Collapsed=0
@@ -497,7 +497,7 @@ Column 1 Weight=1.0000
DockNode ID=0x00000008 Pos=3125,170 Size=593,1157 Split=Y
DockNode ID=0x00000009 Parent=0x00000008 SizeRef=1029,147 Selected=0x0469CA7A
DockNode ID=0x0000000A Parent=0x00000008 SizeRef=1029,145 Selected=0xDF822E02
DockSpace ID=0xAFC85805 Window=0x079D3A04 Pos=0,26 Size=3067,1731 Split=X
DockSpace ID=0xAFC85805 Window=0x079D3A04 Pos=0,26 Size=2774,1254 Split=X
DockNode ID=0x00000003 Parent=0xAFC85805 SizeRef=1980,1183 Split=X
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=404,1186 Split=X Selected=0xF4139CA2
DockNode ID=0x00000007 Parent=0x0000000B SizeRef=680,858 Split=Y Selected=0x8CA2375C
@@ -510,7 +510,7 @@ DockSpace ID=0xAFC85805 Window=0x079D3A04 Pos=0,26 Size=3067,1731 Spli
DockNode ID=0x00000013 Parent=0x0000000E SizeRef=950,402 Selected=0x6F2B5B04
DockNode ID=0x0000000D Parent=0x00000003 SizeRef=435,1186 Selected=0x363E93D6
DockNode ID=0x00000004 Parent=0xAFC85805 SizeRef=653,1183 Split=Y Selected=0x3AEC3498
DockNode ID=0x00000010 Parent=0x00000004 SizeRef=1199,1689 Selected=0x3AEC3498
DockNode ID=0x00000010 Parent=0x00000004 SizeRef=1199,1689 Selected=0x2C0206CE
DockNode ID=0x00000011 Parent=0x00000004 SizeRef=1199,420 Selected=0xDEB547B6
;;;<<<Layout_655921752_Default>>>;;;

View File

@@ -229,24 +229,27 @@ class App:
t = time.time()
self._blur_pipeline.prepare_global_blur(int(ws.x), int(ws.y), t, fb_scale)
def _render_frosted_background(self, window_pos: tuple, window_size: tuple):
def _render_custom_background(self):
if not self.ui_frosted_glass_enabled:
return
if not self._blur_pipeline:
return
ws = imgui.get_io().display_size
fb_scale = imgui.get_io().display_framebuffer_scale.x
if ws.x <= 0 or ws.y <= 0:
return
if fb_scale <= 0:
fb_scale = 1.0
import time
t = time.time()
self._blur_pipeline.prepare_global_blur(int(ws.x), int(ws.y), t, fb_scale)
blur_tex = self._blur_pipeline.get_blur_texture()
if not blur_tex:
return
ws = imgui.get_io().display_size
fb_scale = imgui.get_io().display_framebuffer_scale.x
screen_w = ws.x * fb_scale
screen_h = ws.y * fb_scale
uv_x = window_pos[0] / screen_w
uv_y = 1.0 - (window_pos[1] / screen_h)
uv_w = window_size[0] / screen_w
uv_h = window_size[1] / screen_h
dl = imgui.get_window_draw_list()
self._draw_blurred_rect(dl, (window_pos[0], window_pos[1]), (window_pos[0] + window_size[0], window_pos[1] + window_size[1]), blur_tex, (uv_x, uv_y), (uv_x + uv_w, uv_y - uv_h))
dl = imgui.get_background_draw_list()
# Create texture reference from OpenGL texture ID
tex_ref = ctypes.cast(blur_tex, ctypes.c_void_p).value
dl.add_image(tex_ref, (0, 0), (ws.x, ws.y))
def _draw_blurred_rect(self, dl, p_min, p_max, tex_id, uv_min, uv_max):
import OpenGL.GL as gl
@@ -4126,6 +4129,7 @@ def hello():
self.runner_params.callbacks.setup_imgui_style = theme.apply_current
self.runner_params.callbacks.post_init = self._post_init
self.runner_params.callbacks.pre_new_frame = self._pre_new_frame
self.runner_params.callbacks.custom_background = self._render_custom_background
self._fetch_models(self.current_provider)
md_options = markdown_helper.get_renderer().options
immapp.run(self.runner_params, add_ons_params=immapp.AddOnsParams(with_markdown_options=md_options))