diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/gui/main.lua | 6 | ||||
| -rw-r--r-- | examples/rlgl/main.lua | 62 |
2 files changed, 49 insertions, 19 deletions
diff --git a/examples/gui/main.lua b/examples/gui/main.lua index 25c4ed6..18d8b41 100644 --- a/examples/gui/main.lua +++ b/examples/gui/main.lua @@ -36,10 +36,16 @@ end function RL.draw() RL.ClearBackground( { 50, 20, 75 } ) + -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 ) + if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( 113, "Exit" ) ) then RL.CloseWindow() end + -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 ) + RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( 113, "Kissa" ) ) + -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 ) + if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then windowOpen = false end diff --git a/examples/rlgl/main.lua b/examples/rlgl/main.lua index 7792f75..ac6bf53 100644 --- a/examples/rlgl/main.lua +++ b/examples/rlgl/main.lua @@ -2,8 +2,6 @@ local monitor = 0 local texture = -1 -local vaoId = -1 -local vboId = -1 local triSize = 32.0 local vertices = { 0.0, 0.0, 0.0, @@ -16,6 +14,39 @@ local colors = { RL.BLUE, RL.BLUE, RL.BLUE } +local VBO_VERTEX_POS = 0 +local VBO_COLOR_POS = 1 + +local mesh = { + vaoId = -1, + vboIds = { + vertices = -1, + colors = -1, + } +} + +function uploadMesh() + mesh.vaoId = RL.rlLoadVertexArray() + + RL.rlEnableVertexArray( mesh.vaoId ) + + -- Vertices. + mesh.vboIds.vertices = RL.rlLoadVertexBuffer( vertices, RL.RL_FLOAT, false ) + RL.rlSetVertexAttribute( VBO_VERTEX_POS, 3, RL.RL_FLOAT, false, 0, 0 ) + RL.rlEnableVertexAttribute( VBO_VERTEX_POS ) + -- Colors. + mesh.vboIds.colors = RL.rlLoadVertexBuffer( vertices, RL.RL_UNSIGNED_BYTE, false ) + RL.rlSetVertexAttribute( VBO_COLOR_POS, 4, RL.RL_UNSIGNED_BYTE, false, 0, 0 ) + RL.rlEnableVertexAttribute( VBO_COLOR_POS ) + + RL.rlDisableVertexArray() + + print( "Mesh:" ) + print( "\tvaoId: "..mesh.vaoId ) + print( "\tvboIds.vertices: "..mesh.vboIds.vertices ) + print( "\tvboIds.colors: "..mesh.vboIds.colors ) +end + function RL.init() local mPos = RL.GetMonitorPosition( monitor ) local mSize = RL.GetMonitorSize( monitor ) @@ -25,32 +56,25 @@ function RL.init() RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - vaoId = RL.rlLoadVertexArray() - - RL.rlEnableVertexArray( vaoId ) - -- vboId = RL.rlLoadVertexBuffer( vertexBuffer, RL.RL_UNSIGNED_BYTE, false ) - vboId = RL.rlLoadVertexBuffer( vertices, RL.RL_FLOAT, false ) - RL.rlSetVertexAttribute( 0, 3, RL.RL_FLOAT, false, 0, 0 ) - RL.rlEnableVertexAttribute( 0 ) - - RL.rlDisableVertexArray() - - -- RL.DrawMesh( ) + uploadMesh() +end - -- print( "vaoId", vaoId ) - -- print( "vboId", vboId ) +function drawMesh() end function RL.draw() RL.ClearBackground( { 100, 150, 100 } ) end +-- You need to manually free resources. function RL.exit() - if 0 <= vaoId then - RL.rlUnloadVertexArray( vaoId ) + if 0 <= mesh.vaoId then + RL.rlUnloadVertexArray( mesh.vaoId ) end - if 0 <= vboId then - RL.rlUnloadVertexBuffer( vboId ) + for _, vboId in pairs( mesh.vboIds ) do + if 0 <= vboId then + RL.rlUnloadVertexBuffer( vboId ) + end end end
\ No newline at end of file |
