├── .gitignore ├── API.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── ReiLua_API.lua ├── apiScanner.lua ├── build └── .gitignore ├── changelog ├── cmake └── EnumOption.cmake ├── devnotes ├── docgen.lua ├── examples ├── 2D_camera │ └── main.lua ├── 2D_lights │ └── main.lua ├── ReiLuaGui_examples │ ├── calculator.lua │ ├── file_explorer.lua │ └── main.lua ├── atlas_packer │ └── main.lua ├── automation_events │ └── main.lua ├── basic_lighting │ └── main.lua ├── blend_modes │ └── main.lua ├── bunnymark │ └── main.lua ├── compress_data │ └── main.lua ├── compressed_resource_file │ └── main.lua ├── custom_main_loop │ └── main.lua ├── draw_textured_polygon │ └── main.lua ├── dungeon_crawler │ └── main.lua ├── events │ └── main.lua ├── fast_tilemap │ └── main.lua ├── free_camera3d │ └── main.lua ├── gui │ └── main.lua ├── heightmap │ └── main.lua ├── image_draw │ └── main.lua ├── instancing │ └── main.lua ├── iqm_test │ └── main.lua ├── lightmap │ └── main.lua ├── n-patches │ └── main.lua ├── platformer │ └── main.lua ├── pong │ └── main.lua ├── ray │ └── main.lua ├── ray_box_cells │ └── main.lua ├── raygui_examples │ ├── calculator.lua │ ├── file_browser.lua │ └── main.lua ├── raygui_extensions │ ├── main.lua │ ├── property_list.lua │ ├── sprite_button.lua │ ├── tree_item.lua │ └── tree_view.lua ├── raygui_lib │ └── main.lua ├── resources │ ├── images │ │ ├── LICENCE │ │ ├── apple.png │ │ ├── arcade_platformerV2.png │ │ ├── button.png │ │ ├── cancel.png │ │ ├── cat.png │ │ ├── check-mark.png │ │ ├── circle.png │ │ ├── files.png │ │ ├── gradient.png │ │ ├── grass.png │ │ ├── heightmap.png │ │ ├── light.png │ │ ├── lightmap.png │ │ ├── monkey_tex.png │ │ ├── nPatch.png │ │ ├── open-folder.png │ │ ├── plain-circle.png │ │ ├── previous-button.png │ │ ├── snake.png │ │ ├── tile.png │ │ ├── tiles.png │ │ ├── ui_bgr.png │ │ ├── ui_border.png │ │ └── wabbit_alpha.png │ ├── iqm │ │ └── monkey.iqm │ ├── lib │ │ ├── bounding_box.lua │ │ ├── camera3d.lua │ │ ├── color.lua │ │ ├── gui.lua │ │ ├── matrix.lua │ │ ├── pubsub.lua │ │ ├── quaternion.lua │ │ ├── raygui.lua │ │ ├── rectangle.lua │ │ ├── reference.lua │ │ ├── rune.lua │ │ ├── utillib.lua │ │ ├── vector2.lua │ │ └── vector3.lua │ ├── shaders │ │ ├── glsl100 │ │ │ ├── lightmap.fs │ │ │ ├── lightmap.vs │ │ │ └── wave.fs │ │ ├── glsl120 │ │ │ ├── lightmap.fs │ │ │ └── lightmap.vs │ │ └── glsl330 │ │ │ ├── atlas_repeat.fs │ │ │ ├── base.fs │ │ │ ├── base.vs │ │ │ ├── lighting.fs │ │ │ ├── lighting.vs │ │ │ ├── lighting_instancing.vs │ │ │ ├── lightmap.fs │ │ │ ├── lightmap.vs │ │ │ └── wave.fs │ └── styles │ │ └── style_dark.rgs ├── rlgl_hello_triangle │ └── main.lua ├── shaders │ └── main.lua ├── snake │ └── main.lua ├── stencil_reflection │ └── main.lua ├── textBoxed │ └── main.lua ├── texture_atlas_repeat │ └── main.lua ├── waving_cubes │ └── main.lua └── window │ └── main.lua ├── include ├── GLFW │ ├── glfw3.h │ └── glfw3native.h ├── audio.h ├── bitwiseOp.h ├── core.h ├── easings.h ├── external │ ├── glad.h │ └── stb_rect_pack.h ├── frustum.h ├── lgl.h ├── lights.h ├── lrlgl.h ├── lua │ ├── lapi.h │ ├── lauxlib.h │ ├── lua.h │ ├── luaconf.h │ └── lualib.h ├── lua_core.h ├── luajit │ ├── lauxlib.h │ ├── lua.h │ ├── luaconf.h │ ├── luajit.h │ └── lualib.h ├── main.h ├── models.h ├── platforms │ ├── core_desktop.h │ ├── core_desktop_sdl2.h │ └── core_desktop_sdl3.h ├── raygui.h ├── raylib.h ├── raymath.h ├── rcamera.h ├── reasings.h ├── rgui.h ├── rlgl.h ├── rlights.h ├── rmath.h ├── shapes.h ├── state.h ├── text.h └── textures.h ├── lib └── .gitignore ├── logo.png └── src ├── audio.c ├── bitwiseOp.c ├── core.c ├── easings.c ├── frustum.c ├── gl.c ├── lights.c ├── lua_core.c ├── main.c ├── models.c ├── platforms ├── core_desktop_glfw.c ├── core_desktop_sdl2.c ├── core_desktop_sdl3.c └── core_web.c ├── rgui.c ├── rlgl.c ├── rmath.c ├── shapes.c ├── state.c ├── text.c └── textures.c /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) 2 | include( CMakeDependentOption ) 3 | include( EnumOption ) 4 | 5 | cmake_minimum_required( VERSION 3.9 ) 6 | project( ReiLua ) 7 | 8 | # To make web build 9 | # cmake .. -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DPLATFORM=Web 10 | 11 | set( CMAKE_C_STANDARD 99 ) # Requires C99 standard 12 | 13 | option( SHARED "Build using dynamic libraries." off ) 14 | option( LUAJIT "Use LuaJIT." off ) 15 | option( LUA_EVENTS "Enable Lua event callbacks (RL.event)." off ) 16 | option( DYNAMIC_SYMBOLS "Expose all dynamic symbols with rdynamic." off ) 17 | option( EXPOSE_API_SYMBOLS "Expose dynamic symbols only for get and push functions of variable types." off ) 18 | 19 | enum_option( PLATFORM "Desktop;Desktop_SDL2;Desktop_SDL3;Web" "Platform to build for." ) 20 | 21 | if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) 22 | set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) 23 | set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) 24 | endif() 25 | 26 | file( GLOB SOURCES src/*.c ) 27 | 28 | include_directories( include ) 29 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 30 | 31 | if( PLATFORM STREQUAL "Desktop" ) 32 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP" ) 33 | elseif( PLATFORM STREQUAL "Desktop_SDL2" ) 34 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL2" ) 35 | elseif( PLATFORM STREQUAL "Desktop_SDL3" ) 36 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL3" ) 37 | elseif( PLATFORM STREQUAL "Web" ) 38 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB" ) 39 | endif() 40 | 41 | if( LUA_EVENTS ) 42 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUA_EVENTS" ) 43 | endif() 44 | 45 | if( DYNAMIC_SYMBOLS ) 46 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic" ) 47 | endif() 48 | 49 | if( PLATFORM STREQUAL "Web" ) 50 | target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/web/libraylib.a ) 51 | target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/web/liblua.a ) 52 | 53 | # Try "-s USE_PTHREADS" if not getting pixel perfect rendering. 54 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY" ) 55 | # set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s FORCE_FILESYSTEM=1" ) 56 | set( CMAKE_EXECUTABLE_SUFFIX ".html" ) # This line is used to set your executable to build with the emscripten html template so that you can directly open it. 57 | set( resources_dir "resources@/" ) # Sets resources as root for the virtual file system. 58 | set_target_properties( ${PROJECT_NAME} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}" ) 59 | else() # Desktop 60 | if( SHARED ) 61 | message( Shared ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSHARED" ) 63 | # find_package( raylib 5.0 REQUIRED ) # Requires at least version 5.0 64 | target_link_libraries( ${PROJECT_NAME} raylib ) 65 | 66 | if( LUAJIT ) 67 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT" ) 68 | target_link_libraries( ${PROJECT_NAME} luajit ) 69 | else() 70 | target_link_libraries( ${PROJECT_NAME} lua ) 71 | endif() 72 | else() 73 | message( Static ) 74 | target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libraylib.a ) 75 | 76 | if( LUAJIT ) 77 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT" ) 78 | target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libluajit.a ) 79 | else() 80 | target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/liblua.a ) 81 | endif() 82 | endif() 83 | 84 | if( UNIX ) 85 | set( CMAKE_C_COMPILER "gcc" ) 86 | 87 | if( EXPOSE_API_SYMBOLS ) 88 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS -rdynamic -fvisibility=hidden" ) 89 | endif() 90 | 91 | if ( PLATFORM MATCHES "Desktop_SDL2" ) 92 | include( FindPkgConfig ) 93 | pkg_search_module( SDL2 REQUIRED sdl2 ) 94 | include_directories( ${SDL2_INCLUDE_DIRS} ) 95 | target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} ) 96 | elseif ( PLATFORM MATCHES "Desktop_SDL3" ) 97 | include( FindPkgConfig ) 98 | pkg_search_module( SDL3 REQUIRED sdl3 ) 99 | include_directories( ${SDL3_INCLUDE_DIRS} ) 100 | target_link_libraries( ${PROJECT_NAME} ${SDL3_LIBRARIES} ) 101 | endif() 102 | 103 | if( DRM ) # For Raspberry Pi. 104 | # target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm rt bcm_host m dl pthread ) 105 | # target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm pthread rt m dl ) 106 | target_link_libraries( ${PROJECT_NAME} raylib GLESv2 EGL pthread rt m gbm drm dl atomic ) 107 | else() 108 | # target_link_libraries( ${PROJECT_NAME} m dl pthread ) 109 | target_link_libraries( ${PROJECT_NAME} m dl pthread glfw ) 110 | endif() 111 | elseif( APPLE ) 112 | set( CMAKE_C_COMPILER "clang" ) 113 | 114 | # //TODO Linking to SDL. 115 | 116 | target_link_libraries( ${PROJECT_NAME} "-framework IOKit" ) 117 | target_link_libraries( ${PROJECT_NAME} "-framework Cocoa" ) 118 | target_link_libraries( ${PROJECT_NAME} "-framework OpenGL" ) 119 | elseif( WIN32 ) 120 | if( EXPOSE_API_SYMBOLS ) 121 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS" ) 122 | endif() 123 | 124 | if ( PLATFORM MATCHES "Desktop_SDL2" ) 125 | find_package( SDL2 REQUIRED ) 126 | include_directories( ${SDL2_INCLUDE_DIRS} ) 127 | target_link_libraries( ${PROJECT_NAME} ${SDL2MAIN_LIBRARIES} ) 128 | target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} ) 129 | elseif ( PLATFORM MATCHES "Desktop_SDL3" ) 130 | find_package( SDL3 REQUIRED ) 131 | include_directories( ${SDL3_INCLUDE_DIRS} ) 132 | target_link_libraries( ${PROJECT_NAME} ${SDL3MAIN_LIBRARIES} ) 133 | target_link_libraries( ${PROJECT_NAME} ${SDL3_LIBRARIES} ) 134 | endif() 135 | # Remove this to get console. //TODO Could be build option. 136 | set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-mwindows" ) 137 | target_link_libraries( ${PROJECT_NAME} mingw32 opengl32 gdi32 winmm ) 138 | endif() 139 | endif() 140 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2025 Jussi Viitala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | cmake_install.cmake 3 | Makefile 4 | CMakeFiles 5 | ReiLua 6 | resources 7 | ReiLua.data 8 | ReiLua.html 9 | ReiLua.js 10 | ReiLua.wasm -------------------------------------------------------------------------------- /cmake/EnumOption.cmake: -------------------------------------------------------------------------------- 1 | macro(enum_option var values description) 2 | set(${var}_VALUES ${values}) 3 | list(GET ${var}_VALUES 0 default) 4 | set(${var} "${default}" CACHE STRING "${description}") 5 | set_property(CACHE ${var} PROPERTY STRINGS ${${var}_VALUES}) 6 | if (NOT ";${${var}_VALUES};" MATCHES ";${${var}};") 7 | message(FATAL_ERROR "Unknown value ${${var}}. Only -D${var}=${${var}_VALUES} allowed.") 8 | endif() 9 | endmacro() 10 | -------------------------------------------------------------------------------- /devnotes: -------------------------------------------------------------------------------- 1 | Current { 2 | } 3 | 4 | Backlog { 5 | * Symbols 6 | * Expose symbols on Windows. 7 | * Raygui lib 8 | * Check if could remove flickering from changing draw order by making queue for order 9 | changing and only change them after everything is drawn. 10 | * Platform desktop SDL 11 | * Text input not working on gui. Could this be Raylib issue? 12 | * Haptic functions. 13 | * SDL3 GPU? 14 | * Audio 15 | * AudioStream. 16 | * Models 17 | * Material mapType range checks. 18 | * Mesh bone weight management? 19 | 20 | * Examples 21 | * Platformer example physics update for true framerate independence. 22 | * Android support 23 | } 24 | 25 | Bugs { 26 | * glfwSet*Callback functions segfault on Windows. Should keep Lua events off for now. 27 | } 28 | 29 | Notes { 30 | } 31 | 32 | Needs Testing { 33 | * rlSetUniform 34 | * rlSetShader 35 | * rlReadShaderBuffer 36 | * rlUpdateTexture 37 | * rlReadTexturePixels 38 | * rlReadScreenPixels 39 | } 40 | -------------------------------------------------------------------------------- /examples/2D_camera/main.lua: -------------------------------------------------------------------------------- 1 | local tileTexture = -1 2 | local camera = -1 3 | local cameraPos = { 0, 0 } 4 | local cameraRot = 0.0 5 | local cameraZoom = 1.0 6 | local cameraSpeed = 100.0 7 | local cameraRotSpeed = 100.0 8 | local cameraZoomSpeed = 2.0 9 | 10 | function RL.init() 11 | local monitor = 0 12 | local mPos = RL.GetMonitorPosition( monitor ) 13 | local mSize = RL.GetMonitorSize( monitor ) 14 | local winSize = RL.GetScreenSize() 15 | 16 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 17 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 18 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 19 | RL.SetWindowTitle( "Camera 2D" ) 20 | 21 | tileTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) 22 | camera = RL.CreateCamera2D() 23 | RL.SetCamera2DOffset( camera, { winSize[1] / 2, winSize[2] / 2 } ) 24 | end 25 | 26 | function RL.update( delta ) 27 | -- Move. 28 | if RL.IsKeyDown( RL.KEY_RIGHT ) then 29 | cameraPos[1] = cameraPos[1] + cameraSpeed * delta 30 | elseif RL.IsKeyDown( RL.KEY_LEFT ) then 31 | cameraPos[1] = cameraPos[1] - cameraSpeed * delta 32 | end 33 | if RL.IsKeyDown( RL.KEY_DOWN ) then 34 | cameraPos[2] = cameraPos[2] + cameraSpeed * delta 35 | elseif RL.IsKeyDown( RL.KEY_UP ) then 36 | cameraPos[2] = cameraPos[2] - cameraSpeed * delta 37 | end 38 | -- Rotate. 39 | if RL.IsKeyDown( RL.KEY_E ) then 40 | cameraRot = cameraRot + cameraRotSpeed * delta 41 | elseif RL.IsKeyDown( RL.KEY_Q ) then 42 | cameraRot = cameraRot - cameraRotSpeed * delta 43 | end 44 | -- Zoom. 45 | if RL.IsKeyDown( RL.KEY_R ) then 46 | cameraZoom = cameraZoom + cameraZoom * cameraZoomSpeed * delta 47 | elseif RL.IsKeyDown( RL.KEY_F ) then 48 | cameraZoom = cameraZoom - cameraZoom * cameraZoomSpeed * delta 49 | end 50 | end 51 | 52 | function RL.draw() 53 | RL.ClearBackground( RL.RAYWHITE ) 54 | RL.SetCamera2DTarget( camera, cameraPos ) 55 | RL.SetCamera2DRotation( camera, cameraRot ) 56 | RL.SetCamera2DZoom( camera, cameraZoom ) 57 | 58 | RL.BeginMode2D( camera ) 59 | -- Draw wall. 60 | for y = 0, 4 do 61 | for x = 0, 6 do 62 | RL.DrawTextureRec( tileTexture, { 0, 0, 32, 32 }, { x * 32, y * 32 }, RL.WHITE ) 63 | end 64 | end 65 | 66 | -- Draw hero. 67 | RL.DrawTextureRec( tileTexture, { 3 * 32, 0, 32, 32 }, { cameraPos[1] - 16, cameraPos[2] - 16 }, RL.WHITE ) 68 | RL.EndMode2D() 69 | end 70 | -------------------------------------------------------------------------------- /examples/ReiLuaGui_examples/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."?.lua" 2 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 3 | 4 | Util = require( "utillib" ) 5 | Vec2 = require( "vector2" ) 6 | Rect = require( "rectangle" ) 7 | Color = require( "color" ) 8 | Gui = require( "gui" ) 9 | 10 | Calculator = require( "calculator" ) 11 | FileExplorer = require( "file_explorer" ) 12 | 13 | -- End of calculator definition. 14 | 15 | local calculator = nil 16 | local fileExplorer = nil 17 | local showButton = nil 18 | 19 | local function initGui() 20 | showButton = Gui.element:new( { 21 | bounds = Rect:new( 0, 0, 96, 32 ), 22 | drawBounds = true, 23 | onClicked = function() 24 | calculator:setVisible( true ) 25 | fileExplorer:setVisible( true ) 26 | end, 27 | onMouseOver = function( self ) self.color = Color:newT( RL.LIGHTGRAY ) end, 28 | notMouseOver = function( self ) self.color = Color:newT( RL.GRAY ) end, 29 | } ) 30 | 31 | showButton:add( Gui.text:new( { text = "Show", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) 32 | 33 | calculator = Calculator:new( Vec2:new( 32, 96 ) ) 34 | fileExplorer = FileExplorer:new( Vec2:new( 280, 96 ) ) 35 | end 36 | 37 | function RL.init() 38 | local monitor = 0 39 | local mPos = RL.GetMonitorPosition( monitor ) 40 | local mSize = RL.GetMonitorSize( monitor ) 41 | local winSize = RL.GetScreenSize() 42 | 43 | RL.SetWindowTitle( "ReiLuaGui examples" ) 44 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 45 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 46 | RL.SetWindowSize( winSize ) 47 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 48 | -- Textures. 49 | 50 | -- Note that textures are global. 51 | CancelTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cancel.png" ) 52 | BackTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/previous-button.png" ) 53 | FolderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/open-folder.png" ) 54 | FilesTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/files.png" ) 55 | BorderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) 56 | BgrTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_bgr.png" ) 57 | 58 | RL.GenTextureMipmaps( CancelTexture ) 59 | RL.GenTextureMipmaps( BackTexture ) 60 | RL.GenTextureMipmaps( FolderTexture ) 61 | RL.GenTextureMipmaps( FilesTexture ) 62 | RL.GenTextureMipmaps( BorderTexture ) 63 | RL.GenTextureMipmaps( BgrTexture ) 64 | 65 | RL.SetTextureFilter( CancelTexture, RL.TEXTURE_FILTER_TRILINEAR ) 66 | RL.SetTextureFilter( BackTexture, RL.TEXTURE_FILTER_TRILINEAR ) 67 | RL.SetTextureFilter( FolderTexture, RL.TEXTURE_FILTER_TRILINEAR ) 68 | RL.SetTextureFilter( FilesTexture, RL.TEXTURE_FILTER_TRILINEAR ) 69 | RL.SetTextureFilter( BorderTexture, RL.TEXTURE_FILTER_TRILINEAR ) 70 | RL.SetTextureFilter( BgrTexture, RL.TEXTURE_FILTER_TRILINEAR ) 71 | 72 | RL.SetTextureWrap( BorderTexture, RL.TEXTURE_WRAP_REPEAT ) 73 | RL.SetTextureWrap( BgrTexture, RL.TEXTURE_WRAP_REPEAT ) 74 | 75 | initGui() 76 | end 77 | 78 | function RL.update( delta ) 79 | Gui.update( Vec2:newT( RL.GetMousePosition() ) ) 80 | end 81 | 82 | function RL.draw() 83 | RL.ClearBackground( RL.RAYWHITE ) 84 | 85 | Gui.draw() 86 | end 87 | -------------------------------------------------------------------------------- /examples/atlas_packer/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Util = require( "utillib" ) 4 | Vector2 = require( "vector2" ) 5 | Rectangle = require( "rectangle" ) 6 | 7 | local atlasTexture = nil 8 | local atlasRects = {} 9 | local atlasSize = Vector2:new() 10 | local atlasPadding = 1 11 | local imgPaths = { 12 | "tile.png", 13 | "apple.png", 14 | "snake.png", 15 | "wabbit_alpha.png", 16 | "nPatch.png", 17 | "open-folder.png", 18 | "cat.png", 19 | "tiles.png", 20 | "monkey_tex.png", 21 | } 22 | 23 | local function makeAtlas() 24 | local images = {} 25 | local pathPrefix = RL.GetBasePath().."../resources/images/" 26 | 27 | for i, path in ipairs( imgPaths ) do 28 | images[i] = RL.LoadImage( pathPrefix..path ) 29 | local imgSize = Vector2:newT( RL.GetImageSize( images[i] ) ) 30 | atlasRects[i] = Rectangle:new( 0, 0, imgSize.x, imgSize.y ) 31 | end 32 | 33 | atlasSize:setT( RL.GetScreenSize() ) 34 | atlasRects = RL.RectPack( atlasRects, atlasSize, atlasPadding ) 35 | 36 | local atlasImg = RL.GenImageColor( atlasSize, RL.BLANK ) 37 | 38 | for i, rect in ipairs( atlasRects ) do 39 | print( "Rect", i, Rectangle:tempT( rect ) ) 40 | RL.ImageDraw( atlasImg, images[i], 41 | { 0, 0, rect[3], rect[4] }, 42 | rect, 43 | RL.WHITE 44 | ) 45 | end 46 | 47 | RL.ImageAlphaCrop( atlasImg, 0 ) 48 | print( "Cropped size", Vector2:tempT( RL.GetImageSize( atlasImg ) ) ) 49 | 50 | atlasTexture = RL.LoadTextureFromImage( atlasImg ) 51 | end 52 | 53 | function RL.init() 54 | RL.SetWindowTitle( "Texture Atlas" ) 55 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 56 | 57 | makeAtlas() 58 | end 59 | 60 | function RL.update( delta ) 61 | end 62 | 63 | function RL.draw() 64 | RL.ClearBackground( RL.DARKBLUE ) 65 | 66 | if atlasTexture then 67 | RL.DrawTexture( atlasTexture, { 0, 0 }, RL.WHITE ) 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /examples/automation_events/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Vec2 = require( "vector2" ) 4 | 5 | local eventList = nil 6 | local evenRecording = false 7 | local eventPlaying = false 8 | local frameCounter = 0 9 | local playFrameCounter = 0 10 | local currentPlayFrame = 0 11 | local player = { 12 | pos = Vec2:new( 160, 200 ), 13 | speed = 100.0, 14 | } 15 | 16 | function RL.init() 17 | RL.SetWindowTitle( "Automation Events" ) 18 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 19 | RL.SetTextLineSpacing( 25 ) 20 | 21 | eventList = RL.LoadAutomationEventList( nil ) 22 | RL.SetAutomationEventList( eventList ) 23 | end 24 | 25 | function RL.update( delta ) 26 | local moveDir = Vec2:new( 0, 0 ) 27 | 28 | if RL.IsKeyDown( RL.KEY_RIGHT ) then 29 | moveDir.x = 1 30 | elseif RL.IsKeyDown( RL.KEY_LEFT ) then 31 | moveDir.x = -1 32 | end 33 | 34 | if RL.IsKeyDown( RL.KEY_DOWN ) then 35 | moveDir.y = 1 36 | elseif RL.IsKeyDown( RL.KEY_UP ) then 37 | moveDir.y = -1 38 | end 39 | 40 | player.pos:addEq( moveDir:scale( player.speed * delta ) ) 41 | 42 | -- Events. 43 | 44 | if RL.IsKeyPressed( RL.KEY_S ) then 45 | evenRecording = not evenRecording 46 | 47 | if evenRecording then 48 | RL.StartAutomationEventRecording() 49 | else 50 | RL.StopAutomationEventRecording() 51 | end 52 | end 53 | if RL.IsKeyPressed( RL.KEY_A ) then 54 | eventPlaying = not eventPlaying 55 | evenRecording = false 56 | playFrameCounter = 0 57 | currentPlayFrame = 0 58 | end 59 | 60 | if eventPlaying then 61 | while playFrameCounter == RL.GetAutomationEventFrame( RL.GetAutomationEvent( eventList, currentPlayFrame ) ) do 62 | RL.TraceLog( RL.LOG_INFO, "playFrameCounter: "..playFrameCounter.."\tcurrentPlayFrame: "..currentPlayFrame ) 63 | 64 | RL.PlayAutomationEvent( RL.GetAutomationEvent( eventList, currentPlayFrame ) ) 65 | currentPlayFrame = currentPlayFrame + 1 66 | 67 | if currentPlayFrame == RL.GetAutomationEventListCount( eventList ) then 68 | eventPlaying = false 69 | currentPlayFrame = 0 70 | playFrameCounter = 0 71 | 72 | RL.TraceLog( RL.LOG_INFO, "FINISH PLAYING!" ) 73 | break 74 | end 75 | end 76 | 77 | playFrameCounter = playFrameCounter + 1 78 | end 79 | end 80 | 81 | function RL.draw() 82 | RL.ClearBackground( RL.RAYWHITE ) 83 | RL.DrawCircle( player.pos, 8.0, RL.BLUE ) 84 | 85 | local text = "Toggle recording: S\nToggle play: A\n" 86 | local textColor = RL.GREEN 87 | 88 | if evenRecording then 89 | text = text.."Recording" 90 | textColor = RL.RED 91 | elseif eventPlaying then 92 | text = text.."Playing" 93 | textColor = RL.BLUE 94 | end 95 | 96 | RL.DrawText( text, { 20, 20 }, 20, textColor ) 97 | end 98 | -------------------------------------------------------------------------------- /examples/basic_lighting/main.lua: -------------------------------------------------------------------------------- 1 | -- Based on raylib [shaders] example - basic lighting by Chris Camacho (@codifies) 2 | -- https://github.com/raysan5/raylib/blob/master/examples/shaders/shaders_basic_lighting.c 3 | 4 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 5 | 6 | Util = require( "utillib" ) 7 | Vec2 = require( "vector2" ) 8 | Vec3 = require( "vector3" ) 9 | Cam3D = require( "camera3d" ) 10 | 11 | local monitor = 0 12 | local camera = {} 13 | 14 | local plane = -1 15 | local cube = -1 16 | local material = -1 17 | local shader = -1 18 | local lights = {} 19 | 20 | function RL.init() 21 | local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) 22 | local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) 23 | local winSize = Vec2:new( 1028, 720 ) 24 | 25 | RL.SetGCUnload( false ) 26 | RL.SetWindowTitle( "Simple Lighting" ) 27 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 28 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 29 | RL.SetWindowSize( winSize ) 30 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 31 | 32 | -- Define the camera to look into our 3d world. 33 | camera = Cam3D:new() 34 | 35 | camera:setPosition( { 0, 4, 12 } ) 36 | camera:setTarget( { 0, 0, 0 } ) 37 | camera:setUp( { 0, 1, 0 } ) 38 | -- camera.mode = camera.MODES.ORBITAL 39 | camera.mode = camera.MODES.FIRST_PERSON 40 | 41 | RL.HideCursor() 42 | 43 | -- Generate meshes. 44 | plane = RL.GenMeshPlane( 10, 10, 3, 3 ) 45 | cube = RL.GenMeshCube( { 2, 4, 2 } ) 46 | 47 | -- Load basic lighting shader. 48 | -- NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). 49 | 50 | -- Shader folders. 51 | local glslDir = { 52 | -- [ RL.RL_OPENGL_11 ] = "glsl100", 53 | -- [ RL.RL_OPENGL_21 ] = "glsl120", 54 | [ RL.RL_OPENGL_33 ] = "glsl330", 55 | [ RL.RL_OPENGL_43 ] = "glsl330", 56 | -- [ RL.RL_OPENGL_ES_20 ] = "glsl120", 57 | } 58 | local prefix = RL.GetBasePath().."../resources/shaders/"..glslDir[ RL.rlGetVersion() ].."/" 59 | 60 | shader = RL.LoadShader( prefix.."lighting.vs", prefix.."lighting.fs" ) 61 | 62 | -- Get some required shader locations. 63 | local viewPosLoc = RL.GetShaderLocation( shader, "viewPos" ) 64 | RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_VECTOR_VIEW, viewPosLoc ) 65 | --[[ 66 | NOTE: "matModel" location name is automatically assigned on shader loading, 67 | no need to get the location again if using that uniform name. 68 | ]]-- 69 | 70 | -- Ambient light level (some basic lighting). 71 | local ambientLoc = RL.GetShaderLocation( shader, "ambient" ) 72 | RL.SetShaderValue( shader, ambientLoc, { 0.1, 0.1, 0.1, 1.0 }, RL.SHADER_UNIFORM_VEC4 ) 73 | 74 | -- Create material. 75 | local materialData = { 76 | shader = shader, 77 | maps = { 78 | { 79 | RL.MATERIAL_MAP_ALBEDO, 80 | { 81 | color = RL.WHITE, 82 | }, 83 | }, 84 | }, 85 | } 86 | material = RL.CreateMaterial( materialData ) 87 | 88 | -- Create lights. 89 | table.insert( lights, RL.CreateLight( RL.LIGHT_POINT, { -2, 1, -2 }, RL.Vector3Zero(), RL.YELLOW, shader ) ) 90 | table.insert( lights, RL.CreateLight( RL.LIGHT_POINT, { 2, 1, 2 }, RL.Vector3Zero(), RL.RED, shader ) ) 91 | table.insert( lights, RL.CreateLight( RL.LIGHT_POINT, { -2, 1, 2 }, RL.Vector3Zero(), RL.GREEN, shader ) ) 92 | table.insert( lights, RL.CreateLight( RL.LIGHT_POINT, { 2, 1, -2 }, RL.Vector3Zero(), RL.BLUE, shader ) ) 93 | end 94 | 95 | function RL.update( delta ) 96 | camera:update( delta ) 97 | 98 | -- Check key inputs to enable/disable lights. 99 | if RL.IsKeyPressed( RL.KEY_Y ) then 100 | RL.SetLightEnabled( lights[1], not RL.IsLightEnabled( lights[1] ) ) 101 | end 102 | if RL.IsKeyPressed( RL.KEY_R ) then 103 | RL.SetLightEnabled( lights[2], not RL.IsLightEnabled( lights[2] ) ) 104 | end 105 | if RL.IsKeyPressed( RL.KEY_G ) then 106 | RL.SetLightEnabled( lights[3], not RL.IsLightEnabled( lights[3] ) ) 107 | end 108 | if RL.IsKeyPressed( RL.KEY_B ) then 109 | RL.SetLightEnabled( lights[4], not RL.IsLightEnabled( lights[4] ) ) 110 | end 111 | 112 | -- Update light values (actually, only enable/disable them). 113 | for _, light in ipairs( lights ) do 114 | RL.UpdateLightValues( shader, light ) 115 | end 116 | end 117 | 118 | function RL.draw() 119 | RL.ClearBackground( { 100, 150, 100 } ) 120 | 121 | -- Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f }). 122 | local loc = RL.GetShaderLocationIndex( shader, RL.SHADER_LOC_VECTOR_VIEW ) 123 | RL.SetShaderValue( shader, loc, camera:getPosition():arr(), RL.SHADER_UNIFORM_VEC3 ) 124 | 125 | camera:beginMode3D() 126 | RL.DrawMesh( plane, material, RL.MatrixIdentity() ) 127 | RL.DrawMesh( cube, material, RL.MatrixIdentity() ) 128 | 129 | -- Draw spheres to show where the lights are. 130 | for _, light in ipairs( lights ) do 131 | if RL.IsLightEnabled( light ) then 132 | RL.DrawSphereEx( RL.GetLightPosition( light ), 0.2, 8, 8, RL.GetLightColor( light ) ) 133 | else 134 | RL.DrawSphereWires( RL.GetLightPosition( light ), 0.2, 8, 8, RL.ColorAlpha( RL.GetLightColor( light ), 0.3 ) ) 135 | end 136 | end 137 | 138 | camera:endMode3D() 139 | 140 | RL.DrawText( "Use keys [Y][R][G][B] to toggle lights", { 10, 10 }, 20, RL.DARKGRAY ) 141 | end 142 | 143 | function RL.exit() 144 | RL.UnloadMaterial( material, true ) 145 | RL.UnloadMesh( plane ) 146 | RL.UnloadMesh( cube ) 147 | end 148 | -------------------------------------------------------------------------------- /examples/bunnymark/main.lua: -------------------------------------------------------------------------------- 1 | -- Forked from raylib-lua example by TSnake41 2 | -- https://github.com/TSnake41/raylib-lua/blob/master/examples/textures_bunnymark.lua 3 | 4 | local MAX_BUNNIES = 100000 5 | 6 | -- This is the maximum amount of elements (quads) per batch 7 | -- NOTE: This value is defined in [rlgl] module and can be changed there 8 | local MAX_BATCH_ELEMENTS = 8192 9 | 10 | -- Create the Bunny class. 11 | local Bunny = {} 12 | Bunny.__index = Bunny 13 | 14 | function Bunny:new( pos, spd, col ) 15 | local bunny = {} 16 | setmetatable( bunny, Bunny ) 17 | bunny.position = pos 18 | bunny.speed = spd 19 | bunny.color = col 20 | return bunny 21 | end 22 | 23 | -- Initialization 24 | local screenWidth = 800 25 | local screenHeight = 450 26 | local texSize = { 0, 0 } 27 | local texBunny = -1 28 | local bunnies = {} 29 | 30 | function Bunny:update() 31 | self.position[1] = self.position[1] + self.speed[1] 32 | self.position[2] = self.position[2] + self.speed[2] 33 | 34 | if ( ( self.position[1] + texSize[1] / 2 ) > screenWidth ) 35 | or ( ( self.position[2] + texSize[1] / 2 ) < 0 ) then 36 | self.speed[1] = self.speed[1] * -1 37 | end 38 | 39 | if ( ( self.position[2] + texSize[2] / 2 ) > screenHeight ) 40 | or ( ( self.position[2] + texSize[2] / 2 - 40 ) < 0 ) then 41 | self.speed[2] = self.speed[2] * -1 42 | end 43 | end 44 | 45 | function RL.init() 46 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 47 | RL.SetWindowSize( { screenWidth, screenHeight } ) 48 | RL.SetWindowTitle( "raylib [textures] example - bunnymark" ) 49 | -- Load bunny texture 50 | texBunny = RL.LoadTexture( RL.GetBasePath().."../resources/images/wabbit_alpha.png" ) 51 | texSize = RL.GetTextureSize( texBunny ) 52 | end 53 | 54 | function RL.update( delta ) 55 | if RL.IsMouseButtonDown( 0 ) then 56 | -- Create more bunnies 57 | for i = 1, 100 do 58 | if #bunnies < MAX_BUNNIES then 59 | local speed = { math.random( -250, 250 ) / 60, math.random( -250, 250 ) / 60 } 60 | local color = { math.random( 50, 240 ), math.random( 80, 240 ), math.random( 100, 240 ), 255 } 61 | table.insert( bunnies, Bunny:new( RL.GetMousePosition(), speed, color ) ) 62 | end 63 | end 64 | end 65 | -- Update bunnies 66 | for i = 1, #bunnies do 67 | bunnies[i]:update() 68 | end 69 | end 70 | 71 | function RL.draw() 72 | RL.ClearBackground( RL.RAYWHITE ) 73 | 74 | for i = 1, #bunnies do 75 | local bunny = bunnies[i] 76 | -- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), 77 | -- a draw call is launched and buffer starts being filled again; 78 | -- before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... 79 | -- Process of sending data is costly and it could happen that GPU data has not been completely 80 | -- processed for drawing while new data is tried to be sent (updating current in-use buffers) 81 | -- it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies 82 | RL.DrawTexture( texBunny, { bunny.position[1], bunny.position[2] }, bunny.color ) 83 | end 84 | 85 | RL.DrawRectangle( { 0, 0, screenWidth, 40 }, RL.BLACK) 86 | RL.DrawText( "bunnies: " .. #bunnies, { 120, 10 }, 20, RL.GREEN ) 87 | RL.DrawText( "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, RL.RED ) 88 | RL.DrawFPS( { 10, 10 } ) 89 | end 90 | -------------------------------------------------------------------------------- /examples/compress_data/main.lua: -------------------------------------------------------------------------------- 1 | local textColor = RL.BLACK 2 | local text = "Put data here" 3 | local deCompressedText = "" 4 | local editMode = false 5 | 6 | function RL.init() 7 | RL.SetWindowTitle( "Buffer" ) 8 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 9 | end 10 | 11 | local function compressDecompressData() 12 | local strT = {} 13 | 14 | for i = 1, #text do 15 | table.insert( strT, string.byte( text:sub( i, i ) ) ) 16 | end 17 | 18 | local strBuffer = RL.LoadBuffer( strT, RL.BUFFER_UNSIGNED_CHAR ) 19 | local compBuffer = RL.CompressData( strBuffer ) 20 | local deCompBuffer = RL.DecompressData( compBuffer ) 21 | 22 | deCompressedText = "" 23 | 24 | for _, c in ipairs( RL.GetBufferData( deCompBuffer, 0, RL.GetBufferLength( deCompBuffer ) ) ) do 25 | deCompressedText = deCompressedText..string.char( c ) 26 | end 27 | end 28 | 29 | function RL.draw() 30 | RL.ClearBackground( RL.RAYWHITE ) 31 | RL.DrawText( "Decompressed text: "..deCompressedText, { 20, 200 }, 20, textColor ) 32 | 33 | if 0 < RL.GuiButton( { 20, 20, 168, 32 }, "Compress/Decompress Data" ) then 34 | compressDecompressData() 35 | end 36 | 37 | local pressed = false 38 | pressed, text = RL.GuiTextBox( { 220, 20, 400, 32 }, text, 64, editMode ) 39 | 40 | if 0 < pressed then 41 | editMode = not editMode 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /examples/compressed_resource_file/main.lua: -------------------------------------------------------------------------------- 1 | -- Simple example to store compressed image to file. 2 | -- To store multiple assets, some sort of addressing would be required. 3 | 4 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 5 | 6 | Vector2 = require( "vector2" ) 7 | 8 | local texture = nil 9 | local dataFileName = "data" 10 | local compress = true 11 | -- local compress = false 12 | 13 | local function writeDataFile( path ) 14 | local image = RL.LoadImage( RL.GetBasePath().."../resources/images/arcade_platformerV2.png" ) 15 | 16 | if not image then 17 | return 18 | end 19 | 20 | local imgData = { 21 | size = Vector2:newT( RL.GetImageSize( image ) ), 22 | mipmaps = RL.GetImageMipmaps( image ), 23 | format = RL.GetImageFormat( image ), 24 | data = RL.GetImageData( image ), 25 | } 26 | -- Header and image data. We devide imgData.data by 4 since we use unsigned ints as buffer type. 27 | local totalLength = 4 + RL.GetBufferLength( imgData.data ) / 4 28 | local buffer = RL.LoadBufferFormatted( totalLength, RL.BUFFER_UNSIGNED_INT, 0 ) 29 | 30 | RL.SetBufferData( buffer, 0, { 31 | imgData.size.x, 32 | imgData.size.y, 33 | imgData.mipmaps, 34 | imgData.format, 35 | } ) 36 | RL.CopyBufferData( buffer, imgData.data, 4, 0, RL.GetBufferLength( imgData.data ) ) 37 | 38 | if compress then 39 | RL.ExportBuffer( RL.CompressData( buffer ), path ) 40 | else 41 | RL.ExportBuffer( buffer, path ) 42 | end 43 | end 44 | 45 | local function loadDataFile( path ) 46 | local buffer = RL.LoadBufferFromFile( path, RL.BUFFER_UNSIGNED_INT ) 47 | 48 | if not buffer then 49 | return 50 | end 51 | 52 | if compress then 53 | buffer = RL.DecompressData( buffer ) 54 | end 55 | 56 | local imgData = { 57 | size = Vector2:newT( RL.GetBufferData( buffer, 0, 2 ) ), 58 | mipmaps = RL.GetBufferData( buffer, 2, 1 )[1], 59 | format = RL.GetBufferData( buffer, 3, 1 )[1], 60 | data = nil, 61 | } 62 | local imageDataSize = RL.GetPixelDataSize( imgData.size, imgData.format ) 63 | 64 | imgData.data = RL.LoadBufferFormatted( imageDataSize, RL.BUFFER_UNSIGNED_CHAR, 0 ) 65 | 66 | RL.CopyBufferData( imgData.data, buffer, 0, 4, imageDataSize ) 67 | 68 | local image = RL.LoadImageFromData( 69 | imgData.data, 70 | imgData.size, 71 | imgData.mipmaps, 72 | imgData.format 73 | ) 74 | texture = RL.LoadTextureFromImage( image ) 75 | end 76 | 77 | function RL.init() 78 | RL.SetWindowTitle( "Compressed resource file" ) 79 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 80 | 81 | local path = RL.GetBasePath()..dataFileName 82 | 83 | writeDataFile( path ) 84 | loadDataFile( path ) 85 | end 86 | 87 | function RL.update( delta ) 88 | end 89 | 90 | function RL.draw() 91 | RL.ClearBackground( RL.RAYWHITE ) 92 | 93 | if texture then 94 | RL.DrawTextureEx( texture, { 0, 0 }, 0, 2, RL.WHITE ) 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /examples/custom_main_loop/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Vector2 = require( "vector2" ) 4 | 5 | local function dysfunctionalPrint( message ) 6 | printt( message ) 7 | end 8 | 9 | local function main() 10 | RL.SetConfigFlags( RL.FLAG_VSYNC_HINT ) 11 | RL.InitWindow( { 800, 600 }, "Custom Main Loop" ) 12 | 13 | local catTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) 14 | local catPos = Vector2:new( 20, 20 ) 15 | local catSpeed = 200 16 | 17 | while not RL.WindowShouldClose() do 18 | local delta = RL.GetFrameTime() 19 | local vel = Vector2:new() 20 | 21 | if RL.IsKeyDown( RL.KEY_RIGHT ) then 22 | vel.x = catSpeed * delta 23 | elseif RL.IsKeyDown( RL.KEY_LEFT ) then 24 | vel.x = -catSpeed * delta 25 | end 26 | if RL.IsKeyDown( RL.KEY_DOWN ) then 27 | vel.y = catSpeed * delta 28 | elseif RL.IsKeyDown( RL.KEY_UP ) then 29 | vel.y = -catSpeed * delta 30 | end 31 | 32 | if RL.IsKeyPressed( RL.KEY_ENTER ) then 33 | dysfunctionalPrint( "This will fail and give usefull traceback info" ) 34 | end 35 | 36 | catPos:addEq( vel ) 37 | 38 | RL.BeginDrawing() 39 | RL.ClearBackground( RL.LIGHTGRAY ) 40 | RL.DrawTexture( catTex, catPos, RL.WHITE ) 41 | RL.DrawFPS( { 10, 10 } ) 42 | RL.EndDrawing() 43 | end 44 | end 45 | 46 | -- Call main to get traceback info. 47 | local success, result = xpcall( main, debug.traceback ) 48 | 49 | if not success then 50 | RL.TraceLog( RL.LOG_WARNING, "Error: "..result ) 51 | RL.CloseWindow() 52 | end 53 | -------------------------------------------------------------------------------- /examples/draw_textured_polygon/main.lua: -------------------------------------------------------------------------------- 1 | -- Based on raylib example - Draw Textured Polygon by Chris Camacho (@codifies) 2 | 3 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 4 | 5 | Vec2 = require( "vector2" ) 6 | 7 | local winSize = Vec2:new() 8 | local polygon = { 9 | texture = -1, 10 | texcoords = { 11 | Vec2:new( 0.75, 0.0 ), 12 | Vec2:new( 0.25, 0.0 ), 13 | Vec2:new( 0.0, 0.5 ), 14 | Vec2:new( 0.0, 0.75 ), 15 | Vec2:new( 0.25, 1.0 ), 16 | Vec2:new( 0.375, 0.875 ), 17 | Vec2:new( 0.625, 0.875 ), 18 | Vec2:new( 0.75, 1.0 ), 19 | Vec2:new( 1.0, 0.75 ), 20 | Vec2:new( 1.0, 0.5 ), 21 | Vec2:new( 0.75, 0.0 ), 22 | }, 23 | points = {}, 24 | positions = {}, 25 | angle = 0.0, 26 | } 27 | 28 | function RL.init() 29 | local monitor = 0 30 | local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) 31 | local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) 32 | winSize = Vec2:newT( RL.GetScreenSize() ) 33 | 34 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 35 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 36 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 37 | RL.SetWindowTitle( "Textured Polygon" ) 38 | 39 | polygon.texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) 40 | 41 | -- Define the base poly vertices from the UV's 42 | -- NOTE: They can be specified in any other way 43 | for _, texcoord in ipairs( polygon.texcoords ) do 44 | table.insert( polygon.points, Vec2:new( ( texcoord.x - 0.5 ) * 256, ( texcoord.y - 0.5 ) * 256 ) ) 45 | end 46 | 47 | -- Define the vertices drawing position 48 | -- NOTE: Initially same as points but updated every frame 49 | for _, point in ipairs( polygon.points ) do 50 | table.insert( polygon.positions, point:clone() ) 51 | end 52 | end 53 | 54 | function RL.update( delta ) 55 | polygon.angle = polygon.angle + delta 56 | 57 | -- Update points rotation with an angle transform 58 | -- NOTE: Base points position are not modified 59 | for i = 1, #polygon.points do 60 | polygon.positions[i] = Vec2:newT( RL.Vector2Rotate( polygon.points[i], polygon.angle ) ) 61 | end 62 | end 63 | 64 | -- Draw textured polygon, defined by vertex and texture coordinates 65 | -- NOTE: Polygon center must have straight line path to all points 66 | -- without crossing perimeter, points must be in anticlockwise order 67 | local function drawTexturePoly( texture, center, points, texcoords, tint ) 68 | RL.rlSetTexture( RL.GetTextureId( texture ) ) 69 | 70 | -- Texturing is only supported on RL_QUADS 71 | RL.rlBegin( RL.RL_QUADS ) 72 | RL.rlColor4ub( tint ) 73 | 74 | for i = 1, #points - 1 do 75 | RL.rlTexCoord2f( { 0.5, 0.5 } ) 76 | RL.rlVertex2f( center ) 77 | 78 | RL.rlTexCoord2f( texcoords[i] ) 79 | RL.rlVertex2f( center + points[i] ) 80 | 81 | RL.rlTexCoord2f( texcoords[i + 1] ) 82 | RL.rlVertex2f( center + points[i + 1] ) 83 | -- Dublicate of last vertex to complete quad. 84 | RL.rlTexCoord2f( texcoords[i + 1] ) 85 | RL.rlVertex2f( center + points[i + 1] ) 86 | end 87 | RL.rlEnd() 88 | end 89 | 90 | function RL.draw() 91 | RL.ClearBackground( RL.RAYWHITE ) 92 | 93 | drawTexturePoly( polygon.texture, winSize:scale( 0.5 ), polygon.positions, polygon.texcoords, RL.WHITE ) 94 | end 95 | -------------------------------------------------------------------------------- /examples/dungeon_crawler/main.lua: -------------------------------------------------------------------------------- 1 | local pos = { 2, 0.5, 6 } 2 | local speed = 5.0 3 | local camera = -1 4 | local texture = -1 5 | local textureSize = { 256, 96 } 6 | local res = { 384, 216 } 7 | local winSize = RL.GetScreenSize() 8 | local winScale = 4 9 | local framebuffer = nil 10 | 11 | local TILE_SIZE = 32 12 | local TILE_VERTEX_COLORS = { RL.WHITE, RL.WHITE, RL.WHITE, RL.WHITE } 13 | 14 | local FLOOR = 1 15 | local CEILING = 2 16 | local WALL_N = 3 17 | local WALL_S = 4 18 | local WALL_W = 5 19 | local WALL_E = 6 20 | 21 | local sprites = { 22 | { pos = { 0.5, 0.5 }, tile = { 0, 1 }, dis = 0, size = 0.7 }, 23 | { pos = { 3.5, 0.5 }, tile = { 0, 1 }, dis = 0, size = 0.7 }, 24 | } 25 | 26 | local function getTexCoords( x, y ) 27 | return { 28 | { x * TILE_SIZE / textureSize[1], y * TILE_SIZE / textureSize[2] }, 29 | { x * TILE_SIZE / textureSize[1], ( y * TILE_SIZE + TILE_SIZE ) / textureSize[2] }, 30 | { ( x * TILE_SIZE + TILE_SIZE ) / textureSize[1], ( y * TILE_SIZE + TILE_SIZE ) / textureSize[2] }, 31 | { ( x * TILE_SIZE + TILE_SIZE ) / textureSize[1], y * TILE_SIZE / textureSize[2] }, 32 | } 33 | end 34 | 35 | local function getTileVer( x, y, type ) 36 | local types = { 37 | { { 0, 0, 0 }, { 0, 0, 1 }, { 1, 0, 1 }, { 1, 0, 0 } }, -- Floor. 38 | { { 1, 1, 0 }, { 1, 1, 1 }, { 0, 1, 1 }, { 0, 1, 0 } }, -- Ceiling. 39 | { { 0, 1, 0 }, { 0, 0, 0 }, { 1, 0, 0 }, { 1, 1, 0 } }, -- Wall North. 40 | { { 1, 1, 1 }, { 1, 0, 1 }, { 0, 0, 1 }, { 0, 1, 1 } }, -- Wall South. 41 | { { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 1, 0 } }, -- Wall West. 42 | { { 1, 1, 0 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 1 } }, -- Wall East. 43 | } 44 | local verts = types[ type ] 45 | 46 | for i = 1, 4 do 47 | verts[i][1] = verts[i][1] + x 48 | verts[i][3] = verts[i][3] + y 49 | end 50 | 51 | return verts 52 | end 53 | 54 | local function drawSprites() 55 | for _, sprite in ipairs( sprites ) do 56 | sprite.dis = RL.Vector2Distance( { pos[1], pos[3] }, { sprite.pos[1], sprite.pos[2] } ) 57 | end 58 | 59 | table.sort( sprites, function( a, b ) return a.dis > b.dis end ) 60 | 61 | for _, sprite in ipairs( sprites ) do 62 | RL.DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE }, 63 | { sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, RL.WHITE ) 64 | end 65 | end 66 | 67 | function RL.init() 68 | local monitor = 0 69 | local mPos = RL.GetMonitorPosition( monitor ) 70 | local mSize = RL.GetMonitorSize( monitor ) 71 | 72 | winSize = { res[1] * winScale, res[2] * winScale } 73 | RL.SetWindowSize( winSize ) 74 | RL.SetExitKey( RL.KEY_ESCAPE ) 75 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 76 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 77 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 78 | 79 | texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) 80 | camera = RL.CreateCamera3D() 81 | RL.SetCamera3DPosition( camera, pos ) 82 | RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) 83 | RL.SetCamera3DUp( camera, { 0, 1, 0 } ) 84 | 85 | table.insert( sprites, { pos = { 2.5, 2.5 }, tile = { 1, 1 }, dis = 0, size = 0.8 } ) 86 | table.insert( sprites, { pos = { 1.5, 3.5 }, tile = { 3, 1 }, dis = 0, size = 0.5 } ) 87 | table.insert( sprites, { pos = { 0.5, 3.5 }, tile = { 3, 0 }, dis = 0, size = 0.7 } ) 88 | end 89 | 90 | function RL.draw() 91 | RL.UpdateCamera3D( camera, RL.CAMERA_FIRST_PERSON ) 92 | pos = RL.GetCamera3DPosition( camera ) 93 | 94 | RL.ClearBackground( { 100, 150, 150 } ) 95 | 96 | RL.BeginMode3D( camera ) 97 | -- Floor and ceiling. 98 | for x = 0, 3 do 99 | for y = 0, 10 do 100 | RL.DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), TILE_VERTEX_COLORS ) 101 | RL.DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), TILE_VERTEX_COLORS ) 102 | end 103 | end 104 | -- Walls. 105 | RL.DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) 106 | RL.DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), TILE_VERTEX_COLORS ) 107 | RL.DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), TILE_VERTEX_COLORS ) 108 | RL.DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) 109 | 110 | for x = 0, 3 do 111 | RL.DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) 112 | end 113 | for y = 0, 10 do 114 | RL.DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) 115 | RL.DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) 116 | end 117 | 118 | drawSprites() 119 | RL.EndMode3D() 120 | end 121 | -------------------------------------------------------------------------------- /examples/fast_tilemap/main.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | We can use mesh to draw tilemap in one draw call. 3 | On large maps you could devide the tilemap in sections to cull tiles that are not 4 | in view. 5 | --]] 6 | 7 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 8 | 9 | Util = require( "utillib" ) 10 | Vector2 = require( "vector2" ) 11 | Vector3 = require( "vector3" ) 12 | 13 | QUAD = { 14 | VERTICES = { 15 | Vector3:new( 0, 0, 0 ), Vector3:new( 0, 1, 0 ), Vector3:new( 1, 1, 0 ), 16 | Vector3:new( 0, 0, 0 ), Vector3:new( 1, 1, 0 ), Vector3:new( 1, 0, 0 ) 17 | }, 18 | TEXCOORDS = { 19 | Vector2:new( 0, 0 ), Vector2:new( 0, 1 ), Vector2:new( 1, 1 ), 20 | Vector2:new( 0, 0 ), Vector2:new( 1, 1 ), Vector2:new( 1, 0 ) 21 | }, 22 | } 23 | 24 | local res = Vector2:new( 1024, 720 ) 25 | local winScale = 1 26 | local winSize = res:scale( winScale ) 27 | local monitor = 0 28 | 29 | local tilemap = { 30 | texture = nil, 31 | texSize = Vector2:new(), 32 | mesh = nil, 33 | material = nil, 34 | tileSize = 32, 35 | tilecount = 0, 36 | } 37 | 38 | local function setTile( meshData, pos, texcoord ) 39 | local texelSize = Vector2:new( 1 / tilemap.texSize.x, 1 / tilemap.texSize.y ) 40 | 41 | for i, v in ipairs( QUAD.VERTICES ) do 42 | table.insert( meshData.vertices, ( pos + v ):scale( tilemap.tileSize ) ) 43 | table.insert( meshData.texcoords, ( QUAD.TEXCOORDS[i] + texcoord ) * texelSize:scale( tilemap.tileSize ) ) 44 | table.insert( meshData.colors, RL.WHITE ) 45 | end 46 | 47 | tilemap.tilecount = tilemap.tilecount + 1 48 | end 49 | 50 | local function genTilemap() 51 | local meshData = { vertices = {}, texcoords = {}, colors = {} } 52 | -- Ground. 53 | for x = 0, winSize.x / tilemap.tileSize do 54 | for y = 0, winSize.y / tilemap.tileSize do 55 | setTile( meshData, Vector2:new( x, y ), Vector2:new( 4, 0 ) ) 56 | end 57 | end 58 | -- House. Will be overdrawn to ground but we don't care we are so efficient! (You should though.) 59 | for x = 0, 6 do 60 | for y = 0, 10 do 61 | local tilePos = Vector2:new( x, y ) + Vector2:new( 8, 6 ) 62 | 63 | if ( x == 0 or x == 6 or y == 0 or y == 10 ) and y ~= 4 then 64 | setTile( meshData, tilePos, Vector2:new( 0, 0 ) ) 65 | else 66 | setTile( meshData, tilePos, Vector2:new( 1, 0 ) ) 67 | end 68 | end 69 | end 70 | -- Characters. You probably would not do this, but we do it here to get some variation. 71 | setTile( meshData, Vector2:new( 4, 3 ), Vector2:new( 3, 0 ) ) 72 | setTile( meshData, Vector2:new( 8, 4 ), Vector2:new( 3, 1 ) ) 73 | setTile( meshData, Vector2:new( 10, 8 ), Vector2:new( 1, 1 ) ) 74 | 75 | tilemap.mesh = RL.GenMeshCustom( meshData, false ) 76 | end 77 | 78 | function RL.init() 79 | local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) ) 80 | local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) ) 81 | 82 | RL.SetWindowTitle( "Fast tilemap" ) 83 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 84 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 85 | RL.SetWindowSize( winSize ) 86 | RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } ) 87 | 88 | local path = RL.GetBasePath().."../resources/images/tiles.png" 89 | 90 | tilemap.texture = RL.LoadTexture( path ) 91 | tilemap.texSize:setT( RL.GetTextureSize( tilemap.texture ) ) 92 | 93 | tilemap.material = RL.LoadMaterialDefault() 94 | RL.SetMaterialTexture( tilemap.material, RL.MATERIAL_MAP_ALBEDO, tilemap.texture ) 95 | 96 | genTilemap() 97 | end 98 | 99 | function RL.draw() 100 | RL.ClearBackground( RL.BLACK ) 101 | RL.DrawMesh( tilemap.mesh, tilemap.material, RL.MatrixIdentity() ) 102 | RL.DrawText( "Tile count: "..tostring( tilemap.tilecount ), { 3, 3 }, 20, RL.GREEN ) 103 | end 104 | -------------------------------------------------------------------------------- /examples/free_camera3d/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Util = require( "utillib" ) 4 | Vec2 = require( "vector2" ) 5 | Vec3 = require( "vector3" ) 6 | Cam3D = require( "camera3d" ) 7 | 8 | local monitor = 0 9 | local camera = {} 10 | local targetVisible = false 11 | 12 | function RL.init() 13 | local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) 14 | local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) 15 | local winSize = Vec2:new( 1028, 720 ) 16 | 17 | RL.SetWindowTitle( "Free Camera3D" ) 18 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 19 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 20 | RL.SetWindowSize( winSize ) 21 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 22 | RL.SetTextLineSpacing( 26 ) 23 | 24 | camera = Cam3D:new() 25 | 26 | camera:setPosition( { 0, 8, 16 } ) 27 | camera:setTarget( { 0, 0, 0 } ) 28 | camera:setUp( { 0, 1, 0 } ) 29 | -- camera.mode = camera.MODES.ORBITAL 30 | camera.mode = camera.MODES.FREE 31 | end 32 | 33 | function RL.update( delta ) 34 | camera:update( delta ) 35 | 36 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 37 | if camera.mode == camera.MODES.FREE then 38 | camera.mode = camera.MODES.FIRST_PERSON 39 | else 40 | camera.mode = camera.MODES.FREE 41 | end 42 | end 43 | 44 | if RL.IsKeyPressed( RL.KEY_T ) then 45 | targetVisible = not targetVisible 46 | end 47 | end 48 | 49 | function RL.draw() 50 | RL.ClearBackground( { 100, 150, 100 } ) 51 | 52 | camera:beginMode3D() 53 | RL.DrawGrid( 16, 1 ) 54 | RL.DrawCapsule( { 0, 0, 0 }, { 0, 2, 0 }, 1.0, 8, 6, RL.BLUE ) 55 | RL.DrawCapsuleWires( { 0, -0.01, 0 }, { 0, 2.01, 0 }, 1.01, 8, 6, RL.RED ) 56 | 57 | if targetVisible then 58 | camera:draw() 59 | end 60 | camera:endMode3D() 61 | 62 | local text = "Press space to toggle camera mode.\nCurrent mode: " 63 | 64 | if camera.mode == camera.MODES.FREE then 65 | text = text.."FREE" 66 | elseif camera.mode == camera.MODES.FIRST_PERSON then 67 | text = text.."FIRST_PERSON" 68 | end 69 | 70 | text = text.."\nPress T to toggle target visible.\nVisible: "..tostring( targetVisible ) 71 | 72 | -- RL.DrawText( RL.defaultFont, text, { 16, 16 }, 30, 4, RL.WHITE ) 73 | RL.DrawText( text, { 16, 16 }, 30, RL.WHITE ) 74 | end 75 | -------------------------------------------------------------------------------- /examples/gui/main.lua: -------------------------------------------------------------------------------- 1 | local windowOpen = true 2 | local toggled = false 3 | local checkbox = false 4 | local textBoxText = "Edit" 5 | local textBoxActive = false 6 | local spinnerValue = 3 7 | local spinnerActive = false 8 | local spinnerValueRange = { 0, 10 } 9 | local sliderValue = 5.0 10 | local sliderValueRange = { 0.0, 10.0 } 11 | local dropdownValue = 0 12 | local dropdownActive = false 13 | local index = 0 14 | local listView = { item = 0, scroll = 0 } 15 | local textInputBox = { buttonIndex = 0, text = "", secretViewActive = false } 16 | local colorPicker = { color = { 255, 255, 255 } } 17 | local colorPanel = { color = { 255, 255, 255 }, alpha = 1.0, hue = 1.0, oldHue = 1.0 } 18 | local comboBoxActive = 0 19 | local scrollPanel = { scroll = { 0, 0 }, view = { 0, 0, 320, 200 } } 20 | local guiTabBarActive = 0 21 | local colorPickerHSV = { 0, 0, 0 } 22 | local colorPanelHSV = { 0, 0, 0 } 23 | 24 | local value = 0 25 | 26 | function RL.init() 27 | local monitor = 0 28 | local mPos = RL.GetMonitorPosition( monitor ) 29 | local mSize = RL.GetMonitorSize( monitor ) 30 | local winSize = { 1920, 1080 } 31 | 32 | RL.GuiSetFont( RL.GetFontDefault() ) 33 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 34 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 35 | RL.SetWindowSize( winSize ) 36 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 37 | 38 | RL.GuiSetStyle( RL.LISTVIEW, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT ) 39 | end 40 | 41 | function RL.draw() 42 | RL.ClearBackground( { 50, 20, 75 } ) 43 | 44 | local result = 0 45 | -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 ) 46 | 47 | if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( RL.ICON_CROSS, "Exit" ) ) == 1 then 48 | RL.CloseWindow() 49 | end 50 | 51 | RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( RL.ICON_FOUR_BOXES, "Cat" ) ) 52 | 53 | if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) == 1 then 54 | windowOpen = false 55 | end 56 | 57 | RL.GuiPanel( { 60, 260, 100, 100 }, "Panel" ) 58 | 59 | _, toggled = RL.GuiToggle( { 200, 260, 64, 32 }, "Toggle", toggled ) 60 | 61 | _, index = RL.GuiToggleGroup( { 520, 30, 64, 32 }, "Cat\nDog\nMonkey", index ) 62 | 63 | _, checkbox = RL.GuiCheckBox( { 200, 300, 16, 16 }, "CheckBox", checkbox ) 64 | 65 | result, textBoxText = RL.GuiTextBox( { 32, 400, 120, 32 }, textBoxText, 32, textBoxActive ) 66 | if result == 1 then 67 | textBoxActive = not textBoxActive 68 | end 69 | 70 | result, spinnerValue = RL.GuiSpinner( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive ) 71 | if result == 1 then 72 | spinnerActive = not spinnerActive 73 | end 74 | 75 | _, sliderValue = RL.GuiSliderBar( { 64, 510, 96, 32 }, "min", "max", sliderValue, sliderValueRange[1], sliderValueRange[2] ) 76 | 77 | result, dropdownValue = RL.GuiDropdownBox( { 2, 2, 96, 16 }, "Cat\nDog\nMonkey", dropdownValue, dropdownActive ) 78 | if result == 1 then 79 | dropdownActive = not dropdownActive 80 | end 81 | 82 | _, listView.scroll, listView.item = RL.GuiListView( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listView.scroll, listView.item ) 83 | 84 | result = RL.GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes;No" ) 85 | if 0 <= result then 86 | print( "messageBox.buttonIndex", result ) 87 | end 88 | 89 | result, textInputBox.text, textInputBox.secretViewActive 90 | = RL.GuiTextInputBox( { 420, 510, 300, 150 }, "Input Box", "Put text here", "Button", textInputBox.text, 200, textInputBox.secretViewActive ) 91 | if 0 <= result then 92 | print( "textInputBox.buttonIndex", result ) 93 | end 94 | 95 | _, colorPicker.color = RL.GuiColorPicker( { 620, 20, 150, 150 }, "Color Picker", colorPicker.color ) 96 | 97 | _, colorPanel.color = RL.GuiColorPanel( { 820, 20, 150, 150 }, "Color Panel", colorPanel.color ) 98 | _, colorPanel.alpha = RL.GuiColorBarAlpha( { 820, 180, 150, 20 }, "Color alpha", colorPanel.alpha ) 99 | _, colorPanel.hue = RL.GuiColorBarHue( { 980, 20, 20, 150 }, "Color hue", colorPanel.hue ) 100 | 101 | if colorPanel.hue ~= colorPanel.oldHue then 102 | colorPanel.oldHue = colorPanel.hue 103 | colorPanel.color = RL.ColorFromHSV( colorPanel.hue, 1.0, 1.0 ) 104 | end 105 | 106 | RL.GuiDrawIcon( 121, { 6, 80 }, 2, RL.BLACK ) 107 | 108 | _, comboBoxActive = RL.GuiComboBox( { 5, 150, 80, 20 }, "One;Two;Three", comboBoxActive ) 109 | 110 | _, scrollPanel.scroll, scrollPanel.view = RL.GuiScrollPanel( 111 | { 64, 640, 320, 200 }, 112 | "Scroll panel", 113 | { 0, 0, 640, 400 }, 114 | scrollPanel.scroll, 115 | scrollPanel.view 116 | ) 117 | 118 | _, guiTabBarActive = RL.GuiTabBar( 119 | { 420, 680, 320, 32 }, 120 | RL.GuiIconText( RL.ICON_FILETYPE_PLAY, "Play" )..";"..RL.GuiIconText( RL.ICON_FILETYPE_IMAGE, "Cat.png" )..";"..RL.GuiIconText( RL.ICON_FILE_COPY, "Files" ), 121 | guiTabBarActive 122 | ) 123 | 124 | _, colorPickerHSV = RL.GuiColorPickerHSV( { 1024, 20, 150, 150 }, "GuiColorPuckerHSV", colorPickerHSV ) 125 | _, colorPanelHSV = RL.GuiColorPanelHSV( { 1230, 20, 150, 150 }, "GuiColorPuckerHSV", colorPanelHSV ) 126 | 127 | value = RL.GuiScrollBar( { 0, 0, 10, 200 }, value, 0, 100 ) 128 | end 129 | -------------------------------------------------------------------------------- /examples/heightmap/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Util = require( "utillib" ) 4 | Vec2 = require( "vector2" ) 5 | Vec3 = require( "vector3" ) 6 | Cam3D = require( "camera3d" ) 7 | 8 | local TILE_SIZE = 32 9 | 10 | local monitor = 0 11 | local camera = {} 12 | local groundRenderTexture = nil 13 | local groundTexture = nil 14 | local tilesetTex = nil 15 | local heigthImage = nil 16 | local mesh = nil 17 | local material = nil 18 | 19 | local grassRec = { 6 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE } 20 | local dirtRec = { 4 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE } 21 | local dirtRightRec = { 5 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE } 22 | local dirtLeftRec = { 5 * TILE_SIZE, 2 * TILE_SIZE, TILE_SIZE, TILE_SIZE } 23 | local dirtTopRec = { 6 * TILE_SIZE, 1 * TILE_SIZE, TILE_SIZE, TILE_SIZE } 24 | local dirtBottomRec = { 7 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE } 25 | 26 | local matrix = {} 27 | 28 | function RL.init() 29 | local mPos = RL.GetMonitorPosition( monitor ) 30 | local mSize = RL.GetMonitorSize( monitor ) 31 | local winSize = RL.GetScreenSize() 32 | 33 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 34 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 35 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 36 | 37 | camera = Cam3D:new() 38 | 39 | camera:setPosition( { 0, 8, 16 } ) 40 | camera:setTarget( { 0, 0, 0 } ) 41 | camera:setUp( { 0, 1, 0 } ) 42 | camera.mode = camera.MODES.ORBITAL 43 | 44 | heigthImage = RL.LoadImage( RL.GetBasePath().."../resources/images/heightmap.png" ) 45 | 46 | mesh = RL.GenMeshHeightmap( heigthImage, { 16, 4, 16 } ) 47 | tilesetTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" ) 48 | groundRenderTexture = RL.LoadRenderTexture( { TILE_SIZE * 16, TILE_SIZE * 16 } ) 49 | groundTexture = RL.GetRenderTextureTexture( groundRenderTexture ) 50 | 51 | -- Draw to ground texture. 52 | RL.BeginTextureMode( groundRenderTexture ) 53 | 54 | for x = 1, 16 do 55 | for y = 1, 16 do 56 | local pos = { x - 1, y - 1 } 57 | 58 | if 4 < x and x < 14 and 4 < y and y < 8 then 59 | RL.DrawTextureRec( tilesetTex, dirtRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) 60 | elseif 4 == x and 4 < y and y < 8 then 61 | RL.DrawTextureRec( tilesetTex, dirtRightRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) 62 | elseif 14 == x and 4 < y and y < 8 then 63 | RL.DrawTextureRec( tilesetTex, dirtLeftRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) 64 | elseif 4 < x and x < 14 and 4 == y then 65 | RL.DrawTextureRec( tilesetTex, dirtTopRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) 66 | elseif 4 < x and x < 14 and 8 == y then 67 | RL.DrawTextureRec( tilesetTex, dirtBottomRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) 68 | else 69 | RL.DrawTextureRec( tilesetTex, grassRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, RL.WHITE ) 70 | end 71 | end 72 | end 73 | 74 | RL.EndTextureMode() 75 | 76 | material = RL.LoadMaterialDefault() 77 | RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture ) 78 | 79 | matrix = RL.MatrixTranslate( { -4, 0, -4 } ) 80 | end 81 | 82 | function RL.update( delta ) 83 | camera:update( delta ) 84 | 85 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 86 | if camera.mode == camera.MODES.FREE then 87 | camera.mode = camera.MODES.FIRST_PERSON 88 | else 89 | camera.mode = camera.MODES.FREE 90 | end 91 | end 92 | end 93 | 94 | function RL.draw() 95 | RL.ClearBackground( { 100, 150, 100 } ) 96 | 97 | camera:beginMode3D() 98 | RL.DrawMesh( mesh, material, matrix ) 99 | camera:endMode3D() 100 | end 101 | -------------------------------------------------------------------------------- /examples/image_draw/main.lua: -------------------------------------------------------------------------------- 1 | local monitor = 0 2 | local texture = nil 3 | local image = nil 4 | local catImage = nil 5 | local catCopy = nil 6 | local textImage = nil 7 | 8 | function RL.init() 9 | local mPos = RL.GetMonitorPosition( monitor ) 10 | local mSize = RL.GetMonitorSize( monitor ) 11 | local winSize = RL.GetScreenSize() 12 | 13 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 14 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 15 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 16 | image = RL.GenImageColor( winSize, RL.WHITE ) 17 | -- Test changing working directory. 18 | RL.ChangeDirectory( RL.GetBasePath().."../resources" ) 19 | catImage = RL.LoadImage( RL.GetWorkingDirectory().."/images/cat.png" ) 20 | RL.ImageClearBackground( image, { 150, 60, 100 } ) 21 | RL.ImageDrawPixel( image, { 32, 32 }, RL.WHITE ) 22 | RL.ImageDrawLine( image, { 32, 45 }, { 100, 60 }, RL.GREEN ) 23 | RL.ImageDrawCircle( image, { 64, 32 }, 16, RL.BLUE ) 24 | RL.ImageDrawRectangle( image, { 120, 64, 32, 64 }, RL.BLUE ) 25 | RL.ImageDrawRectangleLines( image, { 160, 64, 32, 64 }, 2.0, RL.BLUE ) 26 | RL.ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, RL.WHITE ) 27 | RL.ImageDrawTextEx( image, RL.GetFontDefault(), "Hello", { 300, 32 }, 48.0, 1.0, RL.WHITE ) 28 | 29 | local src = { 80, 70, 96, 96 } 30 | catCopy = RL.ImageFromImage( catImage, src ) 31 | 32 | RL.ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, RL.WHITE ) 33 | 34 | textImage = RL.ImageTextEx( RL.GetFontDefault(), "Cat", 10, 4, RL.WHITE ) 35 | local imageSize = RL.GetImageSize( textImage ) 36 | RL.ImageDraw( image, textImage, { 0, 0, imageSize[1], imageSize[2] }, { 250, 40, imageSize[1], imageSize[2] }, RL.WHITE ) 37 | 38 | texture = RL.LoadTextureFromImage( image ) 39 | end 40 | 41 | function RL.draw() 42 | RL.ClearBackground( { 100, 150, 100 } ) 43 | RL.DrawTexture( texture, { 0, 0 }, RL.WHITE ) 44 | end 45 | -------------------------------------------------------------------------------- /examples/instancing/main.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | This example is translated from "raylib [shaders] example - Mesh instancing" 3 | -- https://github.com/raysan5/raylib/blob/master/examples/shaders/shaders_mesh_instancing.c 4 | 5 | Contributed by @seanpringle 6 | Reviewed by Max (@moliad) and Ramon Santamaria (@raysan5) 7 | 8 | Modified by Jussi Viitala (@nullstare) for ReiLua style. 9 | ]] 10 | 11 | local MAX_INSTANCES = 10000 12 | 13 | local cube 14 | local transforms = {} 15 | local camera 16 | 17 | local shader 18 | local matInstances 19 | local matDefault 20 | 21 | function RL.init() 22 | local monitor = 0 23 | local mPos = RL.GetMonitorPosition( monitor ) 24 | local mSize = RL.GetMonitorSize( monitor ) 25 | local winSize = RL.GetScreenSize() 26 | 27 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 28 | RL.SetWindowSize( winSize ) 29 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 30 | RL.SetWindowTitle( "Instancing" ) 31 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 32 | 33 | -- Define the camera to look into our 3d world 34 | camera = RL.CreateCamera3D() 35 | RL.SetCamera3DPosition( camera, { -125.0, 125.0, -125.0 } ) 36 | RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) 37 | RL.SetCamera3DUp( camera, { 0, 1, 0 } ) 38 | RL.SetCamera3DFovy( camera, 45 ) 39 | 40 | -- Define mesh to be instanced 41 | cube = RL.GenMeshCube( { 1, 1, 1 } ) 42 | 43 | -- Translate and rotate cubes randomly 44 | for i = 1, MAX_INSTANCES do 45 | local translation = RL.MatrixTranslate( { math.random( -50, 50 ), math.random( -50, 50 ), math.random( -50, 50 ) } ) 46 | local axis = RL.Vector3Normalize( { math.random( 0, 360 ), math.random( 0, 360 ), math.random( 0, 360 ) } ) 47 | local angle = math.rad( math.random( 0, 10 ) ) 48 | local rotation = RL.MatrixRotate( axis, angle ) 49 | 50 | table.insert( transforms, RL.MatrixMultiply( rotation, translation ) ) 51 | end 52 | 53 | -- Load lighting shader 54 | shader = RL.LoadShader( RL.GetBasePath().."../resources/shaders/glsl330/lighting_instancing.vs", 55 | RL.GetBasePath().."../resources/shaders/glsl330/lighting.fs" ) 56 | 57 | -- Get shader locations 58 | local mvpLoc = RL.GetShaderLocation( shader, "mvp" ) 59 | local viewPosLoc = RL.GetShaderLocation( shader, "viewPos" ) 60 | local instanceTransformLoc = RL.GetShaderLocationAttrib( shader, "instanceTransform" ) 61 | RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_MATRIX_MVP, mvpLoc ) 62 | RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_VECTOR_VIEW, viewPosLoc ) 63 | RL.SetShaderLocationIndex( shader, RL.SHADER_LOC_MATRIX_MODEL, instanceTransformLoc ) 64 | 65 | -- Set shader value: ambient light level 66 | local ambientLoc = RL.GetShaderLocation( shader, "ambient" ) 67 | RL.SetShaderValue( shader, ambientLoc, { 0.2, 0.2, 0.2, 0.1 }, RL.SHADER_UNIFORM_VEC4 ) 68 | 69 | -- Create one light 70 | RL.CreateLight( RL.LIGHT_DIRECTIONAL, { 50.0, 50.0, 0.0 }, RL.Vector3Zero(), RL.WHITE, shader ) 71 | 72 | -- NOTE: We are assigning the intancing shader to material.shader 73 | -- to be used on mesh drawing with DrawMeshInstanced() 74 | matInstances = RL.LoadMaterialDefault() 75 | RL.SetMaterialShader( matInstances, shader ) 76 | RL.SetMaterialColor( matInstances, RL.MATERIAL_MAP_DIFFUSE, RL.RED ) 77 | 78 | -- Load default material (using raylib intenral default shader) for non-instanced mesh drawing 79 | -- WARNING: Default shader enables vertex color attribute BUT GenMeshCube() does not generate vertex colors, so, 80 | -- when drawing the color attribute is disabled and a default color value is provided as input for thevertex attribute 81 | matDefault = RL.LoadMaterialDefault() 82 | RL.SetMaterialColor( matDefault, RL.MATERIAL_MAP_DIFFUSE, RL.BLUE ) 83 | end 84 | 85 | function RL.update( delta ) 86 | RL.UpdateCamera3D( camera, RL.CAMERA_ORBITAL ) 87 | 88 | -- Update the light shader with the camera view position 89 | local loc = RL.GetShaderLocationIndex( shader, RL.SHADER_LOC_VECTOR_VIEW ) 90 | RL.SetShaderValue( shader, loc, RL.GetCamera3DPosition( camera ), RL.SHADER_UNIFORM_VEC3 ) 91 | end 92 | 93 | function RL.draw() 94 | RL.ClearBackground( RL.DARKBLUE ) 95 | 96 | RL.BeginMode3D( camera ) 97 | -- Draw cube mesh with default material (BLUE) 98 | RL.DrawMesh( cube, matDefault, RL.MatrixTranslate( { -10.0, 0.0, 0.0 } ) ) 99 | 100 | -- Draw meshes instanced using material containing instancing shader (RED + lighting), 101 | -- transforms[] for the instances should be provided, they are dynamically 102 | -- updated in GPU every frame, so we can animate the different mesh instances 103 | RL.DrawMeshInstanced( cube, matInstances, transforms, MAX_INSTANCES ) 104 | 105 | -- Draw cube mesh with default material (BLUE) 106 | RL.DrawMesh( cube, matDefault, RL.MatrixTranslate( { 10.0, 0.0, 0.0 } ) ) 107 | RL.EndMode3D() 108 | 109 | RL.DrawFPS( { 10, 10 } ) 110 | end 111 | -------------------------------------------------------------------------------- /examples/iqm_test/main.lua: -------------------------------------------------------------------------------- 1 | -- Followed this tutorial. https://www.youtube.com/watch?v=_EurjoraotA 2 | 3 | local monitor = 0 4 | local camera = -1 5 | local texture = nil 6 | local material = -1 7 | local model = -1 8 | local animations = {} 9 | local frame = 0 10 | local curAnim = 0 11 | local frameCount = 0 12 | local animSpeed = 60 13 | 14 | function RL.init() 15 | local mPos = RL.GetMonitorPosition( monitor ) 16 | local mSize = RL.GetMonitorSize( monitor ) 17 | local winSize = RL.GetScreenSize() 18 | 19 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 20 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 21 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 22 | camera = RL.CreateCamera3D() 23 | RL.SetCamera3DPosition( camera, { 0, 2, 4 } ) 24 | RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) 25 | RL.SetCamera3DUp( camera, { 0, 1, 0 } ) 26 | 27 | RL.SetTextLineSpacing( 26 ) 28 | -- If custom material or mesh is set to model, we need to use custom unloading to prevent double free errors. 29 | RL.SetGCUnload( false ) 30 | 31 | texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/monkey_tex.png" ) 32 | 33 | material = RL.CreateMaterial( { 34 | maps = { 35 | { 36 | RL.MATERIAL_MAP_ALBEDO, 37 | { 38 | texture = texture, 39 | color = RL.WHITE, 40 | }, 41 | }, 42 | }, 43 | } ) 44 | model = RL.LoadModel( RL.GetBasePath().."../resources/iqm/monkey.iqm" ) 45 | -- Unload old material. 46 | RL.UnloadMaterial( RL.GetModelMaterial( model, 0 ), true ) 47 | 48 | RL.SetModelMaterial( model, 0, material ) 49 | animations = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" ) 50 | end 51 | 52 | function RL.update( delta ) 53 | if RL.IsKeyPressed( RL.KEY_ENTER ) then 54 | curAnim = curAnim + 1 55 | 56 | if #animations <= curAnim then 57 | curAnim = 0 58 | end 59 | 60 | frame = 0.0 61 | frameCount = RL.GetModelAnimationFrameCount( animations[ curAnim + 1 ] ) 62 | elseif RL.IsKeyPressed( RL.KEY_UP ) then 63 | animSpeed = animSpeed + 5 64 | elseif RL.IsKeyPressed( RL.KEY_DOWN ) then 65 | animSpeed = animSpeed - 5 66 | end 67 | 68 | if RL.IsKeyDown( RL.KEY_SPACE ) then 69 | RL.UpdateModelAnimation( model, animations[ curAnim + 1 ], math.floor( frame ) ) 70 | frame = frame + animSpeed * delta 71 | 72 | if frameCount < frame then 73 | frame = 0.0 74 | elseif frame < 0 then 75 | frame = frameCount 76 | end 77 | end 78 | end 79 | 80 | function RL.draw() 81 | RL.ClearBackground( { 100, 150, 100 } ) 82 | RL.UpdateCamera3D( camera, RL.CAMERA_FIRST_PERSON ) 83 | 84 | RL.BeginMode3D( camera ) 85 | RL.DrawGrid( 8, 1 ) 86 | RL.DrawModelEx( model, { 0, 0, 0 }, { 1.0, 0.0, 0.0 }, -90.0, { 1.0, 1.0, 1.0 }, RL.WHITE ) 87 | RL.EndMode3D() 88 | 89 | RL.DrawText( 90 | "Enter: Change animation\ 91 | Space: Play animation\ 92 | Up arrow: Inreace animation speed\ 93 | Down arrow: Decreace animation speed", 94 | { 10, 10 }, 30, RL.WHITE 95 | ) 96 | end 97 | 98 | function RL.exit() 99 | RL.UnloadTexture( texture ) 100 | RL.UnloadModel( model ) 101 | RL.UnloadModelAnimations( animations ) 102 | end 103 | -------------------------------------------------------------------------------- /examples/lightmap/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Cam3D = require( "camera3d" ) 4 | 5 | local PLANE_SIZE = 8 6 | 7 | local GLSL_VERSION = "330" -- PLATFORM_DESKTOP 8 | -- local GLSL_VERSION = "100" -- PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB 9 | 10 | local monitor = 0 11 | local camera = {} 12 | local tileTexture = nil 13 | local mesh = nil 14 | local material = nil 15 | local lightmap = nil 16 | local shader = nil 17 | 18 | local matrix = {} 19 | 20 | function RL.init() 21 | local mPos = RL.GetMonitorPosition( monitor ) 22 | local mSize = RL.GetMonitorSize( monitor ) 23 | local winSize = RL.GetScreenSize() 24 | 25 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 26 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 27 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 28 | 29 | camera = Cam3D:new() 30 | camera:setPosition( { 0, 8, 16 } ) 31 | camera:setTarget( { 0, 0, 0 } ) 32 | camera:setUp( { 0, 1, 0 } ) 33 | camera.mode = camera.MODES.ORBITAL 34 | 35 | local meshData = { 36 | vertices = { { 0, 0, 0 }, { 0, 0, PLANE_SIZE }, { PLANE_SIZE, 0, PLANE_SIZE }, 37 | { 0, 0, 0 }, { PLANE_SIZE, 0, PLANE_SIZE }, { PLANE_SIZE, 0, 0 } }, 38 | texcoords = { { 0, 0 }, { 0, PLANE_SIZE }, { PLANE_SIZE, PLANE_SIZE }, 39 | { 0, 0 }, { PLANE_SIZE, PLANE_SIZE }, { PLANE_SIZE, 0 } }, 40 | texcoords2 = { { 0, 0 }, { 0, 1 }, { 1, 1 }, 41 | { 0, 0 }, { 1, 1 }, { 1, 0 } }, 42 | colors = { RL.WHITE, RL.WHITE, RL.WHITE, 43 | RL.WHITE, RL.WHITE, RL.WHITE }, 44 | normals = { { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 }, 45 | { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 0 } }, 46 | } 47 | mesh = RL.GenMeshCustom( meshData, true ) 48 | 49 | tileTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tile.png" ) 50 | RL.GenTextureMipmaps( tileTexture ) 51 | RL.SetTextureFilter( tileTexture, RL.TEXTURE_FILTER_TRILINEAR ) 52 | lightmap = RL.LoadTexture( RL.GetBasePath().."../resources/images/lightmap.png" ) 53 | RL.SetTextureFilter( lightmap, RL.TEXTURE_FILTER_TRILINEAR ) 54 | 55 | shader = RL.LoadShader( RL.GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/lightmap.vs", 56 | RL.GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/lightmap.fs" ) 57 | 58 | local materialData = { 59 | shader = shader, 60 | maps = { 61 | { 62 | RL.MATERIAL_MAP_ALBEDO, 63 | { 64 | texture = tileTexture, 65 | color = RL.WHITE, 66 | value = 1.0, 67 | }, 68 | }, 69 | { 70 | RL.MATERIAL_MAP_METALNESS, 71 | { 72 | texture = lightmap, 73 | color = RL.WHITE, 74 | value = 1.0, 75 | }, 76 | }, 77 | }, 78 | } 79 | material = RL.CreateMaterial( materialData ) 80 | matrix = RL.MatrixTranslate( { -PLANE_SIZE / 2, 0, -PLANE_SIZE / 2 } ) 81 | end 82 | 83 | function RL.update( delta ) 84 | camera:update( delta ) 85 | 86 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 87 | if camera.mode == camera.MODES.FREE then 88 | camera.mode = camera.MODES.FIRST_PERSON 89 | else 90 | camera.mode = camera.MODES.FREE 91 | end 92 | end 93 | end 94 | 95 | function RL.draw() 96 | RL.ClearBackground( { 25, 50, 50 } ) 97 | 98 | camera:beginMode3D() 99 | RL.DrawMesh( mesh, material, matrix ) 100 | camera:endMode3D() 101 | end 102 | -------------------------------------------------------------------------------- /examples/n-patches/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Vec2 = require( "vector2" ) 4 | Rect = require( "rectangle" ) 5 | 6 | local dstRec = Rect:new( 100.0, 100.0, 8.0, 8.0 ) 7 | local origin = Vec2:new( 0.0, 0.0 ) 8 | local stretched = true 9 | local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_NINE_PATCH } 10 | -- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_VERTICAL } 11 | -- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_HORIZONTAL } 12 | local nPatchTexture = nil 13 | 14 | function RL.init() 15 | RL.SetWindowTitle( "N-Patches" ) 16 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 17 | 18 | nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/nPatch.png" ) 19 | end 20 | 21 | function RL.update( delta ) 22 | local mousePosition = Vec2:newT( RL.GetMousePosition() ) 23 | 24 | -- Resize the n-patch based on mouse position 25 | dstRec.width = mousePosition.x - dstRec.x; 26 | dstRec.height = mousePosition.y - dstRec.y; 27 | 28 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 29 | stretched = not stretched 30 | end 31 | end 32 | 33 | function RL.draw() 34 | RL.ClearBackground( RL.RAYWHITE ) 35 | local modeText = "Stretched" 36 | 37 | if stretched then 38 | RL.DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, RL.WHITE ) 39 | else 40 | RL.DrawTextureNPatchRepeat( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, RL.WHITE ) 41 | modeText = "Repeat" 42 | end 43 | 44 | RL.DrawText( "Press space to toggle mode: "..modeText, { 20, 20 }, 20, RL.BLACK ) 45 | end 46 | -------------------------------------------------------------------------------- /examples/pong/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Vector2 = require "vector2" 4 | 5 | -- Settings. 6 | local winSize = Vector2:new( 800, 600 ) 7 | local monitor = 0 8 | 9 | -- Constants. 10 | local PLAYER_SPEED = 300 -- Pixels per second. 11 | local BALL_SPEED = 330 -- Pixels per second. 12 | 13 | -- Game objects. 14 | local playerLeft = { 15 | pos = Vector2:new( 0, 0 ), 16 | size = Vector2:new( 10, 70 ), 17 | score = 0, 18 | } 19 | local playerRight = { 20 | pos = Vector2:new( 0, 0 ), 21 | size = Vector2:new( 10, 70 ), 22 | score = 0, 23 | } 24 | local ball = { 25 | pos = Vector2:new( 0, 0 ), 26 | radius = 8.0, 27 | vel = Vector2:new( 0, 0 ), 28 | } 29 | 30 | local function reset() 31 | -- Initialize player positions. 32 | playerLeft.pos.x = playerLeft.size.x 33 | playerLeft.pos.y = winSize.y / 2 - playerLeft.size.y / 2 34 | 35 | playerRight.pos.x = winSize.x - playerRight.size.x * 2 36 | playerRight.pos.y = winSize.y / 2 - playerRight.size.y / 2 37 | 38 | -- Set ball to center. 39 | ball.pos:set( winSize.x / 2, winSize.y / 2 ) 40 | -- Short for if math random result 1, set BALL_SPEED otherwise set -BALL_SPEED. 41 | -- Could be replaced by normal if statement for easier readability. 42 | ball.vel.x = math.random( 0, 1 ) == 1 and BALL_SPEED or -BALL_SPEED 43 | -- Start easy. 44 | ball.vel.y = 0 45 | end 46 | 47 | local function ballHit( padPos, padSize ) 48 | ball.vel.x = -ball.vel.x 49 | 50 | local padCenter = padPos.y + padSize.y / 2 51 | local relHitPos = ball.pos.y - padCenter 52 | ball.vel.y = BALL_SPEED * relHitPos / padSize.y * 2 53 | end 54 | 55 | function RL.init() 56 | -- Set window to center of monitor. 57 | local mPos = Vector2:newT( RL.GetMonitorPosition( monitor ) ) 58 | local mSize = Vector2:newT( RL.GetMonitorSize( monitor ) ) 59 | 60 | RL.SetConfigFlags( RL.FLAG_VSYNC_HINT ) 61 | RL.SetWindowSize( winSize ) 62 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 63 | RL.SetWindowTitle( "Pong" ) 64 | 65 | -- Initialize ball pos. 66 | math.randomseed( os.time() ) 67 | reset() 68 | end 69 | 70 | function RL.update( delta ) 71 | -- Left player controls. 72 | if RL.IsKeyDown( RL.KEY_W ) and 0 < playerLeft.pos.y then 73 | playerLeft.pos.y = playerLeft.pos.y - PLAYER_SPEED * delta 74 | elseif RL.IsKeyDown( RL.KEY_S ) and playerLeft.pos.y + playerLeft.size.y < winSize.y then 75 | playerLeft.pos.y = playerLeft.pos.y + PLAYER_SPEED * delta 76 | end 77 | 78 | -- Right player controls. 79 | if RL.IsKeyDown( RL.KEY_UP ) and 0 < playerRight.pos.y then 80 | playerRight.pos.y = playerRight.pos.y - PLAYER_SPEED * delta 81 | elseif RL.IsKeyDown( RL.KEY_DOWN ) and playerRight.pos.y + playerRight.size.y < winSize.y then 82 | playerRight.pos.y = playerRight.pos.y + PLAYER_SPEED * delta 83 | end 84 | 85 | -- Move ball. 86 | ball.pos = ball.pos + ball.vel:scale( delta ) 87 | 88 | -- Bounce from window edge. 89 | if ( ball.pos.y < ball.radius and ball.vel.y < 0 ) 90 | or ( winSize.y < ball.pos.y + ball.radius and 0 < ball.vel.y ) then 91 | ball.vel.y = -ball.vel.y 92 | end 93 | 94 | -- Bounce from players. 95 | local playerLeftRect = { playerLeft.pos.x, playerLeft.pos.y, 96 | playerLeft.size.x, playerLeft.size.y } 97 | local playerRightRect = { playerRight.pos.x, playerRight.pos.y, 98 | playerRight.size.x, playerRight.size.y } 99 | 100 | if RL.CheckCollisionCircleRec( ball.pos, ball.radius, playerLeftRect ) and ball.vel.x < 0 then 101 | ballHit( playerLeft.pos, playerLeft.size ) 102 | elseif RL.CheckCollisionCircleRec( ball.pos, ball.radius, playerRightRect ) and 0 < ball.vel.x then 103 | ballHit( playerRight.pos, playerRight.size ) 104 | end 105 | 106 | -- Score. 107 | if ball.pos.x < 0 then 108 | playerRight.score = playerRight.score + 1 109 | reset() 110 | elseif winSize.x < ball.pos.x then 111 | playerLeft.score = playerLeft.score + 1 112 | reset() 113 | end 114 | end 115 | 116 | function RL.draw() 117 | RL.ClearBackground( RL.BLACK ) 118 | 119 | -- Draw players. 120 | RL.DrawRectangle( { playerLeft.pos.x, playerLeft.pos.y, playerLeft.size.x, playerLeft.size.y }, RL.WHITE ) 121 | RL.DrawRectangle( { playerRight.pos.x, playerRight.pos.y, playerRight.size.x, playerRight.size.y }, RL.WHITE ) 122 | 123 | -- Draw ball. Ball position will be the center in drawCircle. 124 | RL.DrawCircle( ball.pos, ball.radius, RL.WHITE ) 125 | 126 | -- Draw score. 127 | RL.DrawText( tostring( playerLeft.score ), { 50, 10 }, 40, RL.WHITE ) 128 | local rightTextSize = Vector2:newT( RL.MeasureTextEx( RL.GetFontDefault(), tostring( playerRight.score ), 40, 2 ) ) 129 | RL.DrawText( tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, RL.WHITE ) 130 | end 131 | -------------------------------------------------------------------------------- /examples/ray/main.lua: -------------------------------------------------------------------------------- 1 | local camera = nil 2 | local sphereMesh = nil 3 | local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } } 4 | local rayCol = {} 5 | 6 | local function setupWindow() 7 | local monitor = 0 8 | local mPos = RL.GetMonitorPosition( monitor ) 9 | local mSize = RL.GetMonitorSize( monitor ) 10 | local winSize = RL.GetScreenSize() 11 | 12 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 13 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 14 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 15 | end 16 | 17 | local function ray_collision() 18 | rayCol = RL.GetRayCollisionMesh( ray, sphereMesh, RL.MatrixIdentity() ) 19 | 20 | if rayCol ~= nil and rayCol.hit then 21 | print( "hit", rayCol.hit ) 22 | print( "distance", rayCol.distance ) 23 | print( "point", rayCol.point[1], rayCol.point[2], rayCol.point[3] ) 24 | print( "normal", rayCol.normal[1], rayCol.normal[2], rayCol.normal[3] ) 25 | end 26 | end 27 | 28 | function RL.init() 29 | setupWindow() 30 | 31 | camera = RL.CreateCamera3D() 32 | RL.SetCamera3DPosition( camera, { 0, 2, 4 } ) 33 | RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) 34 | RL.SetCamera3DUp( camera, { 0, 1, 0 } ) 35 | 36 | sphereMesh = RL.GenMeshSphere( 1.0, 8, 10 ) 37 | 38 | ray_collision() 39 | end 40 | 41 | function RL.update( delta ) 42 | if RL.IsMouseButtonPressed( 0 ) then 43 | ray = RL.GetScreenToWorldRay( RL.GetMousePosition(), camera ) 44 | ray_collision() 45 | end 46 | end 47 | 48 | function RL.draw() 49 | RL.ClearBackground( { 100, 150, 100 } ) 50 | RL.UpdateCamera3D( camera, RL.CAMERA_FIRST_PERSON ) 51 | 52 | RL.BeginMode3D( camera ) 53 | RL.DrawGrid( 8, 1 ) 54 | RL.DrawRay( ray, { 255, 100, 100 } ) 55 | 56 | RL.DrawMesh( sphereMesh, RL.GetMaterialDefault(), RL.MatrixIdentity() ) 57 | RL.DrawSphereWires( rayCol.point, 0.05, 4, 8, RL.BLUE ) 58 | RL.DrawLine3D( rayCol.point, RL.Vector3Add( rayCol.point, rayCol.normal ), RL.GREEN ) 59 | RL.EndMode3D() 60 | end 61 | -------------------------------------------------------------------------------- /examples/ray_box_cells/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Util = require( "utillib" ) 4 | Vector2 = require( "vector2" ) 5 | Vector3 = require( "vector3" ) 6 | Rectangle = require( "rectangle" ) 7 | BoundinBox = require( "bounding_box" ) 8 | Cam3D = require( "camera3d" ) 9 | 10 | local monitor = 0 11 | local camera = {} 12 | 13 | local box = BoundinBox:new( { -8, 0, -8 }, { 16, 16, 16 } ) 14 | local cellSize = Vector3:new( 1, 1, 1 ) 15 | local drawCellSize = cellSize:clone() 16 | local ray = nil 17 | local rayCol = nil 18 | local cells = {} 19 | local exitPoint = {} 20 | 21 | local guiMouseHover = false 22 | local spinnerEdit = { 23 | x = false, 24 | y = false, 25 | z = false 26 | } 27 | 28 | function RL.init() 29 | local mPos = Vector2:newT( RL.GetMonitorPosition( monitor ) ) 30 | local mSize = Vector2:newT( RL.GetMonitorSize( monitor ) ) 31 | local winSize = Vector2:new( 1028, 720 ) 32 | 33 | RL.SetWindowTitle( "Ray box cells" ) 34 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 35 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 36 | RL.SetWindowSize( winSize ) 37 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 38 | RL.SetTextLineSpacing( 26 ) 39 | 40 | camera = Cam3D:new() 41 | 42 | camera:setPosition( { 0, 8, 16 } ) 43 | camera:setTarget( { 0, 0, 0 } ) 44 | camera:setUp( { 0, 1, 0 } ) 45 | camera.mode = camera.MODES.FREE 46 | 47 | RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 24 ) 48 | end 49 | 50 | function RL.update( delta ) 51 | camera:update( delta ) 52 | 53 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 54 | if camera.mode == camera.MODES.FREE then 55 | camera.mode = camera.MODES.FIRST_PERSON 56 | else 57 | camera.mode = camera.MODES.FREE 58 | end 59 | end 60 | 61 | -- Raycast. 62 | 63 | if not guiMouseHover and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then 64 | ray = RL.GetScreenToWorldRay( RL.GetMousePosition(), camera.camera ) 65 | rayCol = box:getRayCollisionMAS( ray ) 66 | 67 | cells, exitPoint = RL.GetRayBoxCells( ray, box:maxToPos(), cellSize ) 68 | drawCellSize:setV( cellSize ) 69 | end 70 | end 71 | 72 | local function drawSpinner( axis, pos ) 73 | local result = 0 74 | local bounds = Rectangle:temp( pos.x, pos.y, 96, 24 ) 75 | 76 | result, cellSize[ axis ] = RL.GuiSpinner( bounds, axis, cellSize[ axis ], 1, 16, spinnerEdit[ axis ] ) 77 | 78 | if result == 1 then 79 | spinnerEdit[ axis ] = not spinnerEdit[ axis ] 80 | end 81 | 82 | if bounds:checkCollisionPoint( RL.GetMousePosition() ) then 83 | guiMouseHover = true 84 | end 85 | end 86 | 87 | function RL.draw() 88 | RL.ClearBackground( RL.LIGHTGRAY ) 89 | 90 | camera:beginMode3D() 91 | RL.DrawGrid( 16, 1 ) 92 | RL.DrawCubeWires( box.min + box.max:scale( 0.5 ), box.max, RL.WHITE ) 93 | 94 | if ray then 95 | RL.DrawRay( ray, RL.BLUE ) 96 | RL.DrawSphere( ray[1], 0.1, RL.GREEN ) 97 | end 98 | if rayCol and rayCol.hit then 99 | RL.DrawSphere( rayCol.point, 0.1, RL.RED ) 100 | end 101 | if exitPoint and exitPoint.hit then 102 | RL.DrawSphere( exitPoint.point, 0.1, RL.YELLOW ) 103 | end 104 | if cells then 105 | for _, cell in ipairs( cells ) do 106 | RL.DrawCubeWires( box.min + Vector3:tempT( cell ) * drawCellSize + drawCellSize:scale( 0.5 ), drawCellSize, RL.RED ) 107 | RL.DrawCube( box.min + Vector3:tempT( cell ) * drawCellSize + drawCellSize:scale( 0.5 ), drawCellSize, { 150, 200, 150, 150 } ) 108 | end 109 | end 110 | camera:endMode3D() 111 | 112 | guiMouseHover = false 113 | 114 | drawSpinner( "x", Vector2:temp( 16, 2 ) ) 115 | drawSpinner( "y", Vector2:temp( 16, 22 ) ) 116 | drawSpinner( "z", Vector2:temp( 16, 44 ) ) 117 | end 118 | -------------------------------------------------------------------------------- /examples/raygui_examples/calculator.lua: -------------------------------------------------------------------------------- 1 | local Calculator = {} 2 | Calculator.__index = Calculator 3 | 4 | Calculator.OPERATIONS = { 5 | ADD = 0, 6 | SUB = 1, 7 | DIV = 2, 8 | MUL = 3, 9 | EQUAL = 4, 10 | CLEAR = 5, 11 | } 12 | 13 | function Calculator:new( pos ) 14 | local object = setmetatable( {}, Calculator ) 15 | 16 | object.window = Gui:WindowBox( 17 | Rect:new( pos.x, pos.y, 188, 216 ), 18 | "Calculator", 19 | { -- Callbacks. 20 | close = function() object:setVisible( false ) end, 21 | grab = function() object:setToTop() end, 22 | drag = function( this ) object:setPosition( Vec2:new( this.bounds.x, this.bounds.y ) ) end 23 | } 24 | ) 25 | object.display = Gui:Label( 26 | Rect:new( 0, 0, 180, 20 ), 27 | "" 28 | ) 29 | object.display.position = Vec2:new( 10, 32 ) 30 | object.buttons = {} 31 | 32 | local buttons = { 33 | { "7", { pressed = function() object:addNumber( 7 ) end } }, 34 | { "8", { pressed = function() object:addNumber( 8 ) end } }, 35 | { "9", { pressed = function() object:addNumber( 9 ) end } }, 36 | { "/", { pressed = function() object:addOperation( self.OPERATIONS.DIV ) end } }, 37 | { "4", { pressed = function() object:addNumber( 4 ) end } }, 38 | { "5", { pressed = function() object:addNumber( 5 ) end } }, 39 | { "6", { pressed = function() object:addNumber( 6 ) end } }, 40 | { "*", { pressed = function() object:addOperation( self.OPERATIONS.MUL ) end } }, 41 | { "1", { pressed = function() object:addNumber( 1 ) end } }, 42 | { "2", { pressed = function() object:addNumber( 2 ) end } }, 43 | { "3", { pressed = function() object:addNumber( 3 ) end } }, 44 | { "-", { pressed = function() object:addOperation( self.OPERATIONS.SUB ) end } }, 45 | { "0", { pressed = function() object:addNumber( 0 ) end } }, 46 | { "C", { pressed = function() object:addOperation( self.OPERATIONS.CLEAR ) end } }, 47 | { "=", { pressed = function() object:addOperation( self.OPERATIONS.EQUAL ) end } }, 48 | { "+", { pressed = function() object:addOperation( self.OPERATIONS.ADD ) end } }, 49 | } 50 | local rowCount = 4 51 | local buttonRect = Rect:new( 5, 64, 40, 32 ) 52 | local startPos = Vec2:new( buttonRect.x, buttonRect.y ) 53 | local buttonSpacing = 6 54 | 55 | for i, button in ipairs( buttons ) do 56 | table.insert( object.buttons, Gui:Button( 57 | buttonRect:clone(), 58 | button[1], 59 | button[2] 60 | ) ) 61 | -- Set position in window. 62 | object.buttons[i].position = Vec2:new( buttonRect.x, buttonRect.y ) 63 | 64 | if i % rowCount == 0 then 65 | buttonRect.x = startPos.x 66 | buttonRect.y = buttonRect.y + buttonRect.height + buttonSpacing 67 | else 68 | buttonRect.x = buttonRect.x + buttonRect.width + buttonSpacing 69 | end 70 | end 71 | 72 | object.visible = true 73 | object.numbers = { "", "" } 74 | object.op = nil 75 | 76 | object:setPosition( pos ) 77 | 78 | return object 79 | end 80 | 81 | function Calculator:addNumber( num ) 82 | if self.op == nil then 83 | self.numbers[1] = self.numbers[1]..tostring( num ) 84 | else 85 | self.numbers[2] = self.numbers[2]..tostring( num ) 86 | end 87 | 88 | self:updateDisplay() 89 | end 90 | 91 | function Calculator:addOperation( op ) 92 | if op == self.OPERATIONS.EQUAL then 93 | if self.op == self.OPERATIONS.ADD then 94 | self.numbers[1] = tonumber( self.numbers[1] ) + tonumber( self.numbers[2] ) 95 | elseif self.op == self.OPERATIONS.SUB then 96 | self.numbers[1] = tonumber( self.numbers[1] ) - tonumber( self.numbers[2] ) 97 | elseif self.op == self.OPERATIONS.MUL then 98 | self.numbers[1] = tonumber( self.numbers[1] ) * tonumber( self.numbers[2] ) 99 | elseif self.op == self.OPERATIONS.DIV then 100 | self.numbers[1] = tonumber( self.numbers[1] ) / tonumber( self.numbers[2] ) 101 | end 102 | 103 | self.numbers[2] = "" 104 | self.op = nil 105 | elseif op == self.OPERATIONS.CLEAR then 106 | self.numbers[1] = "" 107 | self.numbers[2] = "" 108 | self.op = nil 109 | else 110 | self.op = op 111 | end 112 | 113 | self:updateDisplay() 114 | end 115 | 116 | function Calculator:updateDisplay() 117 | self.display.text = self.numbers[1] 118 | 119 | if self.op == self.OPERATIONS.ADD then 120 | self.display.text = self.display.text.."+" 121 | elseif self.op == self.OPERATIONS.SUB then 122 | self.display.text = self.display.text.."-" 123 | elseif self.op == self.OPERATIONS.MUL then 124 | self.display.text = self.display.text.."*" 125 | elseif self.op == self.OPERATIONS.DIV then 126 | self.display.text = self.display.text.."/" 127 | end 128 | 129 | self.display.text = self.display.text..self.numbers[2] 130 | end 131 | 132 | function Calculator:setPosition( pos ) 133 | self.display:setPosition( pos + self.display.position ) 134 | 135 | for _, button in ipairs( self.buttons ) do 136 | button:setPosition( pos + button.position ) 137 | end 138 | end 139 | 140 | function Calculator:setToTop() 141 | Gui:setToTop( self.window ) 142 | Gui:setToTop( self.display ) 143 | 144 | for _, button in ipairs( self.buttons ) do 145 | Gui:setToTop( button ) 146 | end 147 | end 148 | 149 | function Calculator:setVisible( visible ) 150 | self.visible = visible 151 | self.window.visible = visible 152 | self.display.visible = visible 153 | 154 | for _, button in ipairs( self.buttons ) do 155 | button.visible = visible 156 | end 157 | end 158 | 159 | return Calculator 160 | -------------------------------------------------------------------------------- /examples/raygui_examples/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."?.lua" 2 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 3 | 4 | Util = require( "utillib" ) 5 | Rect = require( "rectangle" ) 6 | Vec2 = require( "vector2" ) 7 | Color = require( "color" ) 8 | Raygui = require( "raygui" ) 9 | Calculator = require( "calculator" ) 10 | FileBrowser = require( "file_browser" ) 11 | 12 | Gui = Raygui:new() 13 | 14 | local showAllButton = nil 15 | local calculator = nil 16 | local fileBrowser = nil 17 | 18 | local function loadFile( path ) 19 | print( "Load file: "..path ) 20 | end 21 | 22 | local function showAll() 23 | calculator:setVisible( true ) 24 | fileBrowser:setVisible( true ) 25 | end 26 | 27 | function RL.init() 28 | local monitor = 0 29 | local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) 30 | local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) 31 | local winSize = Vec2:new( 1024, 800 ) 32 | 33 | RL.SetWindowTitle( "Raygui examples" ) 34 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 35 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 36 | RL.SetWindowSize( winSize ) 37 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 38 | 39 | RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 ) 40 | RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 ) 41 | 42 | RL.GuiLoadStyle( RL.GetBasePath().."../resources/styles/style_dark.rgs" ) 43 | 44 | showAllButton = Gui:Button( 45 | Rect:new( 0, 0, 108, 28 ), 46 | "Show All", 47 | { -- callbacks. 48 | pressed = function() showAll() end 49 | } 50 | ) 51 | 52 | calculator = Calculator:new( Vec2:new( 32, 32 ) ) 53 | fileBrowser = FileBrowser:new( 54 | Vec2:new( 250, 100 ) 55 | ) 56 | 57 | fileBrowser:popup( fileBrowser.MODES.OPEN, RL.GetBasePath(), loadFile ) 58 | end 59 | 60 | function RL.update( delta ) 61 | Gui:update() 62 | end 63 | 64 | function RL.draw() 65 | RL.ClearBackground( RL.DARKBLUE ) 66 | 67 | Gui:draw() 68 | end 69 | -------------------------------------------------------------------------------- /examples/raygui_extensions/sprite_button.lua: -------------------------------------------------------------------------------- 1 | local SpriteButton = {} 2 | SpriteButton.__index = SpriteButton 3 | 4 | function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip ) 5 | local object = setmetatable( {}, self ) 6 | object._gui = nil 7 | 8 | object.bounds = bounds:clone() 9 | object.text = text 10 | object.buttonTexture = texture 11 | object.nPatchNormal = nPatchNormal 12 | object.nPatchPressed = nPatchPressed 13 | object.callbacks = callbacks -- pressed. 14 | object.styles = styles 15 | object.tooltip = tooltip 16 | 17 | object.visible = true 18 | object.disabled = false 19 | 20 | return object 21 | end 22 | 23 | function SpriteButton:update() 24 | return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) 25 | end 26 | 27 | function SpriteButton:draw() 28 | if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:update() and not RL.GuiIsLocked() 29 | and not RL.GuiGetSliderDragging() then 30 | RL.DrawTextureNPatchRepeat( 31 | self.buttonTexture, self.nPatchPressed, self.bounds, 32 | { 0, 0 }, 0.0, RL.GetColor( RL.GuiGetStyle( RL.BUTTON, RL.BASE_COLOR_PRESSED ) ) 33 | ) 34 | else 35 | RL.DrawTextureNPatchRepeat( 36 | self.buttonTexture, self.nPatchNormal, self.bounds, 37 | { 0, 0 }, 0.0, RL.GetColor( RL.GuiGetStyle( RL.BUTTON, RL.BASE_COLOR_NORMAL ) ) 38 | ) 39 | end 40 | 41 | local result = RL.GuiLabelButton( self.bounds, self.text ) 42 | 43 | if result == 1 and self.callbacks.pressed ~= nil and self._gui:clickedInBounds( self.bounds ) then 44 | self.callbacks.pressed( self ) 45 | end 46 | end 47 | 48 | function SpriteButton:setPosition( pos ) 49 | self.bounds.x = pos.x 50 | self.bounds.y = pos.y 51 | end 52 | 53 | function SpriteButton:register( gui ) 54 | function gui:SpriteButton( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip ) 55 | return self:addControl( SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip ) ) 56 | end 57 | end 58 | 59 | return SpriteButton 60 | -------------------------------------------------------------------------------- /examples/raygui_extensions/tree_item.lua: -------------------------------------------------------------------------------- 1 | local TreeItem = {} 2 | TreeItem.__index = TreeItem 3 | 4 | function TreeItem:new( bounds, text, callbacks, styles, tooltip ) 5 | local object = setmetatable( {}, self ) 6 | object._gui = nil 7 | 8 | object.spacing = 4 -- Between controls. 9 | 10 | object.bounds = bounds:clone() 11 | object.text = text 12 | object.callbacks = callbacks -- select, open. 13 | 14 | object.controls = {} 15 | 16 | object.active = false 17 | object.open = false -- Show controls. 18 | object.visible = true 19 | object.disabled = false 20 | object.styles = styles 21 | object.tooltip = tooltip 22 | 23 | object._depth = 0 24 | object._indentation = 0 25 | object._id = 0 -- Id in treeView. 26 | object._parent = nil 27 | object._childId = 0 -- Id in parent controls. 28 | 29 | return object 30 | end 31 | 32 | function TreeItem:update() 33 | return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) 34 | end 35 | 36 | function TreeItem:setOpenIcon() 37 | if self.open then 38 | return RL.GuiIconText( RL.ICON_ARROW_DOWN_FILL, "" ) 39 | else 40 | return RL.GuiIconText( RL.ICON_ARROW_RIGHT_FILL, "" ) 41 | end 42 | end 43 | 44 | function TreeItem:draw() 45 | local buttonRect = Rectangle:new( 0, 0, 0, 0 ) 46 | local hasContainer = 0 < #self.controls 47 | local lineCol = RL.GetColor( RL.GuiGetStyle( RL.DEFAULT, RL.LINE_COLOR ) ) 48 | 49 | if hasContainer then 50 | buttonRect:set( self.bounds.x, self.bounds.y, self.bounds.height, self.bounds.height ) 51 | end 52 | -- Draw indentation lines. 53 | for i = 0, self._depth - 1 do 54 | RL.DrawRectangle( { 55 | self.bounds.x - i * self._indentation - self._indentation / 2, 56 | self.bounds.y - self.spacing, 57 | 1, 58 | self.bounds.height + self.spacing * 2 59 | }, lineCol ) 60 | end 61 | 62 | local toggleRect = Rectangle:new( 63 | self.bounds.x + buttonRect.width, 64 | self.bounds.y, 65 | self.bounds.width - buttonRect.width, 66 | self.bounds.height 67 | ) 68 | local oldActive = self.active 69 | _, self.active = RL.GuiToggle( toggleRect, self.text, self.active ) 70 | 71 | if self.callbacks.select and oldActive ~= self.active then 72 | self.callbacks.select( self ) 73 | end 74 | 75 | if hasContainer then 76 | local pressed = RL.GuiLabelButton( buttonRect, self:setOpenIcon() ) 77 | 78 | if self.callbacks.open and 0 < pressed then 79 | self.open = not self.open 80 | self.callbacks.open( self ) 81 | end 82 | end 83 | end 84 | 85 | function TreeItem:setPosition( pos ) 86 | self.bounds.x = pos.x 87 | self.bounds.y = pos.y 88 | end 89 | 90 | function TreeItem:register( gui ) 91 | function gui:TreeItem( bounds, text, callbacks, styles, tooltip ) 92 | return self:addControl( TreeItem:new( bounds, text, callbacks, styles, tooltip ) ) 93 | end 94 | end 95 | 96 | return TreeItem 97 | -------------------------------------------------------------------------------- /examples/resources/images/LICENCE: -------------------------------------------------------------------------------- 1 | Resource Author Licence Source Edits 2 | tiles.png Chris Hamons (maintainer) CC0 https://opengameart.org/content/dungeon-crawl-32x32-tiles 3 | arcade_platformerV2.png GrafxKid CC0 https://opengameart.org/content/arcade-platformer-assets 4 | apple.png Jussi Viitala CC0 5 | grass.png Jussi Viitala CC0 6 | snake.png Jussi Viitala CC0 7 | ui_border.png Jussi Viitala CC0 8 | ui_bgr.png Jussi Viitala CC0 9 | gradient.png Jussi Viitala CC0 10 | light.png Jussi Viitala CC0 11 | nPatch.png Jussi Viitala CC0 12 | button.png Jussi Viitala CC0 13 | check-mark.png Delapouite Creative Commons 3.0 https://game-icons.net Resized 14 | circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized 15 | plain-circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized 16 | previous-button.png Delapouite Creative Commons 3.0 https://game-icons.net Resized 17 | open-folder.png Delapouite Creative Commons 3.0 https://game-icons.net Resized 18 | files.png Delapouite Creative Commons 3.0 https://game-icons.net Resized 19 | cancel.png Sbed Creative Commons 3.0 https://game-icons.net Resized 20 | -------------------------------------------------------------------------------- /examples/resources/images/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/apple.png -------------------------------------------------------------------------------- /examples/resources/images/arcade_platformerV2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/arcade_platformerV2.png -------------------------------------------------------------------------------- /examples/resources/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/button.png -------------------------------------------------------------------------------- /examples/resources/images/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/cancel.png -------------------------------------------------------------------------------- /examples/resources/images/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/cat.png -------------------------------------------------------------------------------- /examples/resources/images/check-mark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/check-mark.png -------------------------------------------------------------------------------- /examples/resources/images/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/circle.png -------------------------------------------------------------------------------- /examples/resources/images/files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/files.png -------------------------------------------------------------------------------- /examples/resources/images/gradient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/gradient.png -------------------------------------------------------------------------------- /examples/resources/images/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/grass.png -------------------------------------------------------------------------------- /examples/resources/images/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/heightmap.png -------------------------------------------------------------------------------- /examples/resources/images/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/light.png -------------------------------------------------------------------------------- /examples/resources/images/lightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/lightmap.png -------------------------------------------------------------------------------- /examples/resources/images/monkey_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/monkey_tex.png -------------------------------------------------------------------------------- /examples/resources/images/nPatch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/nPatch.png -------------------------------------------------------------------------------- /examples/resources/images/open-folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/open-folder.png -------------------------------------------------------------------------------- /examples/resources/images/plain-circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/plain-circle.png -------------------------------------------------------------------------------- /examples/resources/images/previous-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/previous-button.png -------------------------------------------------------------------------------- /examples/resources/images/snake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/snake.png -------------------------------------------------------------------------------- /examples/resources/images/tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/tile.png -------------------------------------------------------------------------------- /examples/resources/images/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/tiles.png -------------------------------------------------------------------------------- /examples/resources/images/ui_bgr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/ui_bgr.png -------------------------------------------------------------------------------- /examples/resources/images/ui_border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/ui_border.png -------------------------------------------------------------------------------- /examples/resources/images/wabbit_alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/images/wabbit_alpha.png -------------------------------------------------------------------------------- /examples/resources/iqm/monkey.iqm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/iqm/monkey.iqm -------------------------------------------------------------------------------- /examples/resources/lib/camera3d.lua: -------------------------------------------------------------------------------- 1 | local Vector2 = Vector2 or require( "vector2" ) 2 | local Vector3 = Vector3 or require( "vector3" ) 3 | 4 | Camera3D = {} 5 | Camera3D.meta = { 6 | __index = Camera3D, 7 | } 8 | Camera3D.MODES = { 9 | CUSTOM = 0, 10 | FREE = 1, 11 | FIRST_PERSON = 2, 12 | ORBITAL = 3, 13 | } 14 | Camera3D.KEYS = { 15 | FORWARD = RL.KEY_W, 16 | BACKWARD = RL.KEY_S, 17 | RIGHT = RL.KEY_D, 18 | LEFT = RL.KEY_A, 19 | UP = RL.KEY_R, 20 | DOWN = RL.KEY_F, 21 | PAN = RL.KEY_LEFT_SHIFT, 22 | FAST = RL.KEY_LEFT_SHIFT, 23 | } 24 | Camera3D.MOUSE_MOVE_SPEED = 0.5 25 | Camera3D.KEYBOARD_MOVE_SPEED = 10 26 | Camera3D.KEYBOARD_MOVE_SPEED_MULTI = 3 27 | Camera3D.TURN_SPEED = 0.15 28 | Camera3D.ORBITAL_SPEED = 0.5 29 | Camera3D.ZOOM_AMOUNT = 0.1 30 | 31 | function Camera3D:new() 32 | local object = setmetatable( {}, Camera3D.meta ) 33 | 34 | object.camera = RL.CreateCamera3D() 35 | object.mode = object.MODES.CUSTOM 36 | 37 | object:setPosition( { 0, 0, 0 } ) 38 | object:setTarget( { 0, 0, 0 } ) 39 | object:setUp( { 0, 1, 0 } ) 40 | 41 | return object 42 | end 43 | 44 | function Camera3D:setPosition( pos ) 45 | RL.SetCamera3DPosition( self.camera, pos ) 46 | end 47 | 48 | function Camera3D:setTarget( target ) 49 | RL.SetCamera3DTarget( self.camera, target ) 50 | end 51 | 52 | function Camera3D:setUp( up ) 53 | RL.SetCamera3DUp( self.camera, up ) 54 | end 55 | 56 | function Camera3D:setFoyv( foyv ) 57 | RL.SetCamera3DFovy( self.camera, foyv ) 58 | end 59 | 60 | function Camera3D:setProjection( projection ) 61 | RL.SetCamera3DProjection( self.camera, projection ) 62 | end 63 | 64 | function Camera3D:getPosition() 65 | return Vector3:newT( RL.GetCamera3DPosition( self.camera ) ) 66 | end 67 | 68 | function Camera3D:getTarget() 69 | return Vector3:newT( RL.GetCamera3DTarget( self.camera ) ) 70 | end 71 | 72 | function Camera3D:getUp() 73 | return Vector3:newT( RL.GetCamera3DUp( self.camera ) ) 74 | end 75 | 76 | function Camera3D:getFoyv() 77 | return RL.GetCamera3DFovy( self.camera ) 78 | end 79 | 80 | function Camera3D:getProjection() 81 | return RL.GetCamera3DProjection( self.camera ) 82 | end 83 | 84 | --- Returns the cameras forward vector ( normalized ) 85 | function Camera3D:getForward() 86 | return Vector3:newT( RL.GetCamera3DForward( self.camera ) ) 87 | end 88 | 89 | --- Returns the cameras up vector ( normalized ) Note: The up vector might not be perpendicular to the forward vector 90 | function Camera3D:getUpward() 91 | return Vector3:newT( RL.GetCamera3DUpNormalized( self.camera ) ) 92 | end 93 | 94 | function Camera3D:update( delta ) 95 | if self.mode == self.MODES.FREE then 96 | if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then 97 | local mouseDelta = Vector2:newT( RL.GetMouseDelta() ) 98 | 99 | if RL.IsKeyDown( self.KEYS.PAN ) then 100 | mouseDelta = mouseDelta:scale( self.MOUSE_MOVE_SPEED * delta ) 101 | local forward = RL.GetCamera3DForward( self.camera )[2] 102 | 103 | RL.Camera3DMoveRight( self.camera, -mouseDelta.x, true ) 104 | RL.Camera3DMoveUp( self.camera, mouseDelta.y * ( 1 - math.abs( forward ) ) ) 105 | RL.Camera3DMoveForward( self.camera, mouseDelta.y * -forward, true ) 106 | else 107 | mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta ) 108 | 109 | RL.Camera3DYaw( self.camera, -mouseDelta.x, true ) 110 | RL.Camera3DPitch( self.camera, -mouseDelta.y, true, true, false ) 111 | end 112 | end 113 | 114 | local mouseScroll = RL.GetMouseWheelMove() 115 | 116 | if mouseScroll ~= 0 then 117 | RL.Camera3DMoveToTarget( self.camera, self.ZOOM_AMOUNT * self:getTargetDistance() * -mouseScroll ) 118 | end 119 | elseif self.mode == self.MODES.FIRST_PERSON then 120 | local mouseDelta = Vector2:newT( RL.GetMouseDelta() ) 121 | 122 | mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta ) 123 | 124 | RL.Camera3DYaw( self.camera, -mouseDelta.x, false ) 125 | RL.Camera3DPitch( self.camera, -mouseDelta.y, true, false, false ) 126 | RL.SetMousePosition( Vector2:newT( RL.GetScreenSize() ):scale( 0.5 ) ) 127 | 128 | local distance = self.KEYBOARD_MOVE_SPEED * delta 129 | local forward = RL.GetCamera3DForward( self.camera )[2] 130 | 131 | if RL.IsKeyDown( self.KEYS.FAST ) then 132 | distance = distance * self.KEYBOARD_MOVE_SPEED_MULTI 133 | end 134 | 135 | if RL.IsKeyDown( self.KEYS.FORWARD ) then 136 | RL.Camera3DMoveForward( self.camera, distance, false ) 137 | elseif RL.IsKeyDown( self.KEYS.BACKWARD ) then 138 | RL.Camera3DMoveForward( self.camera, -distance, false ) 139 | end 140 | 141 | if RL.IsKeyDown( self.KEYS.RIGHT ) then 142 | RL.Camera3DMoveRight( self.camera, distance, true ) 143 | elseif RL.IsKeyDown( self.KEYS.LEFT ) then 144 | RL.Camera3DMoveRight( self.camera, -distance, true ) 145 | end 146 | 147 | if RL.IsKeyDown( self.KEYS.UP ) then 148 | RL.Camera3DMoveUp( self.camera, distance * ( 1 - math.abs( forward ) ) ) 149 | RL.Camera3DMoveForward( self.camera, distance * -forward, true ) 150 | elseif RL.IsKeyDown( self.KEYS.DOWN ) then 151 | RL.Camera3DMoveUp( self.camera, -distance * ( 1 - math.abs( forward ) ) ) 152 | RL.Camera3DMoveForward( self.camera, -distance * -forward, true ) 153 | end 154 | elseif self.mode == self.MODES.ORBITAL then 155 | RL.Camera3DYaw( self.camera, self.ORBITAL_SPEED * delta, true ) 156 | end 157 | end 158 | 159 | --- Draw camera target. 160 | function Camera3D:draw() 161 | local targetPos = self:getTarget() 162 | 163 | RL.DrawLine3D( targetPos + Vector3:new( -0.5, 0, 0 ), targetPos + Vector3:new( 0.5, 0, 0 ), RL.GREEN ) 164 | RL.DrawLine3D( targetPos + Vector3:new( 0, -0.5, 0 ), targetPos + Vector3:new( 0, 0.5, 0 ), RL.BLUE ) 165 | RL.DrawLine3D( targetPos + Vector3:new( 0, 0, -0.5 ), targetPos + Vector3:new( 0, 0, 0.5 ), RL.RED ) 166 | end 167 | 168 | function Camera3D:getTargetDistance() 169 | return RL.Vector3Distance( self:getPosition(), self:getTarget() ) 170 | end 171 | 172 | function Camera3D:beginMode3D() 173 | RL.BeginMode3D( self.camera ) 174 | end 175 | 176 | function Camera3D:endMode3D() 177 | RL.EndMode3D() 178 | end 179 | 180 | return Camera3D 181 | -------------------------------------------------------------------------------- /examples/resources/lib/color.lua: -------------------------------------------------------------------------------- 1 | -- For luaJit compatibility. 2 | if table.unpack == nil then 3 | table.unpack = unpack 4 | end 5 | 6 | local Vector3 = Vector3 or require( "vector3" ) 7 | 8 | local Color = {} 9 | local metatable = { 10 | __index = Color, 11 | __tostring = function( c ) 12 | return "{"..math.floor( c.r )..", "..math.floor( c.g )..", "..math.floor( c.b )..", "..math.floor( c.a ).."}" 13 | end, 14 | __add = function( c1, c2 ) 15 | return Color:new( c1.r + c2.r, c1.g + c2.g, c1.b + c2.b, c1.a + c2.a ) 16 | end, 17 | __sub = function( c1, c2 ) 18 | return Color:new( c1.r - c2.r, c1.g - c2.g, c1.b - c2.b, c1.a - c2.a ) 19 | end, 20 | __mul = function( c1, c2 ) 21 | return Color:new( c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a ) 22 | end, 23 | __div = function( c1, c2 ) 24 | return Color:new( c1.r / c2.r, c1.g / c2.g, c1.b / c2.b, c1.a / c2.a ) 25 | end, 26 | __mod = function( c, v ) 27 | return Color:new( c.r % v, c.g % v, c.b % v, c.a % v ) 28 | end, 29 | __pow = function( c, v ) 30 | return Color:new( c.r ^ v, c.g ^ v, c.b ^ v, c.a ^ v ) 31 | end, 32 | __len = function() 33 | return 4 34 | end, 35 | __eq = function( c1, c2 ) 36 | return RL.FloatEquals( c1.r, c2.r ) 37 | and RL.FloatEquals( c1.g, c2.g ) 38 | and RL.FloatEquals( c1.b, c2.b ) 39 | and RL.FloatEquals( c1.a, c2.a ) 40 | end, 41 | __concat = function( a, b ) 42 | return tostring( a )..tostring( b ) 43 | end, 44 | } 45 | 46 | function Color:new( r, g, b, a ) 47 | local object = setmetatable( {}, metatable ) 48 | 49 | object.r = r or 255 50 | object.g = g or object.r 51 | object.b = b or object.g 52 | object.a = a or 255 53 | 54 | return object 55 | end 56 | 57 | function Color:newT( t ) 58 | local object = setmetatable( {}, metatable ) 59 | 60 | object.r, object.g, object.b, object.a = table.unpack( t ) 61 | 62 | return object 63 | end 64 | 65 | function Color:newC( c ) 66 | local object = setmetatable( {}, metatable ) 67 | 68 | object.r = c.r 69 | object.g = c.g 70 | object.b = c.b 71 | object.a = c.a 72 | 73 | return object 74 | end 75 | 76 | function Color:set( r, g, b, a ) 77 | self.r = r or 255 78 | self.g = g or self.r 79 | self.b = b or self.g 80 | self.a = a or 255 81 | end 82 | 83 | function Color:setT( t ) 84 | self.r, self.g, self.b, self.a = table.unpack( t ) 85 | end 86 | 87 | function Color:setC( c ) 88 | self.r = c.r 89 | self.g = c.g 90 | self.b = c.b 91 | self.a = c.a 92 | end 93 | 94 | function Color:serialize() 95 | return "Color:new("..RL.Round( self.r )..","..RL.Round( self.g )..","..RL.Round( self.b )..","..RL.Round( self.a )..")" 96 | end 97 | 98 | function Color:arr() 99 | return { self.r, self.g, self.b, self.a } 100 | end 101 | 102 | function Color:unpack() 103 | return self.r, self.g, self.b, self.a 104 | end 105 | 106 | function Color:clone() 107 | return Color:new( self.r, self.g, self.b, self.a ) 108 | end 109 | 110 | function Color:scale( scalar ) 111 | return Color:new( math.floor( self.r * scalar ), math.floor( self.g * scalar ), math.floor( self.b * scalar ), math.floor( self.a * scalar ) ) 112 | end 113 | 114 | function Color:fade( alpha ) 115 | return Color:newT( RL.Fade( self, alpha ) ) 116 | end 117 | 118 | function Color:toHex() 119 | return RL.ColorToInt( self ) 120 | end 121 | 122 | function Color:fromHex( hexValue ) 123 | return Color:newT( RL.GetColor( hexValue ) ) 124 | end 125 | 126 | function Color:getNormalized() 127 | return RL.ColorNormalize( self ) 128 | end 129 | 130 | function Color:fromNormalized( normalized ) 131 | return Color:newT( RL.ColorFromNormalized( normalized ) ) 132 | end 133 | 134 | function Color:toHSV() 135 | return Vector3:newT( RL.ColorToHSV( self ) ) 136 | end 137 | 138 | function Color:fromHSV( hue, saturation, value ) 139 | return Color:newT( RL.ColorFromHSV( hue, saturation, value ) ) 140 | end 141 | 142 | function Color:tint( tint ) 143 | return Color:newT( RL.ColorTint( self, tint ) ) 144 | end 145 | 146 | function Color:brightness( factor ) 147 | return Color:newT( RL.ColorBrightness( self, factor ) ) 148 | end 149 | 150 | function Color:contrast( contrast ) 151 | return Color:newT( RL.ColorContrast( self, contrast ) ) 152 | end 153 | 154 | function Color:alphaBlend( dst, src, tint ) 155 | return Color:newT( RL.ColorAlphaBlend( dst, src, tint ) ) 156 | end 157 | 158 | function Color:lerp( color, amount ) 159 | return Color:temp( 160 | RL.Lerp( self.r, color.r, amount ), 161 | RL.Lerp( self.g, color.g, amount ), 162 | RL.Lerp( self.b, color.b, amount ), 163 | RL.Lerp( self.a, color.a, amount ) 164 | ):round() 165 | end 166 | 167 | function Color:round() 168 | return Color:new( 169 | RL.Round( self.r ), 170 | RL.Round( self.g ), 171 | RL.Round( self.b ), 172 | RL.Round( self.a ) 173 | ) 174 | end 175 | 176 | function Color:mix( c ) 177 | return Color:temp( 178 | ( self.r + c.r ) / 2, 179 | ( self.g + c.g ) / 2, 180 | ( self.b + c.b ) / 2, 181 | ( self.a + c.a ) / 2 182 | ):round() 183 | end 184 | 185 | function Color:invert() 186 | return Color:new( 255 - self.r, 255 - self.g, 255 - self.b, self.a ) 187 | end 188 | 189 | -- Temp pre generated objects to avoid "slow" table generation. 190 | 191 | local TEMP_COUNT = 100 192 | local tempPool = {} 193 | local curTemp = 1 194 | 195 | for _ = 1, TEMP_COUNT do 196 | table.insert( tempPool, Color:new( 255, 255, 255, 255 ) ) 197 | end 198 | 199 | function Color:temp( r, g, b, a ) 200 | local object = tempPool[ curTemp ] 201 | 202 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 203 | 204 | object.r = r or 255 205 | object.g = g or object.r 206 | object.b = b or object.g 207 | object.a = a or 255 208 | 209 | return object 210 | end 211 | 212 | function Color:tempT( t ) 213 | local object = tempPool[ curTemp ] 214 | 215 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 216 | 217 | object.r, object.g, object.b, object.a = table.unpack( t ) 218 | 219 | return object 220 | end 221 | 222 | function Color:tempC( c ) 223 | local object = tempPool[ curTemp ] 224 | 225 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 226 | 227 | object.r = c.r 228 | object.g = c.g 229 | object.b = c.b 230 | object.a = c.a 231 | 232 | return object 233 | end 234 | 235 | function Color:getTempId() 236 | return curTemp 237 | end 238 | 239 | return Color 240 | -------------------------------------------------------------------------------- /examples/resources/lib/matrix.lua: -------------------------------------------------------------------------------- 1 | -- For luaJit compatibility. 2 | if table.unpack == nil then 3 | table.unpack = unpack 4 | end 5 | 6 | local Matrix = {} 7 | local metatable = { 8 | __index = Matrix, 9 | __tostring = function( m ) 10 | return "{\n" 11 | .." {"..m[1][1]..", "..m[1][2]..", "..m[1][3]..", "..m[1][4].."},\n" 12 | .." {"..m[2][1]..", "..m[2][2]..", "..m[2][3]..", "..m[2][4].."},\n" 13 | .." {"..m[3][1]..", "..m[3][2]..", "..m[3][3]..", "..m[3][4].."},\n" 14 | .." {"..m[4][1]..", "..m[4][2]..", "..m[4][3]..", "..m[4][4].."},\n" 15 | .."}" 16 | end, 17 | __add = function( m1, m2 ) 18 | return Matrix:new( RL.MatrixAdd( m1, m2 ) ) 19 | end, 20 | __sub = function( m1, m2 ) 21 | return Matrix:new( RL.MatrixSubtract( m1, m2 ) ) 22 | end, 23 | __mul = function( m1, m2 ) 24 | return Matrix:new( RL.MatrixMultiply( m1, m2 ) ) 25 | end, 26 | __concat = function( a, b ) 27 | return tostring( a )..tostring( b ) 28 | end, 29 | } 30 | 31 | function Matrix:copyMatrix( orig ) 32 | if orig ~= nil then 33 | for y = 1, 4 do 34 | for x = 1, 4 do 35 | if orig[x][y] ~= nil then 36 | self[x][y] = orig[x][y] 37 | end 38 | end 39 | end 40 | end 41 | end 42 | 43 | function Matrix:new( m ) 44 | local object = setmetatable( {}, metatable ) 45 | 46 | -- Raylib style transposed matrix. 47 | for x = 1, 4 do 48 | object[x] = {} 49 | for y = 1, 4 do 50 | table.insert( object[x], m[x][y] ) 51 | end 52 | end 53 | 54 | return object 55 | end 56 | 57 | function Matrix:set( m ) 58 | self:copyMatrix( m ) 59 | end 60 | 61 | function Matrix:serialize() 62 | local str = { "Matrix:new({" } 63 | 64 | for i, row in ipairs( self ) do 65 | table.insert( str, "{" ) 66 | 67 | for c, v in ipairs( row ) do 68 | table.insert( str, v ) 69 | if c < 4 then 70 | table.insert( str, "," ) 71 | end 72 | end 73 | table.insert( str, "}" ) 74 | if i < 4 then 75 | table.insert( str, "," ) 76 | end 77 | end 78 | table.insert( str, "})" ) 79 | 80 | return table.concat( str ) 81 | end 82 | 83 | function Matrix:clone() 84 | return Matrix:new( self ) 85 | end 86 | 87 | function Matrix:determinant() 88 | return RL.MatrixDeterminant( self ) 89 | end 90 | 91 | function Matrix:trace() 92 | return RL.MatrixTranspose( self ) 93 | end 94 | 95 | function Matrix:transpose() 96 | return Matrix:new( RL.MatrixTranspose( self ) ) 97 | end 98 | 99 | function Matrix:multiply( m2 ) 100 | return Matrix:new( RL.MatrixMultiply( self, m2 ) ) 101 | end 102 | 103 | function Matrix:invert() 104 | return Matrix:new( RL.MatrixInvert( self ) ) 105 | end 106 | 107 | function Matrix:identity() 108 | return Matrix:new( RL.MatrixIdentity() ) 109 | end 110 | 111 | function Matrix:translate( translate ) 112 | return Matrix:new( RL.MatrixTranslate( translate ) ) 113 | end 114 | 115 | function Matrix:rotate( axis, angle ) 116 | return Matrix:new( RL.MatrixRotate( axis, angle ) ) 117 | end 118 | 119 | function Matrix:rotateX( angle ) 120 | return Matrix:new( RL.MatrixRotateX( angle ) ) 121 | end 122 | 123 | function Matrix:rotateY( angle ) 124 | return Matrix:new( RL.MatrixRotateY( angle ) ) 125 | end 126 | 127 | function Matrix:rotateZ( angle ) 128 | return Matrix:new( RL.MatrixRotateZ( angle ) ) 129 | end 130 | 131 | function Matrix:rotateXYZ( angles ) 132 | return Matrix:new( RL.MatrixRotateXYZ( angles ) ) 133 | end 134 | 135 | function Matrix:rotateZYX( angles ) 136 | return Matrix:new( RL.MatrixRotateZYX( angles ) ) 137 | end 138 | 139 | function Matrix:scale( scale ) 140 | return Matrix:new( RL.MatrixScale( scale ) ) 141 | end 142 | 143 | function Matrix:frustrum( left, right, bottom, top, near, far ) 144 | return Matrix:new( RL.MatrixFrustum( left, right, bottom, top, near, far ) ) 145 | end 146 | 147 | function Matrix:perspective( fovy, aspect, near, far ) 148 | return Matrix:new( RL.MatrixPerspective( fovy, aspect, near, far ) ) 149 | end 150 | 151 | function Matrix:ortho( left, right, bottom, top, near, far ) 152 | return Matrix:new( RL.MatrixOrtho( left, right, bottom, top, near, far ) ) 153 | end 154 | 155 | function Matrix:lookAt( eye, target, up ) 156 | return Matrix:new( RL.MatrixLookAt( eye, target, up ) ) 157 | end 158 | 159 | -- Temp pre generated objects to avoid "slow" table generation. 160 | 161 | local TEMP_COUNT = 100 162 | local tempPool = {} 163 | local curTemp = 1 164 | 165 | for _ = 1, TEMP_COUNT do 166 | table.insert( tempPool, Matrix:new( RL.MatrixIdentity() ) ) 167 | end 168 | 169 | function Matrix:temp( m ) 170 | local object = tempPool[ curTemp ] 171 | 172 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 173 | 174 | object:copyMatrix( m ) 175 | 176 | return object 177 | end 178 | 179 | function Matrix:getTempId() 180 | return curTemp 181 | end 182 | 183 | return Matrix 184 | -------------------------------------------------------------------------------- /examples/resources/lib/pubsub.lua: -------------------------------------------------------------------------------- 1 | local PubSub = {} 2 | PubSub.__index = PubSub 3 | 4 | function PubSub:new() 5 | local object = setmetatable( {}, self ) 6 | 7 | object.signals = {} 8 | 9 | return object 10 | end 11 | 12 | function PubSub:add( name ) 13 | self.signals[ name ] = {} 14 | end 15 | 16 | function PubSub:remove( name ) 17 | if self.signals[ name ] ~= nil then 18 | table.remove( self.signals, name ) 19 | end 20 | end 21 | 22 | function PubSub:subscribe( name, func ) 23 | if self.signals[ name ] ~= nil then 24 | table.insert( self.signals[ name ], func ) 25 | end 26 | end 27 | 28 | function PubSub:unSubscribe( name, uFunc ) 29 | if self.signals[ name ] ~= nil then 30 | for i, func in ipairs( self.signals[ name ] ) do 31 | if func == uFunc then 32 | table.remove( self.signals[ name ], i ) 33 | end 34 | end 35 | end 36 | end 37 | 38 | function PubSub:publish( name, ... ) 39 | if self.signals[ name ] ~= nil then 40 | for _, func in ipairs( self.signals[ name ] ) do 41 | func( ... ) 42 | end 43 | end 44 | end 45 | 46 | return PubSub 47 | -------------------------------------------------------------------------------- /examples/resources/lib/quaternion.lua: -------------------------------------------------------------------------------- 1 | -- For luaJit compatibility. 2 | if table.unpack == nil then 3 | table.unpack = unpack 4 | end 5 | 6 | local Vector3 = Vector3 or require( "vector3" ) 7 | local Matrix = Matrix or require( "matrix" ) 8 | 9 | local Quaternion = {} 10 | local metatable = { 11 | __index = Quaternion, 12 | __tostring = function( q ) 13 | return "{"..tostring( q.x )..", "..tostring( q.y )..", "..tostring( q.z )..", "..tostring( q.w ).."}" 14 | end, 15 | __add = function( q1, q2 ) 16 | return Quaternion:newT( RL.QuaternionAdd( q1, q2 ) ) 17 | end, 18 | __sub = function( q1, q2 ) 19 | return Quaternion:newT( RL.QuaternionSubtract( q1, q2 ) ) 20 | end, 21 | __mul = function( q1, q2 ) 22 | return Quaternion:newT( RL.QuaternionMultiply( q1, q2 ) ) 23 | end, 24 | __div = function( q1, q2 ) 25 | return Quaternion:newT( RL.QuaternionDivide( q1, q2 ) ) 26 | end, 27 | __unm = function( q ) 28 | return Quaternion:newT( RL.QuaternionInvert( q ) ) 29 | end, 30 | __len = function() 31 | return 4 32 | end, 33 | __eq = function( q1, q2 ) 34 | return RL.QuaternionEquals( q1, q2 ) 35 | end, 36 | __concat = function( a, b ) 37 | return tostring( a )..tostring( b ) 38 | end, 39 | } 40 | 41 | function Quaternion:new( x, y, z, w ) 42 | local object = setmetatable( {}, metatable ) 43 | 44 | object.x = x or 0 45 | object.y = y or 0 46 | object.z = z or 0 47 | object.w = w or 1 48 | 49 | return object 50 | end 51 | 52 | function Quaternion:newT( t ) 53 | local object = setmetatable( {}, metatable ) 54 | 55 | object.x, object.y, object.z, object.w = table.unpack( t ) 56 | 57 | return object 58 | end 59 | 60 | function Quaternion:newQ( q ) 61 | local object = setmetatable( {}, metatable ) 62 | 63 | object.x = q.x 64 | object.y = q.y 65 | object.z = q.z 66 | object.w = q.w 67 | 68 | return object 69 | end 70 | 71 | function Quaternion:set( x, y, z, w ) 72 | self.x = x or 0 73 | self.y = y or 0 74 | self.z = z or 0 75 | self.w = w or 1 76 | end 77 | 78 | function Quaternion:setT( t ) 79 | self.x, self.y, self.z, self.w = table.unpack( t ) 80 | end 81 | 82 | function Quaternion:setQ( q ) 83 | self.x = q.x 84 | self.y = q.y 85 | self.z = q.z 86 | self.w = q.w 87 | end 88 | 89 | function Quaternion:serialize() 90 | return "Quaternion:new("..self.x..","..self.y..","..self.z..","..self.w..")" 91 | end 92 | 93 | function Quaternion:arr() 94 | return { self.x, self.y, self.z, self.w } 95 | end 96 | 97 | function Quaternion:unpack() 98 | return self.x, self.y, self.z, self.w 99 | end 100 | 101 | function Quaternion:clone() 102 | return Quaternion:new( self.x, self.y, self.z, self.w ) 103 | end 104 | 105 | function Quaternion:addValue( value ) 106 | return Quaternion:newT( RL.QuaternionAddValue( self, value ) ) 107 | end 108 | 109 | function Quaternion:subValue( value ) 110 | return Quaternion:newT( RL.QuaternionSubtractValue( self, value ) ) 111 | end 112 | 113 | function Quaternion:identity() 114 | return Quaternion:newT( RL.QuaternionIdentity() ) 115 | end 116 | 117 | function Quaternion:length() 118 | return RL.QuaternionLength( self ) 119 | end 120 | 121 | function Quaternion:normalize() 122 | return Quaternion:newT( RL.QuaternionNormalize( self ) ) 123 | end 124 | 125 | function Quaternion:invert() 126 | return Quaternion:newT( RL.QuaternionInvert( self ) ) 127 | end 128 | 129 | function Quaternion:scale( scalar ) 130 | return Quaternion:newT( RL.QuaternionScale( self, scalar ) ) 131 | end 132 | 133 | function Quaternion:lerp( q2, value ) 134 | return Quaternion:newT( RL.QuaternionLerp( self, q2, value ) ) 135 | end 136 | 137 | function Quaternion:nLerp( q2, value ) 138 | return Quaternion:newT( RL.QuaternionNLerp( self, q2, value ) ) 139 | end 140 | 141 | function Quaternion:sLerp( q2, value ) 142 | return Quaternion:newT( RL.QuaternionSLerp( self, q2, value ) ) 143 | end 144 | 145 | function Quaternion:fromVector3ToVector3( from, to ) 146 | return Vector3:newT( RL.QuaternionFromVector3ToVector3( from, to ) ) 147 | end 148 | 149 | function Quaternion:fromMatrix( mat ) 150 | return Quaternion:newT( RL.QuaternionFromMatrix( mat ) ) 151 | end 152 | 153 | function Quaternion:toMatrix() 154 | return Matrix:new( RL.QuaternionToMatrix( self ) ) 155 | end 156 | 157 | function Quaternion:fromAxisAngle( axis, angle ) 158 | return Quaternion:newT( RL.QuaternionFromAxisAngle( axis, angle ) ) 159 | end 160 | 161 | function Quaternion:toAxisAngle() 162 | local axis, angle = Quaternion:newT( RL.QuaternionToAxisAngle( self ) ) 163 | return Vector3:new( axis ), angle 164 | end 165 | 166 | function Quaternion:fromEuler( pitch, yaw, roll ) 167 | return Quaternion:newT( RL.QuaternionFromEuler( pitch, yaw, roll ) ) 168 | end 169 | 170 | function Quaternion:toEuler() 171 | return Vector3:newT( RL.QuaternionToEuler( self ) ) 172 | end 173 | 174 | function Quaternion:transform( mat ) 175 | return Quaternion:newT( RL.QuaternionTransform( self, mat ) ) 176 | end 177 | 178 | -- Temp pre generated objects to avoid "slow" table generation. 179 | 180 | local TEMP_COUNT = 100 181 | local tempPool = {} 182 | local curTemp = 1 183 | 184 | for _ = 1, TEMP_COUNT do 185 | table.insert( tempPool, Quaternion:new( 0, 0, 0, 1 ) ) 186 | end 187 | 188 | function Quaternion:temp( x, y, z, w ) 189 | local object = tempPool[ curTemp ] 190 | 191 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 192 | 193 | object.x = x or 0 194 | object.y = y or 0 195 | object.z = z or 0 196 | object.w = w or 1 197 | 198 | return object 199 | end 200 | 201 | function Quaternion:tempT( t ) 202 | local object = tempPool[ curTemp ] 203 | 204 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 205 | 206 | object.x, object.y, object.z, object.w = table.unpack( t ) 207 | 208 | return object 209 | end 210 | 211 | function Quaternion:tempQ( q ) 212 | local object = tempPool[ curTemp ] 213 | 214 | curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1 215 | 216 | object.x = q.x 217 | object.y = q.y 218 | object.z = q.z 219 | object.w = q.w 220 | 221 | return object 222 | end 223 | 224 | function Quaternion:getTempId() 225 | return curTemp 226 | end 227 | 228 | return Quaternion 229 | -------------------------------------------------------------------------------- /examples/resources/lib/reference.lua: -------------------------------------------------------------------------------- 1 | local Reference = {} 2 | local metatable = { 3 | __index = Reference, 4 | __tostring = function( r ) 5 | return tostring( r.t[ r.k ] ) 6 | end, 7 | __add = function( r, v ) 8 | return r.t[ r.k ] + v 9 | end, 10 | __sub = function( r, v ) 11 | return r.t[ r.k ] - v 12 | end, 13 | __mul = function( r, v ) 14 | return r.t[ r.k ] * v 15 | end, 16 | __div = function( r, v ) 17 | return r.t[ r.k ] / v 18 | end, 19 | __mod = function( r, v ) 20 | return math.fmod( r.t[ r.k ], v ) 21 | end, 22 | __pow = function( r, v ) 23 | return r.t[ r.k ] ^ v 24 | end, 25 | __unm = function( r ) 26 | return -r.t[ r.k ] 27 | end, 28 | __eq = function( r, v ) 29 | return r.t[ r.k ] == v 30 | end, 31 | __len = function( r ) 32 | return #r.t[ r.k ] 33 | end, 34 | __lt = function( r, v ) 35 | return r.t[ r.k ] < v 36 | end, 37 | __le = function( r, v ) 38 | return r.t[ r.k ] <= v 39 | end, 40 | __concat = function( a, b ) 41 | return tostring( a )..tostring( b ) 42 | end, 43 | __call = function( r, ... ) 44 | return r.t[ r.k ]( ... ) 45 | end, 46 | } 47 | 48 | -- Table and key. Note that k should be name of the variable so the type must be string. 49 | function Reference:new( t, k ) 50 | local object = setmetatable( {}, metatable ) 51 | 52 | object.t = t 53 | object.k = k 54 | 55 | return object 56 | end 57 | 58 | -- Set new reference. Table and key. Note that k should be name of the variable so the type must be string. 59 | function Reference:ref( t, k ) 60 | self.t = t 61 | self.k = k 62 | end 63 | 64 | function Reference:set( v ) 65 | self.t[ self.k ] = v 66 | end 67 | 68 | function Reference:get() 69 | return self.t[ self.k ] 70 | end 71 | 72 | function Reference:unpack() 73 | return self.t, self.k 74 | end 75 | 76 | function Reference:clone() 77 | return Reference:new( self.t, self.k ) 78 | end 79 | 80 | function Reference:addEq( v ) 81 | self.t[ self.k ] = self.t[ self.k ] + v 82 | end 83 | 84 | function Reference:subEq( v ) 85 | self.t[ self.k ] = self.t[ self.k ] - v 86 | end 87 | 88 | function Reference:mulEq( v ) 89 | self.t[ self.k ] = self.t[ self.k ] * v 90 | end 91 | 92 | function Reference:divEq( v ) 93 | self.t[ self.k ] = self.t[ self.k ] / v 94 | end 95 | 96 | return Reference 97 | -------------------------------------------------------------------------------- /examples/resources/lib/rune.lua: -------------------------------------------------------------------------------- 1 | -- For luaJit compatibility. 2 | if table.unpack == nil then 3 | table.unpack = unpack 4 | end 5 | 6 | local Rune = {} 7 | local metatable = { 8 | __index = Rune, 9 | __tostring = function( r ) 10 | return r.string 11 | end, 12 | __len = function( r ) 13 | return RL.GetCodepointCount( r.string ) 14 | end, 15 | __eq = function( r1, r2 ) 16 | return r1.string == r2.string 17 | end, 18 | __concat = function( a, b ) 19 | return tostring( a )..tostring( b ) 20 | end, 21 | } 22 | 23 | function Rune:new( string ) 24 | local object = setmetatable( {}, metatable ) 25 | 26 | object.string = string or "" 27 | 28 | return object 29 | end 30 | 31 | function Rune:set( string ) 32 | self.string = string or "" 33 | end 34 | 35 | function Rune:serialize() 36 | return "Rune:new("..self.string..")" 37 | end 38 | 39 | function Rune:clone() 40 | return Rune:new( self.string ) 41 | end 42 | 43 | function Rune:len() 44 | return RL.GetCodepointCount( self.string ) 45 | end 46 | 47 | function Rune:getCodepoints() 48 | return RL.LoadCodepoints( self.string ) 49 | end 50 | 51 | function Rune:getCodepoint( index ) 52 | local codepoint = RL.GetCodepoint( self.string, index ) 53 | return codepoint 54 | end 55 | 56 | function Rune:getCodepointSize( index ) 57 | local _, codepointSize = RL.GetCodepoint( self.string, index ) 58 | return codepointSize 59 | end 60 | 61 | function Rune:insert( pos, string ) 62 | local codepoints = self:getCodepoints() 63 | 64 | for i, codepoint in ipairs( RL.LoadCodepoints( string ) ) do 65 | table.insert( codepoints, pos + i - 1, codepoint ) 66 | end 67 | self.string = RL.LoadUTF8( codepoints ) 68 | end 69 | 70 | function Rune:sub( i, j ) 71 | local codepoints = self:getCodepoints() 72 | return RL.LoadUTF8( { table.unpack( codepoints, i, j ) } ) 73 | end 74 | 75 | function Rune:gsub( pattern, repl ) 76 | return string.gsub( self.string, pattern, repl ) 77 | end 78 | 79 | function Rune:split( delimiter ) 80 | local splits = {} 81 | 82 | for str in string.gmatch( self.string, "([^"..delimiter.."]+)" ) do 83 | table.insert( splits, str ) 84 | end 85 | 86 | return splits 87 | end 88 | 89 | return Rune 90 | -------------------------------------------------------------------------------- /examples/resources/lib/utillib.lua: -------------------------------------------------------------------------------- 1 | -- Define useful global functions. 2 | 3 | -- For luaJit compatibility. 4 | if table.unpack == nil then 5 | table.unpack = unpack 6 | end 7 | 8 | local utillib = {} 9 | 10 | function utillib.deepCopy( orig ) 11 | local copy 12 | 13 | if type( orig ) == "table" then 14 | copy = {} 15 | 16 | for origKey, origValue in next, orig, nil do 17 | -- If object has clone method, use that. 18 | if type( origValue ) == "table" and type( origValue.clone ) == "function" then 19 | copy[ utillib.deepCopy( origKey ) ] = origValue:clone() 20 | else 21 | copy[ utillib.deepCopy( origKey ) ] = utillib.deepCopy( origValue ) 22 | end 23 | end 24 | 25 | setmetatable( copy, utillib.deepCopy( getmetatable( orig ) ) ) 26 | else -- number, string, boolean, etc. 27 | copy = orig 28 | end 29 | 30 | return copy 31 | end 32 | 33 | function utillib.sign( v ) 34 | if 0 <= v then 35 | return 1 36 | elseif v < 0 then 37 | return -1 38 | end 39 | end 40 | 41 | function utillib.clamp( val, min, max ) 42 | return math.max( min, math.min( val, max ) ) 43 | end 44 | 45 | function utillib.utf8Sub( s, i, j ) 46 | i = i or 1 47 | j = j or -1 48 | 49 | if i < 1 or j < 1 then 50 | local n = utf8.len(s) 51 | if not n then return nil end 52 | if i < 0 then i = n + 1 + i end 53 | if j < 0 then j = n + 1 + j end 54 | if i < 0 then i = 1 elseif i > n then i = n end 55 | if j < 0 then j = 1 elseif j > n then j = n end 56 | end 57 | 58 | if j < i then return "" end 59 | 60 | i = utf8.offset( s, i ) 61 | j = utf8.offset( s, j + 1 ) 62 | 63 | if i and j then 64 | return s:sub( i, j - 1 ) 65 | elseif i then 66 | return s:sub( i ) 67 | else 68 | return "" 69 | end 70 | end 71 | 72 | function utillib.round( v ) 73 | return math.tointeger( v + 0.5 - ( v + 0.5 ) % 1 ) 74 | end 75 | 76 | -- Use with dictionary style tables. 77 | function utillib.tableLen( t ) 78 | local count = 0 79 | 80 | for _ in pairs(t) do 81 | count = count + 1 82 | end 83 | 84 | return count 85 | end 86 | 87 | function utillib.split( string, sep ) 88 | if sep == nil then 89 | sep = "%s" 90 | end 91 | 92 | local t = {} 93 | 94 | for str in string.gmatch( string, "([^"..sep.."]+)" ) do 95 | table.insert( t, str ) 96 | end 97 | 98 | return t 99 | end 100 | 101 | function utillib.wrapAngleDeg( angle ) 102 | if angle < 0 then 103 | return math.fmod( angle, 360.0 ) + 360.0 104 | else 105 | return math.fmod( angle, 360.0 ) 106 | end 107 | end 108 | 109 | function utillib.wrapAngleRad( angle ) 110 | if angle < 0 then 111 | return math.fmod( angle, RL.PI * 2 ) + RL.PI * 2 112 | else 113 | return math.fmod( angle, RL.PI * 2 ) 114 | end 115 | end 116 | 117 | function utillib.lerp( a, b, f ) 118 | return ( a * ( 1.0 - f ) ) + ( b * f ) 119 | end 120 | 121 | function utillib.toBoolean( v ) 122 | if type( v ) == "string" then 123 | if v == "1" or string.lower( v ) == "true" then 124 | return true 125 | elseif v == "0" or string.lower( v ) == "false" then 126 | return false 127 | end 128 | elseif type( v ) == "number" then 129 | return 0 < v 130 | end 131 | 132 | return false 133 | end 134 | 135 | function utillib.boolToNumber( bool ) 136 | return bool and 1 or 0 137 | end 138 | 139 | -- Print table content. 140 | function utillib.printt( t ) 141 | print( tostring(t).." = {" ) 142 | 143 | for i, item in pairs( t ) do 144 | print( "\t"..tostring(i).." = "..tostring( item ) ) 145 | end 146 | 147 | print( "}" ) 148 | end 149 | 150 | -- Move secuence of elements inside table. 151 | function utillib.tableMove( t, src, len, dest ) 152 | local copy = table.move( t, src, src + len - 1, 1, {} ) 153 | 154 | if src >= dest then 155 | table.move( t, dest, src - 1, dest + len ) 156 | else 157 | table.move( t, src + len, dest + len - 1, src ) 158 | end 159 | 160 | table.move( copy, 1, len, dest, t ) 161 | end 162 | 163 | function utillib.reverseTable( t ) 164 | for i = 1, math.floor( #t / 2 ), 1 do 165 | t[i], t[ #t - i + 1 ] = t[ #t - i + 1 ], t[i] 166 | end 167 | end 168 | 169 | function utillib.randomFloat( min, max ) 170 | return min + math.random() * ( max - min ); 171 | end 172 | 173 | function utillib.printBin( v ) 174 | for i = 63, 0, -1 do 175 | if RL.BitGet( v, i ) then 176 | io.write( "1" ) 177 | else 178 | io.write( "0" ) 179 | end 180 | end 181 | print() 182 | end 183 | 184 | function utillib.capitalize( str ) 185 | return string.format( "%s%s", str:sub( 1, 1 ):upper(), str:sub( 2, -1 ) ) 186 | end 187 | 188 | function utillib.doString( str ) 189 | local func, err = load( str ) 190 | 191 | if func then 192 | local success, result = pcall( func ) 193 | 194 | if success then 195 | return result 196 | else 197 | RL.TraceLog( RL.LOG_WARNING, "Execution error: "..result ) 198 | end 199 | else 200 | RL.TraceLog( RL.LOG_WARNING, "Compilation error: "..err ) 201 | end 202 | end 203 | 204 | return utillib 205 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl100/lightmap.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec2 fragTexCoord2; 8 | varying vec3 fragPosition; 9 | varying vec4 fragColor; 10 | 11 | // Input uniform values 12 | uniform sampler2D texture0; 13 | uniform sampler2D texture1; 14 | 15 | void main() 16 | { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture2D(texture0, fragTexCoord); 19 | vec4 texelColor2 = texture2D(texture1, fragTexCoord2); 20 | 21 | gl_FragColor = texelColor * texelColor2; 22 | } 23 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl100/lightmap.vs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec2 vertexTexCoord2; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | 13 | // Output vertex attributes (to fragment shader) 14 | varying vec3 fragPosition; 15 | varying vec2 fragTexCoord; 16 | varying vec2 fragTexCoord2; 17 | varying vec4 fragColor; 18 | 19 | // NOTE: Add here your custom variables 20 | 21 | void main() 22 | { 23 | // Send vertex attributes to fragment shader 24 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 25 | fragTexCoord = vertexTexCoord; 26 | fragTexCoord2 = vertexTexCoord2; 27 | fragColor = vertexColor; 28 | 29 | // Calculate final vertex position 30 | gl_Position = mvp*vec4(vertexPosition, 1.0); 31 | } 32 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl100/wave.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | uniform float secondes; 14 | 15 | uniform vec2 size; 16 | 17 | uniform float freqX; 18 | uniform float freqY; 19 | uniform float ampX; 20 | uniform float ampY; 21 | uniform float speedX; 22 | uniform float speedY; 23 | 24 | void main() { 25 | float pixelWidth = 1.0 / size.x; 26 | float pixelHeight = 1.0 / size.y; 27 | float aspect = pixelHeight / pixelWidth; 28 | float boxLeft = 0.0; 29 | float boxTop = 0.0; 30 | 31 | vec2 p = fragTexCoord; 32 | p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth; 33 | p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight; 34 | 35 | gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor; 36 | } 37 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl120/lightmap.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec2 fragTexCoord2; 6 | varying vec3 fragPosition; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform sampler2D texture1; 12 | 13 | void main() 14 | { 15 | // Texel color fetching from texture sampler 16 | vec4 texelColor = texture2D(texture0, fragTexCoord); 17 | vec4 texelColor2 = texture2D(texture1, fragTexCoord2); 18 | 19 | gl_FragColor = texelColor * texelColor2; 20 | } 21 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl120/lightmap.vs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec2 vertexTexCoord2; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | 13 | // Output vertex attributes (to fragment shader) 14 | varying vec3 fragPosition; 15 | varying vec2 fragTexCoord; 16 | varying vec2 fragTexCoord2; 17 | varying vec4 fragColor; 18 | 19 | // NOTE: Add here your custom variables 20 | 21 | void main() 22 | { 23 | // Send vertex attributes to fragment shader 24 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 25 | fragTexCoord = vertexTexCoord; 26 | fragTexCoord2 = vertexTexCoord2; 27 | fragColor = vertexColor; 28 | 29 | // Calculate final vertex position 30 | gl_Position = mvp*vec4(vertexPosition, 1.0); 31 | } 32 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/atlas_repeat.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec3 fragPosition; 5 | in vec2 fragTexCoord; 6 | in vec4 fragColor; 7 | 8 | // Input uniform values 9 | uniform sampler2D texture0; 10 | 11 | uniform vec2 atlasSize; 12 | uniform vec2 tileTexSize; 13 | 14 | // Output fragment color 15 | out vec4 finalColor; 16 | 17 | vec2 texTileSize = tileTexSize / atlasSize; 18 | vec2 atlasTileSize = atlasSize / tileTexSize; 19 | 20 | void main() { 21 | vec2 tileTexCoord = fract( vec2( fragPosition.x, fragPosition.y ) / tileTexSize ); 22 | // Get tile texture corner. 23 | vec2 texOffset = floor( fragTexCoord / texTileSize ) * texTileSize; 24 | vec2 fragCoord = tileTexCoord / atlasTileSize + texOffset; 25 | vec4 texelColor = texture( texture0, fragCoord ); 26 | 27 | finalColor = texelColor * fragColor; 28 | } 29 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/base.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture( texture0, fragTexCoord ); 19 | 20 | // NOTE: Implement here your fragment shader code 21 | 22 | finalColor = texelColor * colDiffuse; 23 | } 24 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/base.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes 4 | in vec3 vertexPosition; 5 | in vec2 vertexTexCoord; 6 | in vec3 vertexNormal; 7 | in vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | 12 | // Output vertex attributes (to fragment shader) 13 | out vec3 fragPosition; 14 | out vec2 fragTexCoord; 15 | out vec3 fragNormal; 16 | out vec4 fragColor; 17 | 18 | // NOTE: Add here your custom variables 19 | 20 | void main() { 21 | // Send vertex attributes to fragment shader 22 | fragPosition = vertexPosition; 23 | fragTexCoord = vertexTexCoord; 24 | fragNormal = vertexNormal; 25 | fragColor = vertexColor; 26 | 27 | // Calculate final vertex position 28 | gl_Position = mvp * vec4( vertexPosition, 1.0 ); 29 | } 30 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/lighting.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec3 fragPosition; 5 | in vec2 fragTexCoord; 6 | //in vec4 fragColor; 7 | in vec3 fragNormal; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // Output fragment color 14 | out vec4 finalColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | #define MAX_LIGHTS 4 19 | #define LIGHT_DIRECTIONAL 0 20 | #define LIGHT_POINT 1 21 | 22 | struct MaterialProperty { 23 | vec3 color; 24 | int useSampler; 25 | sampler2D sampler; 26 | }; 27 | 28 | struct Light { 29 | int enabled; 30 | int type; 31 | vec3 position; 32 | vec3 target; 33 | vec4 color; 34 | }; 35 | 36 | // Input lighting values 37 | uniform Light lights[MAX_LIGHTS]; 38 | uniform vec4 ambient; 39 | uniform vec3 viewPos; 40 | 41 | void main() 42 | { 43 | // Texel color fetching from texture sampler 44 | vec4 texelColor = texture(texture0, fragTexCoord); 45 | vec3 lightDot = vec3(0.0); 46 | vec3 normal = normalize(fragNormal); 47 | vec3 viewD = normalize(viewPos - fragPosition); 48 | vec3 specular = vec3(0.0); 49 | 50 | // NOTE: Implement here your fragment shader code 51 | 52 | for (int i = 0; i < MAX_LIGHTS; i++) 53 | { 54 | if (lights[i].enabled == 1) 55 | { 56 | vec3 light = vec3(0.0); 57 | 58 | if (lights[i].type == LIGHT_DIRECTIONAL) 59 | { 60 | light = -normalize(lights[i].target - lights[i].position); 61 | } 62 | 63 | if (lights[i].type == LIGHT_POINT) 64 | { 65 | light = normalize(lights[i].position - fragPosition); 66 | } 67 | 68 | float NdotL = max(dot(normal, light), 0.0); 69 | lightDot += lights[i].color.rgb*NdotL; 70 | 71 | float specCo = 0.0; 72 | if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // 16 refers to shine 73 | specular += specCo; 74 | } 75 | } 76 | 77 | finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0))); 78 | finalColor += texelColor*(ambient/10.0)*colDiffuse; 79 | 80 | // Gamma correction 81 | finalColor = pow(finalColor, vec4(1.0/2.2)); 82 | } 83 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/lighting.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes 4 | in vec3 vertexPosition; 5 | in vec2 vertexTexCoord; 6 | in vec3 vertexNormal; 7 | in vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | uniform mat4 matNormal; 13 | 14 | // Output vertex attributes (to fragment shader) 15 | out vec3 fragPosition; 16 | out vec2 fragTexCoord; 17 | out vec4 fragColor; 18 | out vec3 fragNormal; 19 | 20 | // NOTE: Add here your custom variables 21 | 22 | void main() 23 | { 24 | // Send vertex attributes to fragment shader 25 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 26 | fragTexCoord = vertexTexCoord; 27 | fragColor = vertexColor; 28 | fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); 29 | 30 | // Calculate final vertex position 31 | gl_Position = mvp*vec4(vertexPosition, 1.0); 32 | } 33 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/lighting_instancing.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes 4 | in vec3 vertexPosition; 5 | in vec2 vertexTexCoord; 6 | in vec3 vertexNormal; 7 | //in vec4 vertexColor; // Not required 8 | 9 | in mat4 instanceTransform; 10 | 11 | // Input uniform values 12 | uniform mat4 mvp; 13 | uniform mat4 matNormal; 14 | 15 | // Output vertex attributes (to fragment shader) 16 | out vec3 fragPosition; 17 | out vec2 fragTexCoord; 18 | out vec4 fragColor; 19 | out vec3 fragNormal; 20 | 21 | // NOTE: Add here your custom variables 22 | 23 | void main() 24 | { 25 | // Compute MVP for current instance 26 | mat4 mvpi = mvp*instanceTransform; 27 | 28 | // Send vertex attributes to fragment shader 29 | fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0)); 30 | fragTexCoord = vertexTexCoord; 31 | //fragColor = vertexColor; 32 | fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); 33 | 34 | // Calculate final vertex position 35 | gl_Position = mvpi*vec4(vertexPosition, 1.0); 36 | } 37 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/lightmap.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | // Input vertex attributes (from vertex shader) 3 | in vec2 fragTexCoord; 4 | in vec2 fragTexCoord2; 5 | in vec3 fragPosition; 6 | in vec4 fragColor; 7 | in vec3 fragNormal; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform sampler2D texture1; 12 | 13 | // Output fragment color 14 | out vec4 finalColor; 15 | 16 | void main() { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture( texture0, fragTexCoord ); 19 | vec4 texelColor2 = texture( texture1, fragTexCoord2 ); 20 | vec3 normal = normalize( fragNormal ); 21 | finalColor = texelColor * texelColor2; 22 | } 23 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/lightmap.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | // Input vertex attributes 3 | in vec3 vertexPosition; 4 | in vec2 vertexTexCoord; 5 | in vec2 vertexTexCoord2; 6 | in vec3 vertexNormal; 7 | // in vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | uniform mat4 matNormal; 13 | 14 | // Output vertex attributes (to fragment shader) 15 | out vec3 fragPosition; 16 | out vec2 fragTexCoord; 17 | out vec2 fragTexCoord2; 18 | // out vec4 fragColor; 19 | out vec3 fragNormal; 20 | 21 | void main() { 22 | // Send vertex attributes to fragment shader 23 | fragPosition = vec3( matModel * vec4( vertexPosition, 1.0 ) ); 24 | fragTexCoord = vertexTexCoord; 25 | fragTexCoord2 = vertexTexCoord2; 26 | // fragColor = vertexColor; 27 | fragNormal = normalize( vec3( matNormal * vec4( vertexNormal, 1.0 ) ) ); 28 | 29 | // Calculate final vertex position 30 | gl_Position = mvp * vec4( vertexPosition, 1.0 ); 31 | } 32 | -------------------------------------------------------------------------------- /examples/resources/shaders/glsl330/wave.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | uniform float secondes; 15 | 16 | uniform vec2 size; 17 | 18 | uniform float freqX; 19 | uniform float freqY; 20 | uniform float ampX; 21 | uniform float ampY; 22 | uniform float speedX; 23 | uniform float speedY; 24 | 25 | void main() { 26 | float pixelWidth = 1.0 / size.x; 27 | float pixelHeight = 1.0 / size.y; 28 | float aspect = pixelHeight / pixelWidth; 29 | float boxLeft = 0.0; 30 | float boxTop = 0.0; 31 | 32 | vec2 p = fragTexCoord; 33 | p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth; 34 | p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight; 35 | 36 | finalColor = texture(texture0, p)*colDiffuse*fragColor; 37 | } 38 | -------------------------------------------------------------------------------- /examples/resources/styles/style_dark.rgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/examples/resources/styles/style_dark.rgs -------------------------------------------------------------------------------- /examples/rlgl_hello_triangle/main.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 2 | 3 | Util = require( "utillib" ) 4 | Vector2 = require( "vector2" ) 5 | 6 | local res = Vector2:new( 1024, 720 ) 7 | local winScale = 1 8 | local winSize = res:scale( winScale ) 9 | local monitor = 0 10 | 11 | local triangle = { 12 | texture = { 13 | id = -1, 14 | data = nil, 15 | size = Vector2:new( 0, 0 ), 16 | mipmaps = 0, 17 | format = 0, 18 | }, 19 | vao = -1, 20 | vbos = { 21 | positions = -1, 22 | texcoords = -1, 23 | colors = -1, 24 | }, 25 | } 26 | 27 | local vertexShader = [[ 28 | #version 330 core 29 | layout (location = 0) in vec3 aPos; 30 | layout (location = 1) in vec4 aColor; 31 | layout (location = 2) in vec2 aTexCoord; 32 | 33 | out vec4 flagColor; 34 | out vec2 fragTexCoord; 35 | 36 | void main() { 37 | flagColor = aColor; 38 | fragTexCoord = aTexCoord; 39 | gl_Position = vec4( aPos, 1.0 ); 40 | } 41 | ]] 42 | local fragmentShader = [[ 43 | #version 330 core 44 | out vec4 FragColor; 45 | 46 | in vec4 flagColor; 47 | in vec2 fragTexCoord; 48 | 49 | uniform sampler2D ourTexture; 50 | 51 | void main() { 52 | FragColor = texture( ourTexture, fragTexCoord ) * flagColor; 53 | } 54 | ]] 55 | 56 | local shaderProgram = -1 57 | 58 | -- Let's make our own custom texture. 59 | local function loadTexture( path ) 60 | local image = RL.LoadImage( path ) 61 | 62 | triangle.texture.data = RL.GetImageData( image ) 63 | triangle.texture.size = Vector2:newT( RL.GetImageSize( image ) ) 64 | triangle.texture.format = RL.GetImageFormat( image ) 65 | triangle.texture.mipmaps = RL.GetImageMipmaps( image ) 66 | 67 | triangle.texture.id = RL.rlLoadTexture( 68 | triangle.texture.data, 69 | triangle.texture.size, 70 | triangle.texture.format, 71 | triangle.texture.mipmaps 72 | ) 73 | end 74 | 75 | local function createTriangle() 76 | loadTexture( RL.GetBasePath().."../resources/images/monkey_tex.png" ) 77 | -- Set texture to shader uniform. 78 | local shaderLoc = RL.rlGetLocationUniform( shaderProgram, "ourTexture" ) 79 | 80 | RL.rlEnableShader( shaderProgram ) 81 | -- NOTE: Default texture is always activated as GL_TEXTURE0 so our slot will be 1. 82 | RL.rlSetUniformSampler( shaderLoc, triangle.texture.id ) 83 | RL.rlDisableShader() 84 | 85 | -- Setup triangle buffers. 86 | triangle.vao = RL.rlLoadVertexArray() 87 | RL.rlEnableVertexArray( triangle.vao ) 88 | 89 | -- Positions. 90 | local vertexBuffer = RL.LoadBuffer( 91 | { 92 | -0.5, -0.5, 0.0, 93 | 0.5, -0.5, 0.0, 94 | 0.0, 0.5, 0.0 95 | }, 96 | RL.BUFFER_FLOAT 97 | ) 98 | triangle.vbos.positions = RL.rlLoadVertexBuffer( vertexBuffer, false ) 99 | RL.rlSetVertexAttribute( 0, 3, RL.RL_FLOAT, false, 0, 0 ) 100 | RL.rlEnableVertexAttribute( 0 ) 101 | 102 | -- Colors. 103 | local colors = RL.LoadBuffer( 104 | { 105 | 1, 0, 0, 1, 106 | 0, 1, 0, 1, 107 | 0, 0, 1, 1 108 | }, 109 | RL.BUFFER_FLOAT 110 | ) 111 | triangle.vbos.colors = RL.rlLoadVertexBuffer( colors, false ) 112 | RL.rlSetVertexAttribute( 1, 4, RL.RL_FLOAT, false, 0, 0 ) 113 | RL.rlEnableVertexAttribute( 1 ) 114 | 115 | -- Texcoords. 116 | local texcoors = RL.LoadBuffer( 117 | { 118 | 0, 0, 119 | 1, 0, 120 | 0.5, 1, 121 | }, 122 | RL.BUFFER_FLOAT 123 | ) 124 | triangle.vbos.texcoors = RL.rlLoadVertexBuffer( texcoors, false ) 125 | RL.rlSetVertexAttribute( 2, 2, RL.RL_FLOAT, false, 0, 0 ) 126 | RL.rlEnableVertexAttribute( 2 ) 127 | 128 | -- Disable. 129 | RL.rlDisableVertexBuffer() 130 | RL.rlDisableVertexArray() 131 | end 132 | 133 | function RL.init() 134 | local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) ) 135 | local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) ) 136 | 137 | RL.SetWindowTitle( "RLGL Hello Triangle" ) 138 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 139 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 140 | RL.SetWindowSize( winSize ) 141 | RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } ) 142 | 143 | RL.rlViewport( { 0, 0, res.x ,res.y } ) 144 | shaderProgram = RL.rlLoadShaderCode( vertexShader, fragmentShader ) 145 | 146 | createTriangle() 147 | end 148 | 149 | local function drawTriangle() 150 | -- Texture slot 0 is the default texture. 151 | RL.rlActiveTextureSlot( 1 ) 152 | RL.rlEnableTexture( triangle.texture.id ) 153 | 154 | RL.rlEnableShader( shaderProgram ) 155 | 156 | RL.rlEnableVertexArray( triangle.vao ) 157 | RL.rlDrawVertexArray( 0, 3 ) 158 | 159 | -- Disable. 160 | RL.rlDisableVertexArray() 161 | RL.rlDisableVertexBuffer() 162 | RL.rlDisableTexture() 163 | RL.rlDisableShader() 164 | end 165 | 166 | function RL.draw() 167 | RL.ClearBackground( RL.BLACK ) 168 | drawTriangle() 169 | end 170 | 171 | function RL.exit() 172 | RL.rlUnloadVertexArray( triangle.vao ) 173 | RL.rlUnloadVertexBuffer( triangle.vbos.positions ) 174 | RL.rlUnloadVertexBuffer( triangle.vbos.colors ) 175 | RL.rlUnloadVertexBuffer( triangle.vbos.texcoords ) 176 | RL.rlUnloadTexture( triangle.texture.id ) 177 | end 178 | -------------------------------------------------------------------------------- /examples/shaders/main.lua: -------------------------------------------------------------------------------- 1 | local monitor = 0 2 | local shader = nil 3 | local texture = nil 4 | local textureSize = nil 5 | 6 | local GLSL_VERSION = "330" -- PLATFORM_DESKTOP 7 | -- local GLSL_VERSION = "100" -- PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB 8 | 9 | local secondsLoc 10 | 11 | function RL.init() 12 | local mPos = RL.GetMonitorPosition( monitor ) 13 | local mSize = RL.GetMonitorSize( monitor ) 14 | local winSize = RL.GetScreenSize() 15 | 16 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 17 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 18 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 19 | 20 | texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) 21 | textureSize = RL.GetTextureSize( texture ) 22 | shader = RL.LoadShader( nil, RL.GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/wave.fs" ) 23 | 24 | secondsLoc = RL.GetShaderLocation( shader, "secondes" ) 25 | local sizeLoc = RL.GetShaderLocation( shader, "size" ) 26 | local freqXLoc = RL.GetShaderLocation( shader, "freqX" ) 27 | local freqYLoc = RL.GetShaderLocation( shader, "freqY" ) 28 | local ampXLoc = RL.GetShaderLocation( shader, "ampX" ) 29 | local ampYLoc = RL.GetShaderLocation( shader, "ampY" ) 30 | local speedXLoc = RL.GetShaderLocation( shader, "speedX" ) 31 | local speedYLoc = RL.GetShaderLocation( shader, "speedY" ) 32 | 33 | local freqX = 25.0 34 | local freqY = 25.0 35 | local ampX = 5.0 36 | local ampY = 5.0 37 | local speedX = 8.0 38 | local speedY = 8.0 39 | 40 | RL.SetShaderValue( shader, sizeLoc, textureSize, RL.SHADER_UNIFORM_VEC2 ) 41 | RL.SetShaderValue( shader, freqXLoc, { freqX }, RL.SHADER_UNIFORM_FLOAT ) 42 | RL.SetShaderValue( shader, freqYLoc, { freqY }, RL.SHADER_UNIFORM_FLOAT ) 43 | RL.SetShaderValue( shader, ampXLoc, { ampX }, RL.SHADER_UNIFORM_FLOAT ) 44 | RL.SetShaderValue( shader, ampYLoc, { ampY }, RL.SHADER_UNIFORM_FLOAT ) 45 | RL.SetShaderValue( shader, speedXLoc, { speedX }, RL.SHADER_UNIFORM_FLOAT ) 46 | RL.SetShaderValue( shader, speedYLoc, { speedY }, RL.SHADER_UNIFORM_FLOAT ) 47 | end 48 | 49 | local seconds = 0.0 50 | 51 | function RL.draw() 52 | seconds = seconds + RL.GetFrameTime(); 53 | 54 | RL.SetShaderValue( shader, secondsLoc, { seconds }, RL.SHADER_UNIFORM_FLOAT ); 55 | 56 | RL.ClearBackground( { 100, 150, 100 } ) 57 | 58 | RL.BeginShaderMode( shader ) 59 | RL.DrawTexture( texture, { 0, 0 }, RL.WHITE ); 60 | RL.EndShaderMode() 61 | end 62 | -------------------------------------------------------------------------------- /examples/stencil_reflection/main.lua: -------------------------------------------------------------------------------- 1 | -- Based on JeffM2501 stencil_reflection example for Raylib https://github.com/raylib-extras/examples-cpp/blob/main/stencil_reflection/main.cpp 2 | 3 | package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" 4 | 5 | Vec2 = require( "vector2" ) 6 | Cam3D = require( "camera3d" ) 7 | 8 | local monitor = 0 9 | local camera = Cam3D:new() 10 | 11 | function RL.init() 12 | RL.SetWindowTitle( "Stencil Reflection" ) 13 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 14 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 15 | 16 | local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) 17 | local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) 18 | local winSize = Vec2:newT( RL.GetScreenSize() ) 19 | 20 | RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) 21 | 22 | camera:setPosition( { 0, 2, 6 } ) 23 | camera:setTarget( { 0, 0, 0 } ) 24 | camera:setUp( { 0, 1, 0 } ) 25 | camera.mode = camera.MODES.ORBITAL 26 | end 27 | 28 | function RL.update( delta ) 29 | camera:update( delta ) 30 | 31 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 32 | if camera.mode == camera.MODES.FREE then 33 | camera.mode = camera.MODES.FIRST_PERSON 34 | else 35 | camera.mode = camera.MODES.FREE 36 | end 37 | end 38 | end 39 | 40 | function RL.draw() 41 | RL.ClearBackground( RL.BLACK ) 42 | 43 | camera:beginMode3D() 44 | RL.DrawCube( { 0, 0.5, 0 }, { 1, 1, 1 }, RL.DARKGREEN ) 45 | RL.rlDrawRenderBatchActive() 46 | 47 | RL.glEnable( RL.GL_STENCIL_TEST ) 48 | 49 | RL.glStencilFunc( RL.GL_ALWAYS, 1, 0xFF ) -- Set any stencil to 1 50 | RL.glStencilOp( RL.GL_KEEP, RL.GL_KEEP, RL.GL_REPLACE ) 51 | RL.glStencilMask( 0xFF ) -- Write to stencil buffer. 52 | RL.rlDisableDepthMask() 53 | RL.glClear( RL.GL_STENCIL_BUFFER_BIT ) -- Clear stencil buffer (0 by default) 54 | 55 | RL.DrawPlane( { 0, 0, 0 }, { 3, 3 }, RL.DARKBLUE ) 56 | RL.rlDrawRenderBatchActive() 57 | 58 | RL.glStencilFunc( RL.GL_EQUAL, 1, 0xFF ) -- Pass test if stencil value is 1. 59 | RL.glStencilMask( 0x00 ) -- Don't write anything to stencil buffer. 60 | RL.rlEnableDepthMask() 61 | 62 | RL.DrawCube( { 0, -0.5, 0 }, { 1, 1, 1 }, RL.ColorAlpha( RL.DARKGREEN, 0.5 ) ) 63 | RL.rlDrawRenderBatchActive() 64 | 65 | RL.glDisable( RL.GL_STENCIL_TEST ) 66 | camera:endMode3D() 67 | end 68 | -------------------------------------------------------------------------------- /examples/textBoxed/main.lua: -------------------------------------------------------------------------------- 1 | local textSize = 10 2 | local spacing = 1 3 | local rect = { 100, 64, 200, 200 } 4 | local wordwrap = true 5 | local linkColor = RL.BLUE 6 | local limitHeight = true 7 | local mouseCharId = 0 8 | local textOffset = { 0, 0 } 9 | 10 | function RL.init() 11 | RL.SetWindowTitle( "Text boxed" ) 12 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 13 | end 14 | 15 | function RL.update( delta ) 16 | if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_RIGHT ) then 17 | local mousePos = RL.GetMousePosition() 18 | 19 | rect[3] = mousePos[1] - rect[1] 20 | rect[4] = mousePos[2] - rect[2] 21 | end 22 | 23 | if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) and 0 < mouseCharId then 24 | print( "Pressed link on char "..mouseCharId ) 25 | end 26 | 27 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 28 | wordwrap = not wordwrap 29 | end 30 | end 31 | 32 | function RL.draw() 33 | RL.ClearBackground( RL.RAYWHITE ) 34 | RL.DrawRectangleLines( rect, RL.GREEN ) 35 | 36 | _, textOffset = RL.DrawTextBoxedEx( 37 | RL.GetFontDefault(), 38 | "\tYou can change the size of the box by pressing right mouse and toggle the wordwrap by pressing space. First we will write some text before the hyperlink to show that it is indeed is as powerful feature as adverticed.", 39 | rect, 40 | textSize, spacing, wordwrap, RL.RED, limitHeight, { 0, 0 } 41 | ) 42 | mouseCharId, textOffset = RL.DrawTextBoxedEx( 43 | RL.GetFontDefault(), 44 | " Hyperlink.", 45 | rect, 46 | textSize, spacing, wordwrap, linkColor, limitHeight, textOffset 47 | ) 48 | _, textOffset = RL.DrawTextBoxedEx( 49 | RL.GetFontDefault(), 50 | " Then we demonstrate this further by writin more text after the link. Isn't this just amazing! Don't forget to press left mouse to print text to your console when hovering mouse over the hyperlink.", 51 | rect, 52 | textSize, spacing, wordwrap, RL.RED, limitHeight, textOffset 53 | ) 54 | RL.DrawTextBoxedEx( 55 | RL.GetFontDefault(), 56 | " \a#D28484FF Also supports \a#0000FFFF changing text \a#CCD834FF color in the \a#00FFFFFF middle of \a#B623A3FF the \a#00FF00FF text draw.", 57 | rect, 58 | textSize, spacing, wordwrap, RL.WHITE, limitHeight, textOffset 59 | ) 60 | 61 | if 0 < mouseCharId then 62 | linkColor = RL.GREEN 63 | else 64 | linkColor = RL.BLUE 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /examples/texture_atlas_repeat/main.lua: -------------------------------------------------------------------------------- 1 | local atlas = nil 2 | local shader = nil 3 | 4 | local GLSL_VERSION = "330" -- PLATFORM_DESKTOP 5 | 6 | function RL.init() 7 | RL.SetWindowTitle( "Texture atlas repeat shader" ) 8 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 9 | 10 | local path = RL.GetBasePath().."../resources/" 11 | local shaderPath = path.."/shaders/glsl"..GLSL_VERSION.."/" 12 | 13 | shader = RL.LoadShader( shaderPath.."base.vs", shaderPath.."atlas_repeat.fs" ) 14 | atlas = RL.LoadTexture( path.."images/tiles.png" ) 15 | 16 | local loc = RL.GetShaderLocation( shader, "atlasSize" ) 17 | RL.SetShaderValue( shader, loc, RL.GetTextureSize( atlas ), RL.SHADER_UNIFORM_VEC2 ) 18 | loc = RL.GetShaderLocation( shader, "tileTexSize" ) 19 | RL.SetShaderValue( shader, loc, { 32, 32 }, RL.SHADER_UNIFORM_VEC2 ) 20 | -- Set texture for DrawTriangle. 21 | RL.SetShapesTexture( atlas, { 32 * 4, 0, 32, 32 } ) 22 | end 23 | 24 | function RL.update( delta ) 25 | end 26 | 27 | function RL.draw() 28 | RL.ClearBackground( RL.RAYWHITE ) 29 | 30 | RL.BeginShaderMode( shader ) 31 | RL.DrawTexturePro( atlas, { 0, 0, 32, 32 }, { 0, 0, 64, 64 }, { 0.0 }, 0.0, RL.WHITE ) 32 | RL.DrawTexturePro( atlas, { 32, 0, 32, 32 }, { 0, 64, 128, 64 }, { 0.0 }, 0.0, RL.WHITE ) 33 | RL.DrawTriangle( { 32, 200 }, { 128, 400 }, { 320, 240 }, RL.WHITE ) 34 | RL.EndShaderMode() 35 | end 36 | -------------------------------------------------------------------------------- /examples/waving_cubes/main.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Contributed by Codecat (@codecat) 3 | Reviewed by Ramon Santamaria (@raysan5) 4 | 5 | Modified by Teddy Astie (@TSnake41) for Lua binding. 6 | Modified by Jussi Viitala (@nullstare) for ReiLua style. 7 | ]] 8 | 9 | local camera = -1 10 | local num_blocks = 15 11 | 12 | function RL.init() 13 | local monitor = 0 14 | local mPos = RL.GetMonitorPosition( monitor ) 15 | local mSize = RL.GetMonitorSize( monitor ) 16 | local winSize = RL.GetScreenSize() 17 | 18 | RL.SetWindowTitle( "Waving cubes" ) 19 | RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) 20 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 21 | RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) 22 | 23 | camera = RL.CreateCamera3D() 24 | RL.SetCamera3DPosition( camera, { 30, 20, 30 } ) 25 | RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) 26 | RL.SetCamera3DUp( camera, { 0, 1, 0 } ) 27 | end 28 | 29 | function RL.draw() 30 | local t = RL.GetTime() 31 | local cos = math.cos 32 | local sin = math.sin 33 | 34 | local scale = (2.0 + sin(t)) * 0.7 35 | local camera_time = t * 0.3 36 | local camera_pos = RL.GetCamera3DPosition( camera ) 37 | 38 | camera_pos[1] = cos(camera_time) * 40.0 39 | camera_pos[3] = sin(camera_time) * 40.0 40 | 41 | RL.SetCamera3DPosition( camera, camera_pos ) 42 | RL.ClearBackground( RL.RAYWHITE ) 43 | 44 | RL.BeginMode3D( camera ) 45 | RL.DrawGrid( 10, 5.0 ) 46 | 47 | for x = 0,num_blocks - 1 do 48 | for y = 0,num_blocks - 1 do 49 | for z = 0,num_blocks - 1 do 50 | local block_scale = (x + y + z) / 30 51 | local scatter = sin(block_scale * 20.0 + t * 4.0) 52 | 53 | local cube_pos = { 54 | (x - num_blocks / 2) * (scale * 3.0) + scatter, 55 | (y - num_blocks / 2) * (scale * 2.0) + scatter, 56 | (z - num_blocks / 2) * (scale * 3.0) + scatter 57 | } 58 | local cube_color = RL.ColorFromHSV( (((x + y + z) * 18) % 360), 0.75, 0.9 ) 59 | local cube_size = (2.4 - scale) * block_scale 60 | 61 | RL.DrawCube( cube_pos, { cube_size, cube_size, cube_size }, cube_color ) 62 | end 63 | end 64 | end 65 | RL.EndMode3D() 66 | 67 | RL.DrawFPS( { 10, 10 } ) 68 | end 69 | -------------------------------------------------------------------------------- /examples/window/main.lua: -------------------------------------------------------------------------------- 1 | local textColor = RL.BLACK 2 | local textPos = { 192, 200 } 3 | local textSize = 20 4 | local text = "Congrats! You created your first window!" 5 | 6 | function RL.init() 7 | RL.SetWindowTitle( "First window" ) 8 | RL.SetWindowState( RL.FLAG_VSYNC_HINT ) 9 | end 10 | 11 | function RL.update( delta ) 12 | if RL.IsKeyPressed( RL.KEY_ENTER ) then 13 | local winSize = RL.GetScreenSize() 14 | local measuredSize = RL.MeasureTextEx( RL.GetFontDefault(), text, textSize, 2 ) 15 | 16 | textColor = RL.BLUE 17 | textPos = { winSize[1] / 2 - measuredSize[1] / 2, winSize[2] / 2 - measuredSize[2] / 2 } 18 | end 19 | 20 | if RL.IsKeyPressed( RL.KEY_SPACE ) then 21 | textColor = RL.RED 22 | textPos = { 192, 200 } 23 | end 24 | end 25 | 26 | function RL.draw() 27 | RL.ClearBackground( RL.RAYWHITE ) 28 | RL.DrawText( text, textPos, textSize, textColor ) 29 | end 30 | -------------------------------------------------------------------------------- /include/audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Audio device management functions. */ 4 | int laudioInitAudioDevice( lua_State* L ); 5 | int laudioCloseAudioDevice( lua_State* L ); 6 | int laudioIsAudioDeviceReady( lua_State* L ); 7 | int laudioSetMasterVolume( lua_State* L ); 8 | int laudioGetMasterVolume( lua_State* L ); 9 | /* Wave/Sound loading/unloading functions. */ 10 | int laudioLoadSound( lua_State* L ); 11 | int laudioLoadWave( lua_State* L ); 12 | int laudioLoadWaveFromMemory( lua_State* L ); 13 | int laudioIsWaveValid( lua_State* L ); 14 | int laudioLoadSoundFromWave( lua_State* L ); 15 | int laudioLoadSoundAlias( lua_State* L ); 16 | int laudioIsSoundValid( lua_State* L ); 17 | int laudioUpdateSound( lua_State* L ); 18 | int laudioUnloadWave( lua_State* L ); 19 | int laudioUnloadSound( lua_State* L ); 20 | int laudioUnloadSoundAlias( lua_State* L ); 21 | int laudioExportWave( lua_State* L ); 22 | int laudioExportWaveAsCode( lua_State* L ); 23 | /* Wave/Sound management functions. */ 24 | int laudioPlaySound( lua_State* L ); 25 | int laudioStopSound( lua_State* L ); 26 | int laudioPauseSound( lua_State* L ); 27 | int laudioResumeSound( lua_State* L ); 28 | int laudioIsSoundPlaying( lua_State* L ); 29 | int laudioSetSoundVolume( lua_State* L ); 30 | int laudioSetSoundPitch( lua_State* L ); 31 | int laudioSetSoundPan( lua_State* L ); 32 | int laudioWaveFormat( lua_State* L ); 33 | int laudioLoadWaveSamples( lua_State* L ); 34 | int laudioWaveCopy( lua_State* L ); 35 | int laudioWaveCrop( lua_State* L ); 36 | /* Music management functions. */ 37 | int laudioLoadMusicStream( lua_State* L ); 38 | int laudioLoadMusicStreamFromMemory( lua_State* L ); 39 | int laudioIsMusicValid( lua_State* L ); 40 | int laudioUnloadMusicStream( lua_State* L ); 41 | int laudioPlayMusicStream( lua_State* L ); 42 | int laudioIsMusicStreamPlaying( lua_State* L ); 43 | int laudioUpdateMusicStream( lua_State* L ); 44 | int laudioStopMusicStream( lua_State* L ); 45 | int laudioPauseMusicStream( lua_State* L ); 46 | int laudioResumeMusicStream( lua_State* L ); 47 | int laudioSeekMusicStream( lua_State* L ); 48 | int laudioSetMusicVolume( lua_State* L ); 49 | int laudioSetMusicPitch( lua_State* L ); 50 | int laudioSetMusicPan( lua_State* L ); 51 | int laudioSetMusicLooping( lua_State* L ); 52 | int laudioGetMusicLooping( lua_State* L ); 53 | int laudioGetMusicTimeLength( lua_State* L ); 54 | int laudioGetMusicTimePlayed( lua_State* L ); 55 | -------------------------------------------------------------------------------- /include/bitwiseOp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Arithmetic. */ 4 | int lbitAnd( lua_State* L ); 5 | int lbitOr( lua_State* L ); 6 | int lbitXor( lua_State* L ); 7 | int lbitNot( lua_State* L ); 8 | int lbitShiftLeft( lua_State* L ); 9 | int lbitShiftRight( lua_State* L ); 10 | int lbitSet( lua_State* L ); 11 | int lbitGet( lua_State* L ); 12 | int lbitToggle( lua_State* L ); 13 | -------------------------------------------------------------------------------- /include/frustum.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * RLSprite * Simple Sprite Managment System for Raylib 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2020 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | #pragma once 32 | #ifndef FRUSTUM_H 33 | #define FRUSTUM_H 34 | 35 | #include "raylib.h" 36 | #include "raymath.h" 37 | #include "frustum.h" 38 | 39 | typedef enum 40 | { 41 | Back = 0, 42 | Front = 1, 43 | Bottom = 2, 44 | Top = 3, 45 | Right = 4, 46 | Left = 5, 47 | MAX = 6 48 | }FrustumPlanes; 49 | 50 | typedef struct 51 | { 52 | Vector4 Planes[6]; 53 | }Frustum; 54 | 55 | // RLAPI void ExtractFrustum(Frustum* frustrum); 56 | RLAPI void ExtractFrustum(Frustum* frustum, Matrix projection, Matrix modelview); 57 | RLAPI bool PointInFrustumV(Frustum* frustrum, Vector3 position); 58 | RLAPI bool SphereInFrustumV(Frustum* frustrum, Vector3 position, float radius); 59 | 60 | RLAPI bool AABBoxInFrustum(Frustum* frustrum, Vector3 min, Vector3 max); 61 | 62 | #endif //FRUSTUM_H 63 | -------------------------------------------------------------------------------- /include/lgl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Rendering. */ 4 | int lglClear( lua_State* L ); 5 | /* Frame Buffers. */ 6 | int lglBlitFramebuffer( lua_State* L ); 7 | /* State Management. */ 8 | int lglDepthRange( lua_State* L ); 9 | int lglEnable( lua_State* L ); 10 | int lglDisable( lua_State* L ); 11 | int lglPolygonOffset( lua_State* L ); 12 | int lglStencilFunc( lua_State* L ); 13 | int lglStencilFuncSeparate( lua_State* L ); 14 | int lglStencilMask( lua_State* L ); 15 | int lglStencilMaskSeparate( lua_State* L ); 16 | int lglStencilOp( lua_State* L ); 17 | int lglStencilOpSeparate( lua_State* L ); 18 | /* Utility. */ 19 | int lglGetString( lua_State* L ); 20 | -------------------------------------------------------------------------------- /include/lights.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Light management functions. */ 4 | int llightsCreateLight( lua_State* L ); 5 | int llightsUpdateLightValues( lua_State* L ); 6 | int llightsSetLightType( lua_State* L ); 7 | int llightsSetLightPosition( lua_State* L ); 8 | int llightsSetLightTarget( lua_State* L ); 9 | int llightsSetLightColor( lua_State* L ); 10 | int llightsSetLightEnabled( lua_State* L ); 11 | int llightsGetLightType( lua_State* L ); 12 | int llightsGetLightPosition( lua_State* L ); 13 | int llightsGetLightTarget( lua_State* L ); 14 | int llightsGetLightColor( lua_State* L ); 15 | int llightsIsLightEnabled( lua_State* L ); 16 | -------------------------------------------------------------------------------- /include/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/luajit/luaconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Configuration header. 3 | ** Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef luaconf_h 7 | #define luaconf_h 8 | 9 | #ifndef WINVER 10 | #define WINVER 0x0501 11 | #endif 12 | #include 13 | #include 14 | 15 | /* Default path for loading Lua and C modules with require(). */ 16 | #if defined(_WIN32) 17 | /* 18 | ** In Windows, any exclamation mark ('!') in the path is replaced by the 19 | ** path of the directory of the executable file of the current process. 20 | */ 21 | #define LUA_LDIR "!\\lua\\" 22 | #define LUA_CDIR "!\\" 23 | #define LUA_PATH_DEFAULT \ 24 | ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" 25 | #define LUA_CPATH_DEFAULT \ 26 | ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" 27 | #else 28 | /* 29 | ** Note to distribution maintainers: do NOT patch the following lines! 30 | ** Please read ../doc/install.html#distro and pass PREFIX=/usr instead. 31 | */ 32 | #ifndef LUA_MULTILIB 33 | #define LUA_MULTILIB "lib" 34 | #endif 35 | #ifndef LUA_LMULTILIB 36 | #define LUA_LMULTILIB "lib" 37 | #endif 38 | #define LUA_LROOT "/usr/local" 39 | #define LUA_LUADIR "/lua/5.1/" 40 | #define LUA_LJDIR "/luajit-2.1.0-beta3/" 41 | 42 | #ifdef LUA_ROOT 43 | #define LUA_JROOT LUA_ROOT 44 | #define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR 45 | #define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR 46 | #define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua" 47 | #define LUA_RCPATH ";" LUA_RCDIR "?.so" 48 | #else 49 | #define LUA_JROOT LUA_LROOT 50 | #define LUA_RLPATH 51 | #define LUA_RCPATH 52 | #endif 53 | 54 | #define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua" 55 | #define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR 56 | #define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR 57 | #define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua" 58 | #define LUA_LCPATH1 ";" LUA_LCDIR "?.so" 59 | #define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so" 60 | 61 | #define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH 62 | #define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2 63 | #endif 64 | 65 | /* Environment variable names for path overrides and initialization code. */ 66 | #define LUA_PATH "LUA_PATH" 67 | #define LUA_CPATH "LUA_CPATH" 68 | #define LUA_INIT "LUA_INIT" 69 | 70 | /* Special file system characters. */ 71 | #if defined(_WIN32) 72 | #define LUA_DIRSEP "\\" 73 | #else 74 | #define LUA_DIRSEP "/" 75 | #endif 76 | #define LUA_PATHSEP ";" 77 | #define LUA_PATH_MARK "?" 78 | #define LUA_EXECDIR "!" 79 | #define LUA_IGMARK "-" 80 | #define LUA_PATH_CONFIG \ 81 | LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \ 82 | LUA_EXECDIR "\n" LUA_IGMARK "\n" 83 | 84 | /* Quoting in error messages. */ 85 | #define LUA_QL(x) "'" x "'" 86 | #define LUA_QS LUA_QL("%s") 87 | 88 | /* Various tunables. */ 89 | #define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */ 90 | #define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */ 91 | #define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */ 92 | #define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */ 93 | #define LUA_MAXCAPTURES 32 /* Max. pattern captures. */ 94 | 95 | /* Configuration for the frontend (the luajit executable). */ 96 | #if defined(luajit_c) 97 | #define LUA_PROGNAME "luajit" /* Fallback frontend name. */ 98 | #define LUA_PROMPT "> " /* Interactive prompt. */ 99 | #define LUA_PROMPT2 ">> " /* Continuation prompt. */ 100 | #define LUA_MAXINPUT 512 /* Max. input line length. */ 101 | #endif 102 | 103 | /* Note: changing the following defines breaks the Lua 5.1 ABI. */ 104 | #define LUA_INTEGER ptrdiff_t 105 | #define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */ 106 | /* 107 | ** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using 108 | ** unreasonable amounts of stack space, but still retain ABI compatibility. 109 | ** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it. 110 | */ 111 | #define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ) 112 | 113 | /* The following defines are here only for compatibility with luaconf.h 114 | ** from the standard Lua distribution. They must not be changed for LuaJIT. 115 | */ 116 | #define LUA_NUMBER_DOUBLE 117 | #define LUA_NUMBER double 118 | #define LUAI_UACNUMBER double 119 | #define LUA_NUMBER_SCAN "%lf" 120 | #define LUA_NUMBER_FMT "%.14g" 121 | #define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n)) 122 | #define LUAI_MAXNUMBER2STR 32 123 | #define LUA_INTFRMLEN "l" 124 | #define LUA_INTFRM_T long 125 | 126 | /* Linkage of public API functions. */ 127 | #if defined(LUA_BUILD_AS_DLL) 128 | #if defined(LUA_CORE) || defined(LUA_LIB) 129 | #define LUA_API __declspec(dllexport) 130 | #else 131 | #define LUA_API __declspec(dllimport) 132 | #endif 133 | #else 134 | #define LUA_API extern 135 | #endif 136 | 137 | #define LUALIB_API LUA_API 138 | 139 | /* Compatibility support for assertions. */ 140 | #if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK) 141 | #include 142 | #endif 143 | #ifdef LUA_USE_ASSERT 144 | #define lua_assert(x) assert(x) 145 | #endif 146 | #ifdef LUA_USE_APICHECK 147 | #define luai_apicheck(L, o) { (void)L; assert(o); } 148 | #else 149 | #define luai_apicheck(L, o) { (void)L; } 150 | #endif 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /include/luajit/luajit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/ 3 | ** 4 | ** Copyright (C) 2005-2022 Mike Pall. All rights reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining 7 | ** a copy of this software and associated documentation files (the 8 | ** "Software"), to deal in the Software without restriction, including 9 | ** without limitation the rights to use, copy, modify, merge, publish, 10 | ** distribute, sublicense, and/or sell copies of the Software, and to 11 | ** permit persons to whom the Software is furnished to do so, subject to 12 | ** the following conditions: 13 | ** 14 | ** The above copyright notice and this permission notice shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | ** 25 | ** [ MIT license: https://www.opensource.org/licenses/mit-license.php ] 26 | */ 27 | 28 | #ifndef _LUAJIT_H 29 | #define _LUAJIT_H 30 | 31 | #include "lua.h" 32 | 33 | #define LUAJIT_VERSION "LuaJIT 2.1.0-beta3" 34 | #define LUAJIT_VERSION_NUM 20100 /* Version 2.1.0 = 02.01.00. */ 35 | #define LUAJIT_VERSION_SYM luaJIT_version_2_1_0_beta3 36 | #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2022 Mike Pall" 37 | #define LUAJIT_URL "https://luajit.org/" 38 | 39 | /* Modes for luaJIT_setmode. */ 40 | #define LUAJIT_MODE_MASK 0x00ff 41 | 42 | enum { 43 | LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ 44 | LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ 45 | 46 | LUAJIT_MODE_FUNC, /* Change mode for a function. */ 47 | LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ 48 | LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ 49 | 50 | LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ 51 | 52 | LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ 53 | 54 | LUAJIT_MODE_MAX 55 | }; 56 | 57 | /* Flags or'ed in to the mode. */ 58 | #define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ 59 | #define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ 60 | #define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ 61 | 62 | /* LuaJIT public C API. */ 63 | 64 | /* Control the JIT engine. */ 65 | LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); 66 | 67 | /* Low-overhead profiling API. */ 68 | typedef void (*luaJIT_profile_callback)(void *data, lua_State *L, 69 | int samples, int vmstate); 70 | LUA_API void luaJIT_profile_start(lua_State *L, const char *mode, 71 | luaJIT_profile_callback cb, void *data); 72 | LUA_API void luaJIT_profile_stop(lua_State *L); 73 | LUA_API const char *luaJIT_profile_dumpstack(lua_State *L, const char *fmt, 74 | int depth, size_t *len); 75 | 76 | /* Enforce (dynamic) linker error for version mismatches. Call from main. */ 77 | LUA_API void LUAJIT_VERSION_SYM(void); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/luajit/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Standard library header. 3 | ** Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LUALIB_H 7 | #define _LUALIB_H 8 | 9 | #include "lua.h" 10 | 11 | #define LUA_FILEHANDLE "FILE*" 12 | 13 | #define LUA_COLIBNAME "coroutine" 14 | #define LUA_MATHLIBNAME "math" 15 | #define LUA_STRLIBNAME "string" 16 | #define LUA_TABLIBNAME "table" 17 | #define LUA_IOLIBNAME "io" 18 | #define LUA_OSLIBNAME "os" 19 | #define LUA_LOADLIBNAME "package" 20 | #define LUA_DBLIBNAME "debug" 21 | #define LUA_BITLIBNAME "bit" 22 | #define LUA_JITLIBNAME "jit" 23 | #define LUA_FFILIBNAME "ffi" 24 | 25 | LUALIB_API int luaopen_base(lua_State *L); 26 | LUALIB_API int luaopen_math(lua_State *L); 27 | LUALIB_API int luaopen_string(lua_State *L); 28 | LUALIB_API int luaopen_table(lua_State *L); 29 | LUALIB_API int luaopen_io(lua_State *L); 30 | LUALIB_API int luaopen_os(lua_State *L); 31 | LUALIB_API int luaopen_package(lua_State *L); 32 | LUALIB_API int luaopen_debug(lua_State *L); 33 | LUALIB_API int luaopen_bit(lua_State *L); 34 | LUALIB_API int luaopen_jit(lua_State *L); 35 | LUALIB_API int luaopen_ffi(lua_State *L); 36 | LUALIB_API int luaopen_string_buffer(lua_State *L); 37 | 38 | LUALIB_API void luaL_openlibs(lua_State *L); 39 | 40 | #ifndef lua_assert 41 | #define lua_assert(x) ((void)0) 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define STRING_LEN 1024 4 | 5 | #define VERSION_MAJOR 0 6 | #define VERSION_MINOR 9 7 | #define VERSION_PATCH 0 8 | #define VERSION_DEV 1 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "external/glad.h" 16 | #include "external/stb_rect_pack.h" 17 | 18 | #ifdef PLATFORM_DESKTOP 19 | #include "GLFW/glfw3.h" 20 | #include "GLFW/glfw3native.h" 21 | #elif PLATFORM_DESKTOP_SDL2 22 | #include 23 | #elif PLATFORM_DESKTOP_SDL3 24 | #include 25 | #endif 26 | 27 | #ifdef SHARED 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #else 35 | #include "raylib.h" 36 | #include "rlgl.h" 37 | #include "raymath.h" 38 | #include "raygui.h" 39 | #include "rlights.h" 40 | #include "rcamera.h" 41 | #endif 42 | 43 | #ifdef LUAJIT 44 | #ifdef SHARED 45 | #include 46 | #include 47 | #include 48 | #include 49 | #else 50 | #include "luajit/lua.h" 51 | #include "luajit/luajit.h" 52 | #include "luajit/lualib.h" 53 | #include "luajit/lauxlib.h" 54 | #endif 55 | #else 56 | #ifdef SHARED 57 | #include 58 | #include 59 | #include 60 | #else 61 | #include "lua/lua.h" 62 | #include "lua/lualib.h" 63 | #include "lua/lauxlib.h" 64 | #endif 65 | #endif 66 | -------------------------------------------------------------------------------- /include/models.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Internals. */ 4 | void unloadMaterial( Material* material ); 5 | /* Deleted from raylib. Need for freeing models. */ 6 | void DrawBillboardProNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ); 7 | void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint ); 8 | 9 | /* Basic geometric 3D shapes drawing functions. */ 10 | int lmodelsDrawLine3D( lua_State* L ); 11 | int lmodelsDrawPoint3D( lua_State* L ); 12 | int lmodelsDrawCircle3D( lua_State* L ); 13 | int lmodelsDrawTriangle3D( lua_State* L ); 14 | int lmodelsDrawTriangleStrip3D( lua_State* L ); 15 | int lmodelsDrawCube( lua_State* L ); 16 | int lmodelsDrawCubeWires( lua_State* L ); 17 | int lmodelsDrawSphere( lua_State* L ); 18 | int lmodelsDrawSphereEx( lua_State* L ); 19 | int lmodelsDrawSphereWires( lua_State* L ); 20 | int lmodelsDrawCylinder( lua_State* L ); 21 | int lmodelsDrawCylinderEx( lua_State* L ); 22 | int lmodelsDrawCylinderWires( lua_State* L ); 23 | int lmodelsDrawCylinderWiresEx( lua_State* L ); 24 | int lmodelsDrawCapsule( lua_State* L ); 25 | int lmodelsDrawCapsuleWires( lua_State* L ); 26 | int lmodelsDrawPlane( lua_State* L ); 27 | int lmodelDrawQuad3DTexture( lua_State* L ); 28 | int lmodelsDrawRay( lua_State* L ); 29 | int lmodelsDrawGrid( lua_State* L ); 30 | int lmodelsDrawGridEx( lua_State* L ); 31 | /* Model management functions. */ 32 | int lmodelsLoadModel( lua_State* L ); 33 | int lmodelsLoadModelFromMesh( lua_State* L ); 34 | int lmodelsIsModelValid( lua_State* L ); 35 | int lmodelsUnloadModel( lua_State* L ); 36 | int lmodelsGetModelBoundingBox( lua_State* L ); 37 | int lmodelsSetModelTransform( lua_State* L ); 38 | int lmodelsSetModelMesh( lua_State* L ); 39 | int lmodelsSetModelMaterial( lua_State* L ); 40 | int lmodelsSetModelMeshMaterial( lua_State* L ); 41 | int lmodelsSetModelBone( lua_State* L ); 42 | int lmodelsSetModelBindPose( lua_State* L ); 43 | int lmodelsGetModelTransform( lua_State* L ); 44 | int lmodelsGetModelMeshCount( lua_State* L ); 45 | int lmodelsGetModelMaterialCount( lua_State* L ); 46 | int lmodelsGetModelMesh( lua_State* L ); 47 | int lmodelsGetModelMaterial( lua_State* L ); 48 | int lmodelsGetModelBoneCount( lua_State* L ); 49 | int lmodelsGetModelBone( lua_State* L ); 50 | int lmodelsGetModelBindPose( lua_State* L ); 51 | /* Model drawing functions. */ 52 | int lmodelsDrawModel( lua_State* L ); 53 | int lmodelsDrawModelEx( lua_State* L ); 54 | int lmodelsDrawModelWires( lua_State* L ); 55 | int lmodelsDrawModelWiresEx( lua_State* L ); 56 | int lmodelsDrawModelPoints( lua_State* L ); 57 | int lmodelsDrawModelPointsEx( lua_State* L ); 58 | int lmodelsDrawBoundingBox( lua_State* L ); 59 | int lmodelsDrawBillboard( lua_State* L ); 60 | int lmodelsDrawBillboardRec( lua_State* L ); 61 | int lmodelsDrawBillboardPro( lua_State* L ); 62 | /* Mesh management functions. */ 63 | int lmodelsUpdateMesh( lua_State* L ); 64 | int lmodelsUnloadMesh( lua_State* L ); 65 | int lmodelsDrawMesh( lua_State* L ); 66 | int lmodelsDrawMeshInstanced( lua_State* L ); 67 | int lmodelsSetMeshColor( lua_State* L ); 68 | int lmodelsExportMesh( lua_State* L ); 69 | int lmodelsExportMeshAsCode( lua_State* L ); 70 | int lmodelsGetMeshBoundingBox( lua_State* L ); 71 | int lmodelsGenMeshTangents( lua_State* L ); 72 | int lmodelsGetMeshData( lua_State* L ); 73 | /* Mesh generation functions. */ 74 | int lmodelsGenMeshPoly( lua_State* L ); 75 | int lmodelsGenMeshPlane( lua_State* L ); 76 | int lmodelsGenMeshCube( lua_State* L ); 77 | int lmodelsGenMeshSphere( lua_State* L ); 78 | int lmodelsGenMeshHemiSphere( lua_State* L ); 79 | int lmodelsGenMeshCylinder( lua_State* L ); 80 | int lmodelsGenMeshCone( lua_State* L ); 81 | int lmodelsGenMeshTorus( lua_State* L ); 82 | int lmodelsGenMeshKnot( lua_State* L ); 83 | int lmodelsGenMeshHeightmap( lua_State* L ); 84 | int lmodelsGenMeshCubicmap( lua_State* L ); 85 | int lmodelsGenMeshCustom( lua_State* L ); 86 | /* Material management functions. */ 87 | int lmodelsLoadMaterials( lua_State* L ); 88 | int lmodelsGetMaterialDefault( lua_State* L ); 89 | int lmodelsLoadMaterialDefault( lua_State* L ); 90 | int lmodelsCreateMaterial( lua_State* L ); 91 | int lmodelsIsMaterialValid( lua_State* L ); 92 | int lmodelsUnloadMaterial( lua_State* L ); 93 | int lmodelsSetMaterialTexture( lua_State* L ); 94 | int lmodelsSetMaterialColor( lua_State* L ); 95 | int lmodelsSetMaterialValue( lua_State* L ); 96 | int lmodelsSetMaterialShader( lua_State* L ); 97 | int lmodelsSetMaterialParams( lua_State* L ); 98 | int lmodelsGetMaterialTexture( lua_State* L ); 99 | int lmodelsGetMaterialColor( lua_State* L ); 100 | int lmodelsGetMaterialValue( lua_State* L ); 101 | int lmodelsGetMaterialShader( lua_State* L ); 102 | int lmodelsGetMaterialParams( lua_State* L ); 103 | /* Model animations management functions. */ 104 | int lmodelsLoadModelAnimations( lua_State* L ); 105 | int lmodelsUpdateModelAnimation( lua_State* L ); 106 | int lmodelsUpdateModelAnimationBones( lua_State* L ); 107 | int lmodelsUnloadModelAnimation( lua_State* L ); 108 | int lmodelsUnloadModelAnimations( lua_State* L ); 109 | int lmodelsIsModelAnimationValid( lua_State* L ); 110 | int lmodelsSetModelAnimationBone( lua_State* L ); 111 | int lmodelsSetModelAnimationFramePose( lua_State* L ); 112 | int lmodelsSetModelAnimationName( lua_State* L ); 113 | int lmodelsGetModelAnimationBoneCount( lua_State* L ); 114 | int lmodelsGetModelAnimationFrameCount( lua_State* L ); 115 | int lmodelsGetModelAnimationBone( lua_State* L ); 116 | int lmodelsGetModelAnimationFramePose( lua_State* L ); 117 | int lmodelsGetModelAnimationName( lua_State* L ); 118 | /* Collision detection functions. */ 119 | int lmodelsCheckCollisionSpheres( lua_State* L ); 120 | int lmodelsCheckCollisionBoxes( lua_State* L ); 121 | int lmodelsCheckCollisionBoxSphere( lua_State* L ); 122 | int lmodelsGetRayCollisionSphere( lua_State* L ); 123 | int lmodelsGetRayCollisionBox( lua_State* L ); 124 | int lmodelsGetRayCollisionMesh( lua_State* L ); 125 | int lmodelsGetRayCollisionTriangle( lua_State* L ); 126 | int lmodelsGetRayCollisionQuad( lua_State* L ); 127 | int lmodelsGetRayBoxCells( lua_State* L ); 128 | -------------------------------------------------------------------------------- /include/platforms/core_desktop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GLFW/glfw3.h" 4 | #include "GLFW/glfw3native.h" 5 | 6 | enum EventType { 7 | GLFW_WINDOW_SIZE_EVENT, 8 | GLFW_WINDOW_MAXIMIZE_EVENT, 9 | GLFW_WINDOW_ICONYFY_EVENT, 10 | GLFW_WINDOW_FOCUS_EVENT, 11 | GLFW_WINDOW_DROP_EVENT, 12 | GLFW_KEY_EVENT, 13 | GLFW_CHAR_EVENT, 14 | GLFW_MOUSE_BUTTON_EVENT, 15 | GLFW_MOUSE_CURSOR_POS_EVENT, 16 | GLFW_MOUSE_SCROLL_EVENT, 17 | GLFW_CURSOR_ENTER_EVENT, 18 | GLFW_JOYSTICK_EVENT, 19 | /* NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 */ 20 | GLFW_PEN_TABLET_DATA_EVENT, 21 | GLFW_PEN_TABLET_CURSOR_EVENT, 22 | GLFW_PEN_TABLET_PROXIMITY_EVENT 23 | }; 24 | -------------------------------------------------------------------------------- /include/platforms/core_desktop_sdl2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // #define SDL_EVENT_QUEUE_LEN 128 4 | 5 | #include "SDL.h" 6 | 7 | // typedef struct { 8 | // int SDL_eventQueueLen; 9 | // SDL_Event** SDL_eventQueue; 10 | // } SDL_State; 11 | 12 | // extern SDL_State *SDL_state; 13 | -------------------------------------------------------------------------------- /include/platforms/core_desktop_sdl3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SDL3/SDL.h" 4 | -------------------------------------------------------------------------------- /include/reasings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Linear Easing functions. */ 4 | int leasingsEaseLinear( lua_State* L ); 5 | 6 | /* Sine Easing functions. */ 7 | int leasingsEaseSineIn( lua_State* L ); 8 | int leasingsEaseSineOut( lua_State* L ); 9 | int leasingsEaseSineInOut( lua_State* L ); 10 | 11 | /* Circular Easing functions. */ 12 | int leasingsEaseCircIn( lua_State* L ); 13 | int leasingsEaseCircOut( lua_State* L ); 14 | int leasingsEaseCircInOut( lua_State* L ); 15 | 16 | /* Cubic Easing functions. */ 17 | int leasingsEaseCubicIn( lua_State* L ); 18 | int leasingsEaseCubicOut( lua_State* L ); 19 | int leasingsEaseCubicInOut( lua_State* L ); 20 | 21 | /* Quadratic Easing functions. */ 22 | int leasingsEaseQuadIn( lua_State* L ); 23 | int leasingsEaseQuadOut( lua_State* L ); 24 | int leasingsEaseQuadInOut( lua_State* L ); 25 | 26 | /* Exponential Easing functions. */ 27 | int leasingsEaseExpoIn( lua_State* L ); 28 | int leasingsEaseExpoOut( lua_State* L ); 29 | int leasingsEaseExpoInOut( lua_State* L ); 30 | 31 | /* Back Easing functions. */ 32 | int leasingsEaseBackIn( lua_State* L ); 33 | int leasingsEaseBackOut( lua_State* L ); 34 | int leasingsEaseBackInOut( lua_State* L ); 35 | 36 | /* Bounce Easing functions. */ 37 | int leasingsEaseBounceIn( lua_State* L ); 38 | int leasingsEaseBounceOut( lua_State* L ); 39 | int leasingsEaseBounceInOut( lua_State* L ); 40 | 41 | /* Elastic Easing functions. */ 42 | int leasingsEaseElasticIn( lua_State* L ); 43 | int leasingsEaseElasticOut( lua_State* L ); 44 | int leasingsEaseElasticInOut( lua_State* L ); 45 | -------------------------------------------------------------------------------- /include/rgui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Global gui state control functions. */ 4 | int lguiGuiEnable( lua_State* L ); 5 | int lguiGuiDisable( lua_State* L ); 6 | int lguiGuiLock( lua_State* L ); 7 | int lguiGuiUnlock( lua_State* L ); 8 | int lguiGuiIsLocked( lua_State* L ); 9 | int lguiGuiSetAlpha( lua_State* L ); 10 | int lguiGuiSetState( lua_State* L ); 11 | int lguiGuiGetState( lua_State* L ); 12 | int lguiGuiSetSliderDragging( lua_State* L ); 13 | int lguiGuiGetSliderDragging( lua_State* L ); 14 | int lguiGuiSetSliderActive( lua_State* L ); 15 | int lguiGuiGetSliderActive( lua_State* L ); 16 | /* Font set/get functions. */ 17 | int lguiGuiSetFont( lua_State* L ); 18 | int lguiGuiGetFont( lua_State* L ); 19 | /* Style set/get functions. */ 20 | int lguiGuiSetStyle( lua_State* L ); 21 | int lguiGuiGetStyle( lua_State* L ); 22 | /* Styles loading functions. */ 23 | int lguiGuiLoadStyle( lua_State* L ); 24 | int lguiGuiLoadStyleDefault( lua_State* L ); 25 | /* Tooltips management functions. */ 26 | int lguiGuiEnableTooltip( lua_State* L ); 27 | int lguiGuiDisableTooltip( lua_State* L ); 28 | int lguiGuiSetTooltip( lua_State* L ); 29 | /* Icons functionality. */ 30 | int lguiGuiIconText( lua_State* L ); 31 | int lguiGuiSetIconScale( lua_State* L ); 32 | int lguiGuiGetIcons( lua_State* L ); 33 | int lguiGuiSetIcons( lua_State* L ); 34 | int lguiGuiLoadIcons( lua_State* L ); 35 | int lguiGuiDrawIcon( lua_State* L ); 36 | /* Container/separator controls, useful for controls organization. */ 37 | int lguiGuiWindowBox( lua_State* L ); 38 | int lguiGuiGroupBox( lua_State* L ); 39 | int lguiGuiLine( lua_State* L ); 40 | int lguiGuiPanel( lua_State* L ); 41 | int lguiGuiTabBar( lua_State* L ); 42 | int lguiGuiScrollPanel( lua_State* L ); 43 | /* Basic controls set. */ 44 | int lguiGuiLabel( lua_State* L ); 45 | int lguiGuiButton( lua_State* L ); 46 | int lguiGuiLabelButton( lua_State* L ); 47 | int lguiGuiToggle( lua_State* L ); 48 | int lguiGuiToggleGroup( lua_State* L ); 49 | int lguiGuiToggleSlider( lua_State* L ); 50 | int lguiGuiCheckBox( lua_State* L ); 51 | int lguiGuiComboBox( lua_State* L ); 52 | int lguiGuiDropdownBox( lua_State* L ); 53 | int lguiGuiSpinner( lua_State* L ); 54 | int lguiGuiValueBox( lua_State* L ); 55 | int lguiGuiTextBox( lua_State* L ); 56 | int lguiGuiSlider( lua_State* L ); 57 | int lguiGuiSliderBar( lua_State* L ); 58 | int lguiGuiProgressBar( lua_State* L ); 59 | int lguiGuiStatusBar( lua_State* L ); 60 | int lguiGuiDummyRec( lua_State* L ); 61 | int lguiGuiGrid( lua_State* L ); 62 | int lguiGuiScrollBar( lua_State* L ); 63 | /* Advance controls set. */ 64 | int lguiGuiListView( lua_State* L ); 65 | int lguiGuiListViewEx( lua_State* L ); 66 | int lguiGuiMessageBox( lua_State* L ); 67 | int lguiGuiTextInputBox( lua_State* L ); 68 | int lguiGuiColorPicker( lua_State* L ); 69 | int lguiGuiColorPanel( lua_State* L ); 70 | int lguiGuiColorBarAlpha( lua_State* L ); 71 | int lguiGuiColorBarHue( lua_State* L ); 72 | int lguiGuiColorPickerHSV( lua_State* L ); 73 | int lguiGuiColorPanelHSV( lua_State* L ); 74 | -------------------------------------------------------------------------------- /include/shapes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Basic shapes drawing functions. */ 4 | int lshapesSetShapesTexture( lua_State* L ); 5 | int lshapesGetShapesTexture( lua_State* L ); 6 | int lshapesGetShapesTextureRectangle( lua_State* L ); 7 | int lshapesDrawPixel( lua_State* L ); 8 | int lshapesDrawLine( lua_State* L ); 9 | int lshapesDrawLineBezier( lua_State* L ); 10 | int lshapesDrawLineStrip( lua_State* L ); 11 | int lshapesDrawCircle( lua_State* L ); 12 | int lshapesDrawCircleSector( lua_State* L ); 13 | int lshapesDrawCircleSectorLines( lua_State* L ); 14 | int lshapesDrawCircleGradient( lua_State* L ); 15 | int lshapesDrawCircleLines( lua_State* L ); 16 | int lshapesDrawEllipse( lua_State* L ); 17 | int lshapesDrawEllipseLines( lua_State* L ); 18 | int lshapesDrawRing( lua_State* L ); 19 | int lshapesDrawRingLines( lua_State* L ); 20 | int lshapesDrawRectangle( lua_State* L ); 21 | int lshapesDrawRectanglePro( lua_State* L ); 22 | int lshapesDrawRectangleGradientV( lua_State* L ); 23 | int lshapesDrawRectangleGradientH( lua_State* L ); 24 | int lshapesDrawRectangleGradientEx( lua_State* L ); 25 | int lshapesDrawRectangleLines( lua_State* L ); 26 | int lshapesDrawRectangleLinesEx( lua_State* L ); 27 | int lshapesDrawRectangleRounded( lua_State* L ); 28 | int lshapesDrawRectangleRoundedLines( lua_State* L ); 29 | int lshapesDrawRectangleRoundedLinesEx( lua_State* L ); 30 | int lshapesDrawTriangle( lua_State* L ); 31 | int lshapesDrawTriangleLines( lua_State* L ); 32 | int lshapesDrawTriangleFan( lua_State* L ); 33 | int lshapesDrawTriangleStrip( lua_State* L ); 34 | int lshapesDrawPoly( lua_State* L ); 35 | int lshapesDrawPolyLines( lua_State* L ); 36 | int lshapesDrawPolyLinesEx( lua_State* L ); 37 | /* Splines drawing functions. */ 38 | int lshapesDrawSplineLinear( lua_State* L ); 39 | int lshapesDrawSplineBasis( lua_State* L ); 40 | int lshapesDrawSplineCatmullRom( lua_State* L ); 41 | int lshapesDrawSplineBezierQuadratic( lua_State* L ); 42 | int lshapesDrawSplineBezierCubic( lua_State* L ); 43 | int lshapesDrawSplineSegmentLinear( lua_State* L ); 44 | int lshapesDrawSplineSegmentBasis( lua_State* L ); 45 | int lshapesDrawSplineSegmentCatmullRom( lua_State* L ); 46 | int lshapesDrawSplineSegmentBezierQuadratic( lua_State* L ); 47 | int lshapesDrawSplineSegmentBezierCubic( lua_State* L ); 48 | /* Basic Spline segment point evaluation functions, for a given t [0.0f .. 1.0f]. */ 49 | int lshapesGetSplinePointLinear( lua_State* L ); 50 | int lshapesGetSplinePointBasis( lua_State* L ); 51 | int lshapesGetSplinePointCatmullRom( lua_State* L ); 52 | int lshapesGetSplinePointBezierQuad( lua_State* L ); 53 | int lshapesGetSplinePointBezierCubic( lua_State* L ); 54 | /* Basic shapes collision detection functions. */ 55 | int lshapesCheckCollisionRecs( lua_State* L ); 56 | int lshapesCheckCollisionCircles( lua_State* L ); 57 | int lshapesCheckCollisionCircleRec( lua_State* L ); 58 | int lshapesCheckCollisionCircleLine( lua_State* L ); 59 | int lshapesCheckCollisionPointRec( lua_State* L ); 60 | int lshapesCheckCollisionPointCircle( lua_State* L ); 61 | int lshapesCheckCollisionPointTriangle( lua_State* L ); 62 | int lshapesCheckCollisionPointPoly( lua_State* L ); 63 | int lshapesCheckCollisionLines( lua_State* L ); 64 | int lshapesCheckCollisionPointLine( lua_State* L ); 65 | int lshapesGetCollisionRec( lua_State* L ); 66 | int lshapesRectPack( lua_State* L ); 67 | -------------------------------------------------------------------------------- /include/state.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined PLATFORM_DESKTOP_SDL2 || defined PLATFORM_DESKTOP_SDL3 4 | #define PLATFORM_SDL_EVENT_QUEUE_LEN 128 5 | #endif 6 | 7 | typedef struct { 8 | char* basePath; 9 | bool run; 10 | bool gcUnload; 11 | int lineSpacing; /* We need to store copy here since raylib has it in static. */ 12 | Vector2 mouseOffset; 13 | Vector2 mouseScale; 14 | lua_State* luaState; 15 | int logLevelInvalid; 16 | Font defaultFont; 17 | Font guiFont; 18 | Material defaultMaterial; 19 | Texture defaultTexture; 20 | Texture shapesTexture; 21 | int* RLGLcurrentShaderLocs; 22 | /* Events. */ 23 | #ifdef PLATFORM_DESKTOP 24 | /* Window events. */ 25 | GLFWwindowsizefun raylibWindowSizeCallback; 26 | GLFWwindowmaximizefun raylibWindowMaximizeCallback; 27 | GLFWwindowiconifyfun raylibWindowIconifyCallback; 28 | GLFWwindowfocusfun raylibWindowFocusCallback; 29 | GLFWdropfun raylibWindowDropCallback; 30 | /* Input events. */ 31 | GLFWkeyfun raylibKeyCallback; 32 | GLFWcharfun raylibCharCallback; 33 | GLFWmousebuttonfun raylibMouseButtonCallback; 34 | GLFWcursorposfun raylibMouseCursorPosCallback; 35 | GLFWscrollfun raylibMouseScrollCallback; 36 | GLFWcursorenterfun raylibCursorEnterCallback; 37 | GLFWjoystickfun raylibJoystickCallback; 38 | /* NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 */ 39 | GLFWpentabletdatafun glfwTabletDataCallback; 40 | GLFWpentabletcursorfun glfwTabletCursorCallback; 41 | GLFWpentabletproximityfun glfwTabletProximityCallback; 42 | #elif defined PLATFORM_DESKTOP_SDL2 || defined PLATFORM_DESKTOP_SDL3 43 | int SDL_eventQueueLen; 44 | SDL_Event* SDL_eventQueue; 45 | #endif 46 | } State; 47 | 48 | extern State* state; 49 | 50 | bool stateInit( int argn, const char** argc, const char* basePath ); 51 | void stateContextInit(); 52 | void stateInitInterpret( int argn, const char** argc ); 53 | void stateFree(); 54 | -------------------------------------------------------------------------------- /include/text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void unloadGlyphInfo( GlyphInfo* glyph ); 4 | /* Font loading/unloading functions. */ 5 | int ltextGetFontDefault( lua_State* L ); 6 | int ltextLoadFont( lua_State* L ); 7 | int ltextLoadFontEx( lua_State* L ); 8 | int ltextLoadFontFromImage( lua_State* L ); 9 | int ltextLoadFontFromMemory( lua_State* L ); 10 | int ltextLoadFontFromData( lua_State* L ); 11 | int ltextFontCopy( lua_State* L ); 12 | int ltextIsFontValid( lua_State* L ); 13 | int ltextLoadFontData( lua_State* L ); 14 | int ltextGenImageFontAtlas( lua_State* L ); 15 | int ltextUnloadFont( lua_State* L ); 16 | int ltextExportFontAsCode( lua_State* L ); 17 | /* Text drawing functions. */ 18 | int ltextDrawFPS( lua_State* L ); 19 | int ltextDrawText( lua_State* L ); 20 | int ltextDrawTextEx( lua_State* L ); 21 | int ltextDrawTextPro( lua_State* L ); 22 | int ltextDrawTextCodepoint( lua_State* L ); 23 | int ltextDrawTextCodepoints( lua_State* L ); 24 | int ltextDrawTextBoxed( lua_State* L ); 25 | int ltextDrawTextBoxedEx( lua_State* L ); 26 | /* Text font info functions. */ 27 | int ltextSetTextLineSpacing( lua_State* L ); 28 | int ltextGetTextLineSpacing( lua_State* L ); 29 | int ltextMeasureText( lua_State* L ); 30 | int ltextMeasureTextEx( lua_State* L ); 31 | int ltextGetGlyphIndex( lua_State* L ); 32 | int ltextGetGlyphInfo( lua_State* L ); 33 | int ltextGetGlyphInfoByIndex( lua_State* L ); 34 | int ltextGetGlyphAtlasRec( lua_State* L ); 35 | int ltextGetGlyphAtlasRecByIndex( lua_State* L ); 36 | int ltextGetFontBaseSize( lua_State* L ); 37 | int ltextGetFontGlyphCount( lua_State* L ); 38 | int ltextGetFontGlyphPadding( lua_State* L ); 39 | int ltextGetFontTexture( lua_State* L ); 40 | /* GlyphInfo management functions. */ 41 | int ltextLoadGlyphInfo( lua_State* L ); 42 | int ltextUnloadGlyphInfo( lua_State* L ); 43 | int ltextSetGlyphInfoValue( lua_State* L ); 44 | int ltextSetGlyphInfoOffset( lua_State* L ); 45 | int ltextSetGlyphInfoAdvanceX( lua_State* L ); 46 | int ltextSetGlyphInfoImage( lua_State* L ); 47 | int ltextGetGlyphInfoValue( lua_State* L ); 48 | int ltextGetGlyphInfoOffset( lua_State* L ); 49 | int ltextGetGlyphInfoAdvanceX( lua_State* L ); 50 | int ltextGetGlyphInfoImage( lua_State* L ); 51 | /* Text codepoints management functions (unicode characters). */ 52 | int ltextLoadUTF8( lua_State* L ); 53 | int ltextLoadCodepoints( lua_State* L ); 54 | int ltextGetCodepointCount( lua_State* L ); 55 | int ltextGetCodepoint( lua_State* L ); 56 | int ltextGetCodepointNext( lua_State* L ); 57 | int ltextGetCodepointPrevious( lua_State* L ); 58 | int ltextCodepointToUTF8( lua_State* L ); 59 | /* Text strings management functions (no UTF-8 strings, only byte chars) */ 60 | int ltextTextSubtext( lua_State* L ); 61 | int ltextTextReplace( lua_State* L ); 62 | int ltextTextInsert( lua_State* L ); 63 | int ltextTextSplit( lua_State* L ); 64 | int ltextTextFindIndex( lua_State* L ); 65 | int ltextTextToPascal( lua_State* L ); 66 | int ltextTextToSnake( lua_State* L ); 67 | int ltextTextToCamel( lua_State* L ); 68 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | libraylib.a 2 | liblua.a 3 | libluajit.a 4 | liblua.so 5 | libluajit.so 6 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nullstare/ReiLua/5b8af05e96b33f2d032cc31a329b89e1231d5502/logo.png -------------------------------------------------------------------------------- /src/bitwiseOp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "state.h" 3 | #include "lua_core.h" 4 | #include "core.h" 5 | #include "bitwiseOp.h" 6 | 7 | /* 8 | ## Bitwise Operations - Arithmetic 9 | */ 10 | 11 | /* 12 | > result = RL.BitAnd( int a, int b ) 13 | 14 | Equivalent to a & b in C 15 | 16 | - Success return int 17 | */ 18 | int lbitAnd( lua_State* L ) { 19 | uint64_t a = luaL_checkinteger( L, 1 ); 20 | uint64_t b = luaL_checkinteger( L, 2 ); 21 | 22 | lua_pushinteger( L, a & b ); 23 | 24 | return 1; 25 | } 26 | 27 | /* 28 | > result = RL.BitOr( int a, int b ) 29 | 30 | Equivalent to a | b in C 31 | 32 | - Success return int 33 | */ 34 | int lbitOr( lua_State* L ) { 35 | uint64_t a = luaL_checkinteger( L, 1 ); 36 | uint64_t b = luaL_checkinteger( L, 2 ); 37 | 38 | lua_pushinteger( L, a | b ); 39 | 40 | return 1; 41 | } 42 | 43 | /* 44 | > result = RL.BitXor( int a, int b ) 45 | 46 | Equivalent to a ^ b in C 47 | 48 | - Success return int 49 | */ 50 | int lbitXor( lua_State* L ) { 51 | uint64_t a = luaL_checkinteger( L, 1 ); 52 | uint64_t b = luaL_checkinteger( L, 2 ); 53 | 54 | lua_pushinteger( L, a ^ b ); 55 | 56 | return 1; 57 | } 58 | 59 | /* 60 | > result = RL.BitNot( int v ) 61 | 62 | Equivalent to ~v in C 63 | 64 | - Success return int 65 | */ 66 | int lbitNot( lua_State* L ) { 67 | uint64_t v = luaL_checkinteger( L, 1 ); 68 | 69 | lua_pushinteger( L, ~v ); 70 | 71 | return 1; 72 | } 73 | 74 | /* 75 | > result = RL.BitShiftLeft( int v, int n ) 76 | 77 | Equivalent to v << n in C 78 | 79 | - Success return int 80 | */ 81 | int lbitShiftLeft( lua_State* L ) { 82 | uint64_t v = luaL_checkinteger( L, 1 ); 83 | uint64_t n = luaL_checkinteger( L, 2 ); 84 | 85 | lua_pushinteger( L, v << n ); 86 | 87 | return 1; 88 | } 89 | 90 | /* 91 | > result = RL.BitShiftRight( int v, int n ) 92 | 93 | Equivalent to v >> n in C 94 | 95 | - Success return int 96 | */ 97 | int lbitShiftRight( lua_State* L ) { 98 | uint64_t v = luaL_checkinteger( L, 1 ); 99 | uint64_t n = luaL_checkinteger( L, 2 ); 100 | 101 | lua_pushinteger( L, v >> n ); 102 | 103 | return 1; 104 | } 105 | 106 | /* 107 | > result = RL.BitSet( int v, int i, bool b ) 108 | 109 | Set bit in index i to state b in value v 110 | 111 | - Success return int 112 | */ 113 | int lbitSet( lua_State* L ) { 114 | uint64_t v = luaL_checkinteger( L, 1 ); 115 | uint64_t i = luaL_checkinteger( L, 2 ); 116 | bool b = uluaGetBoolean( L, 3 ); 117 | 118 | lua_pushinteger( L, b ? v | 1UL << i : v & ~( 1UL << i ) ); 119 | 120 | return 1; 121 | } 122 | 123 | /* 124 | > bit = RL.BitGet( int v, int i ) 125 | 126 | Get bit in index i from value v 127 | 128 | - Success return bool 129 | */ 130 | int lbitGet( lua_State* L ) { 131 | uint64_t v = luaL_checkinteger( L, 1 ); 132 | uint64_t i = luaL_checkinteger( L, 2 ); 133 | 134 | lua_pushboolean( L, 0UL < ( v & ( 1UL << i ) ) ); 135 | 136 | return 1; 137 | } 138 | 139 | /* 140 | > result = RL.BitToggle( int v, int i ) 141 | 142 | Toggle bit in index i in value v 143 | 144 | - Success return int 145 | */ 146 | int lbitToggle( lua_State* L ) { 147 | uint64_t v = luaL_checkinteger( L, 1 ); 148 | uint64_t i = luaL_checkinteger( L, 2 ); 149 | 150 | lua_pushinteger( L, v ^ 1UL << i ); 151 | 152 | return 1; 153 | } 154 | -------------------------------------------------------------------------------- /src/lights.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "state.h" 3 | #include "lua_core.h" 4 | #include "core.h" 5 | #include "lights.h" 6 | 7 | #define RLIGHTS_IMPLEMENTATION 8 | #include "rlights.h" 9 | 10 | /* 11 | ## Lights - Light management functions 12 | */ 13 | 14 | /* 15 | > light = RL.CreateLight( int type, Vector3 position, Vector3 target, Color color, Shader shader ) 16 | 17 | Create a light and get shader locations 18 | 19 | - Success return Light 20 | */ 21 | int llightsCreateLight( lua_State* L ) { 22 | int type = luaL_checkinteger( L, 1 ); 23 | Vector3 position = uluaGetVector3( L, 2 ); 24 | Vector3 target = uluaGetVector3( L, 3 ); 25 | Color color = uluaGetColor( L, 4 ); 26 | Shader* shader = uluaGetShader( L, 5 ); 27 | 28 | uluaPushLight( L, CreateLight( type, position, target, color, *shader ) ); 29 | 30 | return 1; 31 | } 32 | 33 | /* 34 | > RL.UpdateLightValues( Shader shader, Light light ) 35 | 36 | Send light properties to shader 37 | */ 38 | int llightsUpdateLightValues( lua_State* L ) { 39 | Shader* shader = uluaGetShader( L, 1 ); 40 | Light* light = uluaGetLight( L, 2 ); 41 | 42 | UpdateLightValues( *shader, *light ); 43 | 44 | return 0; 45 | } 46 | 47 | /* 48 | > RL.SetLightType( Light light, int type ) 49 | 50 | Set light type 51 | */ 52 | int llightsSetLightType( lua_State* L ) { 53 | Light* light = uluaGetLight( L, 1 ); 54 | int type = luaL_checkinteger( L, 2 ); 55 | 56 | light->type = type; 57 | 58 | return 0; 59 | } 60 | 61 | /* 62 | > RL.SetLightPosition( Light light, Vector3 position ) 63 | 64 | Set light position 65 | */ 66 | int llightsSetLightPosition( lua_State* L ) { 67 | Light* light = uluaGetLight( L, 1 ); 68 | Vector3 position = uluaGetVector3( L, 2 ); 69 | 70 | light->position = position; 71 | 72 | return 0; 73 | } 74 | 75 | /* 76 | > RL.SetLightTarget( Light light, Vector3 target ) 77 | 78 | Set light target 79 | */ 80 | int llightsSetLightTarget( lua_State* L ) { 81 | Light* light = uluaGetLight( L, 1 ); 82 | Vector3 target = uluaGetVector3( L, 2 ); 83 | 84 | light->target = target; 85 | 86 | return 0; 87 | } 88 | 89 | /* 90 | > RL.SetLightColor( Light light, Color color ) 91 | 92 | Set light color 93 | */ 94 | int llightsSetLightColor( lua_State* L ) { 95 | Light* light = uluaGetLight( L, 1 ); 96 | Color color = uluaGetColor( L, 2 ); 97 | 98 | light->color = color; 99 | 100 | return 0; 101 | } 102 | 103 | /* 104 | > RL.SetLightEnabled( Light light, bool enabled ) 105 | 106 | Set light enabled 107 | */ 108 | int llightsSetLightEnabled( lua_State* L ) { 109 | Light* light = uluaGetLight( L, 1 ); 110 | bool enabled = uluaGetBoolean( L, 2 ); 111 | 112 | light->enabled = enabled; 113 | 114 | return 0; 115 | } 116 | 117 | /* 118 | > type = RL.GetLightType( Light light ) 119 | 120 | Get light type 121 | 122 | - Success return int 123 | */ 124 | int llightsGetLightType( lua_State* L ) { 125 | Light* light = uluaGetLight( L, 1 ); 126 | 127 | lua_pushinteger( L, light->type ); 128 | 129 | return 1; 130 | } 131 | 132 | /* 133 | > position = RL.GetLightPosition( Light light ) 134 | 135 | Get light position 136 | 137 | - Success return Vector3 138 | */ 139 | int llightsGetLightPosition( lua_State* L ) { 140 | Light* light = uluaGetLight( L, 1 ); 141 | 142 | uluaPushVector3( L, light->position ); 143 | 144 | return 1; 145 | } 146 | 147 | /* 148 | > target = RL.GetLightTarget( Light light ) 149 | 150 | Get light target 151 | 152 | - Success return Vector3 153 | */ 154 | int llightsGetLightTarget( lua_State* L ) { 155 | Light* light = uluaGetLight( L, 1 ); 156 | 157 | uluaPushVector3( L, light->target ); 158 | 159 | return 1; 160 | } 161 | 162 | /* 163 | > color = RL.GetLightColor( Light light ) 164 | 165 | Get light color 166 | 167 | - Success return Color 168 | */ 169 | int llightsGetLightColor( lua_State* L ) { 170 | Light* light = uluaGetLight( L, 1 ); 171 | 172 | uluaPushColor( L, light->color ); 173 | 174 | return 1; 175 | } 176 | 177 | /* 178 | > enabled = RL.IsLightEnabled( Light light ) 179 | 180 | Get light enabled 181 | 182 | - Success return bool 183 | */ 184 | int llightsIsLightEnabled( lua_State* L ) { 185 | Light* light = uluaGetLight( L, 1 ); 186 | 187 | lua_pushboolean( L, light->enabled ); 188 | 189 | return 1; 190 | } 191 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "state.h" 3 | #include "lua_core.h" 4 | 5 | static inline void printVersion() { 6 | if ( VERSION_DEV ) { 7 | TraceLog( LOG_INFO, "ReiLua %d.%d.%d-Dev", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH ); 8 | } 9 | else { 10 | TraceLog( LOG_INFO, "ReiLua %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH ); 11 | } 12 | 13 | #ifdef LUA_VERSION 14 | TraceLog( LOG_INFO, "%s", LUA_VERSION ); 15 | #endif 16 | 17 | #ifdef LUAJIT_VERSION 18 | TraceLog( LOG_INFO, "%s", LUAJIT_VERSION ); 19 | #endif 20 | } 21 | 22 | int main( int argn, const char** argc ) { 23 | char basePath[ STRING_LEN ] = { '\0' }; 24 | bool interpret_mode = false; 25 | 26 | if ( 1 < argn ) { 27 | if ( strcmp( argc[1], "--version" ) == 0 || strcmp( argc[1], "-v" ) == 0 ) { 28 | printVersion(); 29 | return 1; 30 | } 31 | else if ( strcmp( argc[1], "--help" ) == 0 || strcmp( argc[1], "-h" ) == 0 ) { 32 | printf( "Usage: ReiLua [Options] [Directory to main.lua or main]\nOptions:\n-h --help\tThis help\n-v --version\tShow ReiLua version\n-i --interpret\tInterpret mode [File name]\n" ); 33 | return 1; 34 | } 35 | else if ( strcmp( argc[1], "--interpret" ) == 0 || strcmp( argc[1], "-i" ) == 0 ) { 36 | interpret_mode = true; 37 | 38 | if ( 2 < argn ) { 39 | sprintf( basePath, "%s/%s", GetWorkingDirectory(), argc[2] ); 40 | } 41 | } 42 | else{ 43 | sprintf( basePath, "%s/%s", GetWorkingDirectory(), argc[1] ); 44 | } 45 | } 46 | /* If no argument given, assume main.lua is in exe directory. */ 47 | else { 48 | sprintf( basePath, "%s", GetApplicationDirectory() ); 49 | } 50 | 51 | if ( interpret_mode ) { 52 | stateInitInterpret( argn, argc ); 53 | 54 | lua_State* L = state->luaState; 55 | lua_pushcfunction( L, luaTraceback ); 56 | int tracebackidx = lua_gettop( L ); 57 | 58 | luaL_loadfile( L, basePath ); 59 | 60 | if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { 61 | TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); 62 | return false; 63 | } 64 | } 65 | else { 66 | printVersion(); 67 | stateInit( argn, argc, basePath ); 68 | luaCallMain(); 69 | luaCallInit(); 70 | 71 | while ( state->run ) { 72 | luaCallUpdate(); 73 | luaCallDraw(); 74 | if ( WindowShouldClose() ) { 75 | state->run = false; 76 | } 77 | } 78 | luaCallExit(); 79 | } 80 | stateFree(); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /src/platforms/core_web.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "lua_core.h" 3 | #include "core.h" 4 | 5 | void platformDefineGlobals() { 6 | lua_State* L = state->luaState; 7 | 8 | lua_getglobal( L, "RL" ); 9 | /*DOC_DEFINES_START*/ 10 | /*DOC_DEFINES_END*/ 11 | lua_pop( L, -1 ); 12 | } 13 | 14 | /* Functions. */ 15 | 16 | /* Events. */ 17 | 18 | void luaPlatformRegister() { 19 | } 20 | -------------------------------------------------------------------------------- /src/state.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "state.h" 3 | #include "lua_core.h" 4 | #include "textures.h" 5 | #include "models.h" 6 | 7 | State* state; 8 | 9 | bool stateInit( int argn, const char** argc, const char* basePath ) { 10 | state = malloc( sizeof( State ) ); 11 | state->basePath = malloc( STRING_LEN * sizeof( char ) ); 12 | strncpy( state->basePath, basePath, STRING_LEN - 1 ); 13 | state->luaState = NULL; 14 | state->run = luaInit( argn, argc );; 15 | state->logLevelInvalid = LOG_ERROR; 16 | state->gcUnload = true; 17 | state->lineSpacing = 15; 18 | state->mouseOffset = (Vector2){ 0, 0 }; 19 | state->mouseScale = (Vector2){ 1, 1 }; 20 | 21 | #if defined PLATFORM_DESKTOP_SDL2 || defined PLATFORM_DESKTOP_SDL3 22 | state->SDL_eventQueue = malloc( PLATFORM_SDL_EVENT_QUEUE_LEN * sizeof( SDL_Event ) ); 23 | state->SDL_eventQueueLen = 0; 24 | #endif 25 | 26 | return state->run; 27 | } 28 | 29 | /* Init after InitWindow. (When there is OpenGL context.) */ 30 | void stateContextInit() { 31 | state->defaultFont = GetFontDefault(); 32 | state->guiFont = GuiGetFont(); 33 | state->defaultMaterial = LoadMaterialDefault(); 34 | state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 }; 35 | state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 }; 36 | state->RLGLcurrentShaderLocs = malloc( RL_MAX_SHADER_LOCATIONS * sizeof( int ) ); 37 | int* defaultShaderLocs = rlGetShaderLocsDefault(); 38 | 39 | for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) { 40 | state->RLGLcurrentShaderLocs[i] = defaultShaderLocs[i]; 41 | } 42 | } 43 | 44 | void stateInitInterpret( int argn, const char** argc ) { 45 | state = malloc( sizeof( State ) ); 46 | luaInit( argn, argc ); 47 | } 48 | 49 | void stateFree() { 50 | if ( IsAudioDeviceReady() ) { 51 | CloseAudioDevice(); 52 | } 53 | if ( state->luaState != NULL ) { 54 | lua_close( state->luaState ); 55 | state->luaState = NULL; 56 | } 57 | if ( IsWindowReady() ) { 58 | CloseWindow(); 59 | } 60 | #ifdef PLATFORM_DESKTOP_SDL 61 | free( state->SDL_eventQueue ); 62 | #endif 63 | free( state->basePath ); 64 | free( state->RLGLcurrentShaderLocs ); 65 | free( state ); 66 | } 67 | --------------------------------------------------------------------------------