apply effector when using demo lib opengl?

Pixilang programming language
Post Reply
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

apply effector when using demo lib opengl?

Post by AutumnCheney »

hello,

in my demo lib project, i am using a function within the main scene to apply an effector to the entire screen (specifically, the EFF_VBLUR and EFF_HBLUR effects). it works when opengl is disabled, but it doesn't when opengl is enabled

i'd really like to use opengl because it speeds up the rendering on my system, so i would like to know if and how an effector can be applied in opengl

i have a feeling the set_gl_callback function is what i'm looking for, but i don't know how to use it yet :(

pretty please? thank you!
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: apply effector when using demo lib opengl?

Post by NightRadio »

Unfortunately the effector() can't work with OpenGL screen directly, but the following trick can be used:

Code: Select all

$prev_screen = get_screen()
if temp_img <= 0 { temp_img = new( WINDOW_XSIZE, WINDOW_YSIZE, PIXEL ) } else { resize( temp_img, WINDOW_XSIZE, WINDOW_YSIZE ) }
copy( temp_img, $prev_screen ) //Copy pixels from the OpenGL screen to the temp_img
set_screen( temp_img ) //Switch to the temp_img (soft render)
effector( EFF_HBLUR, 64, WHITE, -WINDOW_XSIZE/4, -WINDOW_YSIZE/4, WINDOW_XSIZE/2, WINDOW_YSIZE/2 ) //Apply the effector
set_screen( $prev_screen ) //Switch back to the OpenGL screen
update_gl_data( temp_img ) //Update temp_img - copy modified pixels to GPU memory
pixi( temp_img ) //Show temp_img
But the effector() remains on the CPU side anyway, so it will work as slowly as in non-OpenGL mode.
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: apply effector when using demo lib opengl?

Post by AutumnCheney »

NightRadio wrote: Tue Jan 10, 2023 4:26 pm Unfortunately the effector() can't work with OpenGL screen directly, but the following trick can be used:

Code: Select all

$prev_screen = get_screen()
if temp_img <= 0 { temp_img = new( WINDOW_XSIZE, WINDOW_YSIZE, PIXEL ) } else { resize( temp_img, WINDOW_XSIZE, WINDOW_YSIZE ) }
copy( temp_img, $prev_screen ) //Copy pixels from the OpenGL screen to the temp_img
set_screen( temp_img ) //Switch to the temp_img (soft render)
effector( EFF_HBLUR, 64, WHITE, -WINDOW_XSIZE/4, -WINDOW_YSIZE/4, WINDOW_XSIZE/2, WINDOW_YSIZE/2 ) //Apply the effector
set_screen( $prev_screen ) //Switch back to the OpenGL screen
update_gl_data( temp_img ) //Update temp_img - copy modified pixels to GPU memory
pixi( temp_img ) //Show temp_img
But the effector() remains on the CPU side anyway, so it will work as slowly as in non-OpenGL mode.
thank you! i modified this to use the demo_xsize and demo_ysize variables (it misbehaves if i use the window variables)

and i don't mind the effector not being any faster, it's controlled by the demo time and goes away after a certain amount of time :D
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
Post Reply