Blendmode example refine.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
|
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
|
||||||
|
|
||||||
Vector2 = require( "vector2" )
|
Vector2 = require( "vector2" )
|
||||||
|
Rect = require( "rectangle" )
|
||||||
|
|
||||||
local monitor = 0
|
local monitor = 0
|
||||||
local winSize = Vector2:new( 1920, 1080 )
|
local winSize = Vector2:new( 1920, 1080 )
|
||||||
@@ -14,6 +15,10 @@ local buttonSize = Vector2:new( 20, 20 )
|
|||||||
local fontSize = 20
|
local fontSize = 20
|
||||||
local textTint = RL.BLACK
|
local textTint = RL.BLACK
|
||||||
|
|
||||||
|
local guiRect = Rect:new( 0, 0, 550, 210 )
|
||||||
|
local lightPos = Vector2:new()
|
||||||
|
local lightPos2 = Vector2:new()
|
||||||
|
|
||||||
local framebuffer = nil
|
local framebuffer = nil
|
||||||
|
|
||||||
local blendMode = {
|
local blendMode = {
|
||||||
@@ -93,9 +98,22 @@ function RL.init()
|
|||||||
lightTexSize:setT( RL.GetTextureSize( lightTex ) )
|
lightTexSize:setT( RL.GetTextureSize( lightTex ) )
|
||||||
|
|
||||||
framebuffer = RL.LoadRenderTexture( winSize )
|
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
|
end
|
||||||
|
|
||||||
function RL.update( delta )
|
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
|
end
|
||||||
|
|
||||||
local function drawControl( pos, t, name )
|
local function drawControl( pos, t, name )
|
||||||
@@ -130,11 +148,12 @@ local function drawControls()
|
|||||||
drawControl( pos, blendFactor, "srcAlpha" )
|
drawControl( pos, blendFactor, "srcAlpha" )
|
||||||
drawControl( pos, blendFactor, "dstAlpha" )
|
drawControl( pos, blendFactor, "dstAlpha" )
|
||||||
drawControl( pos, blendFunction, "eqAlpha" )
|
drawControl( pos, blendFunction, "eqAlpha" )
|
||||||
|
|
||||||
|
pos.y = pos.y + 8
|
||||||
|
RL.DrawText( "Set texture positions with mouse right and left.", pos, 20, RL.BLACK )
|
||||||
end
|
end
|
||||||
|
|
||||||
function RL.draw()
|
function RL.draw()
|
||||||
local mousePos = Vector2:newT( RL.GetMousePosition() )
|
|
||||||
|
|
||||||
RL.ClearBackground( RL.BLACK )
|
RL.ClearBackground( RL.BLACK )
|
||||||
|
|
||||||
if framebuffer then
|
if framebuffer then
|
||||||
@@ -161,7 +180,8 @@ function RL.draw()
|
|||||||
blendFunction.options[ blendFunction.eqAlpha ].value
|
blendFunction.options[ blendFunction.eqAlpha ].value
|
||||||
)
|
)
|
||||||
RL.BeginBlendMode( blendMode.options[ blendMode.mode ].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.EndBlendMode()
|
||||||
RL.EndTextureMode()
|
RL.EndTextureMode()
|
||||||
end
|
end
|
||||||
@@ -173,7 +193,6 @@ function RL.draw()
|
|||||||
0.0,
|
0.0,
|
||||||
RL.WHITE
|
RL.WHITE
|
||||||
)
|
)
|
||||||
|
|
||||||
RL.DrawTexturePro(
|
RL.DrawTexturePro(
|
||||||
RL.GetRenderTextureTexture( framebuffer ),
|
RL.GetRenderTextureTexture( framebuffer ),
|
||||||
{ 0, 0, winSize.x, -winSize.y },
|
{ 0, 0, winSize.x, -winSize.y },
|
||||||
@@ -182,6 +201,6 @@ function RL.draw()
|
|||||||
0.0,
|
0.0,
|
||||||
RL.WHITE
|
RL.WHITE
|
||||||
)
|
)
|
||||||
RL.DrawRectangle( { 0, 0, 550, 180 }, { 255, 255, 255, 200 } )
|
RL.DrawRectangle( guiRect, { 255, 255, 255, 200 } )
|
||||||
drawControls()
|
drawControls()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user