summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2025-02-06 23:04:20 +0200
committerjussi2025-02-06 23:04:20 +0200
commit721ef97f16d7b936a3393679327bb23f5d3eb537 (patch)
tree30386757a084d853ae6ec0e2f38215184a6de58a
parent38d41e245782e3dde02dc7717737af09da31ce93 (diff)
downloadreilua-enhanced-721ef97f16d7b936a3393679327bb23f5d3eb537.tar.gz
reilua-enhanced-721ef97f16d7b936a3393679327bb23f5d3eb537.tar.bz2
reilua-enhanced-721ef97f16d7b936a3393679327bb23f5d3eb537.zip
Blend modes example.
-rw-r--r--LICENSE2
-rw-r--r--changelog1
-rw-r--r--devnotes1
-rw-r--r--examples/blend_modes/main.lua187
-rw-r--r--src/models.c9
5 files changed, 192 insertions, 8 deletions
diff --git a/LICENSE b/LICENSE
index 01b385f..c902b85 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2022-2024 Jussi Viitala
+Copyright (c) 2022-2025 Jussi Viitala
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/changelog b/changelog
index 2ea7814..c20be91 100644
--- a/changelog
+++ b/changelog
@@ -37,6 +37,7 @@ DETAILED CHANGES:
- CHANGE: SetBufferData takes table of values.
- ADDED: Texture atlas repeat example.
- CHANGE: UpdateTexture and UpdateTextureRec now take pixel data as Buffer.
+ - ADDED: Blend modes example.
------------------------------------------------------------------------
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
diff --git a/devnotes b/devnotes
index b824569..3aadf64 100644
--- a/devnotes
+++ b/devnotes
@@ -21,7 +21,6 @@ Backlog {
* Textures
* Try making atlas packer with stbrp_pack_rects.
* Examples
- * Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
* Platformer example physics update for true framerate independence.
* Android support
}
diff --git a/examples/blend_modes/main.lua b/examples/blend_modes/main.lua
new file mode 100644
index 0000000..3a99147
--- /dev/null
+++ b/examples/blend_modes/main.lua
@@ -0,0 +1,187 @@
+package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
+
+Vector2 = require( "vector2" )
+
+local monitor = 0
+local winSize = Vector2:new( 1920, 1080 )
+
+local catTex = nil
+local tileTex = nil
+local lightTex = nil
+local lightTexSize = Vector2:new()
+
+local buttonSize = Vector2:new( 20, 20 )
+local fontSize = 20
+local textTint = RL.BLACK
+
+local framebuffer = nil
+
+local blendMode = {
+ mode = 1,
+ options = {
+ { name = "BLEND_ALPHA", value = RL.BLEND_ALPHA },
+ { name = "BLEND_ADDITIVE", value = RL.BLEND_ADDITIVE },
+ { name = "BLEND_MULTIPLIED", value = RL.BLEND_MULTIPLIED },
+ { name = "BLEND_ADD_COLORS", value = RL.BLEND_ADD_COLORS },
+ { name = "BLEND_SUBTRACT_COLORS", value = RL.BLEND_SUBTRACT_COLORS },
+ { name = "BLEND_ALPHA_PREMULTIPLY", value = RL.BLEND_ALPHA_PREMULTIPLY },
+ { name = "BLEND_CUSTOM", value = RL.BLEND_CUSTOM },
+ { name = "BLEND_CUSTOM_SEPARATE", value = RL.BLEND_CUSTOM_SEPARATE },
+ }
+}
+local blendFactor = {
+ srcRGB = 1,
+ dstRGB = 1,
+ srcAlpha = 1,
+ dstAlpha = 1,
+ options = {
+ { name = "RL_ZERO", value = RL.RL_ZERO },
+ { name = "RL_ONE", value = RL.RL_ONE },
+ { name = "RL_SRC_COLOR", value = RL.RL_SRC_COLOR },
+ { name = "RL_ONE_MINUS_SRC_COLOR", value = RL.RL_ONE_MINUS_SRC_COLOR },
+ { name = "RL_SRC_ALPHA", value = RL.RL_SRC_ALPHA },
+ { name = "RL_ONE_MINUS_SRC_ALPHA", value = RL.RL_ONE_MINUS_SRC_ALPHA },
+ { name = "RL_DST_ALPHA", value = RL.RL_DST_ALPHA },
+ { name = "RL_ONE_MINUS_DST_ALPHA", value = RL.RL_ONE_MINUS_DST_ALPHA },
+ { name = "RL_DST_COLOR", value = RL.RL_DST_COLOR },
+ { name = "RL_ONE_MINUS_DST_COLOR", value = RL.RL_ONE_MINUS_DST_COLOR },
+ { name = "RL_SRC_ALPHA_SATURATE", value = RL.RL_SRC_ALPHA_SATURATE },
+ { name = "RL_CONSTANT_COLOR", value = RL.RL_CONSTANT_COLOR },
+ { name = "RL_ONE_MINUS_CONSTANT_COLOR", value = RL.RL_ONE_MINUS_CONSTANT_COLOR },
+ { name = "RL_CONSTANT_ALPHA", value = RL.RL_CONSTANT_ALPHA },
+ { name = "RL_ONE_MINUS_CONSTANT_ALPHA", value = RL.RL_ONE_MINUS_CONSTANT_ALPHA },
+ }
+}
+local blendFunction = {
+ eqRGB = 1,
+ eqAlpha = 1,
+ options = {
+ { name = "RL_FUNC_ADD", value = RL.RL_FUNC_ADD },
+ { name = "RL_MIN", value = RL.RL_MIN },
+ { name = "RL_MAX", value = RL.RL_MAX },
+ { name = "RL_FUNC_SUBTRACT", value = RL.RL_FUNC_SUBTRACT },
+ { name = "RL_FUNC_REVERSE_SUBTRACT", value = RL.RL_FUNC_REVERSE_SUBTRACT },
+ { name = "RL_BLEND_EQUATION", value = RL.RL_BLEND_EQUATION },
+ { name = "RL_BLEND_EQUATION_RGB", value = RL.RL_BLEND_EQUATION_RGB },
+ { name = "RL_BLEND_EQUATION_ALPHA", value = RL.RL_BLEND_EQUATION_ALPHA },
+ { name = "RL_BLEND_DST_RGB", value = RL.RL_BLEND_DST_RGB },
+ { name = "RL_BLEND_SRC_RGB", value = RL.RL_BLEND_SRC_RGB },
+ { name = "RL_BLEND_DST_ALPHA", value = RL.RL_BLEND_DST_ALPHA },
+ { name = "RL_BLEND_SRC_ALPHA", value = RL.RL_BLEND_SRC_ALPHA },
+ { name = "RL_BLEND_COLOR", value = RL.RL_BLEND_COLOR },
+ }
+}
+
+function RL.init()
+ RL.SetWindowTitle( "Blend modes" )
+ RL.SetWindowState( RL.FLAG_VSYNC_HINT )
+ RL.SetWindowSize( winSize )
+
+ local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
+ local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
+ RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } )
+
+ local path = RL.GetBasePath().."../resources/images/"
+
+ catTex = RL.LoadTexture( path.."cat.png" )
+ RL.SetTextureWrap( catTex, RL.TEXTURE_WRAP_REPEAT )
+
+ tileTex = RL.LoadTexture( path.."tile.png" )
+ RL.SetTextureWrap( tileTex, RL.TEXTURE_WRAP_REPEAT )
+
+ lightTex = RL.LoadTexture( path.."light.png" )
+ lightTexSize:setT( RL.GetTextureSize( lightTex ) )
+
+ framebuffer = RL.LoadRenderTexture( winSize )
+end
+
+function RL.update( delta )
+end
+
+local function drawControl( pos, t, name )
+ if RL.GuiButton( { pos.x, pos.y, buttonSize.x, buttonSize.y }, RL.GuiIconText( RL.ICON_ARROW_LEFT, "" ) ) == 1 then
+ t[ name ] = 1 < t[ name ] and t[ name ] - 1 or #t.options
+ end
+ pos.x = pos.x + buttonSize.x + 2
+
+ if RL.GuiButton( { pos.x, pos.y, buttonSize.x, buttonSize.y }, RL.GuiIconText( RL.ICON_ARROW_RIGHT, "" ) ) == 1 then
+ t[ name ] = t[ name ] < #t.options and t[ name ] + 1 or 1
+ end
+ pos.x = pos.x + buttonSize.x + 2
+
+ RL.DrawText( name..": "..t.options[ t[ name ] ].name, pos, fontSize, textTint )
+
+ pos.x = 2
+ pos.y = pos.y + 2 + buttonSize.y
+end
+
+local function drawControls()
+ local pos = Vector2:new( 2 )
+
+ -- Blend mode.
+ drawControl( pos, blendMode, "mode" )
+ -- Blend RPG.
+ pos.y = pos.y + 8
+ drawControl( pos, blendFactor, "srcRGB" )
+ drawControl( pos, blendFactor, "dstRGB" )
+ drawControl( pos, blendFunction, "eqRGB" )
+ -- Blend Alpha.
+ pos.y = pos.y + 8
+ drawControl( pos, blendFactor, "srcAlpha" )
+ drawControl( pos, blendFactor, "dstAlpha" )
+ drawControl( pos, blendFunction, "eqAlpha" )
+end
+
+function RL.draw()
+ local mousePos = Vector2:newT( RL.GetMousePosition() )
+
+ RL.ClearBackground( RL.BLACK )
+
+ if framebuffer then
+ RL.BeginTextureMode( framebuffer )
+ RL.ClearBackground( RL.BLACK )
+ RL.DrawTexturePro( catTex,
+ { 0, 0, winSize.x, winSize.y },
+ { 0, 0, winSize.x, winSize.y },
+ { 0, 0 },
+ 0.0,
+ RL.WHITE
+ )
+ RL.rlSetBlendFactors(
+ blendFactor.options[ blendFactor.srcRGB ].value,
+ blendFactor.options[ blendFactor.dstRGB ].value,
+ blendFunction.options[ blendFunction.eqRGB ].value
+ )
+ RL.rlSetBlendFactorsSeparate(
+ blendFactor.options[ blendFactor.srcRGB ].value,
+ blendFactor.options[ blendFactor.dstRGB ].value,
+ blendFactor.options[ blendFactor.srcAlpha ].value,
+ blendFactor.options[ blendFactor.dstAlpha ].value,
+ blendFunction.options[ blendFunction.eqRGB ].value,
+ blendFunction.options[ blendFunction.eqAlpha ].value
+ )
+ RL.BeginBlendMode( blendMode.options[ blendMode.mode ].value )
+ RL.DrawTexture( lightTex, mousePos - lightTexSize:scale( 0.5 ), RL.WHITE )
+ RL.EndBlendMode()
+ RL.EndTextureMode()
+ end
+
+ RL.DrawTexturePro( tileTex,
+ { 0, 0, winSize.x, winSize.y },
+ { 0, 0, winSize.x, winSize.y },
+ { 0, 0 },
+ 0.0,
+ RL.WHITE
+ )
+
+ RL.DrawTexturePro(
+ RL.GetRenderTextureTexture( framebuffer ),
+ { 0, 0, winSize.x, -winSize.y },
+ { 0, 0, winSize.x, winSize.y },
+ { 0, 0 },
+ 0.0,
+ RL.WHITE
+ )
+ RL.DrawRectangle( { 0, 0, 550, 180 }, { 255, 255, 255, 200 } )
+ drawControls()
+end
diff --git a/src/models.c b/src/models.c
index 45bb825..cd58e4e 100644
--- a/src/models.c
+++ b/src/models.c
@@ -354,8 +354,6 @@ int lmodelDrawQuad3DTexture( lua_State* L ) {
lua_pop( L, 1 );
}
- //TODO Normals. maybe something like Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA)));
-
/* Draw. */
rlCheckRenderBatchLimit( 4 );
rlSetTexture( texture->id );
@@ -2531,12 +2529,11 @@ int lmodelsGetRayBoxCells( lua_State* L ) {
Vector3 cellSize = uluaGetVector3( L, 3 );
/* To avoid possible div by 0 later. */
- ray.direction.x == 0.0f ? EPSILON : ray.direction.x;
- ray.direction.y == 0.0f ? EPSILON : ray.direction.y;
- ray.direction.z == 0.0f ? EPSILON : ray.direction.z;
+ ray.direction.x = ray.direction.x == 0.0f ? EPSILON : ray.direction.x;
+ ray.direction.y = ray.direction.y == 0.0f ? EPSILON : ray.direction.y;
+ ray.direction.z = ray.direction.z == 0.0f ? EPSILON : ray.direction.z;
Vector3 boxSize = Vector3Subtract( box.max, box.min );
- // Vector3 boxSizeCells = Vector3Ceil( Vector3Divide( boxSize, cellSize ) );
Vector3 cellPos = { -1.0f, -1.0f, -1.0f };
Vector3 localRayPos = { 0.0f, 0.0f, 0.0f };