Stencil reflection example.
This commit is contained in:
10
API.md
10
API.md
@@ -10789,6 +10789,16 @@ Set eyes view offsets matrices for stereo rendering
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## OpenGL - Rendering
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> RL.glClear( int mask )
|
||||||
|
|
||||||
|
Clear buffers to preset values
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## OpenGL - Frame Buffers
|
## OpenGL - Frame Buffers
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -7588,6 +7588,13 @@ function RL.rlSetMatrixProjectionStereo( right, left ) end
|
|||||||
---@return any RL.rlSetMatrixViewOffsetStereo
|
---@return any RL.rlSetMatrixViewOffsetStereo
|
||||||
function RL.rlSetMatrixViewOffsetStereo( right, left ) end
|
function RL.rlSetMatrixViewOffsetStereo( right, left ) end
|
||||||
|
|
||||||
|
-- OpenGL - Rendering
|
||||||
|
|
||||||
|
---Clear buffers to preset values
|
||||||
|
---@param mask integer
|
||||||
|
---@return any RL.glClear
|
||||||
|
function RL.glClear( mask ) end
|
||||||
|
|
||||||
-- OpenGL - Frame Buffers
|
-- OpenGL - Frame Buffers
|
||||||
|
|
||||||
---Copy a block of pixels from one framebuffer object to another.
|
---Copy a block of pixels from one framebuffer object to another.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ DETAILED CHANGES:
|
|||||||
- ADDED: Raygui lib tree view.
|
- ADDED: Raygui lib tree view.
|
||||||
- ADDED: Raygui lib examples file browser.
|
- ADDED: Raygui lib examples file browser.
|
||||||
- CHANGE: Position argument added for GetCodepoint, GetCodepointNext and GetCodepointPrevious.
|
- CHANGE: Position argument added for GetCodepoint, GetCodepointNext and GetCodepointPrevious.
|
||||||
- ADDED glEnable, glDisable and glGetString.
|
- ADDED glEnable, glDisable, glGetString and glClear.
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0
|
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||||
|
|||||||
67
examples/stencil_reflection/main.lua
Normal file
67
examples/stencil_reflection/main.lua
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
-- Based on JeffM2501 stencil_reflection example for Raylib https://github.com/raylib-extras/examples-cpp/blob/main/stencil_reflection/main.cpp
|
||||||
|
|
||||||
|
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
|
||||||
|
|
||||||
|
Vec2 = require( "vector2" )
|
||||||
|
Cam3D = require( "camera3d" )
|
||||||
|
|
||||||
|
local monitor = 0
|
||||||
|
local camera = Cam3D:new()
|
||||||
|
|
||||||
|
function RL.init()
|
||||||
|
RL.SetWindowTitle( "Stencil Reflection" )
|
||||||
|
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||||
|
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
|
||||||
|
|
||||||
|
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) )
|
||||||
|
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) )
|
||||||
|
local winSize = Vec2:new( RL.GetScreenSize() )
|
||||||
|
|
||||||
|
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
|
||||||
|
|
||||||
|
camera:setPosition( { 0, 2, 6 } )
|
||||||
|
camera:setTarget( { 0, 0, 0 } )
|
||||||
|
camera:setUp( { 0, 1, 0 } )
|
||||||
|
camera.mode = camera.MODES.ORBITAL
|
||||||
|
end
|
||||||
|
|
||||||
|
function RL.update( delta )
|
||||||
|
camera:update( delta )
|
||||||
|
|
||||||
|
if RL.IsKeyPressed( RL.KEY_SPACE ) then
|
||||||
|
if camera.mode == camera.MODES.FREE then
|
||||||
|
camera.mode = camera.MODES.FIRST_PERSON
|
||||||
|
else
|
||||||
|
camera.mode = camera.MODES.FREE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function RL.draw()
|
||||||
|
RL.ClearBackground( RL.BLACK )
|
||||||
|
|
||||||
|
camera:beginMode3D()
|
||||||
|
RL.DrawCube( { 0, 0.5, 0 }, { 1, 1, 1 }, RL.DARKGREEN )
|
||||||
|
RL.rlDrawRenderBatchActive()
|
||||||
|
|
||||||
|
RL.glEnable( RL.GL_STENCIL_TEST )
|
||||||
|
|
||||||
|
RL.glStencilFunc( RL.GL_ALWAYS, 1, 0xFF ) -- Set any stencil to 1
|
||||||
|
RL.glStencilOp( RL.GL_KEEP, RL.GL_KEEP, RL.GL_REPLACE )
|
||||||
|
RL.glStencilMask( 0xFF ) -- Write to stencil buffer.
|
||||||
|
RL.rlDisableDepthMask()
|
||||||
|
RL.glClear( RL.GL_STENCIL_BUFFER_BIT ) -- Clear stencil buffer (0 by default)
|
||||||
|
|
||||||
|
RL.DrawPlane( { 0, 0, 0 }, { 3, 3 }, RL.DARKBLUE )
|
||||||
|
RL.rlDrawRenderBatchActive()
|
||||||
|
|
||||||
|
RL.glStencilFunc( RL.GL_EQUAL, 1, 0xFF ) -- Pass test if stencil value is 1.
|
||||||
|
RL.glStencilMask( 0x00 ) -- Don't write anything to stencil buffer.
|
||||||
|
RL.rlEnableDepthMask()
|
||||||
|
|
||||||
|
RL.DrawCube( { 0, -0.5, 0 }, { 1, 1, 1 }, RL.ColorAlpha( RL.DARKGREEN, 0.5 ) )
|
||||||
|
RL.rlDrawRenderBatchActive()
|
||||||
|
|
||||||
|
RL.glDisable( RL.GL_STENCIL_TEST )
|
||||||
|
camera:endMode3D()
|
||||||
|
end
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/* Rendering. */
|
||||||
|
int lglClear( lua_State* L );
|
||||||
/* Frame Buffers. */
|
/* Frame Buffers. */
|
||||||
int lglBlitFramebuffer( lua_State* L );
|
int lglBlitFramebuffer( lua_State* L );
|
||||||
/* State Management. */
|
/* State Management. */
|
||||||
|
|||||||
17
src/gl.c
17
src/gl.c
@@ -4,6 +4,23 @@
|
|||||||
#include "textures.h"
|
#include "textures.h"
|
||||||
#include "lgl.h"
|
#include "lgl.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
## OpenGL - Rendering
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
> RL.glClear( int mask )
|
||||||
|
|
||||||
|
Clear buffers to preset values
|
||||||
|
*/
|
||||||
|
int lglClear( lua_State* L ) {
|
||||||
|
unsigned int mask = luaL_checkinteger( L, 1 );
|
||||||
|
|
||||||
|
glClear( mask );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
## OpenGL - Frame Buffers
|
## OpenGL - Frame Buffers
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2298,6 +2298,8 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "rlSetMatrixViewOffsetStereo", lrlglSetMatrixViewOffsetStereo );
|
assingGlobalFunction( "rlSetMatrixViewOffsetStereo", lrlglSetMatrixViewOffsetStereo );
|
||||||
|
|
||||||
/* OpenGL */
|
/* OpenGL */
|
||||||
|
/* Rendering. */
|
||||||
|
assingGlobalFunction( "glClear", lglClear );
|
||||||
/* Frame Buffers. */
|
/* Frame Buffers. */
|
||||||
assingGlobalFunction( "glBlitFramebuffer", lglBlitFramebuffer );
|
assingGlobalFunction( "glBlitFramebuffer", lglBlitFramebuffer );
|
||||||
/* State Management. */
|
/* State Management. */
|
||||||
|
|||||||
Reference in New Issue
Block a user