diff options
| author | jussi | 2025-02-10 21:58:45 +0200 |
|---|---|---|
| committer | jussi | 2025-02-10 21:58:45 +0200 |
| commit | a1bc76d7fd7c1088bdedf4d901d1800456f653bc (patch) | |
| tree | 42c4bffdd8c2c1bed56489b80bac9faa02fc0026 /examples | |
| parent | 721ef97f16d7b936a3393679327bb23f5d3eb537 (diff) | |
| download | reilua-enhanced-a1bc76d7fd7c1088bdedf4d901d1800456f653bc.tar.gz reilua-enhanced-a1bc76d7fd7c1088bdedf4d901d1800456f653bc.tar.bz2 reilua-enhanced-a1bc76d7fd7c1088bdedf4d901d1800456f653bc.zip | |
Blendmode example refine.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/blend_modes/main.lua | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/examples/blend_modes/main.lua b/examples/blend_modes/main.lua index 3a99147..75e90d2 100644 --- a/examples/blend_modes/main.lua +++ b/examples/blend_modes/main.lua @@ -1,6 +1,7 @@ package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" Vector2 = require( "vector2" ) +Rect = require( "rectangle" ) local monitor = 0 local winSize = Vector2:new( 1920, 1080 ) @@ -14,6 +15,10 @@ local buttonSize = Vector2:new( 20, 20 ) local fontSize = 20 local textTint = RL.BLACK +local guiRect = Rect:new( 0, 0, 550, 210 ) +local lightPos = Vector2:new() +local lightPos2 = Vector2:new() + local framebuffer = nil local blendMode = { @@ -93,9 +98,22 @@ function RL.init() lightTexSize:setT( RL.GetTextureSize( lightTex ) ) framebuffer = RL.LoadRenderTexture( winSize ) + + lightPos:setV( winSize:scale( 0.5 ) - lightTexSize:scale( 0.5 ) ) + lightPos2:setV( winSize:scale( 0.5 ) - lightTexSize:scale( 0.5 ) ) end function RL.update( delta ) + local mousePos = Vector2:newT( RL.GetMousePosition() ) + + if not RL.CheckCollisionPointRec( mousePos, guiRect ) then + if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) then + lightPos:setV( mousePos - lightTexSize:scale( 0.5 ) ) + end + if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_RIGHT ) then + lightPos2:setV( mousePos - lightTexSize:scale( 0.5 ) ) + end + end end local function drawControl( pos, t, name ) @@ -130,11 +148,12 @@ local function drawControls() drawControl( pos, blendFactor, "srcAlpha" ) drawControl( pos, blendFactor, "dstAlpha" ) drawControl( pos, blendFunction, "eqAlpha" ) + + pos.y = pos.y + 8 + RL.DrawText( "Set texture positions with mouse right and left.", pos, 20, RL.BLACK ) end function RL.draw() - local mousePos = Vector2:newT( RL.GetMousePosition() ) - RL.ClearBackground( RL.BLACK ) if framebuffer then @@ -161,7 +180,8 @@ function RL.draw() blendFunction.options[ blendFunction.eqAlpha ].value ) RL.BeginBlendMode( blendMode.options[ blendMode.mode ].value ) - RL.DrawTexture( lightTex, mousePos - lightTexSize:scale( 0.5 ), RL.WHITE ) + RL.DrawTexture( lightTex, lightPos, RL.RED ) + RL.DrawTexture( lightTex, lightPos2, RL.BLUE ) RL.EndBlendMode() RL.EndTextureMode() end @@ -173,7 +193,6 @@ function RL.draw() 0.0, RL.WHITE ) - RL.DrawTexturePro( RL.GetRenderTextureTexture( framebuffer ), { 0, 0, winSize.x, -winSize.y }, @@ -182,6 +201,6 @@ function RL.draw() 0.0, RL.WHITE ) - RL.DrawRectangle( { 0, 0, 550, 180 }, { 255, 255, 255, 200 } ) + RL.DrawRectangle( guiRect, { 255, 255, 255, 200 } ) drawControls() end |
