diff options
| author | jussi | 2023-04-06 12:31:37 +0300 |
|---|---|---|
| committer | jussi | 2023-04-06 12:31:37 +0300 |
| commit | 2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a (patch) | |
| tree | 825775577403d9341045571adb266173513c4bbd /examples | |
| parent | 198a74c0aa27389c062c47bc29187c58a9d6c4a1 (diff) | |
| download | reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.tar.gz reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.tar.bz2 reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.zip | |
All global variables and functions are not in global RL table. doc_parser creates also ReiLua_API.lua.
Diffstat (limited to 'examples')
28 files changed, 847 insertions, 850 deletions
diff --git a/examples/2D_camera/main.lua b/examples/2D_camera/main.lua index b23d606..c47ba18 100644 --- a/examples/2D_camera/main.lua +++ b/examples/2D_camera/main.lua @@ -7,62 +7,62 @@ local cameraSpeed = 100.0 local cameraRotSpeed = 100.0 local cameraZoomSpeed = 10.0 -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowTitle( "Camera 2D" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowTitle( "Camera 2D" ) - tileTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" ) - camera = RL_CreateCamera2D() - RL_SetCamera2DOffset( camera, { winSize[1] / 2, winSize[2] / 2 } ) + tileTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) + camera = RL.CreateCamera2D() + RL.SetCamera2DOffset( camera, { winSize[1] / 2, winSize[2] / 2 } ) end -function process( delta ) +function RL.process( delta ) -- Move. - if RL_IsKeyDown( KEY_RIGHT ) then + if RL.IsKeyDown( RL.KEY_RIGHT ) then cameraPos[1] = cameraPos[1] + cameraSpeed * delta - elseif RL_IsKeyDown( KEY_LEFT ) then + elseif RL.IsKeyDown( RL.KEY_LEFT ) then cameraPos[1] = cameraPos[1] - cameraSpeed * delta end - if RL_IsKeyDown( KEY_DOWN ) then + if RL.IsKeyDown( RL.KEY_DOWN ) then cameraPos[2] = cameraPos[2] + cameraSpeed * delta - elseif RL_IsKeyDown( KEY_UP ) then + elseif RL.IsKeyDown( RL.KEY_UP ) then cameraPos[2] = cameraPos[2] - cameraSpeed * delta end -- Rotate. - if RL_IsKeyDown( string.byte( "E" ) ) then -- Or RL_IsKeyDown( KEY_E ) + if RL.IsKeyDown( string.byte( "E" ) ) then -- Or RL.IsKeyDown( KEY_E ) cameraRot = cameraRot + cameraRotSpeed * delta - elseif RL_IsKeyDown( string.byte( "Q" ) ) then + elseif RL.IsKeyDown( string.byte( "Q" ) ) then cameraRot = cameraRot - cameraRotSpeed * delta end -- Zoom. - if RL_IsKeyDown( string.byte( "R" ) ) then + if RL.IsKeyDown( string.byte( "R" ) ) then cameraZoom = cameraZoom + cameraZoomSpeed * delta - elseif RL_IsKeyDown( string.byte( "F" ) ) then + elseif RL.IsKeyDown( string.byte( "F" ) ) then cameraZoom = cameraZoom - cameraZoomSpeed * delta end end -function draw() - RL_ClearBackground( RAYWHITE ) - RL_SetCamera2DTarget( camera, cameraPos ) - RL_SetCamera2DRotation( camera, cameraRot ) - RL_SetCamera2DZoom( camera, cameraZoom ) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) + RL.SetCamera2DTarget( camera, cameraPos ) + RL.SetCamera2DRotation( camera, cameraRot ) + RL.SetCamera2DZoom( camera, cameraZoom ) - RL_BeginMode2D( camera ) + RL.BeginMode2D( camera ) -- Draw wall. for y = 0, 4 do for x = 0, 6 do - RL_DrawTextureRec( tileTexture, { 0, 0, 32, 32 }, { x * 32, y * 32 }, WHITE ) + RL.DrawTextureRec( tileTexture, { 0, 0, 32, 32 }, { x * 32, y * 32 }, RL.WHITE ) end end -- Draw hero. - RL_DrawTextureRec( tileTexture, { 3 * 32, 0, 32, 32 }, { cameraPos[1] - 16, cameraPos[2] - 16 }, WHITE ) - RL_EndMode2D() + RL.DrawTextureRec( tileTexture, { 3 * 32, 0, 32, 32 }, { cameraPos[1] - 16, cameraPos[2] - 16 }, RL.WHITE ) + RL.EndMode2D() end diff --git a/examples/ReiLuaGui_examples/calculator.lua b/examples/ReiLuaGui_examples/calculator.lua index 6f2023b..964763e 100644 --- a/examples/ReiLuaGui_examples/calculator.lua +++ b/examples/ReiLuaGui_examples/calculator.lua @@ -20,7 +20,7 @@ function Calculator:new( pos ) padding = 10, onClicked = function() object:set2Top() - object.dragPos = Vec2:new( RL_GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) + object.dragPos = Vec2:new( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) Gui.heldCallback = function() object:drag() end end, } ) @@ -30,7 +30,7 @@ function Calculator:new( pos ) texture = bgrTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( LIGHTGRAY ), + color = Color:new( RL.LIGHTGRAY ), } ) ) object.handle:add( Gui.texture:new( { @@ -38,8 +38,8 @@ function Calculator:new( pos ) texture = borderTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( LIGHTGRAY ), - nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + color = Color:new( RL.LIGHTGRAY ), + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, } ) ) object.handle:add( Gui.text:new( { text = "Calculator", fontSize = 20, VAling = Gui.ALING.CENTER } ) ) @@ -51,8 +51,8 @@ function Calculator:new( pos ) onClicked = function() object:setVisible( false ) end, - onMouseOver = function( self ) self.items[1].color = Color:new( WHITE ) end, - notMouseOver = function( self ) self.items[1].color = Color:new( BLACK ) end, + onMouseOver = function( self ) self.items[1].color = Color:new( RL.WHITE ) end, + notMouseOver = function( self ) self.items[1].color = Color:new( RL.BLACK ) end, } ) object.closeButton:add( Gui.texture:new( { @@ -73,7 +73,7 @@ function Calculator:new( pos ) texture = bgrTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( GRAY ), + color = Color:new( RL.GRAY ), } ) ) object.panel:add( Gui.texture:new( { @@ -81,8 +81,8 @@ function Calculator:new( pos ) texture = borderTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( LIGHTGRAY ), - nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + color = Color:new( RL.LIGHTGRAY ), + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, } ) ) -- Display. @@ -91,13 +91,13 @@ function Calculator:new( pos ) bounds = Rect:new( 0, 0, object.windowRect.width - 16, object.DISPLAY_HIGHT ), padding = 10, drawBounds = true, - color = Color:new( WHITE ) + color = Color:new( RL.WHITE ) } ) object.display:add( Gui.text:new( { text = "", fontSize = 30, VAling = Gui.ALING.CENTER, maxTextLen = 8 } ) ) -- Buttons. - + local buttonStrings = { "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", "C", "=", "+" } object.buttons = {} @@ -108,8 +108,8 @@ function Calculator:new( pos ) table.insert( object.buttons, Gui.element:new( { bounds = Rect:new( 0, 0, 40, 32 ), drawBounds = true, - onMouseOver = function( self ) self.color = Color:new( WHITE ) end, - notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.WHITE ) end, + notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, } ) ) object.buttons[ #object.buttons ].pos = Vec2:new( 8 + x * 46, object.HANDLE_HIGHT + object.DISPLAY_HIGHT + 16 + y * 38 ) @@ -161,7 +161,7 @@ function Calculator:setPosition( pos ) end function Calculator:drag() - local mousePos = Vec2:new( RL_GetMousePosition() ) + local mousePos = Vec2:new( RL.GetMousePosition() ) local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y ) self:setPosition( mousePos - self.dragPos ) @@ -173,13 +173,13 @@ function Calculator:setVisible( visible ) self.closeButton.visible = visible self.closeButton.disabled = not visible - + self.panel.visible = visible self.panel.disabled = not visible self.display.visible = visible self.display.disabled = not visible - + for _, button in ipairs( self.buttons ) do button.visible = visible button.disabled = not visible @@ -188,7 +188,7 @@ end function Calculator:set2Top() self.panel:set2Top() - + for _, button in ipairs( self.buttons ) do button:set2Top() end diff --git a/examples/ReiLuaGui_examples/file_explorer.lua b/examples/ReiLuaGui_examples/file_explorer.lua index 7ead361..72f6117 100644 --- a/examples/ReiLuaGui_examples/file_explorer.lua +++ b/examples/ReiLuaGui_examples/file_explorer.lua @@ -20,7 +20,7 @@ function FileExplorer:new( pos ) padding = 10, onClicked = function() object:set2Top() - object.dragPos = Vec2:new( RL_GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) + object.dragPos = Vec2:new( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) Gui.heldCallback = function() object:drag() end end, } ) @@ -30,16 +30,16 @@ function FileExplorer:new( pos ) texture = bgrTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( LIGHTGRAY ), + color = Color:new( RL.LIGHTGRAY ), } ) ) - + object.handle:add( Gui.texture:new( { bounds = object.handle.bounds:clone(), texture = borderTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( LIGHTGRAY ), - nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + color = Color:new( RL.LIGHTGRAY ), + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, } ) ) object.handle:add( Gui.text:new( { text = "File Explorer", fontSize = 20, VAling = Gui.ALING.CENTER } ) ) @@ -51,8 +51,8 @@ function FileExplorer:new( pos ) onClicked = function() object:setVisible( false ) end, - onMouseOver = function( self ) self.items[1].color = Color:new( WHITE ) end, - notMouseOver = function( self ) self.items[1].color = Color:new( BLACK ) end, + onMouseOver = function( self ) self.items[1].color = Color:new( RL.WHITE ) end, + notMouseOver = function( self ) self.items[1].color = Color:new( RL.BLACK ) end, } ) object.closeButton:add( Gui.texture:new( { @@ -73,7 +73,7 @@ function FileExplorer:new( pos ) texture = bgrTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( GRAY ), + color = Color:new( RL.GRAY ), } ) ) object.panel:add( Gui.texture:new( { @@ -81,8 +81,8 @@ function FileExplorer:new( pos ) texture = borderTexture, HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, - color = Color:new( LIGHTGRAY ), - nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + color = Color:new( RL.LIGHTGRAY ), + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, } ) ) -- Path. @@ -90,7 +90,7 @@ function FileExplorer:new( pos ) object.pathBox = Gui.element:new( { bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 64, object.HANDLE_HIGHT ), drawBounds = true, - color = Color:new( WHITE ), + color = Color:new( RL.WHITE ), -- onClicked = function() Gui.setInputFocus( object.pathBox ) end, -- inputFocus = function() object.pathBox.color = Color:new( BLUE ) end, -- inputUnfocus = function() object.pathBox.color = Color:new( WHITE ) end, @@ -103,8 +103,8 @@ function FileExplorer:new( pos ) object.backButton = Gui.element:new( { bounds = Rect:new( 0, 0, 56, object.HANDLE_HIGHT ), drawBounds = true, - onMouseOver = function( self ) self.color = Color:new( WHITE ) end, - notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.WHITE ) end, + notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, onClicked = function() object:backDir() end, } ) @@ -112,7 +112,7 @@ function FileExplorer:new( pos ) bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ), texture = backTexture, HAling = Gui.ALING.CENTER, - color = Color:new( BLACK ) + color = Color:new( RL.BLACK ) } ) ) -- Files. @@ -130,7 +130,7 @@ function FileExplorer:new( pos ) object.fileName = Gui.element:new( { bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 70, object.HANDLE_HIGHT ), drawBounds = true, - color = Color:new( WHITE ), + color = Color:new( RL.WHITE ), } ) object.fileName:add( Gui.text:new( { text = "", maxTextLen = 32, allowLineBreak = false, VAling = Gui.ALING.CENTER } ) ) @@ -140,18 +140,18 @@ function FileExplorer:new( pos ) object.openButton = Gui.element:new( { bounds = Rect:new( 0, 0, 64, object.HANDLE_HIGHT ), drawBounds = true, - color = Color:new( WHITE ), + color = Color:new( RL.WHITE ), onClicked = function() object:openFile() end, - onMouseOver = function( self ) self.color = Color:new( WHITE ) end, - notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.WHITE ) end, + notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, } ) object.openButton:add( Gui.text:new( { text = "Open", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) -- Variables. - object.path = RL_GetBasePath() - + object.path = RL.GetBasePath() + -- Take last '/' away. if util.utf8Sub( object.path, utf8.len( object.path ), utf8.len( object.path ) ) == "/" then object.path = util.utf8Sub( object.path, 1, utf8.len( object.path ) - 1 ) @@ -189,7 +189,7 @@ function FileExplorer:changeDir( path ) end function FileExplorer:backDir() - self.path = RL_GetPrevDirectoryPath( self.path ) + self.path = RL.GetPrevDirectoryPath( self.path ) self:updatePath() end @@ -197,11 +197,11 @@ end function FileExplorer:fileSelect( file ) self.file = file - self.fileName.items[1]:set( RL_GetFileName( file ) ) + self.fileName.items[1]:set( RL.GetFileName( file ) ) end function FileExplorer:openFile() - print( self.file, RL_GetFileLength( self.file ) ) + print( self.file, RL.GetFileLength( self.file ) ) end function FileExplorer:updateFiles() @@ -216,8 +216,8 @@ function FileExplorer:updateFiles() local files = {} local folders = {} - for _, file in ipairs( RL_LoadDirectoryFiles( self.path ) ) do - if RL_IsPathFile( file ) then + for _, file in ipairs( RL.LoadDirectoryFiles( self.path ) ) do + if RL.IsPathFile( file ) then table.insert( files, file ) else table.insert( folders, file ) @@ -232,7 +232,7 @@ function FileExplorer:updateFiles() end for _, file in ipairs( files ) do - self:addFileToList( file, filesTexture, WHITE, function() self:fileSelect( file ) end ) + self:addFileToList( file, filesTexture, RL.WHITE, function() self:fileSelect( file ) end ) end end @@ -247,7 +247,7 @@ function FileExplorer:addFileToList( file, texture, color, func ) element:add( Gui.text:new( { bounds = Rect:new( 28, 0, 20, 20 ), - text = RL_GetFileName( file ), + text = RL.GetFileName( file ), fontSize = 20, HAling = Gui.ALING.NONE, VAling = Gui.ALING.CENTER, @@ -264,7 +264,7 @@ function FileExplorer:addFileToList( file, texture, color, func ) end function FileExplorer:drag() - local mousePos = Vec2:new( RL_GetMousePosition() ) + local mousePos = Vec2:new( RL.GetMousePosition() ) local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y ) self:setPosition( mousePos - self.dragPos ) diff --git a/examples/ReiLuaGui_examples/main.lua b/examples/ReiLuaGui_examples/main.lua index f67e27f..29dace8 100644 --- a/examples/ReiLuaGui_examples/main.lua +++ b/examples/ReiLuaGui_examples/main.lua @@ -1,5 +1,5 @@ -package.path = package.path..";"..RL_GetBasePath().."?.lua" -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" +package.path = package.path..";"..RL.GetBasePath().."?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" util = require( "utillib" ) Vec2 = require( "vector2" ) @@ -13,29 +13,29 @@ FileExplorer = require( "file_explorer" ) -- Textures. -- Note that textures are global. -cancelTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cancel.png" ) -backTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/previous-button.png" ) -folderTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/open-folder.png" ) -filesTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/files.png" ) -borderTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_border.png" ) -bgrTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_bgr.png" ) - -RL_GenTextureMipmaps( cancelTexture ) -RL_GenTextureMipmaps( backTexture ) -RL_GenTextureMipmaps( folderTexture ) -RL_GenTextureMipmaps( filesTexture ) -RL_GenTextureMipmaps( borderTexture ) -RL_GenTextureMipmaps( bgrTexture ) - -RL_SetTextureFilter( cancelTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( backTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( folderTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( filesTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( borderTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( bgrTexture, TEXTURE_FILTER_TRILINEAR ) - -RL_SetTextureWrap( borderTexture, TEXTURE_WRAP_REPEAT ) -RL_SetTextureWrap( bgrTexture, TEXTURE_WRAP_REPEAT ) +cancelTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cancel.png" ) +backTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/previous-button.png" ) +folderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/open-folder.png" ) +filesTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/files.png" ) +borderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) +bgrTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_bgr.png" ) + +RL.GenTextureMipmaps( cancelTexture ) +RL.GenTextureMipmaps( backTexture ) +RL.GenTextureMipmaps( folderTexture ) +RL.GenTextureMipmaps( filesTexture ) +RL.GenTextureMipmaps( borderTexture ) +RL.GenTextureMipmaps( bgrTexture ) + +RL.SetTextureFilter( cancelTexture, RL.TEXTURE_FILTER_TRILINEAR ) +RL.SetTextureFilter( backTexture, RL.TEXTURE_FILTER_TRILINEAR ) +RL.SetTextureFilter( folderTexture, RL.TEXTURE_FILTER_TRILINEAR ) +RL.SetTextureFilter( filesTexture, RL.TEXTURE_FILTER_TRILINEAR ) +RL.SetTextureFilter( borderTexture, RL.TEXTURE_FILTER_TRILINEAR ) +RL.SetTextureFilter( bgrTexture, RL.TEXTURE_FILTER_TRILINEAR ) + +RL.SetTextureWrap( borderTexture, RL.TEXTURE_WRAP_REPEAT ) +RL.SetTextureWrap( bgrTexture, RL.TEXTURE_WRAP_REPEAT ) -- End of calculator definition. @@ -51,8 +51,8 @@ function initGui() calculator:setVisible( true ) fileExplorer:setVisible( true ) end, - onMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, - notMouseOver = function( self ) self.color = Color:new( GRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, + notMouseOver = function( self ) self.color = Color:new( RL.GRAY ) end, } ) showButton:add( Gui.text:new( { text = "Show", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) @@ -61,27 +61,27 @@ function initGui() fileExplorer = FileExplorer:new( Vec2:new( 280, 96 ) ) end -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - winSize = RL_GetScreenSize() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + winSize = RL.GetScreenSize() - RL_SetWindowTitle( "ReiLuaGui examples" ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowTitle( "ReiLuaGui examples" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) initGui() end -function process( delta ) - Gui.process( Vec2:new( RL_GetMousePosition() ) ) +function RL.process( delta ) + Gui.process( Vec2:new( RL.GetMousePosition() ) ) end -function draw() - RL_ClearBackground( RAYWHITE ) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) Gui.draw() end diff --git a/examples/ReiLuaGui_test/main.lua b/examples/ReiLuaGui_test/main.lua index b36a7da..8ea6563 100644 --- a/examples/ReiLuaGui_test/main.lua +++ b/examples/ReiLuaGui_test/main.lua @@ -1,4 +1,4 @@ -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" util = require( "utillib" ) Vec2 = require( "vector2" ) @@ -7,16 +7,16 @@ Color = require( "color" ) Gui = require( "gui" ) local container = {} --- local circleTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/circle.png" ) -local circleTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/plain-circle.png" ) -local checkTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/check-mark.png" ) -local borderTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_border.png" ) +-- local circleTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/circle.png" ) +local circleTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/plain-circle.png" ) +local checkTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/check-mark.png" ) +local borderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) local textInput -RL_GenTextureMipmaps( circleTexture ) -RL_GenTextureMipmaps( checkTexture ) -RL_SetTextureFilter( circleTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( checkTexture, TEXTURE_FILTER_TRILINEAR ) +RL.GenTextureMipmaps( circleTexture ) +RL.GenTextureMipmaps( checkTexture ) +RL.SetTextureFilter( circleTexture, RL.TEXTURE_FILTER_TRILINEAR ) +RL.SetTextureFilter( checkTexture, RL.TEXTURE_FILTER_TRILINEAR ) function initGui() -- local label = Gui.label:new( { text = "Dog", bounds = { 32, 32, 96, 96 }, drawBounds = true, Haling = Gui.ALING.CENTER, Valing = Gui.ALING.TOP } ) @@ -45,8 +45,8 @@ function initGui() local dog = Gui.element:new( { bounds = Rect:new( 0, 0, 128, 36 ), onClicked = function() panel:setPosition( Vec2:new( 290, 120 ) ) end, - onMouseOver = function( self ) self.items[1].color = RED end, - notMouseOver = function( self ) self.items[1].color = BLACK end, + onMouseOver = function( self ) self.items[1].color = RL.RED end, + notMouseOver = function( self ) self.items[1].color = RL.BLACK end, drawBounds = true, } ) @@ -58,7 +58,7 @@ function initGui() HAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER, visible = true, - nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, } ) ) dog:add( Gui.texture:new( { bounds = Rect:new( 0, 0, 24, 24 ), texture = circleTexture, HAling = Gui.ALING.RIGHT, color = Color:new( 150, 150, 255 ) } ) ) @@ -81,8 +81,8 @@ function initGui() local element = Gui.element:new( { bounds = Rect:new( 0, 0, 120, 30 ), onClicked = function() panel:setPosition( Vec2:new( 340, 380 ) ) end, - onMouseOver = function( self ) self.color = Color:new( DARKBLUE ) end, - notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.DARKBLUE ) end, + notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, drawBounds = true, } ) @@ -97,18 +97,18 @@ function initGui() local element = Gui.element:new( { bounds = itemBounds:clone(), - onMouseOver = function( self ) self.color = Color:new( DARKBLUE ) end, - notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.DARKBLUE ) end, + notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, drawBounds = true, } ) element:add( Gui.text:new( { text = "Dog" } ) ) container2:add( element ) - + element = Gui.element:new( { bounds = Rect:new( 0, 0, 78, 24 ), -- bounds = Rect:new( 0, 0, 78, 64 ), - onMouseOver = function( self ) self.color = Color:new( DARKBLUE ) end, - notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onMouseOver = function( self ) self.color = Color:new( RL.DARKBLUE ) end, + notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, drawBounds = true, } ) element:add( Gui.text:new( { text = "Cat" } ) ) @@ -123,39 +123,38 @@ function initGui() textInput = Gui.element:new( { bounds = Rect:new( 64, 360, 300, 32 ), drawBounds = true, - color = Color:new( LIGHTGRAY ), + color = Color:new( RL.LIGHTGRAY ), onClicked = function() Gui.setInputFocus( textInput ) end, - inputFocus = function() textInput.color = Color:new( BLUE ) end, + inputFocus = function() textInput.color = Color:new( RL.BLUE ) end, -- inputFocus = function() container:delete() end, -- inputFocus = function() panel:set2Back() end, - inputUnfocus = function() textInput.color = Color:new( LIGHTGRAY ) end, + inputUnfocus = function() textInput.color = Color:new( RL.LIGHTGRAY ) end, } ) textInput:add( Gui.text:new( { text = "", maxTextLen = 16, allowLineBreak = false } ) ) end -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - winSize = RL_GetScreenSize() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + winSize = RL.GetScreenSize() - RL_SetWindowTitle( "ReiLuaGui Test" ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowTitle( "ReiLuaGui Test" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) initGui() end -function process( delta ) - Gui.process( Vec2:new( RL_GetMousePosition() ) ) +function RL.process( delta ) + Gui.process( Vec2:new( RL.GetMousePosition() ) ) end -function draw() - RL_ClearBackground( RAYWHITE ) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) Gui.draw() - RL_DrawText( 0, "Work in progress GuiLib test.", { 10, 10 }, 30, 4, BLACK ) end diff --git a/examples/bunnymark/main.lua b/examples/bunnymark/main.lua index 52f8393..06ab5d6 100644 --- a/examples/bunnymark/main.lua +++ b/examples/bunnymark/main.lua @@ -42,23 +42,23 @@ function Bunny:update() end end -function init() - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( { screenWidth, screenHeight } ) - RL_SetWindowTitle( "raylib [textures] example - bunnymark" ) +function RL.init() + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( { screenWidth, screenHeight } ) + RL.SetWindowTitle( "raylib [textures] example - bunnymark" ) -- Load bunny texture - texBunny = RL_LoadTexture( RL_GetBasePath().."../resources/images/wabbit_alpha.png" ) - texSize = RL_GetTextureSize( texBunny ) + texBunny = RL.LoadTexture( RL.GetBasePath().."../resources/images/wabbit_alpha.png" ) + texSize = RL.GetTextureSize( texBunny ) end -function process( delta ) - if RL_IsMouseButtonDown( 0 ) then +function RL.process( delta ) + if RL.IsMouseButtonDown( 0 ) then -- Create more bunnies for i = 1, 100 do if #bunnies < MAX_BUNNIES then local speed = { math.random( -250, 250 ) / 60, math.random( -250, 250 ) / 60 } local color = { math.random( 50, 240 ), math.random( 80, 240 ), math.random( 100, 240 ), 255 } - table.insert( bunnies, Bunny:new( RL_GetMousePosition(), speed, color ) ) + table.insert( bunnies, Bunny:new( RL.GetMousePosition(), speed, color ) ) end end end @@ -68,8 +68,8 @@ function process( delta ) end end -function draw() - RL_ClearBackground( RAYWHITE ) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) for _, bunny in ipairs( bunnies ) do -- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), @@ -78,11 +78,11 @@ function draw() -- Process of sending data is costly and it could happen that GPU data has not been completely -- processed for drawing while new data is tried to be sent (updating current in-use buffers) -- it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies - RL_DrawTexture( texBunny, { bunny.position[1], bunny.position[2] }, bunny.color ) + RL.DrawTexture( texBunny, { bunny.position[1], bunny.position[2] }, bunny.color ) end - RL_DrawRectangle( { 0, 0, screenWidth, 40 }, BLACK) - RL_DrawText( 0, "bunnies: " .. #bunnies, { 120, 10 }, 20, 2, GREEN ) - RL_DrawText( 0, "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, 2, RED ) - RL_DrawFPS( { 10, 10 } ) + RL.DrawRectangle( { 0, 0, screenWidth, 40 }, RL.BLACK) + RL.DrawText( 0, "bunnies: " .. #bunnies, { 120, 10 }, 20, 2, RL.GREEN ) + RL.DrawText( 0, "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, 2, RL.RED ) + RL.DrawFPS( { 10, 10 } ) end diff --git a/examples/dungeon_crawler/main.lua b/examples/dungeon_crawler/main.lua index e1342ec..8732b0d 100644 --- a/examples/dungeon_crawler/main.lua +++ b/examples/dungeon_crawler/main.lua @@ -4,12 +4,12 @@ local camera = -1 local texture = -1 local textureSize = { 256, 96 } local res = { 384, 216 } -local winSize = RL_GetScreenSize() +local winSize = RL.GetScreenSize() local winScale = 4 local framebuffer = -1 local TILE_SIZE = 32 -local TILE_VERTEX_COLORS = { WHITE, WHITE, WHITE, WHITE } +local TILE_VERTEX_COLORS = { RL.WHITE, RL.WHITE, RL.WHITE, RL.WHITE } local FLOOR = 1 local CEILING = 2 @@ -51,38 +51,37 @@ local function getTileVer( x, y, type ) return verts end -function drawSprites() +local function drawSprites() for _, sprite in ipairs( sprites ) do - sprite.dis = RL_Vector2Distance( { pos[1], pos[3] }, { sprite.pos[1], sprite.pos[2] } ) + sprite.dis = RL.Vector2Distance( { pos[1], pos[3] }, { sprite.pos[1], sprite.pos[2] } ) end - + table.sort( sprites, function( a, b ) return a.dis > b.dis end ) for _, sprite in ipairs( sprites ) do - RL_DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE }, - { sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, WHITE ) + RL.DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE }, + { sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, RL.WHITE ) end end -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) winSize = { res[1] * winScale, res[2] * winScale } - RL_SetWindowSize( winSize ) - RL_SetExitKey( KEY_ESCAPE ) - -- framebuffer = RL_LoadRenderTexture( res ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - - texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, pos ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FIRST_PERSON ) + RL.SetWindowSize( winSize ) + RL.SetExitKey( RL.KEY_ESCAPE ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + + texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, pos ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FIRST_PERSON ) -- for x = 0, 3 do -- for y = 0, 9 do @@ -94,41 +93,41 @@ function init() table.insert( sprites, { pos = { 0.5, 3.5 }, tile = { 3, 0 }, dis = 0, size = 0.7 } ) end -function draw() - RL_UpdateCamera3D( camera ) - pos = RL_GetCamera3DPosition( camera ) +function RL.draw() + RL.UpdateCamera3D( camera ) + pos = RL.GetCamera3DPosition( camera ) - -- RL_BeginTextureMode( framebuffer ) - RL_ClearBackground( { 100, 150, 150 } ) + -- RL.BeginTextureMode( framebuffer ) + RL.ClearBackground( { 100, 150, 150 } ) - RL_BeginMode3D( camera ) + RL.BeginMode3D( camera ) -- Floor and ceiling. for x = 0, 3 do for y = 0, 10 do - RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), TILE_VERTEX_COLORS ) end end -- Walls. - RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) for x = 0, 3 do - RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) end for y = 0, 10 do - RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) - RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL.DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) end drawSprites() - RL_EndMode3D() - -- RL_EndTextureMode() + RL.EndMode3D() + -- RL.EndTextureMode() - -- RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) - -- RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) - -- RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) + -- RL.SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) + -- RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) + -- RL.SetTextureSource( TEXTURE_SOURCE_TEXTURE ) end diff --git a/examples/gui/main.lua b/examples/gui/main.lua index e569b0a..97c18ad 100644 --- a/examples/gui/main.lua +++ b/examples/gui/main.lua @@ -20,94 +20,92 @@ local colorPicker = { color = { 255, 255, 255 } } local colorPanel = { color = { 255, 255, 255 }, alpha = 1.0, hue = 1.0, oldHue = 1.0 } local comboBoxActive = 0 -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) local winSize = { 1920, 1080 } - RL_GuiSetFont( 0 ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.GuiSetFont( 0 ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) end -function process( delta ) +function RL.process( delta ) end -function draw() - RL_ClearBackground( { 50, 20, 75 } ) +function RL.draw() + RL.ClearBackground( { 50, 20, 75 } ) - -- if RL_GuiButton( { 112, 16, 96, 32 }, "Exit" ) then - if RL_GuiButton( { 112, 16, 96, 32 }, RL_GuiIconText( 113, "Exit" ) ) then - RL_CloseWindow() + if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( 113, "Exit" ) ) then + RL.CloseWindow() end - if windowOpen and RL_GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then + if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then windowOpen = false end - RL_GuiPanel( { 60, 260, 100, 100 }, "Panel" ) + RL.GuiPanel( { 60, 260, 100, 100 }, "Panel" ) - toggled = RL_GuiToggle( { 200, 260, 64, 32 }, "Toggle", toggled ) - index = RL_GuiToggleGroup( { 520, 30, 64, 32 }, "Cat\nDog\nMonkey", index ) - checkbox = RL_GuiCheckBox( { 200, 300, 16, 16 }, "CheckBox", checkbox ) + toggled = RL.GuiToggle( { 200, 260, 64, 32 }, "Toggle", toggled ) + index = RL.GuiToggleGroup( { 520, 30, 64, 32 }, "Cat\nDog\nMonkey", index ) + checkbox = RL.GuiCheckBox( { 200, 300, 16, 16 }, "CheckBox", checkbox ) local textBoxToggle = false - textBoxToggle, textBoxText = RL_GuiTextBox( { 32, 400, 120, 32 }, textBoxText, 32, textBoxActive ) - -- textBoxToggle, textBoxText = RL_GuiTextBoxMulti( { 32, 400, 120, 64 }, textBoxText, 120, textBoxActive ) - + textBoxToggle, textBoxText = RL.GuiTextBox( { 32, 400, 120, 32 }, textBoxText, 32, textBoxActive ) + -- textBoxToggle, textBoxText = RL.GuiTextBoxMulti( { 32, 400, 120, 64 }, textBoxText, 120, textBoxActive ) + if textBoxToggle then textBoxActive = not textBoxActive end local spinnerToggle = false - spinnerToggle, spinnerValue = RL_GuiSpinner( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive ) - -- spinnerToggle, spinnerValue = RL_GuiValueBox( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive ) + spinnerToggle, spinnerValue = RL.GuiSpinner( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive ) + -- spinnerToggle, spinnerValue = RL.GuiValueBox( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive ) if spinnerToggle then spinnerActive = not spinnerActive end - sliderValue = RL_GuiSliderBar( { 64, 510, 96, 32 }, "min", "max", sliderValue, sliderValueRange[1], sliderValueRange[2] ) - scrollbarValue = RL_GuiScrollBar( { 64, 550, 130, 32 }, scrollbarValue, 0, 10 ) + sliderValue = RL.GuiSliderBar( { 64, 510, 96, 32 }, "min", "max", sliderValue, sliderValueRange[1], sliderValueRange[2] ) + scrollbarValue = RL.GuiScrollBar( { 64, 550, 130, 32 }, scrollbarValue, 0, 10 ) local dropdownToggle = false - dropdownToggle, dropdownValue = RL_GuiDropdownBox( { 2, 2, 96, 16 }, "Cat\nDog\nMonkey", dropdownValue, dropdownActive ) + dropdownToggle, dropdownValue = RL.GuiDropdownBox( { 2, 2, 96, 16 }, "Cat\nDog\nMonkey", dropdownValue, dropdownActive ) if dropdownToggle then dropdownActive = not dropdownActive end - listView.item, listView.scroll = RL_GuiListView( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listView.scroll, listView.item ) - -- listViewEx.item, listViewEx.scroll, listViewEx.focus = RL_GuiListViewEx( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listViewEx.focus, listViewEx.scroll, listViewEx.item ) - messageBox.buttonIndex = RL_GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes\nNo" ) + listView.item, listView.scroll = RL.GuiListView( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listView.scroll, listView.item ) + messageBox.buttonIndex = RL.GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes\nNo" ) if 0 <= messageBox.buttonIndex then print( "messageBox.buttonIndex", messageBox.buttonIndex ) end textInputBox.buttonIndex, textInputBox.text, textInputBox.secretViewActive - = RL_GuiTextInputBox( { 420, 510, 300, 150 }, "Input Box", "Put text here", "Button",textInputBox.text, 200, textInputBox.secretViewActive ) + = RL.GuiTextInputBox( { 420, 510, 300, 150 }, "Input Box", "Put text here", "Button",textInputBox.text, 200, textInputBox.secretViewActive ) if 0 <= textInputBox.buttonIndex then print( "textInputBox.buttonIndex", textInputBox.buttonIndex ) end - colorPicker.color = RL_GuiColorPicker( { 620, 20, 150, 150 }, "Color Picker", colorPicker.color ) + colorPicker.color = RL.GuiColorPicker( { 620, 20, 150, 150 }, "Color Picker", colorPicker.color ) - colorPanel.color = RL_GuiColorPanel( { 820, 20, 150, 150 }, "Color Panel", colorPanel.color ) - colorPanel.alpha = RL_GuiColorBarAlpha( { 820, 180, 150, 20 }, "Color alpha", colorPanel.alpha ) - colorPanel.hue = RL_GuiColorBarHue( { 980, 20, 20, 150 }, "Color hue", colorPanel.hue ) + colorPanel.color = RL.GuiColorPanel( { 820, 20, 150, 150 }, "Color Panel", colorPanel.color ) + colorPanel.alpha = RL.GuiColorBarAlpha( { 820, 180, 150, 20 }, "Color alpha", colorPanel.alpha ) + colorPanel.hue = RL.GuiColorBarHue( { 980, 20, 20, 150 }, "Color hue", colorPanel.hue ) if colorPanel.hue ~= colorPanel.oldHue then colorPanel.oldHue = colorPanel.hue - colorPanel.color = RL_ColorFromHSV( colorPanel.hue, 1.0, 1.0 ) + colorPanel.color = RL.ColorFromHSV( colorPanel.hue, 1.0, 1.0 ) end - - RL_GuiDrawIcon( 121, { 6, 20 }, 2, WHITE ) - comboBoxActive = RL_GuiComboBox( { 5, 50, 80, 20 }, "One\nTwo\nThree", comboBoxActive ) + RL.GuiDrawIcon( 121, { 6, 20 }, 2, RL.WHITE ) + + comboBoxActive = RL.GuiComboBox( { 5, 50, 80, 20 }, "One\nTwo\nThree", comboBoxActive ) end diff --git a/examples/heightmap/main.lua b/examples/heightmap/main.lua index e8cc4ea..4c66dd6 100644 --- a/examples/heightmap/main.lua +++ b/examples/heightmap/main.lua @@ -18,67 +18,67 @@ local dirtBottomRec = { 7 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE } local matrix = {} -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 0, 8, 16 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FREE ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 0, 8, 16 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FREE ) - heigthImage = RL_LoadImage( RL_GetBasePath().."../resources/images/heightmap.png" ) + heigthImage = RL.LoadImage( RL.GetBasePath().."../resources/images/heightmap.png" ) - mesh = RL_GenMeshHeightmap( heigthImage, { 16, 4, 16 } ) - tilesetTex = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" ) - groundTexture = RL_LoadRenderTexture( { TILE_SIZE * 16, TILE_SIZE * 16 } ) + mesh = RL.GenMeshHeightmap( heigthImage, { 16, 4, 16 } ) + tilesetTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) + groundTexture = RL.LoadRenderTexture( { TILE_SIZE * 16, TILE_SIZE * 16 } ) -- Draw to ground texture. - RL_BeginTextureMode( groundTexture ) + RL.BeginTextureMode( groundTexture ) for x = 1, 16 do for y = 1, 16 do local pos = { x - 1, y - 1 } if 4 < x and x < 14 and 4 < y and y < 8 then - RL_DrawTextureRec( tilesetTex, dirtRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tilesetTex, dirtRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) elseif 4 == x and 4 < y and y < 8 then - RL_DrawTextureRec( tilesetTex, dirtRightRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tilesetTex, dirtRightRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) elseif 14 == x and 4 < y and y < 8 then - RL_DrawTextureRec( tilesetTex, dirtLeftRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tilesetTex, dirtLeftRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) elseif 4 < x and x < 14 and 4 == y then - RL_DrawTextureRec( tilesetTex, dirtTopRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tilesetTex, dirtTopRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) elseif 4 < x and x < 14 and 8 == y then - RL_DrawTextureRec( tilesetTex, dirtBottomRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tilesetTex, dirtBottomRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) else - RL_DrawTextureRec( tilesetTex, grassRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tilesetTex, grassRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) end end end - RL_EndTextureMode() + RL.EndTextureMode() - material = RL_LoadMaterialDefault() - RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) - -- RL_GenTextureMipmaps( groundTexture ) - -- RL_SetTextureFilter( groundTexture, TEXTURE_FILTER_TRILINEAR ) - RL_SetMaterialTexture( material, MATERIAL_MAP_ALBEDO, groundTexture ) - RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) + material = RL.LoadMaterialDefault() + RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE ) + -- RL.GenTextureMipmaps( groundTexture ) + -- RL.SetTextureFilter( groundTexture, TEXTURE_FILTER_TRILINEAR ) + RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE ) - matrix = RL_MatrixMultiply( RL_MatrixIdentity(), RL_MatrixTranslate( { -4, 0, -4 } ) ) + matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) ) end -function draw() - RL_ClearBackground( { 100, 150, 100 } ) - RL_UpdateCamera3D( camera ) +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + RL.UpdateCamera3D( camera ) - RL_BeginMode3D( camera ) - RL_DrawMesh( mesh, material, matrix ) - RL_EndMode3D() + RL.BeginMode3D( camera ) + RL.DrawMesh( mesh, material, matrix ) + RL.EndMode3D() end diff --git a/examples/image_draw/main.lua b/examples/image_draw/main.lua index 2a78a13..8c1ea82 100644 --- a/examples/image_draw/main.lua +++ b/examples/image_draw/main.lua @@ -5,40 +5,40 @@ local catImage = -1 local catCopy = -1 local textImage = -1 -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - image = RL_GenImageColor( winSize[1], winSize[2], WHITE ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + image = RL.GenImageColor( winSize[1], winSize[2], RL.WHITE ) -- Test changing working directory. - RL_ChangeDirectory( RL_GetBasePath().."../resources" ) - catImage = RL_LoadImage( RL_GetWorkingDirectory().."/images/cat.png" ) - RL_ImageClearBackground( image, { 150, 60, 100 } ) - RL_ImageDrawPixel( image, { 32, 32 }, WHITE ) - RL_ImageDrawLine( image, { 32, 45 }, { 100, 60 }, GREEN ) - RL_ImageDrawCircle( image, { 64, 32 }, 16, BLUE ) - RL_ImageDrawRectangle( image, { 120, 64, 32, 64 }, BLUE ) - RL_ImageDrawRectangleLines( image, { 160, 64, 32, 64 }, 2.0, BLUE ) - RL_ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, WHITE ) - RL_ImageDrawTextEx( image, 0, "Hello", { 300, 32 }, 48.0, 1.0, WHITE ) + RL.ChangeDirectory( RL.GetBasePath().."../resources" ) + catImage = RL.LoadImage( RL.GetWorkingDirectory().."/images/cat.png" ) + RL.ImageClearBackground( image, { 150, 60, 100 } ) + RL.ImageDrawPixel( image, { 32, 32 }, RL.WHITE ) + RL.ImageDrawLine( image, { 32, 45 }, { 100, 60 }, RL.GREEN ) + RL.ImageDrawCircle( image, { 64, 32 }, 16, RL.BLUE ) + RL.ImageDrawRectangle( image, { 120, 64, 32, 64 }, RL.BLUE ) + RL.ImageDrawRectangleLines( image, { 160, 64, 32, 64 }, 2.0, RL.BLUE ) + RL.ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, RL.WHITE ) + RL.ImageDrawTextEx( image, 0, "Hello", { 300, 32 }, 48.0, 1.0, RL.WHITE ) local src = { 80, 70, 96, 96 } - catCopy = RL_ImageFromImage( catImage, src ) + catCopy = RL.ImageFromImage( catImage, src ) - RL_ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, WHITE ) + RL.ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, RL.WHITE ) - textImage = RL_ImageText( 0, "Cat", 10, 4, WHITE ) - local imageSize = RL_GetImageSize( textImage ) - RL_ImageDraw( image, textImage, { 0, 0, imageSize[1], imageSize[2] }, { 250, 40, imageSize[1], imageSize[2] }, WHITE ) - - texture = RL_LoadTextureFromImage( image ) + textImage = RL.ImageText( 0, "Cat", 10, 4, RL.WHITE ) + local imageSize = RL.GetImageSize( textImage ) + RL.ImageDraw( image, textImage, { 0, 0, imageSize[1], imageSize[2] }, { 250, 40, imageSize[1], imageSize[2] }, RL.WHITE ) + + texture = RL.LoadTextureFromImage( image ) end -function draw() - RL_ClearBackground( { 100, 150, 100 } ) - RL_DrawTexture( texture, { 0, 0 }, WHITE ) +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + RL.DrawTexture( texture, { 0, 0 }, RL.WHITE ) end diff --git a/examples/instancing/main.lua b/examples/instancing/main.lua index d0760ec..b7e4024 100644 --- a/examples/instancing/main.lua +++ b/examples/instancing/main.lua @@ -18,94 +18,94 @@ local shader local matInstances local matDefault -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowTitle( "Instancing" ) - RL_SetWindowState( FLAG_VSYNC_HINT ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowTitle( "Instancing" ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) -- Define the camera to look into our 3d world - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { -125.0, 125.0, -125.0 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCamera3DFovy( camera, 45 ) - RL_SetCameraMode( camera, CAMERA_ORBITAL ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { -125.0, 125.0, -125.0 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCamera3DFovy( camera, 45 ) + RL.SetCameraMode( camera, RL.CAMERA_ORBITAL ) -- Define mesh to be instanced - cube = RL_GenMeshCube( { 1, 1, 1 } ) + cube = RL.GenMeshCube( { 1, 1, 1 } ) -- Translate and rotate cubes randomly for i = 1, MAX_INSTANCES do - local translation = RL_MatrixTranslate( { math.random( -50, 50 ), math.random( -50, 50 ), math.random( -50, 50 ) } ) - local axis = RL_Vector3Normalize( { math.random( 0, 360 ), math.random( 0, 360 ), math.random( 0, 360 ) } ) + local translation = RL.MatrixTranslate( { math.random( -50, 50 ), math.random( -50, 50 ), math.random( -50, 50 ) } ) + local axis = RL.Vector3Normalize( { math.random( 0, 360 ), math.random( 0, 360 ), math.random( 0, 360 ) } ) local angle = math.rad( math.random( 0, 10 ) ) - local rotation = RL_MatrixRotate( axis, angle ) + local rotation = RL.MatrixRotate( axis, angle ) - table.insert( transforms, RL_MatrixMultiply( rotation, translation ) ) + table.insert( transforms, RL.MatrixMultiply( rotation, translation ) ) end -- Load lighting shader - shader = RL_LoadShader( RL_GetBasePath().."../resources/shaders/glsl330/lighting_instancing.vs", - RL_GetBasePath().."../resources/shaders/glsl330/lighting.fs" ) + shader = RL.LoadShader( RL.GetBasePath().."../resources/shaders/glsl330/lighting_instancing.vs", + RL.GetBasePath().."../resources/shaders/glsl330/lighting.fs" ) -- Get shader locations - local mvpLoc = RL_GetShaderLocation( shader, "mvp" ) - local viewPosLoc = RL_GetShaderLocation( shader, "viewPos" ) - local instanceTransformLoc = RL_GetShaderLocationAttrib( shader, "instanceTransform" ) - RL_SetShaderLocationIndex( shader, SHADER_LOC_MATRIX_MVP, mvpLoc ) - RL_SetShaderLocationIndex( shader, SHADER_LOC_VECTOR_VIEW, viewPosLoc ) - RL_SetShaderLocationIndex( shader, SHADER_LOC_MATRIX_MODEL, instanceTransformLoc ) + local mvpLoc = RL.GetShaderLocation( shader, "mvp" ) + local viewPosLoc = RL.GetShaderLocation( shader, "viewPos" ) + local instanceTransformLoc = RL.GetShaderLocationAttrib( shader, "instanceTransform" ) + RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_MATRIX_MVP, mvpLoc ) + RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_VECTOR_VIEW, viewPosLoc ) + RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_MATRIX_MODEL, instanceTransformLoc ) -- Set shader value: ambient light level - local ambientLoc = RL_GetShaderLocation( shader, "ambient" ) - RL_SetShaderValue( shader, ambientLoc, { 0.2, 0.2, 0.2, 0.1 }, SHADER_UNIFORM_VEC4 ) + local ambientLoc = RL.GetShaderLocation( shader, "ambient" ) + RL.SetShaderValue( shader, ambientLoc, { 0.2, 0.2, 0.2, 0.1 }, RL.SHADER_UNIFORM_VEC4 ) -- Create one light - RL_CreateLight( LIGHT_DIRECTIONAL, { 50.0, 50.0, 0.0 }, RL_Vector3Zero(), WHITE, shader ) + RL.CreateLight( RL.LIGHT_DIRECTIONAL, { 50.0, 50.0, 0.0 }, RL.Vector3Zero(), RL.WHITE, shader ) -- NOTE: We are assigning the intancing shader to material.shader -- to be used on mesh drawing with DrawMeshInstanced() - matInstances = RL_LoadMaterialDefault() - RL_SetMaterialShader( matInstances, shader ) - RL_SetMaterialColor( matInstances, MATERIAL_MAP_DIFFUSE, RED ) + matInstances = RL.LoadMaterialDefault() + RL.SetMaterialShader( matInstances, shader ) + RL.SetMaterialColor( matInstances, RL.MATERIAL_MAP_DIFFUSE, RL.RED ) -- Load default material (using raylib intenral default shader) for non-instanced mesh drawing -- WARNING: Default shader enables vertex color attribute BUT GenMeshCube() does not generate vertex colors, so, -- when drawing the color attribute is disabled and a default color value is provided as input for thevertex attribute - matDefault = RL_LoadMaterialDefault() - RL_SetMaterialColor( matDefault, MATERIAL_MAP_DIFFUSE, BLUE ) + matDefault = RL.LoadMaterialDefault() + RL.SetMaterialColor( matDefault, RL.MATERIAL_MAP_DIFFUSE, RL.BLUE ) end -function process( delta ) - RL_UpdateCamera3D( camera ) +function RL.process( delta ) + RL.UpdateCamera3D( camera ) -- Update the light shader with the camera view position - local loc = RL_GetShaderLocationIndex( shader, SHADER_LOC_VECTOR_VIEW ) - RL_SetShaderValue( shader, loc, RL_GetCamera3DPosition( camera ), SHADER_UNIFORM_VEC3 ) + local loc = RL.GetShaderLocationIndex( shader, RL.SHADER_LOC_VECTOR_VIEW ) + RL.SetShaderValue( shader, loc, RL.GetCamera3DPosition( camera ), RL.SHADER_UNIFORM_VEC3 ) end -function draw() - RL_ClearBackground( DARKBLUE ) +function RL.draw() + RL.ClearBackground( RL.DARKBLUE ) - RL_BeginMode3D( camera ) + RL.BeginMode3D( camera ) -- Draw cube mesh with default material (BLUE) - RL_DrawMesh( cube, matDefault, RL_MatrixTranslate( { -10.0, 0.0, 0.0 } ) ) + RL.DrawMesh( cube, matDefault, RL.MatrixTranslate( { -10.0, 0.0, 0.0 } ) ) -- Draw meshes instanced using material containing instancing shader (RED + lighting), -- transforms[] for the instances should be provided, they are dynamically -- updated in GPU every frame, so we can animate the different mesh instances - RL_DrawMeshInstanced( cube, matInstances, transforms, MAX_INSTANCES ) + RL.DrawMeshInstanced( cube, matInstances, transforms, MAX_INSTANCES ) -- Draw cube mesh with default material (BLUE) - RL_DrawMesh( cube, matDefault, RL_MatrixTranslate( { 10.0, 0.0, 0.0 } ) ) - RL_EndMode3D() + RL.DrawMesh( cube, matDefault, RL.MatrixTranslate( { 10.0, 0.0, 0.0 } ) ) + RL.EndMode3D() - RL_DrawFPS( { 10, 10 } ) + RL.DrawFPS( { 10, 10 } ) end diff --git a/examples/iqm_test/main.lua b/examples/iqm_test/main.lua index 8471c86..486b110 100644 --- a/examples/iqm_test/main.lua +++ b/examples/iqm_test/main.lua @@ -2,7 +2,6 @@ local monitor = 0 local camera = -1 -local texture = -1 local material = -1 local model = -1 local animations = -1 @@ -12,41 +11,41 @@ local curAnim = 0 local frameCount = 0 local animSpeed = 60 -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 0, 2, 4 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FREE ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 0, 2, 4 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FREE ) - material = RL_CreateMaterial( { + material = RL.CreateMaterial( { maps = { { - MATERIAL_MAP_ALBEDO, + RL.MATERIAL_MAP_ALBEDO, { - texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/monkey_tex.png" ), - color = WHITE, + texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/monkey_tex.png" ), + color = RL.WHITE, }, }, }, } ) - - model = RL_LoadModel( RL_GetBasePath().."../resources/iqm/monkey.iqm" ) - RL_SetModelMaterial( model, 0, material ) - animations, animationCount = RL_LoadModelAnimations( RL_GetBasePath().."../resources/iqm/monkey.iqm" ) + + model = RL.LoadModel( RL.GetBasePath().."../resources/iqm/monkey.iqm" ) + RL.SetModelMaterial( model, 0, material ) + animations, animationCount = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" ) print( "animationCount", animationCount ) end -function process( delta ) - if RL_IsKeyPressed( KEY_ENTER ) then +function RL.process( delta ) + if RL.IsKeyPressed( RL.KEY_ENTER ) then curAnim = curAnim + 1 if animationCount <= curAnim then @@ -54,15 +53,15 @@ function process( delta ) end frame = 0.0 - frameCount = RL_GetModelAnimationFrameCount( animations, curAnim ) - elseif RL_IsKeyPressed( KEY_UP ) then + frameCount = RL.GetModelAnimationFrameCount( animations, curAnim ) + elseif RL.IsKeyPressed( RL.KEY_UP ) then animSpeed = animSpeed + 5 - elseif RL_IsKeyPressed( KEY_DOWN ) then + elseif RL.IsKeyPressed( RL.KEY_DOWN ) then animSpeed = animSpeed - 5 end - if RL_IsKeyDown( KEY_SPACE ) then - RL_UpdateModelAnimation( model, animations, curAnim, math.floor( frame ) ) + if RL.IsKeyDown( RL.KEY_SPACE ) then + RL.UpdateModelAnimation( model, animations, curAnim, math.floor( frame ) ) frame = frame + animSpeed * delta if frameCount < frame then @@ -73,19 +72,19 @@ function process( delta ) end end -function draw() - RL_ClearBackground( { 100, 150, 100 } ) - RL_UpdateCamera3D( camera ) - - RL_BeginMode3D( camera ) - RL_DrawGrid( 8, 1 ) - RL_DrawModelEx( model, { 0, 0, 0 }, { 1.0, 0.0, 0.0 }, -90.0, { 1.0, 1.0, 1.0 }, WHITE ) - RL_EndMode3D() +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + RL.UpdateCamera3D( camera ) + + RL.BeginMode3D( camera ) + RL.DrawGrid( 8, 1 ) + RL.DrawModelEx( model, { 0, 0, 0 }, { 1.0, 0.0, 0.0 }, -90.0, { 1.0, 1.0, 1.0 }, RL.WHITE ) + RL.EndMode3D() - RL_DrawText( 0, + RL.DrawText( 0, "Enter: Change animation\ Space: Play animation\ Up arrow: Inreace animation speed\ Down arrow: Decreace animation speed", - { 10, 10 }, 30, 5, WHITE ) + { 10, 10 }, 30, 5, RL.WHITE ) end diff --git a/examples/lightmap/main.lua b/examples/lightmap/main.lua index e0b5da0..ae81345 100644 --- a/examples/lightmap/main.lua +++ b/examples/lightmap/main.lua @@ -10,20 +10,20 @@ local shader = -1 local matrix = {} -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 0, 8, 16 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FREE ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 0, 8, 16 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FREE ) local ts = PLANE_SIZE local meshData = { @@ -33,61 +33,61 @@ function init() { 0, 0 }, { ts, ts }, { ts, 0 } }, texcoords2 = { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, { 1, 0 } }, - colors = { WHITE, WHITE, WHITE, - WHITE, WHITE, WHITE }, + colors = { RL.WHITE, RL.WHITE, RL.WHITE, + RL.WHITE, RL.WHITE, RL.WHITE }, normals = { { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 } }, } - mesh = RL_GenMeshCustom( meshData, true ) + mesh = RL.GenMeshCustom( meshData, true ) -- local meshEdit = { -- vertices = { { 0, 1, 0 }, { 0, 0, PLANE_SIZE }, { PLANE_SIZE, 0, PLANE_SIZE }, -- { 0, 1, 0 }, { PLANE_SIZE, 0, PLANE_SIZE }, { PLANE_SIZE, 0, 0 } }, -- } - -- RL_UpdateMesh( mesh, meshEdit ) - - tileTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tile.png" ) - RL_GenTextureMipmaps( tileTexture ) - RL_SetTextureFilter( tileTexture, TEXTURE_FILTER_TRILINEAR ) - lightmap = RL_LoadTexture( RL_GetBasePath().."../resources/images/lightmap.png" ) - RL_GenTextureMipmaps( lightmap ) - RL_SetTextureFilter( lightmap, TEXTURE_FILTER_TRILINEAR ) - RL_SetTextureWrap( lightmap, TEXTURE_WRAP_CLAMP ) + -- RL.UpdateMesh( mesh, meshEdit ) + + tileTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tile.png" ) + RL.GenTextureMipmaps( tileTexture ) + RL.SetTextureFilter( tileTexture, RL.TEXTURE_FILTER_TRILINEAR ) + lightmap = RL.LoadTexture( RL.GetBasePath().."../resources/images/lightmap.png" ) + RL.GenTextureMipmaps( lightmap ) + RL.SetTextureFilter( lightmap, RL.TEXTURE_FILTER_TRILINEAR ) + RL.SetTextureWrap( lightmap, RL.TEXTURE_WRAP_CLAMP ) - shader = RL_LoadShader( RL_GetBasePath().."../resources/shaders/glsl330/lightmap.vs", - RL_GetBasePath().."../resources/shaders/glsl330/lightmap.fs" ) + shader = RL.LoadShader( RL.GetBasePath().."../resources/shaders/glsl330/lightmap.vs", + RL.GetBasePath().."../resources/shaders/glsl330/lightmap.fs" ) local materialData = { shader = shader, maps = { { - MATERIAL_MAP_ALBEDO, + RL.MATERIAL_MAP_ALBEDO, { texture = tileTexture, - color = WHITE, + color = RL.WHITE, value = 1.0, }, }, { - MATERIAL_MAP_METALNESS, + RL.MATERIAL_MAP_METALNESS, { texture = lightmap, - color = WHITE, + color = RL.WHITE, value = 1.0, }, }, }, } - material = RL_CreateMaterial( materialData ) + material = RL.CreateMaterial( materialData ) - matrix = RL_MatrixMultiply( RL_MatrixIdentity(), RL_MatrixTranslate( { -4, 0, -4 } ) ) + matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) ) end -function draw() - RL_ClearBackground( { 25, 50, 50 } ) - RL_UpdateCamera3D( camera ) +function RL.draw() + RL.ClearBackground( { 25, 50, 50 } ) + RL.UpdateCamera3D( camera ) - RL_BeginMode3D( camera ) - RL_DrawMesh( mesh, material, matrix ) - RL_EndMode3D() + RL.BeginMode3D( camera ) + RL.DrawMesh( mesh, material, matrix ) + RL.EndMode3D() end diff --git a/examples/n-patches/main.lua b/examples/n-patches/main.lua index 91ea409..a4491bc 100644 --- a/examples/n-patches/main.lua +++ b/examples/n-patches/main.lua @@ -2,24 +2,24 @@ local dstRec = { 160.0, 160.0, 8.0, 8.0 }; local origin = { 0.0, 0.0 } -- local ninePatchInfo = { { 0.0, 0.0, 24.0, 24.0 }, 8, 8, 8, 8, NPATCH_NINE_PATCH } -local ninePatchInfo = { source = { 0, 0, 24.0, 24.0 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH } +local ninePatchInfo = { source = { 0, 0, 24.0, 24.0 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH } -local nPatchTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_border.png" ) +local nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) -function init() - RL_SetWindowTitle( "N-Patches" ) - RL_SetWindowState( FLAG_VSYNC_HINT ) +function RL.init() + RL.SetWindowTitle( "N-Patches" ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) end -function process( delta ) - local mousePosition = RL_GetMousePosition(); +function RL.process( delta ) + local mousePosition = RL.GetMousePosition(); -- Resize the n-patch based on mouse position dstRec[3] = mousePosition[1] - dstRec[1]; dstRec[4] = mousePosition[2] - dstRec[2]; end -function draw() - RL_ClearBackground( RAYWHITE ) - RL_DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, WHITE ) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) + RL.DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, RL.WHITE ) end diff --git a/examples/pixelated/main.lua b/examples/pixelated/main.lua index f5239ac..49f5c42 100644 --- a/examples/pixelated/main.lua +++ b/examples/pixelated/main.lua @@ -1,57 +1,56 @@ local tex = -1 local pos = { 32, 32 } local speed = 60.0 -local sound = -1 local monitor = 0 -local mPos = RL_GetMonitorPosition( monitor ) -local mSize = RL_GetMonitorSize( monitor ) +local mPos = RL.GetMonitorPosition( monitor ) +local mSize = RL.GetMonitorSize( monitor ) local framebuffer = -1 local res = { 320, 180 } local scale = 5 local winSize = { res[1] * scale, res[2] * scale } -function init() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowSize( winSize ) - tex = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" ) +function RL.init() + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowSize( winSize ) + tex = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) -- Create framebuffer. - framebuffer = RL_LoadRenderTexture( res ) + framebuffer = RL.LoadRenderTexture( res ) end -function process( delta ) - if RL_IsKeyDown( KEY_RIGHT ) then +function RL.process( delta ) + if RL.IsKeyDown( RL.KEY_RIGHT ) then pos[1] = pos[1] + delta * speed - elseif RL_IsKeyDown( KEY_LEFT ) then + elseif RL.IsKeyDown( RL.KEY_LEFT ) then pos[1] = pos[1] - delta * speed end - if RL_IsKeyDown( KEY_UP ) then + if RL.IsKeyDown( RL.KEY_UP ) then pos[2] = pos[2] - delta * speed - elseif RL_IsKeyDown( KEY_DOWN ) then + elseif RL.IsKeyDown( RL.KEY_DOWN ) then pos[2] = pos[2] + delta * speed end - if RL_IsWindowResized() then - winSize = RL_GetScreenSize() + if RL.IsWindowResized() then + winSize = RL.GetScreenSize() end end -function draw() - RL_ClearBackground( { 0, 0, 0 } ) +function RL.draw() + RL.ClearBackground( { 0, 0, 0 } ) - RL_BeginTextureMode( framebuffer ) - RL_ClearBackground( { 100, 150, 100 } ) - RL_DrawPixel( { 100, 100 }, { 255, 50, 100 } ) - RL_DrawLine( { 120, 100 }, { 140, 150 }, 2.4, { 255, 150, 255 } ) - RL_DrawRectangle( { 200, 120, 40, 50 }, { 100, 170, 255 } ) - RL_DrawTexturePro( tex, { 166, 138, 128, 128 }, { pos[1], pos[2], 128, 128 }, { 16, 16 }, 0.0, WHITE ) - RL_DrawText( 0, "Cat MIAU!!", { 16, 32 }, 10, 1, { 255, 180, 155 } ) - RL_DrawTriangle( { 0, 32 }, { 32, 16 }, { 0, 0 }, RED ) - RL_EndTextureMode() + RL.BeginTextureMode( framebuffer ) + RL.ClearBackground( { 100, 150, 100 } ) + RL.DrawPixel( { 100, 100 }, { 255, 50, 100 } ) + RL.DrawLine( { 120, 100 }, { 140, 150 }, 2.4, { 255, 150, 255 } ) + RL.DrawRectangle( { 200, 120, 40, 50 }, { 100, 170, 255 } ) + RL.DrawTexturePro( tex, { 166, 138, 128, 128 }, { pos[1], pos[2], 128, 128 }, { 16, 16 }, 0.0, RL.WHITE ) + RL.DrawText( 0, "Cat MIAU!!", { 16, 32 }, 10, 1, { 255, 180, 155 } ) + RL.DrawTriangle( { 0, 32 }, { 32, 16 }, { 0, 0 }, RL.RED ) + RL.EndTextureMode() - RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) - RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } ) - RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE ) + RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE ) end diff --git a/examples/platformer/main.lua b/examples/platformer/main.lua index dde3c1e..7f5486f 100644 --- a/examples/platformer/main.lua +++ b/examples/platformer/main.lua @@ -1,8 +1,14 @@ -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" -util = require( "utillib" ) +Util = require( "utillib" ) Vec2 = require( "vector2" ) +-- print( "RL", RL, #RL ) + +-- for i, v in pairs( RL ) do +-- print( i, v ) +-- end + local TILE_SIZE = 16 local PLAYER_MAXSPEED = 1.5 local PLAYER_ACCELL = 5 @@ -11,11 +17,11 @@ local GRAVITY = 6 local JUMP_STR = 3 local WALK_ANIM_SPEED = 12 -local tex = RL_LoadTexture( RL_GetBasePath().."../resources/images/arcade_platformerV2.png" ) +local tex = RL.LoadTexture( RL.GetBasePath().."../resources/images/arcade_platformerV2.png" ) local res = Vec2:new( 160, 144 ) local winScale = 5 local winSize = res:scale( winScale ) -local framebuffer = RL_LoadRenderTexture( res ) +local framebuffer = RL.LoadRenderTexture( res ) local monitor = 0 local tilemap = { size = Vec2:new( res.x / TILE_SIZE, res.y / TILE_SIZE ), @@ -80,21 +86,21 @@ local function createMap() tilemap.tiles[1][8] = 6 end -function init() - local monitorPos = Vec2:new( RL_GetMonitorPosition( monitor ) ) - local monitorSize = Vec2:new( RL_GetMonitorSize( monitor ) ) +function RL.init() + local monitorPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) + local monitorSize = Vec2:new( RL.GetMonitorSize( monitor ) ) - RL_SetWindowTitle( "Platformer" ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } ) + RL.SetWindowTitle( "Platformer" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } ) createMap() end local function isTileWall( pos ) - if RL_CheckCollisionPointRec( { pos.x, pos.y }, { 0, 0, tilemap.size.x - 1, tilemap.size.y - 1 } ) then + if RL.CheckCollisionPointRec( { pos.x, pos.y }, { 0, 0, tilemap.size.x - 1, tilemap.size.y - 1 } ) then return 0 < tilemap.tiles[ pos.x + 1 ][ pos.y + 1 ] else return false @@ -103,7 +109,7 @@ end local function tileCollision( entity ) local vPos = entity.pos + entity.vel -- Future pos with current vel. - local vRect = util.tableClone( entity.colRect ) + local vRect = Util.tableClone( entity.colRect ) local tinyGap = 0.001 -- Tiny gap between collisionRect and tile to prevent getting stuck on all seams. -- Move test rect to predicted position. @@ -172,14 +178,14 @@ end local function playerMovement( delta ) local moving = { false, false } - if RL_IsKeyDown( KEY_RIGHT ) then + if RL.IsKeyDown( RL.KEY_RIGHT ) then player.vel.x = player.vel.x + PLAYER_ACCELL * delta moving[1] = true if 0 < player.vel.x then player.facing = 1 end - elseif RL_IsKeyDown( KEY_LEFT ) then + elseif RL.IsKeyDown( RL.KEY_LEFT ) then player.vel.x = player.vel.x - PLAYER_ACCELL * delta moving[1] = true @@ -188,7 +194,7 @@ local function playerMovement( delta ) end end - if RL_IsKeyPressed( KEY_SPACE ) and player.onFloor then + if RL.IsKeyPressed( RL.KEY_SPACE ) and player.onFloor then player.vel.y = -JUMP_STR player.onFloor = false end @@ -205,7 +211,7 @@ local function playerMovement( delta ) end end - player.vel.x = util.clamp( player.vel.x, -PLAYER_MAXSPEED, PLAYER_MAXSPEED ) + player.vel.x = Util.clamp( player.vel.x, -PLAYER_MAXSPEED, PLAYER_MAXSPEED ) player.vel.y = player.vel.y + GRAVITY * delta @@ -220,16 +226,16 @@ local function playerMovement( delta ) player.colRect[2] = player.pos.y - player.colRect[4] end -function process( delta ) - if RL_IsWindowResized() then - winSize:set( RL_GetScreenSize() ) +function RL.process( delta ) + if RL.IsWindowResized() then + winSize:set( RL.GetScreenSize() ) end playerMovement( delta ) end local function drawMap() - RL_DrawTextureRec( tex, { 0, 160, res.x, res.y }, { 0, 0 }, WHITE ) + RL.DrawTextureRec( tex, { 0, 160, res.x, res.y }, { 0, 0 }, RL.WHITE ) for x = 1, tilemap.size.x do for y = 1, tilemap.size.y do @@ -237,7 +243,7 @@ local function drawMap() local pos = Vec2:new( x - 1, y - 1 ) if 0 < tile then - RL_DrawTextureRec( tex, tilemap.tileRects[ tile ], { pos.x * TILE_SIZE, pos.y * TILE_SIZE }, WHITE ) + RL.DrawTextureRec( tex, tilemap.tileRects[ tile ], { pos.x * TILE_SIZE, pos.y * TILE_SIZE }, RL.WHITE ) end end end @@ -250,7 +256,7 @@ local function drawPlayer() if math.abs( player.vel.x ) < 0.1 then player.curFrame = 1 else - player.animPos = player.animPos + WALK_ANIM_SPEED * ( math.abs( player.vel.x ) / PLAYER_MAXSPEED ) * RL_GetFrameTime() + player.animPos = player.animPos + WALK_ANIM_SPEED * ( math.abs( player.vel.x ) / PLAYER_MAXSPEED ) * RL.GetFrameTime() local frame = math.ceil( player.animPos ) if #player.walkAnimFrames < frame then @@ -270,7 +276,7 @@ local function drawPlayer() -- Draw rect. - local src = util.tableClone( player.frames[ player.curFrame ] ) + local src = Util.tableClone( player.frames[ player.curFrame ] ) local dst = { player.pos.x - src[3] / 2, player.pos.y - src[4], @@ -282,19 +288,19 @@ local function drawPlayer() src[3] = -src[3] end - RL_DrawTexturePro( tex, src, dst, { 0, 0 }, 0.0, WHITE ) + RL.DrawTexturePro( tex, src, dst, { 0, 0 }, 0.0, RL.WHITE ) end -function draw() - RL_ClearBackground( RED ) +function RL.draw() + RL.ClearBackground( RL.RED ) - RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) - RL_BeginTextureMode( framebuffer ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE ) + RL.BeginTextureMode( framebuffer ) drawMap() drawPlayer() - RL_EndTextureMode() + RL.EndTextureMode() - RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) - RL_DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, WHITE ) - RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE ) + RL.DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE ) end diff --git a/examples/point_triangle_collision/main.lua b/examples/point_triangle_collision/main.lua index 3c16e5e..a855dd8 100644 --- a/examples/point_triangle_collision/main.lua +++ b/examples/point_triangle_collision/main.lua @@ -1,4 +1,4 @@ -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" util = require "utillib" Vec2 = require "vector2" @@ -8,7 +8,6 @@ local MOVE_SPEED = 0.5 local monitor = 0 local camera = -1 -local texture = -1 local tri = { a = Vec3:new( 0, 0, 0 ), -- a = Vec3:new( 0, 1, 0 ), @@ -26,27 +25,25 @@ local point = { local debugText = "" local function calcNormal( tri ) - tri.normal = Vec3:new( RL_Vector3Normalize( RL_Vector3CrossProduct( tri.b - tri.a, tri.c - tri.a ) ) ) + tri.normal = Vec3:new( RL.Vector3Normalize( RL.Vector3CrossProduct( tri.b - tri.a, tri.c - tri.a ) ) ) end -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) local winSize = { 1920, 1080 } - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowSize( winSize ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 0, 1, 2 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FREE ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowSize( winSize ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 0, 1, 2 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FREE ) calcNormal( tri ) - - texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tile.png" ) end local function checkCollisionPointTriangle( p, a, b, c, n ) @@ -78,48 +75,48 @@ local function checkCollisionPointTriangle( p, a, b, c, n ) return 0.0 < result.x and 0.0 < result.y and 0.0 < result.z and distance < 0.0, distance end -function process( delta ) +function RL.process( delta ) debugText = "" - if RL_IsKeyDown( string.byte( "D" ) ) then + if RL.IsKeyDown( string.byte( "D" ) ) then point.pos.x = point.pos.x + MOVE_SPEED * delta - elseif RL_IsKeyDown( string.byte( "A" ) ) then + elseif RL.IsKeyDown( string.byte( "A" ) ) then point.pos.x = point.pos.x - MOVE_SPEED * delta end - if RL_IsKeyDown( string.byte( "S" ) ) then + if RL.IsKeyDown( string.byte( "S" ) ) then point.pos.z = point.pos.z + MOVE_SPEED * delta - elseif RL_IsKeyDown( string.byte( "W" ) ) then + elseif RL.IsKeyDown( string.byte( "W" ) ) then point.pos.z = point.pos.z - MOVE_SPEED * delta end - if RL_IsKeyDown( string.byte( "R" ) ) then + if RL.IsKeyDown( string.byte( "R" ) ) then point.pos.y = point.pos.y + MOVE_SPEED * delta - elseif RL_IsKeyDown( string.byte( "F" ) ) then + elseif RL.IsKeyDown( string.byte( "F" ) ) then point.pos.y = point.pos.y - MOVE_SPEED * delta end if checkCollisionPointTriangle( point.pos, tri.a, tri.b, tri.c, tri.normal ) then - point.color = RED + point.color = RL.RED else - point.color = GREEN + point.color = RL.GREEN end end -function draw() - RL_ClearBackground( { 100, 150, 100 } ) - RL_UpdateCamera3D( camera ) - - RL_BeginMode3D( camera ) - RL_DrawGrid( 8, 1 ) - RL_DrawTriangle3D( tri.a, tri.b, tri.c, { 200, 100, 100 } ) - - RL_DrawLine3D( { point.pos.x - point.lineLen, point.pos.y, point.pos.z }, - { point.pos.x + point.lineLen, point.pos.y, point.pos.z }, BLUE ) - RL_DrawLine3D( { point.pos.x, point.pos.y - point.lineLen, point.pos.z }, - { point.pos.x, point.pos.y + point.lineLen, point.pos.z }, BLUE ) - RL_DrawLine3D( { point.pos.x, point.pos.y, point.pos.z - point.lineLen }, - { point.pos.x, point.pos.y, point.pos.z + point.lineLen }, BLUE ) - RL_DrawSphereWires( point.pos, point.radius, 3, 8, point.color ) - RL_EndMode3D() - - RL_DrawText( 0, debugText, { 10, 10 }, 30, 4, WHITE ) +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + RL.UpdateCamera3D( camera ) + + RL.BeginMode3D( camera ) + RL.DrawGrid( 8, 1 ) + RL.DrawTriangle3D( tri.a, tri.b, tri.c, { 200, 100, 100 } ) + + RL.DrawLine3D( { point.pos.x - point.lineLen, point.pos.y, point.pos.z }, + { point.pos.x + point.lineLen, point.pos.y, point.pos.z }, RL.BLUE ) + RL.DrawLine3D( { point.pos.x, point.pos.y - point.lineLen, point.pos.z }, + { point.pos.x, point.pos.y + point.lineLen, point.pos.z }, RL.BLUE ) + RL.DrawLine3D( { point.pos.x, point.pos.y, point.pos.z - point.lineLen }, + { point.pos.x, point.pos.y, point.pos.z + point.lineLen }, RL.BLUE ) + RL.DrawSphereWires( point.pos, point.radius, 3, 8, point.color ) + RL.EndMode3D() + + RL.DrawText( 0, debugText, { 10, 10 }, 30, 4, RL.WHITE ) end diff --git a/examples/pong/main.lua b/examples/pong/main.lua index 7de5517..cc980ea 100644 --- a/examples/pong/main.lua +++ b/examples/pong/main.lua @@ -27,7 +27,7 @@ local function reset() -- Initialize player positions. playerLeft.pos[1] = playerLeft.size[1] playerLeft.pos[2] = winSize[2] / 2 - playerLeft.size[2] / 2 - + playerRight.pos[1] = winSize[1] - playerRight.size[1] * 2 playerRight.pos[2] = winSize[2] / 2 - playerRight.size[2] / 2 @@ -48,33 +48,33 @@ local function ballHit( padPos, padSize ) ball.vel[2] = BALL_SPEED * relHitPos / padSize[2] * 2 end -function init() +function RL.init() -- Set window to center of monitor. - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowTitle( "Pong" ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowTitle( "Pong" ) -- Initialize ball pos. math.randomseed( os.time() ) reset() end -function process( delta ) +function RL.process( delta ) -- Left player controls. - if RL_IsKeyDown( string.byte( "W" ) ) and 0 < playerLeft.pos[2] then + if RL.IsKeyDown( string.byte( "W" ) ) and 0 < playerLeft.pos[2] then playerLeft.pos[2] = playerLeft.pos[2] - PLAYER_SPEED * delta - elseif RL_IsKeyDown( string.byte( "S" ) ) and playerLeft.pos[2] + playerLeft.size[2] < winSize[2] then + elseif RL.IsKeyDown( string.byte( "S" ) ) and playerLeft.pos[2] + playerLeft.size[2] < winSize[2] then playerLeft.pos[2] = playerLeft.pos[2] + PLAYER_SPEED * delta end -- Right player controls. - if RL_IsKeyDown( KEY_UP ) and 0 < playerRight.pos[2] then + if RL.IsKeyDown( RL.KEY_UP ) and 0 < playerRight.pos[2] then playerRight.pos[2] = playerRight.pos[2] - PLAYER_SPEED * delta - elseif RL_IsKeyDown( KEY_DOWN ) and playerRight.pos[2] + playerRight.size[2] < winSize[2] then + elseif RL.IsKeyDown( RL.KEY_DOWN ) and playerRight.pos[2] + playerRight.size[2] < winSize[2] then playerRight.pos[2] = playerRight.pos[2] + PLAYER_SPEED * delta end @@ -94,9 +94,9 @@ function process( delta ) local playerRightRect = { playerRight.pos[1], playerRight.pos[2], playerRight.size[1], playerRight.size[2] } - if RL_CheckCollisionCircleRec( ball.pos, ball.radius, playerLeftRect ) and ball.vel[1] < 0 then + if RL.CheckCollisionCircleRec( ball.pos, ball.radius, playerLeftRect ) and ball.vel[1] < 0 then ballHit( playerLeft.pos, playerLeft.size ) - elseif RL_CheckCollisionCircleRec( ball.pos, ball.radius, playerRightRect ) and 0 < ball.vel[1] then + elseif RL.CheckCollisionCircleRec( ball.pos, ball.radius, playerRightRect ) and 0 < ball.vel[1] then ballHit( playerRight.pos, playerRight.size ) end @@ -110,18 +110,18 @@ function process( delta ) end end -function draw() - RL_ClearBackground( BLACK ) +function RL.draw() + RL.ClearBackground( RL.BLACK ) -- Draw players. - RL_DrawRectangle( { playerLeft.pos[1], playerLeft.pos[2], playerLeft.size[1], playerLeft.size[2] }, WHITE ) - RL_DrawRectangle( { playerRight.pos[1], playerRight.pos[2], playerRight.size[1], playerRight.size[2] }, WHITE ) + RL.DrawRectangle( { playerLeft.pos[1], playerLeft.pos[2], playerLeft.size[1], playerLeft.size[2] }, RL.WHITE ) + RL.DrawRectangle( { playerRight.pos[1], playerRight.pos[2], playerRight.size[1], playerRight.size[2] }, RL.WHITE ) -- Draw ball. Ball position will be the center in drawCircle. - RL_DrawCircle( ball.pos, ball.radius, WHITE ) + RL.DrawCircle( ball.pos, ball.radius, RL.WHITE ) -- Draw scire - RL_DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, WHITE ) - local rightTextSize = RL_MeasureText( 0, playerRight.score, 40, 2 ) - RL_DrawText( 0, playerRight.score, { winSize[1] - 50 - rightTextSize[1], 10 }, 40, 2, WHITE ) + RL.DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, RL.WHITE ) + local rightTextSize = RL.MeasureText( 0, playerRight.score, 40, 2 ) + RL.DrawText( 0, playerRight.score, { winSize[1] - 50 - rightTextSize[1], 10 }, 40, 2, RL.WHITE ) end diff --git a/examples/pong_vec/main.lua b/examples/pong_vec/main.lua index 4bf3d35..2b81452 100644 --- a/examples/pong_vec/main.lua +++ b/examples/pong_vec/main.lua @@ -1,6 +1,6 @@ -- Pong example using Vector2 library. -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" Vec2 = require "vector2" @@ -54,33 +54,33 @@ local function ballHit( padPos, padSize ) ball.vel.y = BALL_SPEED * relHitPos / padSize.y * 2 end -function init() +function RL.init() -- Set window to center of monitor. - local mPos = Vec2:new( RL_GetMonitorPosition( monitor ) ) - local mSize = Vec2:new( RL_GetMonitorSize( monitor ) ) + local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) + local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) - RL_SetConfigFlags( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) - RL_SetWindowTitle( "Pong" ) + RL.SetConfigFlags( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) + RL.SetWindowTitle( "Pong" ) -- Initialize ball pos. math.randomseed( os.time() ) reset() end -function process( delta ) +function RL.process( delta ) -- Left player controls. - if RL_IsKeyDown( KEY_W ) and 0 < playerLeft.pos.y then + if RL.IsKeyDown( RL.KEY_W ) and 0 < playerLeft.pos.y then playerLeft.pos.y = playerLeft.pos.y - PLAYER_SPEED * delta - elseif RL_IsKeyDown( KEY_S ) and playerLeft.pos.y + playerLeft.size.y < winSize.y then + elseif RL.IsKeyDown( RL.KEY_S ) and playerLeft.pos.y + playerLeft.size.y < winSize.y then playerLeft.pos.y = playerLeft.pos.y + PLAYER_SPEED * delta end -- Right player controls. - if RL_IsKeyDown( KEY_UP ) and 0 < playerRight.pos.y then + if RL.IsKeyDown( RL.KEY_UP ) and 0 < playerRight.pos.y then playerRight.pos.y = playerRight.pos.y - PLAYER_SPEED * delta - elseif RL_IsKeyDown( KEY_DOWN ) and playerRight.pos.y + playerRight.size.y < winSize.y then + elseif RL.IsKeyDown( RL.KEY_DOWN ) and playerRight.pos.y + playerRight.size.y < winSize.y then playerRight.pos.y = playerRight.pos.y + PLAYER_SPEED * delta end @@ -99,9 +99,9 @@ function process( delta ) local playerRightRect = { playerRight.pos.x, playerRight.pos.y, playerRight.size.x, playerRight.size.y } - if RL_CheckCollisionCircleRec( ball.pos, ball.radius, playerLeftRect ) and ball.vel.x < 0 then + if RL.CheckCollisionCircleRec( ball.pos, ball.radius, playerLeftRect ) and ball.vel.x < 0 then ballHit( playerLeft.pos, playerLeft.size ) - elseif RL_CheckCollisionCircleRec( ball.pos, ball.radius, playerRightRect ) and 0 < ball.vel.x then + elseif RL.CheckCollisionCircleRec( ball.pos, ball.radius, playerRightRect ) and 0 < ball.vel.x then ballHit( playerRight.pos, playerRight.size ) end @@ -115,18 +115,18 @@ function process( delta ) end end -function draw() - RL_ClearBackground( BLACK ) +function RL.draw() + RL.ClearBackground( RL.BLACK ) -- Draw players. - RL_DrawRectangle( { playerLeft.pos.x, playerLeft.pos.y, playerLeft.size.x, playerLeft.size.y }, WHITE ) - RL_DrawRectangle( { playerRight.pos.x, playerRight.pos.y, playerRight.size.x, playerRight.size.y }, WHITE ) + RL.DrawRectangle( { playerLeft.pos.x, playerLeft.pos.y, playerLeft.size.x, playerLeft.size.y }, RL.WHITE ) + RL.DrawRectangle( { playerRight.pos.x, playerRight.pos.y, playerRight.size.x, playerRight.size.y }, RL.WHITE ) -- Draw ball. Ball position will be the center in drawCircle. - RL_DrawCircle( ball.pos, ball.radius, WHITE ) + RL.DrawCircle( ball.pos, ball.radius, RL.WHITE ) -- Draw score. - RL_DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, WHITE ) - local rightTextSize = Vec2:new( RL_MeasureText( 0, playerRight.score, 40, 2 ) ) - RL_DrawText( 0, playerRight.score, { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, WHITE ) + RL.DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, RL.WHITE ) + local rightTextSize = Vec2:new( RL.MeasureText( 0, playerRight.score, 40, 2 ) ) + RL.DrawText( 0, playerRight.score, { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, RL.WHITE ) end diff --git a/examples/ray/main.lua b/examples/ray/main.lua index 0c594d0..18b7394 100644 --- a/examples/ray/main.lua +++ b/examples/ray/main.lua @@ -4,17 +4,17 @@ local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } } local function setupWindow() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) end function ray_collision() - local rayCol = RL_GetRayCollisionMesh( ray, sphereMesh, RL_MatrixIdentity() ) + local rayCol = RL.GetRayCollisionMesh( ray, sphereMesh, RL.MatrixIdentity() ) if rayCol ~= nil and rayCol.hit then print( "hit", rayCol.hit ) @@ -24,35 +24,35 @@ function ray_collision() end end -function init() +function RL.init() setupWindow() - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 0, 2, 4 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FREE ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 0, 2, 4 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FREE ) - sphereMesh = RL_GenMeshSphere( 1.0, 8, 10 ) + sphereMesh = RL.GenMeshSphere( 1.0, 8, 10 ) ray_collision() end -function process( delta ) - if RL_IsMouseButtonPressed( 0 ) then - ray = RL_GetMouseRay( RL_GetMousePosition(), camera ) +function RL.process( delta ) + if RL.IsMouseButtonPressed( 0 ) then + ray = RL.GetMouseRay( RL.GetMousePosition(), camera ) ray_collision() end end -function draw() - RL_ClearBackground( { 100, 150, 100 } ) - RL_UpdateCamera3D( camera ) - - RL_BeginMode3D( camera ) - RL_DrawGrid( 8, 1 ) - RL_DrawRay( ray, { 255, 100, 100 } ) +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + RL.UpdateCamera3D( camera ) - RL_DrawMesh( sphereMesh, 0, RL_MatrixIdentity() ) - RL_EndMode3D() + RL.BeginMode3D( camera ) + RL.DrawGrid( 8, 1 ) + RL.DrawRay( ray, { 255, 100, 100 } ) + + RL.DrawMesh( sphereMesh, 0, RL.MatrixIdentity() ) + RL.EndMode3D() end diff --git a/examples/resources/lib/gui.lua b/examples/resources/lib/gui.lua index 305fb47..8335247 100644 --- a/examples/resources/lib/gui.lua +++ b/examples/resources/lib/gui.lua @@ -10,7 +10,7 @@ Color = require( "color" ) To if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS || action == GLFW_REPEAT)) - Now GLFW_REPEAT can be read by "RL_GetKeyPressed". + Now GLFW_REPEAT can be read by "RL.GetKeyPressed". ]] Gui = { @@ -39,7 +39,7 @@ Gui = { RECTANGLE_ROUNDED_LINES = 8, }, - mouseButton = MOUSE_BUTTON_LEFT, + mouseButton = RL.MOUSE_BUTTON_LEFT, font = 0, fontSize = 20, padding = 2, @@ -114,12 +114,12 @@ function Gui.set2Back( cell ) end function Gui.process( mousePosition ) - local mouseWheel = RL_GetMouseWheelMove() + local mouseWheel = RL.GetMouseWheelMove() Gui._mousePos = mousePosition if Gui.heldCallback ~= nil then - if RL_IsMouseButtonDown( Gui.mouseButton ) then + if RL.IsMouseButtonDown( Gui.mouseButton ) then Gui.heldCallback() else Gui.heldCallback = nil @@ -129,7 +129,7 @@ function Gui.process( mousePosition ) end local foundFirst = false - + -- Go backwards on process check so we trigger the top most ui first and stop there. for i = #Gui._cells, 1, -1 do local cell = Gui._cells[i] @@ -137,11 +137,11 @@ function Gui.process( mousePosition ) if cell ~= nil then if not foundFirst and cell.isMouseOver ~= nil and cell:isMouseOver( mousePosition ) and not cell.disabled then -- On clicked. - if RL_IsMouseButtonPressed( Gui.mouseButton ) and cell.onClicked ~= nil then + if RL.IsMouseButtonPressed( Gui.mouseButton ) and cell.onClicked ~= nil then cell:onClicked() end -- On held. - if RL_IsMouseButtonDown( Gui.mouseButton ) and cell.onHeld ~= nil then + if RL.IsMouseButtonDown( Gui.mouseButton ) and cell.onHeld ~= nil then cell:onHeld() end -- Mouse wheel scrolling. @@ -149,19 +149,19 @@ function Gui.process( mousePosition ) if cell._parent ~= nil and cell._parent.scrollable then cell = cell._parent end - + if cell.scrollable then local pos = Vec2:new( cell._scrollRect.x, cell._scrollRect.y ) local scrollVec = Vec2:new( 0, cell.scrollAmount * mouseWheel ) - - if RL_IsKeyDown( KEY_LEFT_SHIFT ) then + + if RL.IsKeyDown( RL.KEY_LEFT_SHIFT ) then scrollVec = Vec2:new( cell.scrollAmount * mouseWheel, 0 ) end - + cell:scroll( pos - scrollVec ) end end - + foundFirst = true elseif cell.notMouseOver ~= nil then cell:notMouseOver() @@ -172,7 +172,7 @@ function Gui.process( mousePosition ) -- Text input. if Gui._inputItem ~= nil then repeat - local char = RL_GetCharPressed() + local char = RL.GetCharPressed() if 0 < char then if utf8.len( Gui._inputItem.text ) < Gui._inputItem.maxTextLen then @@ -183,24 +183,24 @@ function Gui.process( mousePosition ) until char == 0 repeat - local key = RL_GetKeyPressed() + local key = RL.GetKeyPressed() if 0 < key then - if key == KEY_BACKSPACE then + if key == RL.KEY_BACKSPACE then Gui._inputItem.text = util.utf8Sub( Gui._inputItem.text, 0, utf8.len( Gui._inputItem.text ) - 1 ) - elseif key == KEY_ENTER or key == KEY_KP_ENTER then + elseif key == RL.KEY_ENTER or key == RL.KEY_KP_ENTER then if Gui._inputItem.allowLineBreak then Gui._inputItem.text = Gui._inputItem.text.."\n" else Gui.inputUnfocus() end - elseif key == KEY_ESCAPE then + elseif key == RL.KEY_ESCAPE then Gui.inputUnfocus() end end until key == 0 - if readyToUnfocusInput and RL_IsMouseButtonPressed( Gui.mouseButton ) then + if readyToUnfocusInput and RL.IsMouseButtonPressed( Gui.mouseButton ) then Gui.inputUnfocus() end @@ -234,7 +234,7 @@ function Text:new( set ) object.text = setProperty( set, "text", "" ) object.fontSize = setProperty( set, "fontSize", Gui.fontSize ) object.spacing = setProperty( set, "spacing", Gui.spacing ) - object.color = setProperty( set, "color", Color:new( BLACK ) ) + object.color = setProperty( set, "color", Color:new( RL.BLACK ) ) object.maxTextLen = setProperty( set, "maxTextLen", nil ) object.allowLineBreak = setProperty( set, "allowLineBreak", false ) @@ -253,7 +253,7 @@ function Text:set( text ) self.text = text end - local textSize = Vec2:new( RL_MeasureText( self.font, self.text, self.fontSize, self.spacing ) ) + local textSize = Vec2:new( RL.MeasureText( self.font, self.text, self.fontSize, self.spacing ) ) self.bounds.width = textSize.x self.bounds.height = textSize.y @@ -264,7 +264,7 @@ function Text:draw() return end - RL_DrawText( self.font, self.text, { self._parent.bounds.x + self.bounds.x, self._parent.bounds.y + self.bounds.y }, self.fontSize, self.spacing, self.color ) + RL.DrawText( self.font, self.text, { self._parent.bounds.x + self.bounds.x, self._parent.bounds.y + self.bounds.y }, self.fontSize, self.spacing, self.color ) end -- Texture. @@ -283,7 +283,7 @@ function Texture:new( set ) object.source = setProperty( set, "source", Rect:new( 0, 0, 0, 0 ) ) object.origin = setProperty( set, "origin", Vec2:new( 0, 0 ) ) object.rotation = setProperty( set, "rotation", 0 ) - object.color = setProperty( set, "color", Color:new( WHITE ) ) + object.color = setProperty( set, "color", Color:new( RL.WHITE ) ) object.nPatchInfo = setProperty( set, "nPatchInfo", nil ) object.visible = setProperty( set, "visible", true ) @@ -299,7 +299,7 @@ function Texture:set( texture ) return end - local texSize = Vec2:new( RL_GetTextureSize( texture ) ) + local texSize = Vec2:new( RL.GetTextureSize( texture ) ) if self.bounds.width == 0 or self.bounds.height == 0 then self.bounds.width = texSize.x @@ -326,9 +326,9 @@ function Texture:draw() } if self.nPatchInfo ~= nil then - RL_DrawTextureNPatch( self.texture, self.nPatchInfo, dst, self.origin, self.rotation, self.color ) + RL.DrawTextureNPatch( self.texture, self.nPatchInfo, dst, self.origin, self.rotation, self.color ) else - RL_DrawTexturePro( self.texture, self.source, dst, self.origin, self.rotation, self.color ) + RL.DrawTexturePro( self.texture, self.source, dst, self.origin, self.rotation, self.color ) end end @@ -359,7 +359,7 @@ function Shape:new( set ) object.roundness = setProperty( set, "roundness", 1 ) object.segments = setProperty( set, "segments", 4 ) - object.color = setProperty( set, "color", Color:new( WHITE ) ) + object.color = setProperty( set, "color", Color:new( RL.WHITE ) ) object.visible = setProperty( set, "visible", true ) object._parent = nil @@ -392,23 +392,23 @@ function Shape:draw() local pos = Vec2:new( self._parent.bounds.x, self._parent.bounds.y ) if self.shape == Gui.SHAPE.LINE then - RL_DrawLine( self.startPos + pos, self.endPos + pos, self.thickness, self.color ) + RL.DrawLine( self.startPos + pos, self.endPos + pos, self.thickness, self.color ) elseif self.shape == Gui.SHAPE.CIRCLE then - RL_DrawCircle( self.center + pos, self.radius, self.color ) + RL.DrawCircle( self.center + pos, self.radius, self.color ) elseif self.shape == Gui.SHAPE.CIRCLE_LINES then - RL_DrawCircleLines( self.center + pos, self.radius, self.color ) + RL.DrawCircleLines( self.center + pos, self.radius, self.color ) elseif self.shape == Gui.SHAPE.ELLIPSE then - RL_DrawEllipse( self.center + pos, self.radiusH, self.radiusV, self.color ) + RL.DrawEllipse( self.center + pos, self.radiusH, self.radiusV, self.color ) elseif self.shape == Gui.SHAPE.ELLIPSE_LINES then - RL_DrawEllipseLines( self.center + pos, self.radiusH, self.radiusV, self.color ) + RL.DrawEllipseLines( self.center + pos, self.radiusH, self.radiusV, self.color ) elseif self.shape == Gui.SHAPE.RECTANGLE then - RL_DrawRectangle( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.color ) + RL.DrawRectangle( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.color ) elseif self.shape == Gui.SHAPE.RECTANGLE_LINES then - RL_DrawRectangleLines( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.color ) + RL.DrawRectangleLines( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.color ) elseif self.shape == Gui.SHAPE.RECTANGLE_ROUNDED then - RL_DrawRectangleRounded( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.roundness, self.segments, self.color ) + RL.DrawRectangleRounded( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.roundness, self.segments, self.color ) elseif self.shape == Gui.SHAPE.RECTANGLE_ROUNDED_LINES then - RL_DrawRectangleRoundedLines( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.roundness, self.segments, self.thickness, self.color ) + RL.DrawRectangleRoundedLines( { self.bounds.x + pos.x, self.bounds.y + pos.y, self.bounds.width, self.bounds.height }, self.roundness, self.segments, self.thickness, self.color ) end end @@ -428,10 +428,10 @@ function Element:new( set ) object.visible = setProperty( set, "visible", true ) object.disabled = setProperty( set, "disabled", false ) object.drawBounds = setProperty( set, "drawBounds", false ) - object.color = setProperty( set, "color", Color:new( GRAY ) ) + object.color = setProperty( set, "color", Color:new( RL.GRAY ) ) object.items = {} - + object._visibilityBounds = nil -- Callbacks. object.onMouseOver = setProperty( set, "onMouseOver", nil ) @@ -481,10 +481,10 @@ function Element:add( item ) end function Element:isMouseOver( mousePosition ) - local over = RL_CheckCollisionPointRec( mousePosition, self.bounds ) + local over = RL.CheckCollisionPointRec( mousePosition, self.bounds ) if over and self._visibilityBounds ~= nil then - over = RL_CheckCollisionPointRec( mousePosition, self._visibilityBounds ) + over = RL.CheckCollisionPointRec( mousePosition, self._visibilityBounds ) end if over and self.onMouseOver ~= nil then @@ -498,7 +498,7 @@ function Element:draw() local usedScissor = false if self._visibilityBounds ~= nil then - local rect = Rect:new( RL_GetCollisionRec( self.bounds, self._visibilityBounds ) ) + local rect = Rect:new( RL.GetCollisionRec( self.bounds, self._visibilityBounds ) ) -- Use scissor mode only on partyally visible. if rect.width == 0 and rect.height == 0 then @@ -506,12 +506,12 @@ function Element:draw() elseif math.floor( rect.width ) ~= math.floor( self.bounds.width ) or math.floor( rect.height ) ~= math.floor( self.bounds.height ) then usedScissor = true - RL_BeginScissorMode( self._visibilityBounds ) + RL.BeginScissorMode( self._visibilityBounds ) end end - + if self.drawBounds then - RL_DrawRectangle( self.bounds, self.color ) + RL.DrawRectangle( self.bounds, self.color ) end for _, item in ipairs( self.items ) do @@ -519,7 +519,7 @@ function Element:draw() end if usedScissor then - RL_EndScissorMode() + RL.EndScissorMode() end end @@ -557,15 +557,15 @@ function Container:new( set ) object.showScrollbar = setProperty( set, "showScrollbar", false ) object.scrollbarWidth = setProperty( set, "scrollbarWidth", Gui.scrollbarWidth ) object.scrollAmount = setProperty( set, "scrollAmount", Gui.scrollAmount ) -- When using mouse scroll. - object.color = setProperty( set, "color", Color:new( WHITE ) ) + object.color = setProperty( set, "color", Color:new( RL.WHITE ) ) object.drawBounds = setProperty( set, "drawBounds", false ) object.drawScrollRect = setProperty( set, "drawScrollRect", false ) -- For grid container. Do not set both. object.columns = setProperty( set, "columns", nil ) object.rows = setProperty( set, "rows", nil ) - + object.cells = {} - + object._visibilityBounds = nil -- Will give this to it's children. object._scrollRect = Rect:new( 0, 0, 0, 0 ) object._VScrollbarRect = Rect:new( 0, 0, 0, 0 ) @@ -638,10 +638,10 @@ function Container:mouseScroll( v ) end function Container:isMouseOver( mousePosition ) - local over = RL_CheckCollisionPointRec( mousePosition, self.bounds ) + local over = RL.CheckCollisionPointRec( mousePosition, self.bounds ) if over and self._visibilityBounds ~= nil then - over = RL_CheckCollisionPointRec( mousePosition, self._visibilityBounds ) + over = RL.CheckCollisionPointRec( mousePosition, self._visibilityBounds ) end if over and self.onMouseOver ~= nil then @@ -668,7 +668,7 @@ function Container:updateScrollbar() self._VScrollbar.visible = false self._VScrollbar.disabled = true end - + if self.bounds.width < self._scrollRect.width then self._HScrollbar.bounds.width = self.bounds.width self._HScrollbar.bounds.height = self.scrollbarWidth @@ -701,7 +701,7 @@ function Container:update() self._VScrollbar = Element:new( { padding = 0, drawBounds = true, - color = Color:new( GRAY ), + color = Color:new( RL.GRAY ), onClicked = function() Gui.heldCallback = function() self:mouseScroll( Vec2:new( 0, 1 ) ) end end, } ) @@ -710,7 +710,7 @@ function Container:update() VAling = Gui.ALING.NONE, bounds = Rect:new( 0, 0, 0, 0 ), shape = Gui.SHAPE.RECTANGLE_ROUNDED, - color = Color:new( LIGHTGRAY ), + color = Color:new( RL.LIGHTGRAY ), } ) ) end @@ -718,7 +718,7 @@ function Container:update() self._HScrollbar = Element:new( { padding = 0, drawBounds = true, - color = Color:new( GRAY ), + color = Color:new( RL.GRAY ), onClicked = function() Gui.heldCallback = function() self:mouseScroll( Vec2:new( 1, 0 ) ) end end, } ) @@ -727,7 +727,7 @@ function Container:update() VAling = Gui.ALING.CENTER, bounds = Rect:new( 0, 0, 0, 0 ), shape = Gui.SHAPE.RECTANGLE_ROUNDED, - color = Color:new( LIGHTGRAY ), + color = Color:new( RL.LIGHTGRAY ), } ) ) end end @@ -748,7 +748,7 @@ function Container:update() elseif self.HAling == Gui.ALING.RIGHT then pos.x = self.bounds.x + self.bounds.width - cell.bounds.width - self.spacing end - + cell.bounds.x = pos.x - self._scrollRect.x cell.bounds.y = pos.y - self._scrollRect.y @@ -811,7 +811,7 @@ function Container:delete() for _, cell in ipairs( self.cells ) do cell:delete() end - + if self._VScrollbar ~= nil then Gui.delete( self._VScrollbar ) end @@ -828,7 +828,7 @@ function Container:set2Top() for _, cell in ipairs( self.cells ) do cell:set2Top() end - + if self._VScrollbar ~= nil then Gui.set2Top( self._VScrollbar ) end @@ -844,27 +844,27 @@ function Container:set2Back() if self._HScrollbar ~= nil then Gui.set2Back( self._HScrollbar ) end - + for _, cell in ipairs( self.cells ) do cell:set2Back() end - + Gui.set2Back( self ) end function Container:draw() if self.drawBounds then - RL_DrawRectangle( self.bounds, self.color ) + RL.DrawRectangle( self.bounds, self.color ) end if self.drawScrollRect then - RL_DrawRectangleLines( { + RL.DrawRectangleLines( { self.bounds.x - self._scrollRect.x, self.bounds.y - self._scrollRect.y, self._scrollRect.width, self._scrollRect.height, }, - RED ) + RL.RED ) end end diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua index 7fb7405..3021465 100644 --- a/examples/resources/lib/utillib.lua +++ b/examples/resources/lib/utillib.lua @@ -15,7 +15,7 @@ function utillib.deepCopy( orig ) for origKey, origValue in next, orig, nil do -- If object has clone method, use that. if type( origValue ) == "table" and type( origValue.clone ) == "function" then - copy[ utillib.deepCopy( origKey ) ] = orig_value:clone() + copy[ utillib.deepCopy( origKey ) ] = origValue:clone() else copy[ utillib.deepCopy( origKey ) ] = utillib.deepCopy( origValue ) end @@ -128,9 +128,9 @@ end function utillib.wrapAngleRad( angle ) if angle < 0 then - return math.fmod( angle, PI * 2 ) + PI * 2 + return math.fmod( angle, RL.PI * 2 ) + RL.PI * 2 else - return math.fmod( angle, PI * 2 ) + return math.fmod( angle, RL.PI * 2 ) end end diff --git a/examples/resources/lib/vector2.lua b/examples/resources/lib/vector2.lua index 70a2a35..65452cf 100644 --- a/examples/resources/lib/vector2.lua +++ b/examples/resources/lib/vector2.lua @@ -38,7 +38,7 @@ Vector2.meta = { return len end, __eq = function( v1, v2 ) - return RL_Vector2Equals( v1, v2 ) == 1 + return RL.Vector2Equals( v1, v2 ) == 1 end, } @@ -91,79 +91,79 @@ function Vector2:max( v2 ) end function Vector2:addValue( value ) - return Vector2:new( RL_Vector2AddValue( self, value ) ) + return Vector2:new( RL.Vector2AddValue( self, value ) ) end function Vector2:subValue( value ) - return Vector2:new( RL_Vector2SubtractValue( self, value ) ) + return Vector2:new( RL.Vector2SubtractValue( self, value ) ) end function Vector2:length() - return RL_Vector2Length( self ) + return RL.Vector2Length( self ) end function Vector2:lengthSqr() - return RL_Vector2LengthSqr( self ) + return RL.Vector2LengthSqr( self ) end function Vector2:dot( v2 ) - return RL_Vector2DotProduct( self, v2 ) + return RL.Vector2DotProduct( self, v2 ) end function Vector2:distance( v2 ) - return RL_Vector2Distance( self, v2 ) + return RL.Vector2Distance( self, v2 ) end function Vector2:distanceSqr( v2 ) - return RL_Vector2DistanceSqr( self, v2 ) + return RL.Vector2DistanceSqr( self, v2 ) end function Vector2:angle( v2 ) - return RL_Vector2Angle( self, v2 ) + return RL.Vector2Angle( self, v2 ) end function Vector2:scale( scale ) - return Vector2:new( RL_Vector2Scale( self, scale ) ) + return Vector2:new( RL.Vector2Scale( self, scale ) ) end function Vector2:normalize() - return Vector2:new( RL_Vector2Normalize( self ) ) + return Vector2:new( RL.Vector2Normalize( self ) ) end function Vector2:transform( mat ) - return Vector2:new( RL_Vector2Transform( self, mat ) ) + return Vector2:new( RL.Vector2Transform( self, mat ) ) end function Vector2:lerp( v2, value ) - return Vector2:new( RL_Vector2Lerp( self, v2, value ) ) + return Vector2:new( RL.Vector2Lerp( self, v2, value ) ) end function Vector2:reflect( normal ) - return Vector2:new( RL_Vector2Reflect( self, normal ) ) + return Vector2:new( RL.Vector2Reflect( self, normal ) ) end function Vector2:rotate( angle ) - return Vector2:new( RL_Vector2Rotate( self, angle ) ) + return Vector2:new( RL.Vector2Rotate( self, angle ) ) end function Vector2:moveTowards( target, maxDistance ) - return Vector2:new( RL_Vector2MoveTowards( self, target, maxDistance ) ) + return Vector2:new( RL.Vector2MoveTowards( self, target, maxDistance ) ) end function Vector2:invert() - return Vector2:new( RL_Vector2Invert( self ) ) + return Vector2:new( RL.Vector2Invert( self ) ) end function Vector2:clamp( min, max ) - return Vector2:new( RL_Vector2Clamp( self, min, max ) ) + return Vector2:new( RL.Vector2Clamp( self, min, max ) ) end function Vector2:clampValue( min, max ) - return Vector2:new( RL_Vector2ClampValue( self, min, max ) ) + return Vector2:new( RL.Vector2ClampValue( self, min, max ) ) end function Vector2:equals( v2 ) - return RL_Vector2Equals( self, v2 ) + return RL.Vector2Equals( self, v2 ) end return Vector2 diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua index b93601e..2a25a5f 100644 --- a/examples/resources/lib/vector3.lua +++ b/examples/resources/lib/vector3.lua @@ -38,7 +38,7 @@ Vector3.meta = { return len end, __eq = function( v1, v2 ) - return RL_Vector3Equals( v1, v2 ) == 1 + return RL.Vector3Equals( v1, v2 ) == 1 end, } @@ -85,104 +85,104 @@ function Vector3:abs() end function Vector3:min( v2 ) - return Vector3:new( RL_Vector3Min( self, v2 ) ) + return Vector3:new( RL.Vector3Min( self, v2 ) ) end function Vector3:max( v2 ) - return Vector3:new( RL_Vector3Max( self, v2 ) ) + return Vector3:new( RL.Vector3Max( self, v2 ) ) end function Vector3:addValue( value ) - return Vector3:new( RL_Vector3AddValue( self, value ) ) + return Vector3:new( RL.Vector3AddValue( self, value ) ) end function Vector3:subValue( value ) - return Vector3:new( RL_Vector3SubtractValue( self, value ) ) + return Vector3:new( RL.Vector3SubtractValue( self, value ) ) end function Vector3:scale( scalar ) - return Vector3:new( RL_Vector3Scale( self, scalar ) ) + return Vector3:new( RL.Vector3Scale( self, scalar ) ) end function Vector3:cross( v2 ) - return Vector3:new( RL_Vector3CrossProduct( self, v2 ) ) + return Vector3:new( RL.Vector3CrossProduct( self, v2 ) ) end function Vector3:perpendicular() - return Vector3:new( RL_Vector3Perpendicular( self ) ) + return Vector3:new( RL.Vector3Perpendicular( self ) ) end function Vector3:length() - return RL_Vector3Length( self ) + return RL.Vector3Length( self ) end function Vector3:lengthSqr() - return RL_Vector3LengthSqr( self ) + return RL.Vector3LengthSqr( self ) end function Vector3:dot( v2 ) - return RL_Vector3DotProduct( self, v2 ) + return RL.Vector3DotProduct( self, v2 ) end function Vector3:distance( v2 ) - return RL_Vector3Distance( self, v2 ) + return RL.Vector3Distance( self, v2 ) end function Vector3:distanceSqr( v2 ) - return RL_Vector3DistanceSqr( self, v2 ) + return RL.Vector3DistanceSqr( self, v2 ) end function Vector3:angle( v2 ) - return RL_Vector3Angle( self, v2 ) + return RL.Vector3Angle( self, v2 ) end function Vector3:negate() - return Vector3:new( RL_Vector3Negate( self ) ) + return Vector3:new( RL.Vector3Negate( self ) ) end function Vector3:normalize() - return Vector3:new( RL_Vector3Normalize( self ) ) + return Vector3:new( RL.Vector3Normalize( self ) ) end function Vector3:orthoNormalize( v2 ) - local r1, r2 = RL_Vector3OrthoNormalize( self, v2 ) + local r1, r2 = RL.Vector3OrthoNormalize( self, v2 ) return Vector3:new( r1[1], r1[2], r1[3] ), Vector3:new( r2[1], r2[2], r2[3] ) end function Vector3:transform( mat ) - return Vector3:new( RL_Vector3Transform( self, mat ) ) + return Vector3:new( RL.Vector3Transform( self, mat ) ) end function Vector3:rotateByQuaternion( q ) - return Vector3:new( RL_Vector3RotateByQuaternion( self, q ) ) + return Vector3:new( RL.Vector3RotateByQuaternion( self, q ) ) end function Vector3:rotateByAxisAngle( axis, angle ) - return Vector3:new( RL_Vector3RotateByAxisAngle( self, axis, angle ) ) + return Vector3:new( RL.Vector3RotateByAxisAngle( self, axis, angle ) ) end function Vector3:lerp( v2, value ) - return Vector3:new( RL_Vector3Lerp( self, v2, value ) ) + return Vector3:new( RL.Vector3Lerp( self, v2, value ) ) end function Vector3:reflect( normal ) - return Vector3:new( RL_Vector3Reflect( self, normal ) ) + return Vector3:new( RL.Vector3Reflect( self, normal ) ) end function Vector3:invert() - return Vector3:new( RL_Vector3Invert( self ) ) + return Vector3:new( RL.Vector3Invert( self ) ) end function Vector3:clamp( min, max ) - return Vector3:new( RL_Vector3Clamp( self, min, max ) ) + return Vector3:new( RL.Vector3Clamp( self, min, max ) ) end function Vector3:clampValue( min, max ) - return Vector3:new( RL_Vector3ClampValue( self, min, max ) ) + return Vector3:new( RL.Vector3ClampValue( self, min, max ) ) end function Vector3:equals( v2 ) - return RL_Vector3Equals( self, v2 ) + return RL.Vector3Equals( self, v2 ) end return Vector3 diff --git a/examples/shaders/main.lua b/examples/shaders/main.lua index a91f1ee..e5f59ed 100644 --- a/examples/shaders/main.lua +++ b/examples/shaders/main.lua @@ -8,27 +8,27 @@ local GLSL_VERSION = "330" -- PLATFORM_DESKTOP local secondsLoc -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() - - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - - texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" ) - textureSize = RL_GetTextureSize( texture ) - shader = RL_LoadShader( nil, RL_GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/wave.fs" ) - - secondsLoc = RL_GetShaderLocation( shader, "secondes" ) - local sizeLoc = RL_GetShaderLocation( shader, "size" ) - local freqXLoc = RL_GetShaderLocation( shader, "freqX" ) - local freqYLoc = RL_GetShaderLocation( shader, "freqY" ) - local ampXLoc = RL_GetShaderLocation( shader, "ampX" ) - local ampYLoc = RL_GetShaderLocation( shader, "ampY" ) - local speedXLoc = RL_GetShaderLocation( shader, "speedX" ) - local speedYLoc = RL_GetShaderLocation( shader, "speedY" ) +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() + + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + + texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) + textureSize = RL.GetTextureSize( texture ) + shader = RL.LoadShader( nil, RL.GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/wave.fs" ) + + secondsLoc = RL.GetShaderLocation( shader, "secondes" ) + local sizeLoc = RL.GetShaderLocation( shader, "size" ) + local freqXLoc = RL.GetShaderLocation( shader, "freqX" ) + local freqYLoc = RL.GetShaderLocation( shader, "freqY" ) + local ampXLoc = RL.GetShaderLocation( shader, "ampX" ) + local ampYLoc = RL.GetShaderLocation( shader, "ampY" ) + local speedXLoc = RL.GetShaderLocation( shader, "speedX" ) + local speedYLoc = RL.GetShaderLocation( shader, "speedY" ) local freqX = 25.0 local freqY = 25.0 @@ -37,25 +37,25 @@ function init() local speedX = 8.0 local speedY = 8.0 - RL_SetShaderValue( shader, sizeLoc, textureSize, SHADER_UNIFORM_VEC2 ) - RL_SetShaderValue( shader, freqXLoc, { freqX }, SHADER_UNIFORM_FLOAT ) - RL_SetShaderValue( shader, freqYLoc, { freqY }, SHADER_UNIFORM_FLOAT ) - RL_SetShaderValue( shader, ampXLoc, { ampX }, SHADER_UNIFORM_FLOAT ) - RL_SetShaderValue( shader, ampYLoc, { ampY }, SHADER_UNIFORM_FLOAT ) - RL_SetShaderValue( shader, speedXLoc, { speedX }, SHADER_UNIFORM_FLOAT ) - RL_SetShaderValue( shader, speedYLoc, { speedY }, SHADER_UNIFORM_FLOAT ) + RL.SetShaderValue( shader, sizeLoc, textureSize, RL.SHADER_UNIFORM_VEC2 ) + RL.SetShaderValue( shader, freqXLoc, { freqX }, RL.SHADER_UNIFORM_FLOAT ) + RL.SetShaderValue( shader, freqYLoc, { freqY }, RL.SHADER_UNIFORM_FLOAT ) + RL.SetShaderValue( shader, ampXLoc, { ampX }, RL.SHADER_UNIFORM_FLOAT ) + RL.SetShaderValue( shader, ampYLoc, { ampY }, RL.SHADER_UNIFORM_FLOAT ) + RL.SetShaderValue( shader, speedXLoc, { speedX }, RL.SHADER_UNIFORM_FLOAT ) + RL.SetShaderValue( shader, speedYLoc, { speedY }, RL.SHADER_UNIFORM_FLOAT ) end local seconds = 0.0 -function draw() - seconds = seconds + RL_GetFrameTime(); +function RL.draw() + seconds = seconds + RL.GetFrameTime(); - RL_SetShaderValue( shader, secondsLoc, { seconds }, SHADER_UNIFORM_FLOAT ); + RL.SetShaderValue( shader, secondsLoc, { seconds }, RL.SHADER_UNIFORM_FLOAT ); - RL_ClearBackground( { 100, 150, 100 } ) + RL.ClearBackground( { 100, 150, 100 } ) - RL_BeginShaderMode( shader ) - RL_DrawTexture( texture, { 0, 0 }, WHITE ); - RL_EndShaderMode() + RL.BeginShaderMode( shader ) + RL.DrawTexture( texture, { 0, 0 }, RL.WHITE ); + RL.EndShaderMode() end diff --git a/examples/snake/main.lua b/examples/snake/main.lua index dd752e4..0f07317 100644 --- a/examples/snake/main.lua +++ b/examples/snake/main.lua @@ -7,8 +7,8 @@ local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum wannabe. -- Resources local framebuffer = -1 local monitor = 0 -local monitorPos = RL_GetMonitorPosition( monitor ) -local monitorSize = RL_GetMonitorSize( monitor ) +local monitorPos = RL.GetMonitorPosition( monitor ) +local monitorSize = RL.GetMonitorSize( monitor ) local winScale = 6 local winSize = { RESOLUTION[1] * winScale, RESOLUTION[2] * winScale } local gameState = STATE.GAME @@ -64,18 +64,18 @@ end -- Init. -function init() - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { monitorPos[1] + monitorSize[1] / 2 - winSize[1] / 2, monitorPos[2] + monitorSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowTitle( "Snake" ) - RL_SetWindowIcon( RL_LoadImage( RL_GetBasePath().."../resources/images/apple.png" ) ) +function RL.init() + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { monitorPos[1] + monitorSize[1] / 2 - winSize[1] / 2, monitorPos[2] + monitorSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowTitle( "Snake" ) + RL.SetWindowIcon( RL.LoadImage( RL.GetBasePath().."../resources/images/apple.png" ) ) - framebuffer = RL_LoadRenderTexture( RESOLUTION ) - grassTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/grass.png" ) - snakeTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/snake.png" ) - appleTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/apple.png" ) + framebuffer = RL.LoadRenderTexture( RESOLUTION ) + grassTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/grass.png" ) + snakeTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/snake.png" ) + appleTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/apple.png" ) setSnake() setApplePos() @@ -122,25 +122,25 @@ local function moveSnake() moveTimer = moveTimer + 1.0 end -function process( delta ) +function RL.process( delta ) if gameState == STATE.GAME then -- Run game. -- Controls. - if RL_IsKeyPressed( KEY_RIGHT ) and 0 <= snake.heading[1] then + if RL.IsKeyPressed( RL.KEY_RIGHT ) and 0 <= snake.heading[1] then snake.control = { 1, 0 } - elseif RL_IsKeyPressed( KEY_LEFT ) and snake.heading[1] <= 0 then + elseif RL.IsKeyPressed( RL.KEY_LEFT ) and snake.heading[1] <= 0 then snake.control = { -1, 0 } - elseif RL_IsKeyPressed( KEY_DOWN ) and 0 <= snake.heading[2] then + elseif RL.IsKeyPressed( RL.KEY_DOWN ) and 0 <= snake.heading[2] then snake.control = { 0, 1 } - elseif RL_IsKeyPressed( KEY_UP ) and snake.heading[2] <= 0 then + elseif RL.IsKeyPressed( RL.KEY_UP ) and snake.heading[2] <= 0 then snake.control = { 0, -1 } end - + moveTimer = moveTimer - gameSpeed * delta - + if moveTimer <= 0.0 then moveSnake() end - elseif gameState == STATE.OVER and RL_IsKeyPressed( KEY_ENTER ) then -- Reset game. + elseif gameState == STATE.OVER and RL.IsKeyPressed( RL.KEY_ENTER ) then -- Reset game. setSnake() setApplePos() gameState = STATE.GAME @@ -152,7 +152,7 @@ end local function drawGrass() for y = 0, LEVEL_SIZE - 1 do for x = 0, LEVEL_SIZE - 1 do - RL_DrawTexture( grassTexture, { x * TILE_SIZE, y * TILE_SIZE }, WHITE ) + RL.DrawTexture( grassTexture, { x * TILE_SIZE, y * TILE_SIZE }, RL.WHITE ) end end end @@ -168,14 +168,14 @@ end local function drawSnake() for i, seg in ipairs( snake.segments ) do - local angle = math.deg( RL_Vector2Angle( { 0, 0 }, seg.heading ) ) + local angle = math.deg( RL.Vector2Angle( { 0, 0 }, seg.heading ) ) local source = { 16, 0, 8, 8 } if i == 1 then -- Tail segment. Yes tail is actually the 'first' segment. source[1] = 8 if 1 < #snake.segments then - angle = math.deg( RL_Vector2Angle( { 0, 0 }, snake.segments[ 2 ].heading ) ) + angle = math.deg( RL.Vector2Angle( { 0, 0 }, snake.segments[ 2 ].heading ) ) end elseif i < #snake.segments and not vector2IsEqual( seg.heading, snake.segments[ i+1 ].heading ) then -- Turned middle segments. source[1] = 0 @@ -191,34 +191,34 @@ local function drawSnake() end end -- Notice that we set the origin to center { 4, 4 } that acts as pivot point. We also have to adjust our dest position by 4. - RL_DrawTexturePro( snakeTexture, source, { seg.pos[1] * TILE_SIZE + 4, seg.pos[2] * TILE_SIZE + 4, 8, 8 }, { 4, 4 }, angle, WHITE ) + RL.DrawTexturePro( snakeTexture, source, { seg.pos[1] * TILE_SIZE + 4, seg.pos[2] * TILE_SIZE + 4, 8, 8 }, { 4, 4 }, angle, RL.WHITE ) end -- Let's draw the head last to keep it on top. - local angle = math.deg( RL_Vector2Angle( { 0, 0 }, snake.heading ) ) - RL_DrawTexturePro( snakeTexture, { 24, 0, 8, 8 }, { snake.headPos[1] * TILE_SIZE + 4, snake.headPos[2] * TILE_SIZE + 4, 8, 8 }, { 4, 4 }, angle, WHITE ) + local angle = math.deg( RL.Vector2Angle( { 0, 0 }, snake.heading ) ) + RL.DrawTexturePro( snakeTexture, { 24, 0, 8, 8 }, { snake.headPos[1] * TILE_SIZE + 4, snake.headPos[2] * TILE_SIZE + 4, 8, 8 }, { 4, 4 }, angle, RL.WHITE ) end local function drawApple() - RL_DrawTexture( appleTexture, { applePos[1] * TILE_SIZE, applePos[2] * TILE_SIZE }, WHITE ) + RL.DrawTexture( appleTexture, { applePos[1] * TILE_SIZE, applePos[2] * TILE_SIZE }, RL.WHITE ) end -function draw() +function RL.draw() -- Clear the window to black. - RL_ClearBackground( BLACK ) + RL.ClearBackground( RL.BLACK ) -- Draw to framebuffer. - RL_BeginTextureMode( framebuffer ) - RL_ClearBackground( BLACK ) + RL.BeginTextureMode( framebuffer ) + RL.ClearBackground( RL.BLACK ) drawGrass() drawSnake() drawApple() if gameState == STATE.OVER then - RL_DrawText( 0, "Press Enter to\nrestart", { 10, 10 }, 10, 2, WHITE ) + RL.DrawText( 0, "Press Enter to\nrestart", { 10, 10 }, 10, 2, RL.WHITE ) end - RL_EndTextureMode() + RL.EndTextureMode() -- Draw framebuffer to window. - RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) - RL_DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) - RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE ) + RL.DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, RL.WHITE ) + RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE ) end diff --git a/examples/waving_cubes/main.lua b/examples/waving_cubes/main.lua index eab9758..d8cd143 100644 --- a/examples/waving_cubes/main.lua +++ b/examples/waving_cubes/main.lua @@ -9,40 +9,40 @@ local camera = -1 local num_blocks = 15 -function init() +function RL.init() local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - local winSize = RL_GetScreenSize() - - RL_SetWindowTitle( "Waving cubes" ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = RL.GetScreenSize() - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 30, 20, 30 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetWindowTitle( "Waving cubes" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 30, 20, 30 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) end -function draw() - local t = RL_GetTime() +function RL.draw() + local t = RL.GetTime() local cos = math.cos local sin = math.sin local scale = (2.0 + sin(t)) * 0.7 local camera_time = t * 0.3 - local camera_pos = RL_GetCamera3DPosition( camera ) + local camera_pos = RL.GetCamera3DPosition( camera ) camera_pos[1] = cos(camera_time) * 40.0 camera_pos[3] = sin(camera_time) * 40.0 - - RL_SetCamera3DPosition( camera, camera_pos ) - RL_ClearBackground( RAYWHITE ) - RL_BeginMode3D( camera ) - RL_DrawGrid( 10, 5.0 ) + RL.SetCamera3DPosition( camera, camera_pos ) + RL.ClearBackground( RL.RAYWHITE ) + + RL.BeginMode3D( camera ) + RL.DrawGrid( 10, 5.0 ) for x = 0,num_blocks - 1 do for y = 0,num_blocks - 1 do @@ -55,14 +55,14 @@ function draw() (y - num_blocks / 2) * (scale * 2.0) + scatter, (z - num_blocks / 2) * (scale * 3.0) + scatter } - local cube_color = RL_ColorFromHSV( (((x + y + z) * 18) % 360), 0.75, 0.9 ) + local cube_color = RL.ColorFromHSV( (((x + y + z) * 18) % 360), 0.75, 0.9 ) local cube_size = (2.4 - scale) * block_scale - RL_DrawCube( cube_pos, { cube_size, cube_size, cube_size }, cube_color ) + RL.DrawCube( cube_pos, { cube_size, cube_size, cube_size }, cube_color ) end end end - RL_EndMode3D() + RL.EndMode3D() - RL_DrawFPS( { 10, 10 } ) + RL.DrawFPS( { 10, 10 } ) end diff --git a/examples/window/main.lua b/examples/window/main.lua index 1fa5744..9816188 100644 --- a/examples/window/main.lua +++ b/examples/window/main.lua @@ -1,29 +1,29 @@ -local textColor = BLACK +local textColor = RL.BLACK local textPos = { 192, 200 } local imageFont = -1 local text = "Congrats! You created your first window!" -function init() - RL_SetWindowTitle( "First window" ) - RL_SetWindowState( FLAG_VSYNC_HINT ) +function RL.init() + RL.SetWindowTitle( "First window" ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) end -function process( delta ) - if RL_IsKeyPressed( KEY_ENTER ) then - local textSize = RL_MeasureText( 0, text, 20, 2 ) - local winSize = RL_GetScreenSize() +function RL.process( delta ) + if RL.IsKeyPressed( RL.KEY_ENTER ) then + local textSize = RL.MeasureText( 0, text, 20, 2 ) + local winSize = RL.GetScreenSize() - textColor = BLUE + textColor = RL.BLUE textPos = { winSize[1] / 2 - textSize[1] / 2, winSize[2] / 2 - textSize[2] / 2 } end - if RL_IsKeyPressed( KEY_SPACE ) then - textColor = BLACK + if RL.IsKeyPressed( RL.KEY_SPACE ) then + textColor = RL.BLACK textPos = { 192, 200 } end end -function draw() - RL_ClearBackground( RAYWHITE ) - RL_DrawText( 0, text, textPos, 20, 2, textColor ) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) + RL.DrawText( 0, text, textPos, 20, 2, textColor ) end |
