├── .editorconfig ├── .github └── workflows │ └── Tests.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── bin ├── CMakeLists.txt └── raylib-lua-sol.cpp ├── cmake └── CTestCustom.cmake ├── examples ├── CMakeLists.txt ├── audio │ ├── audio_module_playing.lua │ ├── audio_music_stream.lua │ ├── audio_raw_stream.lua │ ├── audio_sound_loading.lua │ └── resources │ │ ├── chiptun1.mod │ │ ├── coin.wav │ │ ├── guitar_noodling.ogg │ │ ├── mini1111.xm │ │ ├── sound.wav │ │ ├── spring.wav │ │ ├── tanatana.flac │ │ ├── tanatana.ogg │ │ └── weird.wav ├── core │ ├── core_2d_camera.lua │ ├── core_3d_camera_first_person.lua │ ├── core_3d_camera_free.lua │ ├── core_3d_mode.lua │ ├── core_3d_picking.lua │ ├── core_basic_window.lua │ ├── core_color_select.lua │ ├── core_drop_files.lua │ ├── core_gestures_detection.lua │ ├── core_input_gamepad.lua │ ├── core_input_keys.lua │ ├── core_input_mouse.lua │ ├── core_mouse_wheel.lua │ ├── core_random_values.lua │ ├── core_storage_values.lua │ ├── core_vr_simulator.lua │ ├── core_world_screen.lua │ └── resources │ │ ├── ps3.png │ │ └── xbox.png ├── models │ ├── models_billboard.lua │ ├── models_box_collisions.lua │ ├── models_cubicmap.lua │ ├── models_geometric_shapes.lua │ ├── models_heightmap.lua │ ├── models_mesh_picking.lua │ ├── models_obj_loading.lua │ └── resources │ │ ├── billboard.png │ │ ├── cubicmap.png │ │ ├── cubicmap_atlas.png │ │ ├── heightmap.png │ │ ├── model │ │ ├── dwarf.obj │ │ ├── dwarf_diffuse.png │ │ ├── dwarf_normal.png │ │ └── dwarf_specular.png │ │ ├── tower.obj │ │ └── tower.png ├── shaders │ ├── resources │ │ ├── fudesumi.png │ │ ├── model │ │ │ ├── dwarf.obj │ │ │ ├── dwarf_diffuse.png │ │ │ ├── dwarf_normal.png │ │ │ └── dwarf_specular.png │ │ └── shaders │ │ │ ├── glsl100 │ │ │ ├── base.fs │ │ │ ├── base.vs │ │ │ ├── bloom.fs │ │ │ ├── blur.fs │ │ │ ├── cross_hatching.fs │ │ │ ├── cross_stitching.fs │ │ │ ├── distortion.fs │ │ │ ├── dream_vision.fs │ │ │ ├── fisheye.fs │ │ │ ├── grayscale.fs │ │ │ ├── pixelizer.fs │ │ │ ├── posterization.fs │ │ │ ├── predator.fs │ │ │ ├── scanlines.fs │ │ │ ├── sobel.fs │ │ │ └── swirl.fs │ │ │ └── glsl330 │ │ │ ├── base.fs │ │ │ ├── base.vs │ │ │ ├── bloom.fs │ │ │ ├── blur.fs │ │ │ ├── cross_hatching.fs │ │ │ ├── cross_stitching.fs │ │ │ ├── depth.fs │ │ │ ├── distortion.fs │ │ │ ├── dream_vision.fs │ │ │ ├── fisheye.fs │ │ │ ├── grayscale.fs │ │ │ ├── overdraw.fs │ │ │ ├── pixelizer.fs │ │ │ ├── posterization.fs │ │ │ ├── predator.fs │ │ │ ├── scanlines.fs │ │ │ ├── sobel.fs │ │ │ └── swirl.fs │ ├── shaders_custom_uniform.lua │ ├── shaders_model_shader.lua │ ├── shaders_postprocessing.lua │ └── shaders_shapes_textures.lua ├── shapes │ ├── shapes_basic_shapes.lua │ ├── shapes_colors_palette.lua │ ├── shapes_lines_bezier.lua │ ├── shapes_logo_raylib.lua │ └── shapes_logo_raylib_anim.lua ├── text │ ├── resources │ │ ├── KAISG.ttf │ │ ├── bmfont.fnt │ │ ├── bmfont.png │ │ ├── custom_alagard.png │ │ ├── custom_jupiter_crash.png │ │ ├── custom_mecha.png │ │ ├── fonts │ │ │ ├── alagard.png │ │ │ ├── alpha_beta.png │ │ │ ├── jupiter_crash.png │ │ │ ├── mecha.png │ │ │ ├── pixantiqua.png │ │ │ ├── pixelplay.png │ │ │ ├── romulus.png │ │ │ └── setback.png │ │ ├── pixantiqua.fnt │ │ ├── pixantiqua.ttf │ │ └── pixantiqua_0.png │ ├── text_bmfont_ttf.lua │ ├── text_bmfont_unordered.lua │ ├── text_format_text.lua │ ├── text_input_box.lua │ ├── text_raylib_fonts.lua │ ├── text_sprite_fonts.lua │ ├── text_ttf_loading.lua │ └── text_writing_anim.lua └── textures │ ├── resources │ ├── cat.png │ ├── parrots.png │ ├── raylib_logo.png │ ├── scarfy.png │ ├── smoke.png │ └── wabbit_alpha.png │ ├── textures_bunnymark.lua │ ├── textures_image_drawing.lua │ ├── textures_image_loading.lua │ ├── textures_image_processing.lua │ ├── textures_logo_raylib.lua │ ├── textures_particles_blending.lua │ ├── textures_raw_data.lua │ ├── textures_rectangle.lua │ ├── textures_srcrec_dstrec.lua │ └── textures_to_image.lua ├── include ├── CMakeLists.txt ├── raylib-lua-sol-raymath.hpp ├── raylib-lua-sol-rlgl.hpp └── raylib-lua-sol.hpp ├── logo └── raylib-lua-sol_256x256.png └── tests ├── CMakeLists.txt └── raylib-lua-sol-tests.lua /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /.github/workflows/Tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-ubuntu: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | with: 11 | submodules: recursive 12 | - name: Install Dependencies 13 | run: sudo apt-get install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev 14 | - name: Configure 15 | run: cmake -B build . 16 | - name: Build 17 | run: cmake --build build --config Release 18 | - name: Test 19 | working-directory: build 20 | run: ctest --output-on-failure 21 | 22 | build-windows: 23 | runs-on: windows-latest 24 | strategy: 25 | fail-fast: false 26 | max-parallel: 1 27 | matrix: 28 | compiler: [mingw-w64,msvc16] 29 | include: 30 | - compiler: mingw-w64 31 | PLATFORM_NAME: "MinGW Makefiles" 32 | - compiler: msvc16 33 | PLATFORM_NAME: "Visual Studio 16 2019" 34 | steps: 35 | - uses: actions/checkout@v2 36 | with: 37 | submodules: recursive 38 | 39 | # Setup Visual Studio 40 | - name: Setup MSBuild 41 | uses: microsoft/setup-msbuild@v1.0.2 42 | if: matrix.compiler == 'msvc16' 43 | 44 | - name: Configure 45 | run: cmake -G "${{ matrix.platform_name }}" -B build_${{ matrix.compiler }} . 46 | 47 | - name: Build 48 | run: cmake --build build_${{ matrix.compiler }} --config Release 49 | 50 | - name: Test (mingw-w64) 51 | run: build_${{ matrix.compiler }}\bin\raylib-lua-sol.exe tests/raylib-lua-sol-tests.lua 52 | if: matrix.compiler == 'mingw-w64' 53 | 54 | - name: Test (msvc16) 55 | run: build_${{ matrix.compiler }}\bin\Release\raylib-lua-sol.exe tests/raylib-lua-sol-tests.lua 56 | if: matrix.compiler == 'msvc16' 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/sol2"] 2 | path = vendor/sol2 3 | url = https://github.com/ThePhD/sol2.git 4 | [submodule "vendor/raylib"] 5 | path = vendor/raylib 6 | url = https://github.com/raysan5/raylib.git 7 | [submodule "vendor/lua-5.3.5"] 8 | path = vendor/lua 9 | url = https://github.com/lua/lua.git 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.11) 2 | project (raylib-lua-sol 3 | VERSION 0.2.2 4 | DESCRIPTION "Lua bindings for raylib" 5 | HOMEPAGE_URL "https://github.com/RobLoach/raylib-lua-sol" 6 | LANGUAGES C CXX) 7 | 8 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 9 | configure_file(${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake ${CMAKE_BINARY_DIR}) 10 | 11 | if (MSVC) 12 | #add_compile_options("/SUBSYSTEM:WINDOWS") 13 | #add_compile_options("/ENTRY:mainCRTStartup") 14 | #ADD_DEFINITIONS(/bigobj) 15 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") 16 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") 17 | SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /bigobj") 18 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj") 19 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj") 20 | elseif(MINGW OR CYGWIN) 21 | add_definitions(-O3) 22 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj") 23 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj") 24 | SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Wa,-mbig-obj") 25 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wa,-mbig-obj") 26 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Os -Wa,-mbig-obj") 27 | endif() 28 | 29 | # Options 30 | option(BUILD_BIN "Binary" ON) 31 | option(BUILD_EXAMPLES "Examples" ON) 32 | 33 | add_subdirectory(include) 34 | 35 | if (BUILD_BIN) 36 | # raylib 37 | find_package(raylib 3.0.0) 38 | if (NOT raylib_FOUND) 39 | set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples 40 | set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games 41 | add_subdirectory(vendor/raylib) 42 | endif() 43 | 44 | # Lua 45 | set(LUA_DIR vendor/lua) 46 | set(LUA_SRC 47 | ${LUA_DIR}/lapi.c 48 | ${LUA_DIR}/lcode.c 49 | ${LUA_DIR}/lctype.c 50 | ${LUA_DIR}/ldebug.c 51 | ${LUA_DIR}/ldo.c 52 | ${LUA_DIR}/ldump.c 53 | ${LUA_DIR}/lfunc.c 54 | ${LUA_DIR}/lgc.c 55 | ${LUA_DIR}/llex.c 56 | ${LUA_DIR}/lmem.c 57 | ${LUA_DIR}/lobject.c 58 | ${LUA_DIR}/lopcodes.c 59 | ${LUA_DIR}/lparser.c 60 | ${LUA_DIR}/lstate.c 61 | ${LUA_DIR}/lstring.c 62 | ${LUA_DIR}/ltable.c 63 | ${LUA_DIR}/ltm.c 64 | ${LUA_DIR}/lundump.c 65 | ${LUA_DIR}/lvm.c 66 | ${LUA_DIR}/lzio.c 67 | ${LUA_DIR}/lauxlib.c 68 | ${LUA_DIR}/lbaselib.c 69 | ${LUA_DIR}/lcorolib.c 70 | ${LUA_DIR}/ldblib.c 71 | ${LUA_DIR}/liolib.c 72 | ${LUA_DIR}/lmathlib.c 73 | ${LUA_DIR}/loslib.c 74 | ${LUA_DIR}/lstrlib.c 75 | ${LUA_DIR}/ltablib.c 76 | ${LUA_DIR}/lutf8lib.c 77 | ${LUA_DIR}/loadlib.c 78 | ${LUA_DIR}/linit.c 79 | ) 80 | add_library(lua STATIC ${LUA_SRC}) 81 | target_compile_definitions(lua PRIVATE LUA_COMPAT_5_2) 82 | target_include_directories(lua INTERFACE ${LUA_DIR}) 83 | 84 | # Sol2 85 | set(SOL2_DIR vendor/sol2) 86 | add_library(sol2 INTERFACE) 87 | target_include_directories(sol2 INTERFACE ${SOL2_DIR}/include/) 88 | 89 | # Add the binary. 90 | add_subdirectory(bin) 91 | endif() 92 | 93 | if (BUILD_EXAMPLES) 94 | add_subdirectory(examples) 95 | endif() 96 | 97 | include(CTest) 98 | enable_testing() 99 | if(BUILD_TESTING) 100 | add_subdirectory(tests) 101 | endif() 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | raylib-lua-sol is licensed under an unmodified zlib/libpng license, which is an OSI-certified, 2 | BSD-like license that allows static linking with closed source software: 3 | 4 | Copyright (c) 2019 Rob Loach (@RobLoach) 5 | 6 | This software is provided "as-is", without any express or implied warranty. In no event 7 | will the authors be held liable for any damages arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, including commercial 10 | applications, and to alter it and redistribute it freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not claim that you 13 | wrote the original software. If you use this software in a product, an acknowledgment 14 | in the product documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented 17 | as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source distribution. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![raylib-lua-sol Logo](logo/raylib-lua-sol_256x256.png) 2 | 3 | # raylib-lua-sol 4 | 5 | [Lua](http://www.lua.org/) bindings for [raylib](https://www.raylib.com/), a simple and easy-to-use library to enjoy videogames programming, with [sol](https://github.com/ThePhD/sol2) (www.raylib.com) 6 | 7 | *raylib-lua-sol* bindings are self-contained in a header-only file: [raylib-lua-sol.hpp](include/raylib-lua-sol.hpp). Just include that file 8 | in your project to allow loading and execution of raylib code written in Lua and Sol. 9 | 10 | *raylib-lua-sol* could be useful for prototyping, tools development, graphic applications, embedded systems and education. 11 | 12 | Ready to learn? Check out the [code examples](examples)! 13 | 14 | ## Example 15 | 16 | ``` lua 17 | local screenWidth = 800 18 | local screenHeight = 450 19 | 20 | InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window") 21 | 22 | SetTargetFPS(60) 23 | 24 | while not WindowShouldClose() do 25 | BeginDrawing() 26 | ClearBackground(RAYWHITE) 27 | DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY) 28 | EndDrawing() 29 | end 30 | CloseWindow() 31 | ``` 32 | 33 | ## CLI 34 | 35 | A [`raylib-lua-sol`](bin/raylib-lua-sol.cpp) CLI launcher is provided. This launcher allows you to run raylib lua programs from command line, or just with *drag & drop* of .lua files into *raylib-lua-sol.exe*. 36 | 37 | Note that launcher can also be compiled for other platforms, just need to link with Lua, raylib and sol libraries. For more details, just check comments on sources. 38 | 39 | ``` bash 40 | bin/raylib-lua-sol examples/core_basic_window.lua 41 | ``` 42 | 43 | ## Prebuild On Windows 44 | 45 | Require: 46 | 47 | - C Compiler: MinGW([Cygwin](https://cygwin.com/install.html),...) or [Visual Studio](https://visualstudio.microsoft.com/downloads/). 48 | - [CMake](https://cmake.org/download/). 49 | 50 | ## Prebuild On GNU Linux 51 | 52 | ```bash 53 | sudo apt install build-essential git cmake 54 | ``` 55 | 56 | ### Unbuntu 57 | 58 | ```bash 59 | sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev 60 | ``` 61 | 62 | ### Fedora 63 | 64 | ```bash 65 | sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel 66 | ``` 67 | 68 | ## Build 69 | 70 | *raylib-lua-sol* uses cmake as a primary development target. Would appreciate adding more project templates, however. 71 | 72 | ``` bash 73 | git clone https://github.com/RobLoach/raylib-lua-sol.git 74 | cd raylib-lua-sol 75 | git submodule update --init 76 | cmake -B build . 77 | cmake --build build --config Release 78 | ``` 79 | 80 | ## Development 81 | 82 | To run tests, use `make test`... 83 | 84 | ``` bash 85 | cd build 86 | make test 87 | ``` 88 | 89 | # License 90 | 91 | raylib-lua-sol is licensed under an unmodified zlib/libpng license, which is an OSI-certified, 92 | BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details. 93 | 94 | *Copyright (c) 2019 Rob Loach ([@RobLoach](https://twitter.com/RobLoach))* 95 | -------------------------------------------------------------------------------- /bin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(raylib-lua-sol raylib-lua-sol.cpp) 2 | 3 | target_compile_definitions(raylib-lua-sol PUBLIC -DLUA -DPHYSAC_NO_THREADS) 4 | 5 | set_target_properties(raylib-lua-sol PROPERTIES 6 | CXX_STANDARD 17 7 | CXX_EXTENSIONS OFF 8 | ) 9 | 10 | target_link_libraries(raylib-lua-sol 11 | raylib-lua-sol-hpp 12 | raylib 13 | lua 14 | sol2 15 | ) 16 | 17 | target_include_directories(raylib-lua-sol PUBLIC 18 | ${CMAKE_CURRENT_SOURCE_DIR}/../include 19 | ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/lua 20 | ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib/src 21 | ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/sol2/include 22 | ) 23 | -------------------------------------------------------------------------------- /bin/raylib-lua-sol.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * raylib-lua-sol v0.0.1 - Launcher for raylib Lua applications. 4 | * 5 | * DEPENDENCIES: 6 | * 7 | * raylib - http://www.raylib.com 8 | * sol - https://github.com/ThePhD/sol2/ 9 | * Lua - http://www.lua.org 10 | * 11 | * COMPILATION (GCC): 12 | * 13 | * mkdir build 14 | * cd build 15 | * cmake .. 16 | * make 17 | * 18 | * USAGE: 19 | * 20 | * Just launch your raylib .lua file from command line: 21 | * ./raylib-lua-sol core_basic_window.lua 22 | * 23 | * or drag & drop your .lua file over raylib-lua-sol.exe 24 | * 25 | * 26 | * LICENSE: zlib/libpng 27 | * 28 | * Copyright (c) 2018 Rob Loach (@RobLoach) 29 | * 30 | * This software is provided "as-is", without any express or implied warranty. In no event 31 | * will the authors be held liable for any damages arising from the use of this software. 32 | * 33 | * Permission is granted to anyone to use this software for any purpose, including commercial 34 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 35 | * 36 | * 1. The origin of this software must not be misrepresented; you must not claim that you 37 | * wrote the original software. If you use this software in a product, an acknowledgment 38 | * in the product documentation would be appreciated but is not required. 39 | * 40 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented 41 | * as being the original software. 42 | * 43 | * 3. This notice may not be removed or altered from any source distribution. 44 | * 45 | ********************************************************************************************/ 46 | 47 | #include 48 | #include 49 | 50 | #include "raylib.h" 51 | 52 | #define SOL_PRINT_ERRORS 1 53 | #define SOL_ALL_SAFETIES_ON 1 54 | #include 55 | 56 | #include "raylib-lua-sol.hpp" 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | std::string executableName; 61 | std::string fileToLoad; 62 | 63 | switch (argc) { 64 | case 0: 65 | executableName = "raylib-lua-sol"; 66 | fileToLoad = "main.lua"; 67 | break; 68 | case 1: 69 | executableName = argv[0]; 70 | fileToLoad = "main.lua"; 71 | break; 72 | default: 73 | executableName = argv[0]; 74 | fileToLoad = argv[1]; 75 | break; 76 | } 77 | 78 | if (!FileExists(fileToLoad.c_str())) { 79 | std::cout << "Usage:" << std::endl << " " << GetFileName(executableName.c_str()) << " myfile.lua" << std::endl << std::endl; 80 | std::cout << "Attempted file " << fileToLoad << " was not found." << std::endl; 81 | return 1; 82 | } 83 | 84 | if (!IsFileExtension(fileToLoad.c_str(), ".lua")) { 85 | std::cout << "Expected file to be a .lua file." << std::endl; 86 | return 1; 87 | } 88 | 89 | // Build the Lua environment. 90 | sol::state lua; 91 | 92 | // Load some of the Lua base libraries. 93 | // TODO: Use JIT compiler 94 | lua.open_libraries( 95 | sol::lib::base, 96 | sol::lib::package, 97 | sol::lib::string, 98 | sol::lib::math, 99 | sol::lib::table); 100 | 101 | // Bootstrap Raylib. 102 | raylib_lua_sol(lua); 103 | 104 | // Execute the script. 105 | auto result = lua.safe_script_file(fileToLoad, sol::script_pass_on_error); 106 | if (!result.valid()) { 107 | sol::error err = result; 108 | std::cerr << "The code was unable to run." << std::endl << err.what() << std::endl; 109 | return 1; 110 | } 111 | 112 | return 0; 113 | } 114 | -------------------------------------------------------------------------------- /cmake/CTestCustom.cmake: -------------------------------------------------------------------------------- 1 | set(CTEST_CUSTOM_TESTS_IGNORE 2 | pkg-config--static 3 | ) 4 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Get the sources together 2 | set(example_dirs audio core models shaders text textures) 3 | set(example_sources) 4 | set(example_resources) 5 | 6 | # Examples directories 7 | foreach(example_dir ${example_dirs}) 8 | file(GLOB sources ${example_dir}/*.lua) 9 | list(APPEND example_sources ${sources}) 10 | 11 | # Any all resources. 12 | file(GLOB resources ${example_dir}/resources/*) 13 | list(APPEND example_resources ${resources}) 14 | endforeach() 15 | 16 | # Add all examples. 17 | foreach(example_source ${example_sources}) 18 | # Create the basename for the example 19 | get_filename_component(example_name ${example_source} NAME) 20 | 21 | configure_file(${example_source} ${example_name} COPYONLY) 22 | 23 | string(REGEX MATCH ".*/.*/" resources_dir ${example_source}) 24 | string(APPEND resources_dir "resources") 25 | endforeach() 26 | 27 | # Resources 28 | file(COPY ${example_resources} DESTINATION "resources/") 29 | -------------------------------------------------------------------------------- /examples/audio/audio_module_playing.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [audio] example - Module playing (streaming) 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | MAX_CIRCLES = 64 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)") 20 | 21 | InitAudioDevice() -- Initialize audio device 22 | 23 | local colors = { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, 24 | YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE } 25 | 26 | -- Creates ome circles for visual effect 27 | local circles = {} 28 | 29 | for i = MAX_CIRCLES, 1, -1 do 30 | circles[i] = {} 31 | circles[i].alpha = 0.0 32 | circles[i].radius = GetRandomValue(10, 40) 33 | circles[i].position = Vector2(0, 0) 34 | circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius) 35 | circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius) 36 | circles[i].speed = GetRandomValue(1, 100)/20000.0 37 | circles[i].color = colors[GetRandomValue(1, 14)] 38 | end 39 | 40 | local xm = LoadMusicStream("resources/mini1111.xm") 41 | 42 | PlayMusicStream(xm) 43 | 44 | local timePlayed = 0.0 45 | 46 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 47 | ------------------------------------------------------------------------------------------- 48 | 49 | -- Main game loop 50 | while not WindowShouldClose() do -- Detect window close button or ESC key 51 | -- Update 52 | --------------------------------------------------------------------------------------- 53 | for i = MAX_CIRCLES, 1, -1 do 54 | circles[i].alpha = circles[i].alpha + circles[i].speed 55 | circles[i].radius = circles[i].radius + circles[i].speed*10.0 56 | 57 | if (circles[i].alpha > 1.0) then circles[i].speed = circles[i].speed*-1 end 58 | 59 | if (circles[i].alpha <= 0.0) then 60 | circles[i].alpha = 0.0 61 | circles[i].radius = GetRandomValue(10, 40) 62 | circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius) 63 | circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius) 64 | circles[i].color = colors[GetRandomValue(1, 14)] 65 | circles[i].speed = GetRandomValue(1, 100)/20000.0 66 | end 67 | end 68 | 69 | -- Get timePlayed scaled to bar dimensions 70 | timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2 71 | 72 | UpdateMusicStream(xm) -- Update music buffer with new stream data 73 | --------------------------------------------------------------------------------------- 74 | 75 | -- Draw 76 | --------------------------------------------------------------------------------------- 77 | BeginDrawing() 78 | 79 | ClearBackground(RAYWHITE) 80 | 81 | for i = MAX_CIRCLES, 1, -1 do 82 | DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)) 83 | end 84 | 85 | -- Draw time bar 86 | DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY) 87 | DrawRectangle(20, screenHeight - 20 - 12, timePlayed//1, 12, MAROON) 88 | DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE) 89 | 90 | EndDrawing() 91 | --------------------------------------------------------------------------------------- 92 | end 93 | 94 | -- De-Initialization 95 | ------------------------------------------------------------------------------------------- 96 | UnloadMusicStream(xm) -- Unload music stream buffers from RAM 97 | 98 | CloseAudioDevice() -- Close audio device (music streaming is automatically stopped) 99 | 100 | CloseWindow() -- Close window and OpenGL context 101 | ------------------------------------------------------------------------------------------- 102 | -------------------------------------------------------------------------------- /examples/audio/audio_music_stream.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [audio] example - Music playing (streaming) 4 | -- 5 | -- NOTE: This example requires OpenAL Soft library installed 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)") 20 | 21 | InitAudioDevice() -- Initialize audio device 22 | 23 | local music = LoadMusicStream("resources/guitar_noodling.ogg") 24 | 25 | PlayMusicStream(music) 26 | 27 | local framesCounter = 0 28 | local timePlayed = 0.0 29 | 30 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 31 | ------------------------------------------------------------------------------------------- 32 | 33 | -- Main game loop 34 | while not WindowShouldClose() do -- Detect window close button or ESC key 35 | -- Update 36 | --------------------------------------------------------------------------------------- 37 | framesCounter = framesCounter + 1 38 | 39 | timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4 -- We scale by 4 to fit 400 pixels 40 | 41 | UpdateMusicStream(music) -- Update music buffer with new stream data 42 | --------------------------------------------------------------------------------------- 43 | 44 | -- Draw 45 | --------------------------------------------------------------------------------------- 46 | BeginDrawing() 47 | 48 | ClearBackground(RAYWHITE) 49 | 50 | DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY) 51 | 52 | DrawRectangle(200, 250, 400, 12, LIGHTGRAY) 53 | DrawRectangle(200, 250, timePlayed//1, 12, MAROON) 54 | 55 | EndDrawing() 56 | --------------------------------------------------------------------------------------- 57 | end 58 | 59 | -- De-Initialization 60 | ------------------------------------------------------------------------------------------- 61 | UnloadMusicStream(music) -- Unload music stream buffers from RAM 62 | 63 | CloseAudioDevice() -- Close audio device (music streaming is automatically stopped) 64 | 65 | CloseWindow() -- Close window and OpenGL context 66 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/audio/audio_raw_stream.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [audio] example - Raw audio streaming 4 | -- 5 | -- NOTE: This example requires OpenAL Soft library installed 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | MAX_SAMPLES = 20000 15 | DEG2RAD = math.pi/180.0 16 | 17 | -- Initialization 18 | ------------------------------------------------------------------------------------------- 19 | local screenWidth = 800 20 | local screenHeight = 450 21 | 22 | InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming") 23 | 24 | InitAudioDevice() -- Initialize audio device 25 | 26 | -- Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono) 27 | local stream = InitAudioStream(22050, 32, 1) 28 | 29 | -- Fill audio stream with some samples (sine wave) 30 | local data = {} 31 | 32 | for i = 1, MAX_SAMPLES do 33 | data[i] = math.sin(((2*math.pi*i)/2)*DEG2RAD) 34 | end 35 | 36 | -- NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop 37 | -- for that reason, there is a clip everytime audio stream is looped 38 | 39 | PlayAudioStream(stream) 40 | 41 | local totalSamples = MAX_SAMPLES 42 | local samplesLeft = totalSamples 43 | 44 | local position = Vector2(0, 0) 45 | 46 | SetTargetFPS(30) -- Set our game to run at 30 frames-per-second 47 | ------------------------------------------------------------------------------------------- 48 | 49 | -- Main game loop 50 | while not WindowShouldClose() do -- Detect window close button or ESC key 51 | -- Update 52 | --------------------------------------------------------------------------------------- 53 | 54 | -- Refill audio stream if required 55 | if (IsAudioBufferProcessed(stream)) then 56 | local numSamples = 0 57 | 58 | if (samplesLeft >= 4096) then numSamples = 4096 59 | else numSamples = samplesLeft end 60 | 61 | UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples) 62 | 63 | samplesLeft = samplesLeft - numSamples 64 | 65 | -- Reset samples feeding (loop audio) 66 | if (samplesLeft <= 0) then samplesLeft = totalSamples end 67 | end 68 | --------------------------------------------------------------------------------------- 69 | 70 | -- Draw 71 | --------------------------------------------------------------------------------------- 72 | BeginDrawing() 73 | 74 | ClearBackground(RAYWHITE) 75 | 76 | DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY) 77 | 78 | -- NOTE: Draw a part of the sine wave (only screen width) 79 | for i = 1, GetScreenWidth() do 80 | position.x = (i - 1) 81 | position.y = 250 + 50*data[i] 82 | 83 | DrawPixelV(position, RED) 84 | end 85 | 86 | EndDrawing() 87 | --------------------------------------------------------------------------------------- 88 | end 89 | 90 | -- De-Initialization 91 | ------------------------------------------------------------------------------------------- 92 | CloseAudioStream(stream) -- Close raw audio stream and delete buffers from RAM 93 | 94 | CloseAudioDevice() -- Close audio device (music streaming is automatically stopped) 95 | 96 | CloseWindow() -- Close window and OpenGL context 97 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/audio/audio_sound_loading.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [audio] example - Sound loading and playing 4 | -- 5 | -- NOTE: This example requires OpenAL Soft library installed 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing") 20 | 21 | InitAudioDevice() -- Initialize audio device 22 | 23 | local fxWav = LoadSound("resources/weird.wav") -- Load WAV audio file 24 | local fxOgg = LoadSound("resources/tanatana.ogg") -- Load OGG audio file 25 | 26 | SetTargetFPS(60) 27 | ------------------------------------------------------------------------------------------- 28 | 29 | -- Main game loop 30 | while not WindowShouldClose() do -- Detect window close button or ESC key 31 | -- Update 32 | --------------------------------------------------------------------------------------- 33 | if (IsKeyPressed(KEY_SPACE)) then PlaySound(fxWav) end -- Play WAV sound 34 | if (IsKeyPressed(KEY_ENTER)) then PlaySound(fxOgg) end -- Play OGG sound 35 | --------------------------------------------------------------------------------------- 36 | 37 | -- Draw 38 | --------------------------------------------------------------------------------------- 39 | BeginDrawing() 40 | 41 | ClearBackground(RAYWHITE) 42 | 43 | DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY) 44 | 45 | DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY) 46 | 47 | EndDrawing() 48 | --------------------------------------------------------------------------------------- 49 | end 50 | 51 | -- De-Initialization 52 | ------------------------------------------------------------------------------------------- 53 | UnloadSound(fxWav) -- Unload sound data 54 | UnloadSound(fxOgg) -- Unload sound data 55 | 56 | CloseAudioDevice() -- Close audio device 57 | 58 | CloseWindow() -- Close window and OpenGL context 59 | ------------------------------------------------------------------------------------------- 60 | -------------------------------------------------------------------------------- /examples/audio/resources/chiptun1.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/chiptun1.mod -------------------------------------------------------------------------------- /examples/audio/resources/coin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/coin.wav -------------------------------------------------------------------------------- /examples/audio/resources/guitar_noodling.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/guitar_noodling.ogg -------------------------------------------------------------------------------- /examples/audio/resources/mini1111.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/mini1111.xm -------------------------------------------------------------------------------- /examples/audio/resources/sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/sound.wav -------------------------------------------------------------------------------- /examples/audio/resources/spring.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/spring.wav -------------------------------------------------------------------------------- /examples/audio/resources/tanatana.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/tanatana.flac -------------------------------------------------------------------------------- /examples/audio/resources/tanatana.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/tanatana.ogg -------------------------------------------------------------------------------- /examples/audio/resources/weird.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/audio/resources/weird.wav -------------------------------------------------------------------------------- /examples/core/core_3d_camera_first_person.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - 3d camera first person 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | -------------------------------------------------------------------------------------------- 11 | 12 | MAX_COLUMNS = 20 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person") 20 | 21 | -- Define the camera to look into our 3d world (position, target, up vector) 22 | local camera = Camera(Vector3(4.0, 2.0, 4.0), Vector3(0.0, 1.8, 0.0), Vector3(0.0, 1.0, 0.0), 60.0) 23 | 24 | -- Generates some random columns 25 | local heights = {} 26 | local positions = {} 27 | local colors = {} 28 | 29 | for i = 1, MAX_COLUMNS do 30 | heights[i] = GetRandomValue(1, 12) 31 | positions[i] = Vector3(GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15)) 32 | colors[i] = Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255) 33 | end 34 | 35 | local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position 36 | 37 | SetCameraMode(camera, CAMERA_FIRST_PERSON) -- Set a first person camera mode 38 | 39 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 40 | ------------------------------------------------------------------------------------------- 41 | 42 | -- Main game loop 43 | while not WindowShouldClose() do -- Detect window close button or ESC key 44 | -- Update 45 | --------------------------------------------------------------------------------------- 46 | UpdateCamera(camera) -- Update camera 47 | --------------------------------------------------------------------------------------- 48 | 49 | -- Draw 50 | --------------------------------------------------------------------------------------- 51 | BeginDrawing() 52 | 53 | ClearBackground(RAYWHITE) 54 | 55 | BeginMode3D(camera) 56 | 57 | DrawPlane(Vector3(0.0, 0.0, 0.0), Vector2(32.0, 32.0), LIGHTGRAY) -- Draw ground 58 | DrawCube(Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, BLUE) -- Draw a blue wall 59 | DrawCube(Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, LIME) -- Draw a green wall 60 | DrawCube(Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, GOLD) -- Draw a yellow wall 61 | 62 | -- Draw some cubes around 63 | for i = 1, MAX_COLUMNS do 64 | DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i]) 65 | DrawCubeWires(positions[i], 2.0, heights[i], 2.0, MAROON) 66 | end 67 | 68 | EndMode3D() 69 | 70 | DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5)) 71 | DrawRectangleLines( 10, 10, 220, 70, BLUE) 72 | 73 | DrawText("First person camera default controls:", 20, 20, 10, BLACK) 74 | DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY) 75 | DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY) 76 | 77 | EndDrawing() 78 | --------------------------------------------------------------------------------------- 79 | end 80 | 81 | -- De-Initialization 82 | ------------------------------------------------------------------------------------------- 83 | CloseWindow() -- Close window and OpenGL context 84 | ------------------------------------------------------------------------------------------- 85 | -------------------------------------------------------------------------------- /examples/core/core_3d_camera_free.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Initialize 3d camera free 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | -------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ---------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera() 21 | camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position 22 | camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point 23 | camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) 24 | camera.fovy = 45.0 -- Camera field-of-view Y 25 | 26 | local cubePosition = Vector3(0.0, 0.0, 0.0) 27 | 28 | SetCameraMode(camera, CAMERA_FREE) -- Set a free camera mode 29 | 30 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 31 | ------------------------------------------------------------------------------------------- 32 | 33 | -- Main game loop 34 | while not WindowShouldClose() do -- Detect window close button or ESC key 35 | -- Update 36 | --------------------------------------------------------------------------------------- 37 | UpdateCamera(camera) -- Update camera 38 | --------------------------------------------------------------------------------------- 39 | 40 | -- Draw 41 | --------------------------------------------------------------------------------------- 42 | BeginDrawing() 43 | 44 | ClearBackground(RAYWHITE) 45 | 46 | BeginMode3D(camera) 47 | 48 | DrawCube(cubePosition, 2.0, 2.0, 2.0, RED) 49 | DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON) 50 | 51 | DrawGrid(10, 1.0) 52 | 53 | EndMode3D() 54 | 55 | DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5)) 56 | DrawRectangleLines( 10, 10, 320, 133, BLUE) 57 | 58 | DrawText("Free camera default controls:", 20, 20, 10, BLACK) 59 | DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY) 60 | DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY) 61 | DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY) 62 | DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY) 63 | DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY) 64 | 65 | EndDrawing() 66 | --------------------------------------------------------------------------------------- 67 | end 68 | 69 | -- De-Initialization 70 | ------------------------------------------------------------------------------------------- 71 | CloseWindow() -- Close window and OpenGL context 72 | ------------------------------------------------------------------------------------------- 73 | -------------------------------------------------------------------------------- /examples/core/core_3d_mode.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Initialize 3d mode 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = {} 21 | camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position 22 | camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point 23 | camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) 24 | camera.fovy = 45.0 -- Camera field-of-view Y 25 | 26 | local cubePosition = Vector3(0.0, 0.0, 0.0) 27 | 28 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 29 | ------------------------------------------------------------------------------------------- 30 | 31 | -- Main game loop 32 | while not WindowShouldClose() do -- Detect window close button or ESC key 33 | -- Update 34 | --------------------------------------------------------------------------------------- 35 | -- TODO: Update your variables here 36 | --------------------------------------------------------------------------------------- 37 | 38 | -- Draw 39 | --------------------------------------------------------------------------------------- 40 | BeginDrawing() 41 | 42 | ClearBackground(RAYWHITE) 43 | 44 | BeginMode3D(camera) -- ERROR: Lua Error: attempt to index a number value (?) 45 | 46 | DrawCube(cubePosition, 2.0, 2.0, 2.0, RED) 47 | DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON) 48 | 49 | DrawGrid(10, 1.0) 50 | 51 | EndMode3D() 52 | 53 | DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY) 54 | 55 | DrawFPS(10, 10) 56 | 57 | EndDrawing() 58 | --------------------------------------------------------------------------------------- 59 | end 60 | 61 | -- De-Initialization 62 | ------------------------------------------------------------------------------------------- 63 | CloseWindow() -- Close window and OpenGL context 64 | ------------------------------------------------------------------------------------------- 65 | -------------------------------------------------------------------------------- /examples/core/core_3d_picking.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Picking in 3d mode 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera() 21 | camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position 22 | camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point 23 | camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) 24 | camera.fovy = 45.0 -- Camera field-of-view Y 25 | 26 | local cubePosition = Vector3(0.0, 1.0, 0.0) 27 | local cubeSize = Vector3(2.0, 2.0, 2.0) 28 | 29 | local ray = Ray() -- Picking line ray 30 | 31 | local collision = false 32 | 33 | SetCameraMode(camera, CAMERA_FREE) -- Set a free camera mode 34 | 35 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 36 | ------------------------------------------------------------------------------------------- 37 | 38 | -- Main game loop 39 | while not WindowShouldClose() do -- Detect window close button or ESC key 40 | -- Update 41 | --------------------------------------------------------------------------------------- 42 | UpdateCamera(camera) -- Update camera 43 | 44 | if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) then 45 | -- NOTE: This function is NOT WORKING properly! 46 | ray = GetMouseRay(GetMousePosition(), camera) 47 | 48 | -- Check collision between ray and box 49 | collision = CheckCollisionRayBox(ray, 50 | BoundingBox(Vector3(cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2), 51 | Vector3(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2))) 52 | 53 | --print("collision check:", collision) 54 | end 55 | --------------------------------------------------------------------------------------- 56 | 57 | -- Draw 58 | --------------------------------------------------------------------------------------- 59 | BeginDrawing() 60 | 61 | ClearBackground(RAYWHITE) 62 | 63 | BeginMode3D(camera) 64 | 65 | if (collision) then 66 | DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED) 67 | DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON) 68 | 69 | DrawCubeWires(cubePosition, cubeSize.x + 0.2, cubeSize.y + 0.2, cubeSize.z + 0.2, GREEN) 70 | else 71 | DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY) 72 | DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY) 73 | end 74 | 75 | DrawRay(ray, MAROON) 76 | 77 | DrawGrid(10, 1.0) 78 | 79 | EndMode3D() 80 | 81 | DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY) 82 | 83 | if (collision) then 84 | DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30))/2, screenHeight*0.1, 30, GREEN) 85 | end 86 | 87 | DrawFPS(10, 10) 88 | 89 | EndDrawing() 90 | --------------------------------------------------------------------------------------- 91 | end 92 | 93 | -- De-Initialization 94 | ------------------------------------------------------------------------------------------- 95 | CloseWindow() -- Close window and OpenGL context 96 | ------------------------------------------------------------------------------------------- 97 | -------------------------------------------------------------------------------- /examples/core/core_basic_window.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Basic window 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window") 18 | 19 | SetTargetFPS(60) -- Set target frames-per-second 20 | ------------------------------------------------------------------------------------------- 21 | 22 | -- Main game loop 23 | while not WindowShouldClose() do -- Detect window close button or ESC key 24 | -- Update 25 | --------------------------------------------------------------------------------------- 26 | -- TODO: Update your variables here 27 | --------------------------------------------------------------------------------------- 28 | 29 | -- Draw 30 | --------------------------------------------------------------------------------------- 31 | BeginDrawing() 32 | 33 | ClearBackground(RAYWHITE) 34 | 35 | DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY) 36 | 37 | EndDrawing() 38 | --------------------------------------------------------------------------------------- 39 | end 40 | 41 | -- De-Initialization 42 | ------------------------------------------------------------------------------------------- 43 | CloseWindow() -- Close window and OpenGL context 44 | ------------------------------------------------------------------------------------------- 45 | -------------------------------------------------------------------------------- /examples/core/core_color_select.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Color selection by mouse (collision detection) 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | NUM_RECTANGLES = 21 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)") 20 | 21 | local colors = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, 22 | GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, 23 | GREEN, SKYBLUE, PURPLE, BEIGE } 24 | 25 | local colorsRecs = {} -- Rectangles array 26 | local selected = {} 27 | 28 | -- Fills colorsRecs data (for every rectangle) 29 | for i = 1, NUM_RECTANGLES do 30 | colorsRecs[i] = Rectangle() 31 | colorsRecs[i].x = 20 + 100*((i-1)%7) + 10*((i-1)%7) 32 | colorsRecs[i].y = 60 + 100*((i-1)//7) + 10*((i-1)//7) -- Using floor division: // 33 | colorsRecs[i].width = 100 34 | colorsRecs[i].height = 100 35 | selected[i] = false 36 | end 37 | 38 | local mousePoint = Vector2() 39 | 40 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 41 | ------------------------------------------------------------------------------------------- 42 | 43 | -- Main game loop 44 | while not WindowShouldClose() do -- Detect window close button or ESC key 45 | -- Update 46 | --------------------------------------------------------------------------------------- 47 | mousePoint = GetMousePosition() 48 | 49 | for i = 1, NUM_RECTANGLES do -- Iterate along all the rectangles 50 | if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) then 51 | colors[i].a = 120 52 | if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) then selected[i] = not selected[i] end 53 | else colors[i].a = 255 end 54 | end 55 | --------------------------------------------------------------------------------------- 56 | 57 | -- Draw 58 | --------------------------------------------------------------------------------------- 59 | BeginDrawing() 60 | 61 | ClearBackground(RAYWHITE) 62 | 63 | for i = 1, NUM_RECTANGLES do -- Draw all rectangles 64 | DrawRectangleRec(colorsRecs[i], colors[i]) 65 | 66 | -- Draw four rectangles around selected rectangle 67 | if (selected[i]) then 68 | DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE) -- Square top rectangle 69 | DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE) -- Square left rectangle 70 | DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE) -- Square right rectangle 71 | DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE) -- Square bottom rectangle 72 | end 73 | end 74 | 75 | EndDrawing() 76 | --------------------------------------------------------------------------------------- 77 | end 78 | 79 | -- De-Initialization 80 | ------------------------------------------------------------------------------------------- 81 | CloseWindow() -- Close window and OpenGL context 82 | ------------------------------------------------------------------------------------------- 83 | -------------------------------------------------------------------------------- /examples/core/core_drop_files.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Windows drop files 4 | -- 5 | -- This example only works on platforms that support drag & drop (Windows, Linux, OSX) 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files") 20 | 21 | local count = 0 22 | local droppedFiles = {} 23 | 24 | SetTargetFPS(60) 25 | ------------------------------------------------------------------------------------------- 26 | 27 | -- Main game loop 28 | while not WindowShouldClose() do -- Detect window close button or ESC key 29 | -- Update 30 | --------------------------------------------------------------------------------------- 31 | if (IsFileDropped()) then 32 | droppedFiles = GetDroppedFiles() 33 | count = #droppedFiles 34 | end 35 | --------------------------------------------------------------------------------------- 36 | 37 | -- Draw 38 | --------------------------------------------------------------------------------------- 39 | BeginDrawing() 40 | 41 | ClearBackground(RAYWHITE) 42 | 43 | if (count == 0) then DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY) 44 | else 45 | DrawText("Dropped files:", 100, 40, 20, DARKGRAY) 46 | 47 | for i = 0, count-1 do 48 | if (i%2 == 0) then DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5)) 49 | else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3)) end 50 | 51 | DrawText(droppedFiles[i+1], 120, 100 + 40*i, 10, GRAY) 52 | end 53 | 54 | DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY) 55 | end 56 | 57 | EndDrawing() 58 | --------------------------------------------------------------------------------------- 59 | end 60 | 61 | -- De-Initialization 62 | ------------------------------------------------------------------------------------------- 63 | ClearDroppedFiles() -- Clear internal buffers 64 | 65 | CloseWindow() -- Close window and OpenGL context 66 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/core/core_gestures_detection.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Gestures Detection 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | MAX_GESTURE_STRINGS = 20 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection") 20 | 21 | local touchPosition = Vector2(0, 0) 22 | local touchArea = Rectangle(220, 10, screenWidth - 230, screenHeight - 20) 23 | 24 | local gesturesCount = 0 25 | local gestureStrings = {} 26 | 27 | for i = 1, MAX_GESTURE_STRINGS do gestureStrings[i] = "" end 28 | 29 | local currentGesture = GESTURES_NONE 30 | local lastGesture = GESTURES_NONE 31 | 32 | --SetGesturesEnabled(0b0000000000001001) -- Enable only some gestures to be detected 33 | 34 | SetTargetFPS(60) 35 | ------------------------------------------------------------------------------------------- 36 | 37 | -- Main game loop 38 | while not WindowShouldClose() do -- Detect window close button or ESC key 39 | -- Update 40 | --------------------------------------------------------------------------------------- 41 | lastGesture = currentGesture 42 | currentGesture = GetGestureDetected() 43 | touchPosition = GetTouchPosition(0) 44 | 45 | if (CheckCollisionPointRec(touchPosition, touchArea) and (currentGesture ~= GESTURES_NONE)) then 46 | if (currentGesture ~= lastGesture) then 47 | -- Store gesture string 48 | if (currentGesture == GESTURES_TAP) then gestureStrings[gesturesCount] = "GESTURE TAP" 49 | elseif (currentGesture == GESTURES_DOUBLETAP) then gestureStrings[gesturesCount] = "GESTURE DOUBLETAP" 50 | elseif (currentGesture == GESTURES_HOLD) then gestureStrings[gesturesCount] = "GESTURE HOLD" 51 | elseif (currentGesture == GESTURES_DRAG) then gestureStrings[gesturesCount] = "GESTURE DRAG" 52 | elseif (currentGesture == GESTURES_SWIPE_RIGHT) then gestureStrings[gesturesCount] = "GESTURE SWIPE RIGHT" 53 | elseif (currentGesture == GESTURES_SWIPE_LEFT) then gestureStrings[gesturesCount] = "GESTURE SWIPE LEFT" 54 | elseif (currentGesture == GESTURES_SWIPE_UP) then gestureStrings[gesturesCount] = "GESTURE SWIPE UP" 55 | elseif (currentGesture == GESTURES_SWIPE_DOWN) then gestureStrings[gesturesCount] = "GESTURE SWIPE DOWN" 56 | elseif (currentGesture == GESTURES_PINCH_IN) then gestureStrings[gesturesCount] = "GESTURE PINCH IN" 57 | elseif (currentGesture == GESTURES_PINCH_OUT) then gestureStrings[gesturesCount] = "GESTURE PINCH OUT" 58 | end 59 | 60 | gesturesCount = gesturesCount + 1 61 | 62 | -- Reset gestures strings 63 | if (gesturesCount >= MAX_GESTURE_STRINGS) then 64 | for i = 1, MAX_GESTURE_STRINGS do gestureStrings[i] = "\0" end 65 | gesturesCount = 0 66 | end 67 | end 68 | end 69 | --------------------------------------------------------------------------------------- 70 | 71 | -- Draw 72 | --------------------------------------------------------------------------------------- 73 | BeginDrawing() 74 | 75 | ClearBackground(RAYWHITE) 76 | 77 | DrawRectangleRec(touchArea, GRAY) 78 | DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE) 79 | 80 | DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5)) 81 | 82 | for i = 1, gesturesCount do 83 | if ((i - 1)%2 == 0) then DrawRectangle(10, 30 + 20*(i - 1), 200, 20, Fade(LIGHTGRAY, 0.5)) 84 | else DrawRectangle(10, 30 + 20*(i - 1), 200, 20, Fade(LIGHTGRAY, 0.3)) end 85 | 86 | if (i < gesturesCount) then DrawText(gestureStrings[i], 35, 36 + 20*(i - 1), 10, DARKGRAY) 87 | else DrawText(gestureStrings[i], 35, 36 + 20*(i - 1), 10, MAROON) end 88 | end 89 | 90 | DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY) 91 | DrawText("DETECTED GESTURES", 50, 15, 10, GRAY) 92 | 93 | if (currentGesture ~= GESTURE_NONE) then DrawCircleV(touchPosition, 30, MAROON) end 94 | 95 | EndDrawing() 96 | --------------------------------------------------------------------------------------- 97 | end 98 | 99 | -- De-Initialization 100 | ------------------------------------------------------------------------------------------- 101 | CloseWindow() -- Close window and OpenGL context 102 | ------------------------------------------------------------------------------------------- 103 | -------------------------------------------------------------------------------- /examples/core/core_input_keys.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Keyboard input 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window") 18 | 19 | local ballPosition = Vector2(screenWidth/2, screenHeight/2) 20 | 21 | SetTargetFPS(60) -- Set target frames-per-second 22 | ------------------------------------------------------------------------------------------- 23 | 24 | -- Main game loop 25 | while not WindowShouldClose() do -- Detect window close button or ESC key 26 | -- Update 27 | --------------------------------------------------------------------------------------- 28 | if (IsKeyDown(KEY_RIGHT)) then ballPosition.x = ballPosition.x + 0.8 end 29 | if (IsKeyDown(KEY_LEFT)) then ballPosition.x = ballPosition.x - 0.8 end 30 | if (IsKeyDown(KEY_UP)) then ballPosition.y = ballPosition.y - 0.8 end 31 | if (IsKeyDown(KEY_DOWN)) then ballPosition.y = ballPosition.y + 0.8 end 32 | --------------------------------------------------------------------------------------- 33 | 34 | -- Draw 35 | --------------------------------------------------------------------------------------- 36 | BeginDrawing() 37 | 38 | ClearBackground(RAYWHITE) 39 | 40 | DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY) 41 | 42 | DrawCircleV(ballPosition, 50, MAROON) 43 | 44 | EndDrawing() 45 | --------------------------------------------------------------------------------------- 46 | end 47 | 48 | -- De-Initialization 49 | ------------------------------------------------------------------------------------------- 50 | CloseWindow() -- Close window and OpenGL context 51 | ------------------------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /examples/core/core_input_mouse.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Mouse input 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input") 18 | 19 | local ballPosition = Vector2(-100.0, -100.0) 20 | local ballColor = DARKBLUE 21 | 22 | SetTargetFPS(60) -- Set target frames-per-second 23 | ----------------------------------------------------------------------------------------- 24 | 25 | -- Main game loop 26 | while not WindowShouldClose() do -- Detect window close button or ESC key 27 | -- Update 28 | ------------------------------------------------------------------------------------ 29 | ballPosition = GetMousePosition() 30 | 31 | if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) then ballColor = MAROON 32 | elseif (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) then ballColor = LIME 33 | elseif (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) then ballColor = DARKBLUE 34 | end 35 | ------------------------------------------------------------------------------------ 36 | 37 | -- Draw 38 | ------------------------------------------------------------------------------------ 39 | BeginDrawing() 40 | 41 | ClearBackground(RAYWHITE) 42 | 43 | DrawCircleV(ballPosition, 40, ballColor) 44 | 45 | DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY) 46 | 47 | EndDrawing() 48 | ------------------------------------------------------------------------------------ 49 | end 50 | 51 | -- De-Initialization 52 | ---------------------------------------------------------------------------------------- 53 | CloseWindow() -- Close window and OpenGL context 54 | ---------------------------------------------------------------------------------------- 55 | -------------------------------------------------------------------------------- /examples/core/core_mouse_wheel.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] examples - Mouse wheel 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel") 18 | 19 | local boxPositionY = screenHeight/2 - 40 20 | local scrollSpeed = 4 -- Scrolling speed in pixels 21 | 22 | SetTargetFPS(60) -- Set target frames-per-second 23 | ---------------------------------------------------------------------------------------- 24 | 25 | -- Main game loop 26 | while not WindowShouldClose() do -- Detect window close button or ESC key 27 | -- Update 28 | ------------------------------------------------------------------------------------ 29 | boxPositionY = boxPositionY - (GetMouseWheelMove()*scrollSpeed) 30 | ------------------------------------------------------------------------------------ 31 | 32 | -- Draw 33 | ------------------------------------------------------------------------------------ 34 | BeginDrawing() 35 | 36 | ClearBackground(RAYWHITE) 37 | 38 | DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON) 39 | 40 | DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY) 41 | DrawText(string.format("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY) 42 | 43 | EndDrawing() 44 | ------------------------------------------------------------------------------------ 45 | end 46 | 47 | -- De-Initialization 48 | ---------------------------------------------------------------------------------------- 49 | CloseWindow() -- Close window and OpenGL context 50 | ---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/core/core_random_values.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Generate random values 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values") 18 | 19 | local framesCounter = 0 -- Variable used to count frames 20 | 21 | local randValue = GetRandomValue(-8, 5) -- Get a random integer number between -8 and 5 (both included) 22 | 23 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 24 | ---------------------------------------------------------------------------------------- 25 | 26 | -- Main game loop 27 | while not WindowShouldClose() do -- Detect window close button or ESC key 28 | -- Update 29 | ------------------------------------------------------------------------------------ 30 | framesCounter = framesCounter + 1 31 | 32 | -- Every two seconds (120 frames) a new random value is generated 33 | if (((framesCounter/120)%2) == 1) then 34 | randValue = GetRandomValue(-8, 5) 35 | framesCounter = 0 36 | end 37 | ------------------------------------------------------------------------------------ 38 | 39 | -- Draw 40 | ------------------------------------------------------------------------------------ 41 | BeginDrawing() 42 | 43 | ClearBackground(RAYWHITE) 44 | 45 | DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON) 46 | 47 | DrawText(string.format("%i", randValue), 360, 180, 80, LIGHTGRAY) 48 | 49 | EndDrawing() 50 | ------------------------------------------------------------------------------------ 51 | end 52 | 53 | -- De-Initialization 54 | ---------------------------------------------------------------------------------------- 55 | CloseWindow() -- Close window and OpenGL context 56 | ---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/core/core_storage_values.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Storage save/load values 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- NOTE: Storage positions must start with 0, directly related to file memory layout 13 | STORAGE_SCORE = 0 14 | STORAGE_HISCORE = 1 15 | 16 | -- Initialization 17 | ------------------------------------------------------------------------------------------- 18 | local screenWidth = 800 19 | local screenHeight = 450 20 | 21 | InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values") 22 | 23 | local score = 0 24 | local hiscore = 0 25 | 26 | local framesCounter = 0 27 | 28 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 29 | ------------------------------------------------------------------------------------------- 30 | 31 | -- Main game loop 32 | while not WindowShouldClose() do -- Detect window close button or ESC key 33 | -- Update 34 | --------------------------------------------------------------------------------------- 35 | if (IsKeyPressed(KEY_R)) then 36 | score = GetRandomValue(1000, 2000) 37 | hiscore = GetRandomValue(2000, 4000) 38 | end 39 | 40 | if (IsKeyPressed(KEY_ENTER)) then 41 | StorageSaveValue(STORAGE_SCORE, score) 42 | StorageSaveValue(STORAGE_HISCORE, hiscore) 43 | elseif (IsKeyPressed(KEY_SPACE)) then 44 | -- NOTE: If requested position could not be found, value 0 is returned 45 | score = StorageLoadValue(STORAGE_SCORE) 46 | hiscore = StorageLoadValue(STORAGE_HISCORE) 47 | end 48 | 49 | framesCounter = framesCounter + 1 50 | --------------------------------------------------------------------------------------- 51 | 52 | -- Draw 53 | --------------------------------------------------------------------------------------- 54 | BeginDrawing() 55 | 56 | ClearBackground(RAYWHITE) 57 | 58 | DrawText(string.format("SCORE: %i", score), 280, 130, 40, MAROON) 59 | DrawText(string.format("HI-SCORE: %i", hiscore), 210, 200, 50, BLACK) 60 | 61 | DrawText(string.format("frames: %i", framesCounter), 10, 10, 20, LIME) 62 | 63 | DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY) 64 | DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY) 65 | DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY) 66 | 67 | EndDrawing() 68 | --------------------------------------------------------------------------------------- 69 | end 70 | 71 | -- De-Initialization 72 | ------------------------------------------------------------------------------------------- 73 | CloseWindow() -- Close window and OpenGL context 74 | ------------------------------------------------------------------------------------------- 75 | -------------------------------------------------------------------------------- /examples/core/core_vr_simulator.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - Oculus Rift CV1 4 | -- 5 | -- NOTE: Example requires linkage with LibOVR 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 1080 17 | local screenHeight = 600 18 | 19 | -- NOTE: screenWidth/screenHeight should match VR device aspect ratio 20 | 21 | InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift") 22 | 23 | -- NOTE: If device is not available, it fallbacks to default device (simulator) 24 | InitVrSimulator(VrDevice.OCULUS_RIFT_CV1) -- Init VR device (Oculus Rift CV1) 25 | 26 | -- Define the camera to look into our 3d world 27 | local camera = {} 28 | camera.position = Vector3(5.0, 5.0, 5.0) -- Camera position 29 | camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point 30 | camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) 31 | camera.fovy = 60.0 -- Camera field-of-view Y 32 | 33 | local cubePosition = Vector3(0.0, 0.0, 0.0) 34 | 35 | SetCameraMode(CAMERA_FIRST_PERSON); -- Set first person camera mode 36 | 37 | SetTargetFPS(90) -- Set our game to run at 90 frames-per-second 38 | ---------------------------------------------------------------------------------------- 39 | 40 | -- Main game loop 41 | while not WindowShouldClose() do -- Detect window close button or ESC key 42 | -- Update 43 | ------------------------------------------------------------------------------------ 44 | UpdateCamera(camera); -- Update camera (simulator mode) 45 | 46 | if (IsKeyPressed(KEY_SPACE)) then ToggleVrMode() end -- Toggle VR mode 47 | ------------------------------------------------------------------------------------ 48 | 49 | -- Draw 50 | ------------------------------------------------------------------------------------ 51 | BeginDrawing() 52 | 53 | ClearBackground(RAYWHITE) 54 | 55 | BeginVrDrawing(); 56 | 57 | BeginMode3D(camera) 58 | 59 | DrawCube(cubePosition, 2.0, 2.0, 2.0, RED) 60 | DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON) 61 | 62 | DrawGrid(40, 1.0) 63 | 64 | EndMode3D() 65 | 66 | EndVrDrawing(); 67 | 68 | DrawFPS(10, 10) 69 | 70 | EndDrawing() 71 | ------------------------------------------------------------------------------------ 72 | end 73 | 74 | -- De-Initialization 75 | ---------------------------------------------------------------------------------------- 76 | CloseVrSimulator() -- Close VR device 77 | 78 | CloseWindow() -- Close window and OpenGL context 79 | ---------------------------------------------------------------------------------------- 80 | -------------------------------------------------------------------------------- /examples/core/core_world_screen.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [core] example - World to screen 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera(Vector3(10.0, 10.0, 10.0), Vector3(), Vector3(0.0, 1.0, 0.0), 45, CAMERA_PERSPECTIVE) 21 | 22 | local cubePosition = Vector3() 23 | 24 | SetCameraMode(camera, CAMERA_FREE) -- Set a free camera mode 25 | 26 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 27 | ---------------------------------------------------------------------------------------- 28 | 29 | -- Main game loop 30 | while not WindowShouldClose() do -- Detect window close button or ESC key 31 | -- Update 32 | ------------------------------------------------------------------------------------ 33 | UpdateCamera(camera) -- Update camera 34 | 35 | -- Calculate cube screen space position (with a little offset to be in top) 36 | local cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera) 37 | ------------------------------------------------------------------------------------ 38 | 39 | -- Draw 40 | ------------------------------------------------------------------------------------ 41 | BeginDrawing() 42 | 43 | ClearBackground(RAYWHITE) 44 | 45 | BeginMode3D(camera) 46 | 47 | DrawCube(cubePosition, 2.0, 2.0, 2.0, RED) 48 | DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON) 49 | 50 | DrawGrid(10, 1.0) 51 | 52 | EndMode3D() 53 | 54 | DrawText("Enemy: 100 / 100", cubeScreenPosition.x//1 - MeasureText("Enemy: 100 / 100", 20)//2, cubeScreenPosition.y//1, 20, BLACK) 55 | DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))//2, 25, 20, GRAY) 56 | 57 | EndDrawing() 58 | ------------------------------------------------------------------------------------ 59 | end 60 | 61 | -- De-Initialization 62 | ---------------------------------------------------------------------------------------- 63 | CloseWindow() -- Close window and OpenGL context 64 | ---------------------------------------------------------------------------------------- 65 | -------------------------------------------------------------------------------- /examples/core/resources/ps3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/core/resources/ps3.png -------------------------------------------------------------------------------- /examples/core/resources/xbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/core/resources/xbox.png -------------------------------------------------------------------------------- /examples/models/models_billboard.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [models] example - Drawing billboards 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) 21 | 22 | local bill = LoadTexture("resources/billboard.png") -- Our texture billboard 23 | local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard 24 | 25 | SetCameraMode(camera, CAMERA_ORBITAL) -- Set an orbital camera mode 26 | 27 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 28 | ------------------------------------------------------------------------------------------- 29 | 30 | -- Main game loop 31 | while not WindowShouldClose() do -- Detect window close button or ESC key 32 | -- Update 33 | --------------------------------------------------------------------------------------- 34 | UpdateCamera(camera) -- Update camera 35 | --------------------------------------------------------------------------------------- 36 | 37 | -- Draw 38 | --------------------------------------------------------------------------------------- 39 | BeginDrawing() 40 | 41 | ClearBackground(RAYWHITE) 42 | 43 | BeginMode3D(camera) 44 | 45 | DrawBillboard(camera, bill, billPosition, 2.0, WHITE) 46 | 47 | DrawGrid(10, 1.0) -- Draw a grid 48 | 49 | EndMode3D() 50 | 51 | DrawFPS(10, 10) 52 | 53 | EndDrawing() 54 | --------------------------------------------------------------------------------------- 55 | end 56 | 57 | -- De-Initialization 58 | ------------------------------------------------------------------------------------------- 59 | UnloadTexture(bill) -- Unload texture 60 | 61 | CloseWindow() -- Close window and OpenGL context 62 | ------------------------------------------------------------------------------------------- 63 | -------------------------------------------------------------------------------- /examples/models/models_cubicmap.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [models] example - Cubicmap loading and drawing 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera(Vector3(16.0, 14.0, 16.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) 21 | 22 | local image = LoadImage("resources/cubicmap.png") -- Load cubicmap image (RAM) 23 | local cubicmap = LoadTextureFromImage(image) -- Convert image to texture to display (VRAM) 24 | local map = LoadCubicmap(image) -- Load cubicmap model (generate model from image) 25 | 26 | -- NOTE: By default each cube is mapped to one part of texture atlas 27 | local texture = LoadTexture("resources/cubicmap_atlas.png") -- Load map texture 28 | map.material.texDiffuse = texture -- Set map diffuse texture 29 | 30 | local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position 31 | 32 | UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM 33 | 34 | SetCameraMode(camera, CAMERA_ORBITAL) -- Set an orbital camera mode 35 | 36 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 37 | ------------------------------------------------------------------------------------------- 38 | 39 | -- Main game loop 40 | while not WindowShouldClose() do -- Detect window close button or ESC key 41 | -- Update 42 | --------------------------------------------------------------------------------------- 43 | UpdateCamera(camera) -- Update camera 44 | --------------------------------------------------------------------------------------- 45 | 46 | -- Draw 47 | --------------------------------------------------------------------------------------- 48 | BeginDrawing() 49 | 50 | ClearBackground(RAYWHITE) 51 | 52 | BeginMode3D(camera) 53 | 54 | DrawModel(map, mapPosition, 1.0, WHITE) 55 | 56 | EndMode3D() 57 | 58 | DrawTextureEx(cubicmap, (Vector2)(screenWidth - cubicmap.width*4 - 20, 20), 0.0, 4.0, WHITE) 59 | DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN) 60 | 61 | DrawText("cubicmap image used to", 658, 90, 10, GRAY) 62 | DrawText("generate map 3d model", 658, 104, 10, GRAY) 63 | 64 | DrawFPS(10, 10) 65 | 66 | EndDrawing() 67 | --------------------------------------------------------------------------------------- 68 | end 69 | 70 | -- De-Initialization 71 | ------------------------------------------------------------------------------------------- 72 | UnloadTexture(cubicmap) -- Unload cubicmap texture 73 | UnloadTexture(texture) -- Unload map texture 74 | UnloadModel(map) -- Unload map model 75 | 76 | CloseWindow() -- Close window and OpenGL context 77 | ------------------------------------------------------------------------------------------- 78 | -------------------------------------------------------------------------------- /examples/models/models_geometric_shapes.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [models] example - Draw some basic geometric shapes (cube, sphere, cylinder...) 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) 21 | 22 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 23 | ------------------------------------------------------------------------------------------- 24 | 25 | -- Main game loop 26 | while not WindowShouldClose() do -- Detect window close button or ESC key 27 | -- Update 28 | --------------------------------------------------------------------------------------- 29 | -- TODO: Update your variables here 30 | --------------------------------------------------------------------------------------- 31 | 32 | -- Draw 33 | --------------------------------------------------------------------------------------- 34 | BeginDrawing() 35 | 36 | ClearBackground(RAYWHITE) 37 | 38 | BeginMode3D(camera) -- ERROR: Lua Error: attempt to index a number value 39 | 40 | DrawCube(Vector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, RED) 41 | DrawCubeWires(Vector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, GOLD) 42 | DrawCubeWires(Vector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, MAROON) 43 | 44 | DrawSphere(Vector3(-1.0, 0.0, -2.0), 1.0, GREEN) 45 | DrawSphereWires(Vector3(1.0, 0.0, 2.0), 2.0, 16, 16, LIME) 46 | 47 | DrawCylinder(Vector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, SKYBLUE) 48 | DrawCylinderWires(Vector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, DARKBLUE) 49 | DrawCylinderWires(Vector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, BROWN) 50 | 51 | DrawCylinder(Vector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, GOLD) 52 | DrawCylinderWires(Vector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, PINK) 53 | 54 | DrawGrid(10, 1.0) -- Draw a grid 55 | 56 | EndMode3D() 57 | 58 | DrawFPS(10, 10) 59 | 60 | EndDrawing() 61 | --------------------------------------------------------------------------------------- 62 | end 63 | 64 | -- De-Initialization 65 | ------------------------------------------------------------------------------------------- 66 | CloseWindow() -- Close window and OpenGL context 67 | ------------------------------------------------------------------------------------------- 68 | -------------------------------------------------------------------------------- /examples/models/models_heightmap.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [models] example - Heightmap loading and drawing 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing") 18 | 19 | -- Define our custom camera to look into our 3d world 20 | local camera = Camera(Vector3(18.0, 16.0, 18.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) 21 | 22 | local image = LoadImage("resources/heightmap.png") -- Load heightmap image (RAM) 23 | local texture = LoadTextureFromImage(image) -- Convert image to texture (VRAM) 24 | local map = LoadHeightmap(image, Vector3(16, 8, 16)) -- Load heightmap model with defined size 25 | map.material.texDiffuse = texture -- Set map diffuse texture 26 | local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (depends on model scaling!) 27 | 28 | UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM 29 | 30 | SetCameraMode(camera, CAMERA_ORBITAL) -- Set an orbital camera mode 31 | 32 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 33 | ---------------------------------------------------------------------------------------- 34 | 35 | -- Main game loop 36 | while not WindowShouldClose() do -- Detect window close button or ESC key 37 | -- Update 38 | --------------------------------------------------------------------------------------- 39 | UpdateCamera(camera) -- Update camera 40 | --------------------------------------------------------------------------------------- 41 | 42 | -- Draw 43 | --------------------------------------------------------------------------------------- 44 | BeginDrawing() 45 | 46 | ClearBackground(RAYWHITE) 47 | 48 | BeginMode3D(camera) 49 | 50 | -- NOTE: Model is scaled to 1/4 of its original size (128x128 units) 51 | DrawModel(map, mapPosition, 1.0, RED) 52 | 53 | DrawGrid(20, 1.0) 54 | 55 | EndMode3D() 56 | 57 | DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE) 58 | DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN) 59 | 60 | DrawFPS(10, 10) 61 | 62 | EndDrawing() 63 | --------------------------------------------------------------------------------------- 64 | end 65 | 66 | -- De-Initialization 67 | ------------------------------------------------------------------------------------------- 68 | UnloadTexture(texture) -- Unload texture 69 | UnloadModel(map) -- Unload model 70 | 71 | CloseWindow() -- Close window and OpenGL context 72 | ------------------------------------------------------------------------------------------- 73 | -------------------------------------------------------------------------------- /examples/models/models_obj_loading.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [models] example - Load and draw a 3d model (OBJ) 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading") 18 | 19 | -- Define the camera to look into our 3d world 20 | local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) 21 | 22 | local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model 23 | local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture 24 | dwarf.material.texDiffuse = texture -- Set dwarf model diffuse texture 25 | local position = Vector3(0.0, 0.0, 0.0) -- Set model position 26 | 27 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 28 | ------------------------------------------------------------------------------------------- 29 | 30 | -- Main game loop 31 | while not WindowShouldClose() do -- Detect window close button or ESC key 32 | -- Update 33 | --------------------------------------------------------------------------------------- 34 | -- ... 35 | --------------------------------------------------------------------------------------- 36 | 37 | -- Draw 38 | --------------------------------------------------------------------------------------- 39 | BeginDrawing() 40 | 41 | ClearBackground(RAYWHITE) 42 | 43 | BeginMode3D(camera) 44 | 45 | DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture 46 | 47 | DrawGrid(10, 1.0) -- Draw a grid 48 | 49 | DrawGizmo(position) -- Draw gizmo 50 | 51 | EndMode3D() 52 | 53 | DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY) 54 | 55 | DrawFPS(10, 10) 56 | 57 | EndDrawing() 58 | --------------------------------------------------------------------------------------- 59 | end 60 | 61 | -- De-Initialization 62 | ------------------------------------------------------------------------------------------- 63 | UnloadTexture(texture) -- Unload texture 64 | UnloadModel(dwarf) -- Unload model 65 | 66 | CloseWindow() -- Close window and OpenGL context 67 | ------------------------------------------------------------------------------------------- 68 | -------------------------------------------------------------------------------- /examples/models/resources/billboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/billboard.png -------------------------------------------------------------------------------- /examples/models/resources/cubicmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/cubicmap.png -------------------------------------------------------------------------------- /examples/models/resources/cubicmap_atlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/cubicmap_atlas.png -------------------------------------------------------------------------------- /examples/models/resources/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/heightmap.png -------------------------------------------------------------------------------- /examples/models/resources/model/dwarf_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/model/dwarf_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/model/dwarf_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/model/dwarf_normal.png -------------------------------------------------------------------------------- /examples/models/resources/model/dwarf_specular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/model/dwarf_specular.png -------------------------------------------------------------------------------- /examples/models/resources/tower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/models/resources/tower.png -------------------------------------------------------------------------------- /examples/shaders/resources/fudesumi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/shaders/resources/fudesumi.png -------------------------------------------------------------------------------- /examples/shaders/resources/model/dwarf_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/shaders/resources/model/dwarf_diffuse.png -------------------------------------------------------------------------------- /examples/shaders/resources/model/dwarf_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/shaders/resources/model/dwarf_normal.png -------------------------------------------------------------------------------- /examples/shaders/resources/model/dwarf_specular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/shaders/resources/model/dwarf_specular.png -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/base.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 | // NOTE: Add here your custom variables 14 | uniform vec2 resolution = vec2(800, 450); 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture2D(texture0, fragTexCoord); 20 | 21 | // NOTE: Implement here your fragment shader code 22 | 23 | gl_FragColor = texelColor*colDiffuse; 24 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/base.vs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec3 vertexNormal; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvpMatrix; 11 | 12 | // Output vertex attributes (to fragment shader) 13 | varying vec2 fragTexCoord; 14 | varying vec4 fragColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | void main() 19 | { 20 | // Send vertex attributes to fragment shader 21 | fragTexCoord = vertexTexCoord; 22 | fragColor = vertexColor; 23 | 24 | // Calculate final vertex position 25 | gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/bloom.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 | // NOTE: Add here your custom variables 14 | 15 | const vec2 size = vec2(800, 450); // render size 16 | const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance 17 | const float quality = 2.5; // lower = smaller glow, better quality 18 | 19 | void main() 20 | { 21 | vec4 sum = vec4(0); 22 | vec2 sizeFactor = vec2(1)/size*quality; 23 | 24 | // Texel color fetching from texture sampler 25 | vec4 source = texture2D(texture0, fragTexCoord); 26 | 27 | const int range = 2; // should be = (samples - 1)/2; 28 | 29 | for (int x = -range; x <= range; x++) 30 | { 31 | for (int y = -range; y <= range; y++) 32 | { 33 | sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor); 34 | } 35 | } 36 | 37 | // Calculate final fragment color 38 | gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse; 39 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/blur.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 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values must be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308); 20 | vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703); 21 | 22 | void main() 23 | { 24 | // Texel color fetching from texture sampler 25 | vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x; 26 | 27 | tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; 28 | tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; 29 | 30 | tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; 31 | tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; 32 | 33 | gl_FragColor = vec4(tc, 1.0); 34 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/cross_hatching.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 | // NOTE: Add here your custom variables 14 | 15 | float hatchOffsetY = 5.0; 16 | float lumThreshold01 = 0.9; 17 | float lumThreshold02 = 0.7; 18 | float lumThreshold03 = 0.5; 19 | float lumThreshold04 = 0.3; 20 | 21 | void main() 22 | { 23 | vec3 tc = vec3(1.0, 1.0, 1.0); 24 | float lum = length(texture2D(texture0, fragTexCoord).rgb); 25 | 26 | if (lum < lumThreshold01) 27 | { 28 | if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 29 | } 30 | 31 | if (lum < lumThreshold02) 32 | { 33 | if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 34 | } 35 | 36 | if (lum < lumThreshold03) 37 | { 38 | if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 39 | } 40 | 41 | if (lum < lumThreshold04) 42 | { 43 | if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 44 | } 45 | 46 | gl_FragColor = vec4(tc, 1.0); 47 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/cross_stitching.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 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values must be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | float stitchingSize = 6.0; 20 | int invert = 0; 21 | 22 | vec4 PostFX(sampler2D tex, vec2 uv) 23 | { 24 | vec4 c = vec4(0.0); 25 | float size = stitchingSize; 26 | vec2 cPos = uv * vec2(renderWidth, renderHeight); 27 | vec2 tlPos = floor(cPos / vec2(size, size)); 28 | tlPos *= size; 29 | 30 | int remX = int(mod(cPos.x, size)); 31 | int remY = int(mod(cPos.y, size)); 32 | 33 | if (remX == 0 && remY == 0) tlPos = cPos; 34 | 35 | vec2 blPos = tlPos; 36 | blPos.y += (size - 1.0); 37 | 38 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 39 | { 40 | if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); 41 | else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 42 | } 43 | else 44 | { 45 | if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 46 | else c = vec4(0.0, 0.0, 0.0, 1.0); 47 | } 48 | 49 | return c; 50 | } 51 | 52 | void main() 53 | { 54 | vec3 tc = PostFX(texture0, fragTexCoord).rgb; 55 | 56 | gl_FragColor = vec4(tc, 1.0); 57 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/distortion.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | 8 | // Input uniform values 9 | uniform sampler2D texture0; 10 | 11 | // NOTE: Default parameters for Oculus Rift DK2 device 12 | const vec2 LeftLensCenter = vec2(0.2863248, 0.5); 13 | const vec2 RightLensCenter = vec2(0.7136753, 0.5); 14 | const vec2 LeftScreenCenter = vec2(0.25, 0.5); 15 | const vec2 RightScreenCenter = vec2(0.75, 0.5); 16 | const vec2 Scale = vec2(0.25, 0.45); 17 | const vec2 ScaleIn = vec2(4.0, 2.5); 18 | const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0); 19 | const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); 20 | 21 | void main() 22 | { 23 | // The following two variables need to be set per eye 24 | vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; 25 | vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; 26 | 27 | // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) 28 | vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] 29 | float rSq = theta.x*theta.x + theta.y*theta.y; 30 | vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); 31 | //vec2 tc = LensCenter + Scale*theta1; 32 | 33 | // Detect whether blue texture coordinates are out of range since these will scaled out the furthest 34 | vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); 35 | vec2 tcBlue = LensCenter + Scale*thetaBlue; 36 | 37 | if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 38 | else 39 | { 40 | // Do blue texture lookup 41 | float blue = texture2D(texture0, tcBlue).b; 42 | 43 | // Do green lookup (no scaling) 44 | vec2 tcGreen = LensCenter + Scale*theta1; 45 | float green = texture2D(texture0, tcGreen).g; 46 | 47 | // Do red scale and lookup 48 | vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); 49 | vec2 tcRed = LensCenter + Scale*thetaRed; 50 | float red = texture2D(texture0, tcRed).r; 51 | 52 | gl_FragColor = vec4(red, green, blue, 1.0); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/dream_vision.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 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | vec4 color = texture2D(texture0, fragTexCoord); 18 | 19 | color += texture2D(texture0, fragTexCoord + 0.001); 20 | color += texture2D(texture0, fragTexCoord + 0.003); 21 | color += texture2D(texture0, fragTexCoord + 0.005); 22 | color += texture2D(texture0, fragTexCoord + 0.007); 23 | color += texture2D(texture0, fragTexCoord + 0.009); 24 | color += texture2D(texture0, fragTexCoord + 0.011); 25 | 26 | color += texture2D(texture0, fragTexCoord - 0.001); 27 | color += texture2D(texture0, fragTexCoord - 0.003); 28 | color += texture2D(texture0, fragTexCoord - 0.005); 29 | color += texture2D(texture0, fragTexCoord - 0.007); 30 | color += texture2D(texture0, fragTexCoord - 0.009); 31 | color += texture2D(texture0, fragTexCoord - 0.011); 32 | 33 | color.rgb = vec3((color.r + color.g + color.b)/3.0); 34 | color = color/9.5; 35 | 36 | gl_FragColor = color; 37 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/fisheye.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 | // NOTE: Add here your custom variables 14 | 15 | const float PI = 3.1415926535; 16 | 17 | void main() 18 | { 19 | float aperture = 178.0; 20 | float apertureHalf = 0.5 * aperture * (PI / 180.0); 21 | float maxFactor = sin(apertureHalf); 22 | 23 | vec2 uv = vec2(0.0); 24 | vec2 xy = 2.0 * fragTexCoord.xy - 1.0; 25 | float d = length(xy); 26 | 27 | if (d < (2.0 - maxFactor)) 28 | { 29 | d = length(xy * maxFactor); 30 | float z = sqrt(1.0 - d * d); 31 | float r = atan(d, z) / PI; 32 | float phi = atan(xy.y, xy.x); 33 | 34 | uv.x = r * cos(phi) + 0.5; 35 | uv.y = r * sin(phi) + 0.5; 36 | } 37 | else 38 | { 39 | uv = fragTexCoord.xy; 40 | } 41 | 42 | gl_FragColor = texture2D(texture0, uv); 43 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/grayscale.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 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor; 19 | 20 | // Convert texel color to grayscale using NTSC conversion weights 21 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 22 | 23 | // Calculate final fragment color 24 | gl_FragColor = vec4(gray, gray, gray, texelColor.a); 25 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/pixelizer.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 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values must be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | float pixelWidth = 5.0; 20 | float pixelHeight = 5.0; 21 | 22 | void main() 23 | { 24 | float dx = pixelWidth*(1.0/renderWidth); 25 | float dy = pixelHeight*(1.0/renderHeight); 26 | 27 | vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); 28 | 29 | vec3 tc = texture2D(texture0, coord).rgb; 30 | 31 | gl_FragColor = vec4(tc, 1.0); 32 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/posterization.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 | // NOTE: Add here your custom variables 14 | 15 | float gamma = 0.6; 16 | float numColors = 8.0; 17 | 18 | void main() 19 | { 20 | vec3 color = texture2D(texture0, fragTexCoord.xy).rgb; 21 | 22 | color = pow(color, vec3(gamma, gamma, gamma)); 23 | color = color*numColors; 24 | color = floor(color); 25 | color = color/numColors; 26 | color = pow(color, vec3(1.0/gamma)); 27 | 28 | gl_FragColor = vec4(color, 1.0); 29 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/predator.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 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | vec3 color = texture2D(texture0, fragTexCoord).rgb; 18 | vec3 colors[3]; 19 | colors[0] = vec3(0.0, 0.0, 1.0); 20 | colors[1] = vec3(1.0, 1.0, 0.0); 21 | colors[2] = vec3(1.0, 0.0, 0.0); 22 | 23 | float lum = (color.r + color.g + color.b)/3.0; 24 | 25 | vec3 tc = vec3(0.0, 0.0, 0.0); 26 | 27 | if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5); 28 | else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5); 29 | 30 | gl_FragColor = vec4(tc, 1.0); 31 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/scanlines.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 | // NOTE: Add here your custom variables 14 | 15 | float offset = 0.0; 16 | float frequency = 450.0/3.0; 17 | 18 | uniform float time; 19 | 20 | void main() 21 | { 22 | /* 23 | // Scanlines method 1 24 | float tval = 0; //time 25 | vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); 26 | 27 | vec4 color = texture2D(texture0, fragTexCoord); 28 | 29 | color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); 30 | color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); 31 | color *= vec4(0.8, 1.0, 0.7, 1); 32 | color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); 33 | color *= 0.97 + 0.03*sin(110.0*tval); 34 | 35 | fragColor = color; 36 | */ 37 | // Scanlines method 2 38 | float globalPos = (fragTexCoord.y + offset) * frequency; 39 | float wavePos = cos((fract(globalPos) - 0.5)*3.14); 40 | 41 | vec4 color = texture2D(texture0, fragTexCoord); 42 | 43 | gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); 44 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/sobel.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 | // NOTE: Add here your custom variables 14 | vec2 resolution = vec2(800.0, 450.0); 15 | 16 | void main() 17 | { 18 | float x = 1.0/resolution.x; 19 | float y = 1.0/resolution.y; 20 | 21 | vec4 horizEdge = vec4(0.0); 22 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 23 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; 24 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 25 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 26 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; 27 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 28 | 29 | vec4 vertEdge = vec4(0.0); 30 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 31 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; 32 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 33 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 34 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; 35 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 36 | 37 | vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); 38 | 39 | gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a); 40 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/swirl.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 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values should be passed from code 16 | const float renderWidth = 800; 17 | const float renderHeight = 450; 18 | 19 | float radius = 250.0; 20 | float angle = 0.8; 21 | 22 | uniform vec2 center; 23 | 24 | void main() 25 | { 26 | vec2 texSize = vec2(renderWidth, renderHeight); 27 | vec2 tc = fragTexCoord*texSize; 28 | tc -= center; 29 | 30 | float dist = length(tc); 31 | 32 | if (dist < radius) 33 | { 34 | float percent = (radius - dist)/radius; 35 | float theta = percent*percent*angle*8.0; 36 | float s = sin(theta); 37 | float c = cos(theta); 38 | 39 | tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); 40 | } 41 | 42 | tc += center; 43 | vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;; 44 | 45 | gl_FragColor = vec4(color.rgb, 1.0);; 46 | } -------------------------------------------------------------------------------- /examples/shaders/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 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord); 20 | 21 | // NOTE: Implement here your fragment shader code 22 | 23 | finalColor = texelColor*colDiffuse; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/shaders/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 mvpMatrix; 11 | 12 | // Output vertex attributes (to fragment shader) 13 | out vec2 fragTexCoord; 14 | out vec4 fragColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | void main() 19 | { 20 | // Send vertex attributes to fragment shader 21 | fragTexCoord = vertexTexCoord; 22 | fragColor = vertexColor; 23 | 24 | // Calculate final vertex position 25 | gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/bloom.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 | const vec2 size = vec2(800, 450); // render size 17 | const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance 18 | const float quality = 2.5; // lower = smaller glow, better quality 19 | 20 | void main() 21 | { 22 | vec4 sum = vec4(0); 23 | vec2 sizeFactor = vec2(1)/size*quality; 24 | 25 | // Texel color fetching from texture sampler 26 | vec4 source = texture(texture0, fragTexCoord); 27 | 28 | const int range = 2; // should be = (samples - 1)/2; 29 | 30 | for (int x = -range; x <= range; x++) 31 | { 32 | for (int y = -range; y <= range; y++) 33 | { 34 | sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor); 35 | } 36 | } 37 | 38 | // Calculate final fragment color 39 | finalColor = ((sum/(samples*samples)) + source)*colDiffuse; 40 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/blur.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 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | 20 | float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); 21 | float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); 22 | 23 | void main() 24 | { 25 | // Texel color fetching from texture sampler 26 | vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0]; 27 | 28 | for (int i = 1; i < 3; i++) 29 | { 30 | texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; 31 | texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; 32 | } 33 | 34 | finalColor = vec4(texelColor, 1.0); 35 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/cross_hatching.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 | float hatchOffsetY = 5.0; 17 | float lumThreshold01 = 0.9; 18 | float lumThreshold02 = 0.7; 19 | float lumThreshold03 = 0.5; 20 | float lumThreshold04 = 0.3; 21 | 22 | void main() 23 | { 24 | vec3 tc = vec3(1.0, 1.0, 1.0); 25 | float lum = length(texture(texture0, fragTexCoord).rgb); 26 | 27 | if (lum < lumThreshold01) 28 | { 29 | if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 30 | } 31 | 32 | if (lum < lumThreshold02) 33 | { 34 | if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 35 | } 36 | 37 | if (lum < lumThreshold03) 38 | { 39 | if (mod(gl_FragCoord.x + gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 40 | } 41 | 42 | if (lum < lumThreshold04) 43 | { 44 | if (mod(gl_FragCoord.x - gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 45 | } 46 | 47 | finalColor = vec4(tc, 1.0); 48 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/cross_stitching.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 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800.0; 18 | const float renderHeight = 450.0; 19 | 20 | float stitchingSize = 6.0; 21 | 22 | uniform int invert = 0; 23 | 24 | vec4 PostFX(sampler2D tex, vec2 uv) 25 | { 26 | vec4 c = vec4(0.0); 27 | float size = stitchingSize; 28 | vec2 cPos = uv * vec2(renderWidth, renderHeight); 29 | vec2 tlPos = floor(cPos / vec2(size, size)); 30 | tlPos *= size; 31 | 32 | int remX = int(mod(cPos.x, size)); 33 | int remY = int(mod(cPos.y, size)); 34 | 35 | if (remX == 0 && remY == 0) tlPos = cPos; 36 | 37 | vec2 blPos = tlPos; 38 | blPos.y += (size - 1.0); 39 | 40 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 41 | { 42 | if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); 43 | else c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 44 | } 45 | else 46 | { 47 | if (invert == 1) c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 48 | else c = vec4(0.0, 0.0, 0.0, 1.0); 49 | } 50 | 51 | return c; 52 | } 53 | 54 | void main() 55 | { 56 | vec3 tc = PostFX(texture0, fragTexCoord).rgb; 57 | 58 | finalColor = vec4(tc, 1.0); 59 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/depth.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; // Depth texture 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 | { 18 | float zNear = 0.01; // camera z near 19 | float zFar = 10.0; // camera z far 20 | float z = texture(texture0, fragTexCoord).x; 21 | 22 | // Linearize depth value 23 | float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); 24 | 25 | // Calculate final fragment color 26 | finalColor = vec4(depth, depth, depth, 1.0f); 27 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/distortion.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | 6 | // Input uniform values 7 | uniform sampler2D texture0; 8 | 9 | // Output fragment color 10 | out vec4 finalColor; 11 | 12 | // NOTE: Default parameters for Oculus Rift DK2 device 13 | const vec2 LeftLensCenter = vec2(0.2863248, 0.5); 14 | const vec2 RightLensCenter = vec2(0.7136753, 0.5); 15 | const vec2 LeftScreenCenter = vec2(0.25, 0.5); 16 | const vec2 RightScreenCenter = vec2(0.75, 0.5); 17 | const vec2 Scale = vec2(0.25, 0.45); 18 | const vec2 ScaleIn = vec2(4.0, 2.5); 19 | const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0); 20 | const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); 21 | 22 | void main() 23 | { 24 | // The following two variables need to be set per eye 25 | vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; 26 | vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; 27 | 28 | // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) 29 | vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] 30 | float rSq = theta.x*theta.x + theta.y*theta.y; 31 | vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); 32 | //vec2 tc = LensCenter + Scale*theta1; 33 | 34 | // Detect whether blue texture coordinates are out of range since these will scaled out the furthest 35 | vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); 36 | vec2 tcBlue = LensCenter + Scale*thetaBlue; 37 | 38 | if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); 39 | else 40 | { 41 | // Do blue texture lookup 42 | float blue = texture(texture0, tcBlue).b; 43 | 44 | // Do green lookup (no scaling) 45 | vec2 tcGreen = LensCenter + Scale*theta1; 46 | float green = texture(texture0, tcGreen).g; 47 | 48 | // Do red scale and lookup 49 | vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); 50 | vec2 tcRed = LensCenter + Scale*thetaRed; 51 | float red = texture(texture0, tcRed).r; 52 | 53 | finalColor = vec4(red, green, blue, 1.0); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/dream_vision.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | uniform sampler2D texture0; 8 | uniform vec4 colDiffuse; 9 | 10 | // NOTE: Add here your custom variables 11 | 12 | void main() 13 | { 14 | vec4 color = texture(texture0, fragTexCoord); 15 | 16 | color += texture(texture0, fragTexCoord + 0.001); 17 | color += texture(texture0, fragTexCoord + 0.003); 18 | color += texture(texture0, fragTexCoord + 0.005); 19 | color += texture(texture0, fragTexCoord + 0.007); 20 | color += texture(texture0, fragTexCoord + 0.009); 21 | color += texture(texture0, fragTexCoord + 0.011); 22 | 23 | color += texture(texture0, fragTexCoord - 0.001); 24 | color += texture(texture0, fragTexCoord - 0.003); 25 | color += texture(texture0, fragTexCoord - 0.005); 26 | color += texture(texture0, fragTexCoord - 0.007); 27 | color += texture(texture0, fragTexCoord - 0.009); 28 | color += texture(texture0, fragTexCoord - 0.011); 29 | 30 | color.rgb = vec3((color.r + color.g + color.b)/3.0); 31 | color = color/9.5; 32 | 33 | fragColor = color; 34 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/fisheye.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | uniform sampler2D texture0; 8 | uniform vec4 colDiffuse; 9 | 10 | // NOTE: Add here your custom variables 11 | 12 | const float PI = 3.1415926535; 13 | 14 | void main() 15 | { 16 | float aperture = 178.0; 17 | float apertureHalf = 0.5 * aperture * (PI / 180.0); 18 | float maxFactor = sin(apertureHalf); 19 | 20 | vec2 uv = vec2(0); 21 | vec2 xy = 2.0 * fragTexCoord.xy - 1.0; 22 | float d = length(xy); 23 | 24 | if (d < (2.0 - maxFactor)) 25 | { 26 | d = length(xy * maxFactor); 27 | float z = sqrt(1.0 - d * d); 28 | float r = atan(d, z) / PI; 29 | float phi = atan(xy.y, xy.x); 30 | 31 | uv.x = r * cos(phi) + 0.5; 32 | uv.y = r * sin(phi) + 0.5; 33 | } 34 | else 35 | { 36 | uv = fragTexCoord.xy; 37 | } 38 | 39 | fragColor = texture(texture0, uv); 40 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/grayscale.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 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor; 20 | 21 | // Convert texel color to grayscale using NTSC conversion weights 22 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 23 | 24 | // Calculate final fragment color 25 | finalColor = vec4(gray, gray, gray, texelColor.a); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/overdraw.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 | { 18 | // To show overdraw, we just render all the fragments 19 | // with a solid color and some transparency 20 | 21 | // NOTE: This is not a postpro render, 22 | // it will only render all screen texture in a plain color 23 | 24 | finalColor = vec4(1.0, 0.0, 0.0, 0.2); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/pixelizer.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 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | 20 | uniform float pixelWidth = 5.0; 21 | uniform float pixelHeight = 5.0; 22 | 23 | void main() 24 | { 25 | float dx = pixelWidth*(1.0/renderWidth); 26 | float dy = pixelHeight*(1.0/renderHeight); 27 | 28 | vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); 29 | 30 | vec3 tc = texture(texture0, coord).rgb; 31 | 32 | finalColor = vec4(tc, 1.0); 33 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/posterization.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 | float gamma = 0.6; 17 | float numColors = 8.0; 18 | 19 | void main() 20 | { 21 | // Texel color fetching from texture sampler 22 | vec3 texelColor = texture(texture0, fragTexCoord.xy).rgb; 23 | 24 | texelColor = pow(texelColor, vec3(gamma, gamma, gamma)); 25 | texelColor = texelColor*numColors; 26 | texelColor = floor(texelColor); 27 | texelColor = texelColor/numColors; 28 | texelColor = pow(texelColor, vec3(1.0/gamma)); 29 | 30 | finalColor = vec4(texelColor, 1.0); 31 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/predator.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 | { 18 | // Texel color fetching from texture sampler 19 | vec3 texelColor = texture(texture0, fragTexCoord).rgb; 20 | vec3 colors[3]; 21 | colors[0] = vec3(0.0, 0.0, 1.0); 22 | colors[1] = vec3(1.0, 1.0, 0.0); 23 | colors[2] = vec3(1.0, 0.0, 0.0); 24 | 25 | float lum = (texelColor.r + texelColor.g + texelColor.b)/3.0; 26 | 27 | int ix = (lum < 0.5)? 0:1; 28 | 29 | vec3 tc = mix(colors[ix], colors[ix + 1], (lum - float(ix)*0.5)/0.5); 30 | 31 | finalColor = vec4(tc, 1.0); 32 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/scanlines.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 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | float offset = 0.0; 20 | 21 | uniform float time; 22 | 23 | void main() 24 | { 25 | float frequency = renderHeight/3.0; 26 | /* 27 | // Scanlines method 1 28 | float tval = 0; //time 29 | vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); 30 | 31 | vec4 color = texture(texture0, fragTexCoord); 32 | 33 | color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); 34 | color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); 35 | color *= vec4(0.8, 1.0, 0.7, 1); 36 | color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); 37 | color *= 0.97 + 0.03*sin(110.0*tval); 38 | 39 | fragColor = color; 40 | */ 41 | // Scanlines method 2 42 | float globalPos = (fragTexCoord.y + offset) * frequency; 43 | float wavePos = cos((fract(globalPos) - 0.5)*3.14); 44 | 45 | // Texel color fetching from texture sampler 46 | vec4 texelColor = texture(texture0, fragTexCoord); 47 | 48 | finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos); 49 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/sobel.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 | uniform vec2 resolution = vec2(800, 450); 16 | 17 | void main() 18 | { 19 | float x = 1.0/resolution.x; 20 | float y = 1.0/resolution.y; 21 | 22 | vec4 horizEdge = vec4(0.0); 23 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 24 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; 25 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 26 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 27 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; 28 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 29 | 30 | vec4 vertEdge = vec4(0.0); 31 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 32 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; 33 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 34 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 35 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; 36 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 37 | 38 | vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); 39 | 40 | finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a); 41 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/swirl.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 | // NOTE: Render size values should be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | 20 | float radius = 250.0; 21 | float angle = 0.8; 22 | 23 | uniform vec2 center = vec2(200.0, 200.0); 24 | 25 | void main() 26 | { 27 | vec2 texSize = vec2(renderWidth, renderHeight); 28 | vec2 tc = fragTexCoord*texSize; 29 | tc -= center; 30 | 31 | float dist = length(tc); 32 | 33 | if (dist < radius) 34 | { 35 | float percent = (radius - dist)/radius; 36 | float theta = percent*percent*angle*8.0; 37 | float s = sin(theta); 38 | float c = cos(theta); 39 | 40 | tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); 41 | } 42 | 43 | tc += center; 44 | vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;; 45 | 46 | finalColor = vec4(color.rgb, 1.0);; 47 | } -------------------------------------------------------------------------------- /examples/shaders/shaders_model_shader.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shaders] example - Apply a shader to a 3d model 4 | -- 5 | -- NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, 6 | -- OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. 7 | -- 8 | -- NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example 9 | -- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders 10 | -- raylib comes with shaders ready for both versions, check raylib/shaders install folder 11 | -- 12 | -- This example has been created using raylib 1.6 (www.raylib.com) 13 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 14 | -- 15 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 16 | -- 17 | ------------------------------------------------------------------------------------------- 18 | 19 | -- Initialization 20 | ------------------------------------------------------------------------------------------- 21 | local screenWidth = 800 22 | local screenHeight = 450 23 | 24 | SetConfigFlags(FLAG_MSAA_4X_HINT) -- Enable Multi Sampling Anti Aliasing 4x (if available) 25 | 26 | InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader") 27 | 28 | -- Define the camera to look into our 3d world 29 | local camera = Camera(Vector3(3.0, 3.0, 3.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) 30 | 31 | local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model 32 | local texture = LoadTexture("resources/model/dwarf_diffuse.png") -- Load model texture 33 | local shader = LoadShader("resources/shaders/glsl330/base.vs", 34 | "resources/shaders/glsl330/grayscale.fs") -- Load model shader 35 | 36 | dwarf.material.shader = shader -- Set shader effect to 3d model 37 | dwarf.material.texDiffuse = texture -- Bind texture to model 38 | 39 | local position = Vector3(0.0, 0.0, 0.0) -- Set model position 40 | 41 | -- Setup orbital camera 42 | SetCameraMode(camera, CAMERA_ORBITAL) -- Set an orbital camera mode 43 | 44 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 45 | ------------------------------------------------------------------------------------------- 46 | 47 | -- Main game loop 48 | while not WindowShouldClose() do -- Detect window close button or ESC key 49 | -- Update 50 | --------------------------------------------------------------------------------------- 51 | UpdateCamera(camera) -- Update camera 52 | --------------------------------------------------------------------------------------- 53 | 54 | -- Draw 55 | --------------------------------------------------------------------------------------- 56 | BeginDrawing() 57 | 58 | ClearBackground(RAYWHITE) 59 | 60 | BeginMode3D(camera) 61 | 62 | DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture 63 | 64 | DrawGrid(10, 1.0) -- Draw a grid 65 | 66 | EndMode3D() 67 | 68 | DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY) 69 | 70 | DrawFPS(10, 10) 71 | 72 | EndDrawing() 73 | --------------------------------------------------------------------------------------- 74 | end 75 | 76 | -- De-Initialization 77 | ------------------------------------------------------------------------------------------- 78 | UnloadShader(shader) -- Unload shader 79 | UnloadTexture(texture) -- Unload texture 80 | UnloadModel(dwarf) -- Unload model 81 | 82 | CloseWindow() -- Close window and OpenGL context 83 | ------------------------------------------------------------------------------------------- 84 | -------------------------------------------------------------------------------- /examples/shaders/shaders_shapes_textures.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shaders] example - Apply a shader to some shape or texture 4 | -- 5 | -- NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, 6 | -- OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. 7 | -- 8 | -- NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example 9 | -- on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders 10 | -- raylib comes with shaders ready for both versions, check raylib/shaders install folder 11 | -- 12 | -- This example has been created using raylib 1.6 (www.raylib.com) 13 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 14 | -- 15 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 16 | -- 17 | ------------------------------------------------------------------------------------------- 18 | 19 | -- Initialization 20 | ------------------------------------------------------------------------------------------- 21 | local screenWidth = 800 22 | local screenHeight = 450 23 | 24 | InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders") 25 | 26 | local fudesumi = LoadTexture("resources/fudesumi.png") 27 | 28 | -- NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version 29 | local shader = LoadShader("resources/shaders/glsl330/base.vs", 30 | "resources/shaders/glsl330/grayscale.fs") 31 | 32 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 33 | ------------------------------------------------------------------------------------------- 34 | 35 | -- Main game loop 36 | while not WindowShouldClose() do -- Detect window close button or ESC key 37 | -- Update 38 | --------------------------------------------------------------------------------------- 39 | -- TODO: Update your variables here 40 | --------------------------------------------------------------------------------------- 41 | 42 | -- Draw 43 | --------------------------------------------------------------------------------------- 44 | BeginDrawing() 45 | 46 | ClearBackground(RAYWHITE) 47 | 48 | -- Start drawing with default shader 49 | 50 | DrawText("USING DEFAULT SHADER", 20, 40, 10, RED) 51 | 52 | DrawCircle(80, 120, 35, DARKBLUE) 53 | DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE) 54 | DrawCircleLines(80, 340, 80, DARKBLUE) 55 | 56 | 57 | -- Activate our custom shader to be applied on next shapes/textures drawings 58 | BeginShaderMode(shader) 59 | 60 | DrawText("USING CUSTOM SHADER", 190, 40, 10, RED) 61 | 62 | DrawRectangle(250 - 60, 90, 120, 60, RED) 63 | DrawRectangleGradient(250 - 90, 170, 180, 130, MAROON, GOLD) 64 | DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE) 65 | 66 | -- Activate our default shader for next drawings 67 | EndShaderMode() 68 | 69 | DrawText("USING DEFAULT SHADER", 370, 40, 10, RED) 70 | 71 | DrawTriangle(Vector2(430, 80), 72 | Vector2(430 - 60, 150), 73 | Vector2(430 + 60, 150), VIOLET) 74 | 75 | DrawTriangleLines(Vector2(430, 160), 76 | Vector2(430 - 20, 230), 77 | Vector2(430 + 20, 230), DARKBLUE) 78 | 79 | DrawPoly(Vector2(430, 320), 6, 80, 0, BROWN) 80 | 81 | -- Activate our custom shader to be applied on next shapes/textures drawings 82 | BeginShaderMode(shader) 83 | 84 | DrawTexture(fudesumi, 500, -30, WHITE) -- Using custom shader 85 | 86 | -- Activate our default shader for next drawings 87 | EndShaderMode() 88 | 89 | DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY) 90 | 91 | EndDrawing() 92 | --------------------------------------------------------------------------------------- 93 | end 94 | 95 | -- De-Initialization 96 | ------------------------------------------------------------------------------------------- 97 | UnloadShader(shader) -- Unload shader 98 | UnloadTexture(fudesumi) -- Unload texture 99 | 100 | CloseWindow() -- Close window and OpenGL context 101 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shapes/shapes_basic_shapes.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...) 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing") 18 | 19 | SetTargetFPS(60) -- Set target frames-per-second 20 | ------------------------------------------------------------------------------------------- 21 | 22 | -- Main game loop 23 | while not WindowShouldClose() do -- Detect window close button or ESC key 24 | -- Update 25 | --------------------------------------------------------------------------------------- 26 | -- TODO: Update your variables here 27 | --------------------------------------------------------------------------------------- 28 | 29 | -- Draw 30 | --------------------------------------------------------------------------------------- 31 | BeginDrawing() 32 | 33 | ClearBackground(RAYWHITE) 34 | 35 | DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY) 36 | 37 | DrawLine(18, 42, screenWidth - 18, 42, BLACK) 38 | 39 | DrawCircle(screenWidth/4, 120, 35, DARKBLUE) 40 | DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE) 41 | DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE) 42 | 43 | DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED) 44 | DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD) 45 | DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE) 46 | 47 | DrawTriangle(Vector2(screenWidth/4*3, 80), 48 | Vector2(screenWidth/4*3 - 60, 150), 49 | Vector2(screenWidth/4*3 + 60, 150), VIOLET) 50 | 51 | DrawTriangleLines(Vector2(screenWidth/4*3, 160), 52 | Vector2(screenWidth/4*3 - 20, 230), 53 | Vector2(screenWidth/4*3 + 20, 230), DARKBLUE) 54 | 55 | DrawPoly(Vector2(screenWidth/4*3, 320), 6, 80, 0, BROWN) 56 | 57 | EndDrawing() 58 | --------------------------------------------------------------------------------------- 59 | end 60 | 61 | -- De-Initialization 62 | ------------------------------------------------------------------------------------------- 63 | CloseWindow() -- Close window and OpenGL context 64 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shapes/shapes_colors_palette.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shapes] example - Draw raylib custom color palette 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette") 18 | 19 | SetTargetFPS(60) -- Set target frames-per-second 20 | ------------------------------------------------------------------------------------------- 21 | 22 | -- Main game loop 23 | while not WindowShouldClose() do -- Detect window close button or ESC key 24 | -- Update 25 | --------------------------------------------------------------------------------------- 26 | -- TODO: Update your variables here 27 | --------------------------------------------------------------------------------------- 28 | 29 | -- Draw 30 | --------------------------------------------------------------------------------------- 31 | BeginDrawing() 32 | 33 | ClearBackground(RAYWHITE) 34 | 35 | DrawText("raylib color palette", 28, 42, 20, BLACK) 36 | 37 | DrawRectangle(26, 80, 100, 100, DARKGRAY) 38 | DrawRectangle(26, 188, 100, 100, GRAY) 39 | DrawRectangle(26, 296, 100, 100, LIGHTGRAY) 40 | DrawRectangle(134, 80, 100, 100, MAROON) 41 | DrawRectangle(134, 188, 100, 100, RED) 42 | DrawRectangle(134, 296, 100, 100, PINK) 43 | DrawRectangle(242, 80, 100, 100, ORANGE) 44 | DrawRectangle(242, 188, 100, 100, GOLD) 45 | DrawRectangle(242, 296, 100, 100, YELLOW) 46 | DrawRectangle(350, 80, 100, 100, DARKGREEN) 47 | DrawRectangle(350, 188, 100, 100, LIME) 48 | DrawRectangle(350, 296, 100, 100, GREEN) 49 | DrawRectangle(458, 80, 100, 100, DARKBLUE) 50 | DrawRectangle(458, 188, 100, 100, BLUE) 51 | DrawRectangle(458, 296, 100, 100, SKYBLUE) 52 | DrawRectangle(566, 80, 100, 100, DARKPURPLE) 53 | DrawRectangle(566, 188, 100, 100, VIOLET) 54 | DrawRectangle(566, 296, 100, 100, PURPLE) 55 | DrawRectangle(674, 80, 100, 100, DARKBROWN) 56 | DrawRectangle(674, 188, 100, 100, BROWN) 57 | DrawRectangle(674, 296, 100, 100, BEIGE) 58 | 59 | 60 | DrawText("DARKGRAY", 65, 166, 10, BLACK) 61 | DrawText("GRAY", 93, 274, 10, BLACK) 62 | DrawText("LIGHTGRAY", 61, 382, 10, BLACK) 63 | DrawText("MAROON", 186, 166, 10, BLACK) 64 | DrawText("RED", 208, 274, 10, BLACK) 65 | DrawText("PINK", 204, 382, 10, BLACK) 66 | DrawText("ORANGE", 295, 166, 10, BLACK) 67 | DrawText("GOLD", 310, 274, 10, BLACK) 68 | DrawText("YELLOW", 300, 382, 10, BLACK) 69 | DrawText("DARKGREEN", 382, 166, 10, BLACK) 70 | DrawText("LIME", 420, 274, 10, BLACK) 71 | DrawText("GREEN", 410, 382, 10, BLACK) 72 | DrawText("DARKBLUE", 498, 166, 10, BLACK) 73 | DrawText("BLUE", 526, 274, 10, BLACK) 74 | DrawText("SKYBLUE", 505, 382, 10, BLACK) 75 | DrawText("DARKPURPLE", 592, 166, 10, BLACK) 76 | DrawText("VIOLET", 621, 274, 10, BLACK) 77 | DrawText("PURPLE", 620, 382, 10, BLACK) 78 | DrawText("DARKBROWN", 705, 166, 10, BLACK) 79 | DrawText("BROWN", 733, 274, 10, BLACK) 80 | DrawText("BEIGE", 737, 382, 10, BLACK) 81 | 82 | EndDrawing() 83 | --------------------------------------------------------------------------------------- 84 | end 85 | 86 | -- De-Initialization 87 | ------------------------------------------------------------------------------------------- 88 | CloseWindow() -- Close window and OpenGL context 89 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shapes/shapes_lines_bezier.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shapes] example - Cubic-bezier lines 4 | -- 5 | -- This example has been created using raylib 1.7 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2017 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | SetConfigFlags(FLAG_MSAA_4X_HINT); 18 | InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines") 19 | 20 | local startPoint = Vector2(0, 0) 21 | local endPoint = Vector2(screenWidth, screenHeight) 22 | 23 | SetTargetFPS(60) -- Set target frames-per-second 24 | ------------------------------------------------------------------------------------------- 25 | 26 | -- Main game loop 27 | while not WindowShouldClose() do -- Detect window close button or ESC key 28 | -- Update 29 | --------------------------------------------------------------------------------------- 30 | if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) then startPoint = GetMousePosition() 31 | elseif (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) then endPoint = GetMousePosition() end 32 | --------------------------------------------------------------------------------------- 33 | 34 | -- Draw 35 | --------------------------------------------------------------------------------------- 36 | BeginDrawing() 37 | 38 | ClearBackground(RAYWHITE) 39 | 40 | DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY) 41 | 42 | DrawLineBezier(startPoint, endPoint, 2.0, RED) 43 | 44 | EndDrawing() 45 | --------------------------------------------------------------------------------------- 46 | end 47 | 48 | -- De-Initialization 49 | ------------------------------------------------------------------------------------------- 50 | CloseWindow() -- Close window and OpenGL context 51 | ------------------------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /examples/shapes/shapes_logo_raylib.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shapes] example - Draw raylib logo using basic shapes 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | local luaColor = Color(0, 0, 124) 17 | 18 | InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes") 19 | 20 | SetTargetFPS(60) -- Set target frames-per-second 21 | ------------------------------------------------------------------------------------------- 22 | 23 | -- Main game loop 24 | while not WindowShouldClose() do -- Detect window close button or ESC key 25 | -- Update 26 | --------------------------------------------------------------------------------------- 27 | -- TODO: Update your variables here 28 | --------------------------------------------------------------------------------------- 29 | 30 | -- Draw 31 | --------------------------------------------------------------------------------------- 32 | BeginDrawing() 33 | 34 | ClearBackground(RAYWHITE) 35 | 36 | DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, luaColor) 37 | DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE) 38 | DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, luaColor) 39 | DrawText("lua", screenWidth/2 - 29, screenHeight/2 + 18, 50, luaColor) 40 | 41 | DrawText("this is NOT a texture!", 350, 370, 10, GRAY) 42 | 43 | EndDrawing() 44 | --------------------------------------------------------------------------------------- 45 | end 46 | 47 | -- De-Initialization 48 | ------------------------------------------------------------------------------------------- 49 | CloseWindow() -- Close window and OpenGL context 50 | ------------------------------------------------------------------------------------------- 51 | -------------------------------------------------------------------------------- /examples/text/resources/KAISG.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/KAISG.ttf -------------------------------------------------------------------------------- /examples/text/resources/bmfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/bmfont.png -------------------------------------------------------------------------------- /examples/text/resources/custom_alagard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/custom_alagard.png -------------------------------------------------------------------------------- /examples/text/resources/custom_jupiter_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/custom_jupiter_crash.png -------------------------------------------------------------------------------- /examples/text/resources/custom_mecha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/custom_mecha.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/alagard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/alagard.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/alpha_beta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/alpha_beta.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/jupiter_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/jupiter_crash.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/mecha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/mecha.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/pixantiqua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/pixantiqua.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/pixelplay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/pixelplay.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/romulus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/romulus.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/setback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/fonts/setback.png -------------------------------------------------------------------------------- /examples/text/resources/pixantiqua.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/pixantiqua.ttf -------------------------------------------------------------------------------- /examples/text/resources/pixantiqua_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/text/resources/pixantiqua_0.png -------------------------------------------------------------------------------- /examples/text/text_bmfont_ttf.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [text] example - BMFont and TTF SpriteFonts loading 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading") 18 | 19 | local msgBm = "THIS IS AN AngelCode SPRITE FONT" 20 | local msgTtf = "THIS FONT has been GENERATED from TTF" 21 | 22 | -- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) 23 | local fontBm = LoadFont("resources/bmfont.fnt") -- BMFont (AngelCode) 24 | local fontTtf = LoadFont("resources/pixantiqua.ttf") -- TTF font 25 | 26 | local fontPosition = Vector2(0, 0) 27 | fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2 28 | fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80 29 | 30 | SetTargetFPS(60) -- Set target frames-per-second 31 | ------------------------------------------------------------------------------------------- 32 | 33 | -- Main game loop 34 | while not WindowShouldClose() do -- Detect window close button or ESC key 35 | -- Update 36 | --------------------------------------------------------------------------------------- 37 | -- TODO: Update variables here... 38 | --------------------------------------------------------------------------------------- 39 | 40 | -- Draw 41 | --------------------------------------------------------------------------------------- 42 | BeginDrawing() 43 | 44 | ClearBackground(RAYWHITE) 45 | 46 | DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON) 47 | DrawTextEx(fontTtf, msgTtf, Vector2(60.0, 240.0), fontTtf.baseSize, 2, LIME) 48 | 49 | EndDrawing() 50 | --------------------------------------------------------------------------------------- 51 | end 52 | 53 | -- De-Initialization 54 | ------------------------------------------------------------------------------------------- 55 | UnloadSpriteFont(fontBm) -- AngelCode SpriteFont unloading 56 | UnloadSpriteFont(fontTtf) -- TTF SpriteFont unloading 57 | 58 | CloseWindow() -- Close window and OpenGL context 59 | ------------------------------------------------------------------------------------------- 60 | -------------------------------------------------------------------------------- /examples/text/text_bmfont_unordered.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [text] example - BMFont unordered chars loading and drawing 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing") 18 | 19 | -- NOTE: Using chars outside the [32..127] limits! 20 | -- NOTE: If a character is not found in the font, it just renders a space 21 | local msg = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ" 22 | 23 | -- NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) 24 | local font = LoadFont("resources/pixantiqua.fnt") -- BMFont (AngelCode) 25 | 26 | SetTargetFPS(60) 27 | ------------------------------------------------------------------------------------------- 28 | 29 | -- Main game loop 30 | while not WindowShouldClose() do -- Detect window close button or ESC key 31 | -- Update 32 | --------------------------------------------------------------------------------------- 33 | -- TODO: Update variables here... 34 | --------------------------------------------------------------------------------------- 35 | 36 | -- Draw 37 | --------------------------------------------------------------------------------------- 38 | BeginDrawing() 39 | 40 | ClearBackground(RAYWHITE) 41 | 42 | DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY) 43 | DrawText(string.format("Font base size: %i", font.baseSize), 40, 80, 20, GRAY) 44 | DrawText(string.format("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY) 45 | 46 | DrawTextEx(font, msg, Vector2(40, 180), font.baseSize, 0, MAROON) 47 | 48 | EndDrawing() 49 | --------------------------------------------------------------------------------------- 50 | end 51 | 52 | -- De-Initialization 53 | ------------------------------------------------------------------------------------------- 54 | UnloadSpriteFont(font) -- AngelCode SpriteFont unloading 55 | 56 | CloseWindow() -- Close window and OpenGL context 57 | ------------------------------------------------------------------------------------------- 58 | -------------------------------------------------------------------------------- /examples/text/text_format_text.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [text] example - Text formatting 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting") 18 | 19 | local score = 100020 20 | local hiscore = 200450 21 | local lives = 5 22 | 23 | SetTargetFPS(60) -- Set target frames-per-second 24 | ------------------------------------------------------------------------------------------- 25 | 26 | -- Main game loop 27 | while not WindowShouldClose() do -- Detect window close button or ESC key 28 | -- Update 29 | --------------------------------------------------------------------------------------- 30 | -- TODO: Update your variables here 31 | --------------------------------------------------------------------------------------- 32 | 33 | -- Draw 34 | --------------------------------------------------------------------------------------- 35 | BeginDrawing() 36 | 37 | ClearBackground(RAYWHITE) 38 | 39 | DrawText(string.format("Score: %08i", score), 200, 80, 20, RED) 40 | 41 | DrawText(string.format("HiScore: %08i", hiscore), 200, 120, 20, GREEN) 42 | 43 | DrawText(string.format("Lives: %02i", lives), 200, 160, 40, BLUE) 44 | 45 | DrawText(string.format("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK) 46 | 47 | EndDrawing() 48 | --------------------------------------------------------------------------------------- 49 | end 50 | 51 | -- De-Initialization 52 | ------------------------------------------------------------------------------------------- 53 | CloseWindow() -- Close window and OpenGL context 54 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/text/text_input_box.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [shapes] example - Input Box 4 | -- 5 | -- This example has been created using raylib 1.7 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2017 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | local MAX_INPUT_CHARS = 9 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [shapes] example - input box") 20 | 21 | local name = ' ' -- TODO: name should be a string but its values must be accessed individually... 22 | local letterCount = 0 23 | 24 | local textBox = Rectangle(screenWidth/2 - 100, 180, 225, 50) 25 | local mouseOnText = false 26 | 27 | local framesCounter = 0 28 | 29 | SetTargetFPS(60) -- Set target frames-per-second 30 | ------------------------------------------------------------------------------------------- 31 | 32 | -- Main game loop 33 | while not WindowShouldClose() do -- Detect window close button or ESC key 34 | -- Update 35 | --------------------------------------------------------------------------------------- 36 | if (CheckCollisionPointRec(GetMousePosition(), textBox)) then mouseOnText = true 37 | else mouseOnText = false end 38 | 39 | if (mouseOnText) then 40 | local key = GetKeyPressed() 41 | 42 | -- NOTE: Only allow keys in range [32..125] 43 | if ((key >= 32) and (key <= 125) and (letterCount < MAX_INPUT_CHARS)) then 44 | name[letterCount] = key 45 | letterCount = letterCount + 1 46 | end 47 | 48 | if (key == KEY_BACKSPACE) then 49 | letterCount = letterCount - 1 50 | name[letterCount] = '\0' 51 | 52 | if (letterCount < 0) then letterCount = 0 end 53 | end 54 | end 55 | 56 | if (mouseOnText) then framesCounter = framesCounter + 1 57 | else framesCounter = 0 end 58 | --------------------------------------------------------------------------------------- 59 | 60 | -- Draw 61 | --------------------------------------------------------------------------------------- 62 | BeginDrawing() 63 | 64 | ClearBackground(RAYWHITE) 65 | 66 | DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY) 67 | 68 | DrawRectangleRec(textBox, LIGHTGRAY) 69 | if (mouseOnText) then DrawRectangleLines(textBox.x, textBox.y, textBox.width, textBox.height, RED) 70 | else DrawRectangleLines(textBox.x, textBox.y, textBox.width, textBox.height, DARKGRAY) end 71 | 72 | DrawText(name, textBox.x + 5, textBox.y + 8, 40, MAROON) 73 | 74 | DrawText(string.format("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY) 75 | 76 | if (mouseOnText) then 77 | if (letterCount < MAX_INPUT_CHARS) then 78 | -- Draw blinking underscore char 79 | if (((framesCounter/20)%2) == 0) then DrawText("_", textBox.x + 8 + MeasureText(name, 40), textBox.y + 12, 40, MAROON) end 80 | else DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, GRAY) end 81 | end 82 | 83 | EndDrawing() 84 | --------------------------------------------------------------------------------------- 85 | end 86 | 87 | -- De-Initialization 88 | ------------------------------------------------------------------------------------------- 89 | CloseWindow() -- Close window and OpenGL context 90 | ------------------------------------------------------------------------------------------- 91 | -------------------------------------------------------------------------------- /examples/text/text_raylib_fonts.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [text] example - raylib bitmap font (rbmf) loading and usage 4 | -- 5 | -- NOTE: raylib is distributed with some free to use fonts (even for commercial pourposes!) 6 | -- To view details and credits for those fonts, check raylib license file 7 | -- 8 | -- This example has been created using raylib 1.6 (www.raylib.com) 9 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 10 | -- 11 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 12 | -- 13 | ------------------------------------------------------------------------------------------- 14 | 15 | -- Initialization 16 | ------------------------------------------------------------------------------------------- 17 | local screenWidth = 800 18 | local screenHeight = 450 19 | 20 | InitWindow(screenWidth, screenHeight, "raylib [text] example - rBMF fonts") 21 | 22 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 23 | local fonts = {} 24 | 25 | fonts[1] = LoadFont("resources/fonts/alagard.png") 26 | fonts[2] = LoadFont("resources/fonts/pixelplay.png") 27 | fonts[3] = LoadFont("resources/fonts/mecha.png") 28 | fonts[4] = LoadFont("resources/fonts/setback.png") 29 | fonts[5] = LoadFont("resources/fonts/romulus.png") 30 | fonts[6] = LoadFont("resources/fonts/pixantiqua.png") 31 | fonts[7] = LoadFont("resources/fonts/alpha_beta.png") 32 | fonts[8] = LoadFont("resources/fonts/jupiter_crash.png") 33 | 34 | local messages = { "ALAGARD FONT designed by Hewett Tsoi", 35 | "PIXELPLAY FONT designed by Aleksander Shevchuk", 36 | "MECHA FONT designed by Captain Falcon", 37 | "SETBACK FONT designed by Brian Kent (AEnigma)", 38 | "ROMULUS FONT designed by Hewett Tsoi", 39 | "PIXANTIQUA FONT designed by Gerhard Grossmann", 40 | "ALPHA_BETA FONT designed by Brian Kent (AEnigma)", 41 | "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" } 42 | 43 | local spacings = { 2, 4, 8, 4, 3, 4, 4, 1 } 44 | 45 | local positions = {} 46 | 47 | for i = 1, 8 do 48 | positions[i] = Vector2(0, 0) 49 | positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2 50 | positions[i].y = 60 + fonts[i].baseSize + 45*(i - 1) 51 | end 52 | 53 | -- Small Y position corrections 54 | positions[4].y = positions[4].y + 8 55 | positions[5].y = positions[5].y + 2 56 | positions[8].y = positions[8].y - 8 57 | 58 | local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED } 59 | 60 | SetTargetFPS(60) -- Set target frames-per-second 61 | ------------------------------------------------------------------------------------------- 62 | 63 | -- Main game loop 64 | while not WindowShouldClose() do -- Detect window close button or ESC key 65 | -- Update 66 | --------------------------------------------------------------------------------------- 67 | -- TODO: Update your variables here 68 | --------------------------------------------------------------------------------------- 69 | 70 | -- Draw 71 | --------------------------------------------------------------------------------------- 72 | BeginDrawing() 73 | 74 | ClearBackground(RAYWHITE) 75 | 76 | DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY) 77 | DrawLine(220, 50, 590, 50, DARKGRAY) 78 | 79 | for i = 1, 8 do 80 | DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]) 81 | end 82 | 83 | EndDrawing() 84 | --------------------------------------------------------------------------------------- 85 | end 86 | 87 | -- De-Initialization 88 | ------------------------------------------------------------------------------------------- 89 | for i = 1, 8 do UnloadSpriteFont(fonts[i]) end -- SpriteFont unloading 90 | 91 | CloseWindow() -- Close window and OpenGL context 92 | ------------------------------------------------------------------------------------------- 93 | -------------------------------------------------------------------------------- /examples/text/text_sprite_fonts.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [text] example - SpriteFont loading and usage 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage") 18 | 19 | local msg1 = "THIS IS A custom SPRITE FONT..." 20 | local msg2 = "...and this is ANOTHER CUSTOM font..." 21 | local msg3 = "...and a THIRD one! GREAT! :D" 22 | 23 | -- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) 24 | local font1 = LoadFont("resources/custom_mecha.png") -- SpriteFont loading 25 | local font2 = LoadFont("resources/custom_alagard.png") -- SpriteFont loading 26 | local font3 = LoadFont("resources/custom_jupiter_crash.png") -- SpriteFont loading 27 | 28 | local fontPosition1 = Vector2(0, 0) 29 | local fontPosition2 = Vector2(0, 0) 30 | local fontPosition3 = Vector2(0, 0) 31 | 32 | fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2 33 | fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80 34 | 35 | fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2 36 | fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10 37 | 38 | fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2 39 | fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50 40 | 41 | SetTargetFPS(60) -- Set target frames-per-second 42 | ------------------------------------------------------------------------------------------- 43 | 44 | -- Main game loop 45 | while not WindowShouldClose() do -- Detect window close button or ESC key 46 | -- Update 47 | --------------------------------------------------------------------------------------- 48 | -- TODO: Update variables here... 49 | --------------------------------------------------------------------------------------- 50 | 51 | -- Draw 52 | --------------------------------------------------------------------------------------- 53 | BeginDrawing() 54 | 55 | ClearBackground(RAYWHITE) 56 | 57 | DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE) 58 | DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE) 59 | DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE) 60 | 61 | EndDrawing() 62 | --------------------------------------------------------------------------------------- 63 | end 64 | 65 | -- De-Initialization 66 | ------------------------------------------------------------------------------------------- 67 | UnloadSpriteFont(font1) -- SpriteFont unloading 68 | UnloadSpriteFont(font2) -- SpriteFont unloading 69 | UnloadSpriteFont(font3) -- SpriteFont unloading 70 | 71 | CloseWindow() -- Close window and OpenGL context 72 | ------------------------------------------------------------------------------------------- 73 | -------------------------------------------------------------------------------- /examples/text/text_writing_anim.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [text] example - Text Writing Animation 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim") 18 | 19 | local message = "This sample illustrates a text writing\nanimation effect! Check it out! )" 20 | 21 | local framesCounter = 0 22 | 23 | SetTargetFPS(60) -- Set target frames-per-second 24 | ------------------------------------------------------------------------------------------- 25 | 26 | -- Main game loop 27 | while not WindowShouldClose() do -- Detect window close button or ESC key 28 | -- Update 29 | --------------------------------------------------------------------------------------- 30 | framesCounter = framesCounter + 1 31 | 32 | if (IsKeyPressed(KEY_ENTER)) then framesCounter = 0 end 33 | --------------------------------------------------------------------------------------- 34 | 35 | -- Draw 36 | --------------------------------------------------------------------------------------- 37 | BeginDrawing() 38 | 39 | ClearBackground(RAYWHITE) 40 | 41 | DrawText(string.sub(message, 0, framesCounter//10), 210, 160, 20, MAROON) 42 | 43 | DrawText("PRESS [ENTER] to RESTART!", 240, 280, 20, LIGHTGRAY) 44 | 45 | EndDrawing() 46 | --------------------------------------------------------------------------------------- 47 | end 48 | 49 | -- De-Initialization 50 | ------------------------------------------------------------------------------------------- 51 | CloseWindow() -- Close window and OpenGL context 52 | ------------------------------------------------------------------------------------------- 53 | -------------------------------------------------------------------------------- /examples/textures/resources/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/textures/resources/cat.png -------------------------------------------------------------------------------- /examples/textures/resources/parrots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/textures/resources/parrots.png -------------------------------------------------------------------------------- /examples/textures/resources/raylib_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/textures/resources/raylib_logo.png -------------------------------------------------------------------------------- /examples/textures/resources/scarfy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/textures/resources/scarfy.png -------------------------------------------------------------------------------- /examples/textures/resources/smoke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/textures/resources/smoke.png -------------------------------------------------------------------------------- /examples/textures/resources/wabbit_alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/examples/textures/resources/wabbit_alpha.png -------------------------------------------------------------------------------- /examples/textures/textures_bunnymark.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Bunnymark 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) 9 | -- 10 | -------------------------------------------------------------------------------------------- 11 | 12 | local MAX_BUNNIES = 100000 -- 100K bunnies limit 13 | 14 | -- This is the maximum amount of elements (quads) per batch 15 | -- NOTE: This value is defined in [rlgl] module and can be changed there 16 | local MAX_BATCH_ELEMENTS = 8192 17 | 18 | -- Create the Bunny class. 19 | Bunny = {} 20 | Bunny.__index = Bunny 21 | function Bunny:new(pos, spd, col) 22 | local bunny = {} 23 | setmetatable(bunny,Bunny) 24 | bunny.position = pos 25 | bunny.speed = spd 26 | bunny.color = col 27 | return bunny 28 | end 29 | function Bunny:update(texture) 30 | self.position.x = self.position.x + self.speed.x 31 | self.position.y = self.position.y + self.speed.y 32 | if ((self.position.x + texture.width/2) > GetScreenWidth()) or ((self.position.x + texture.width/2) < 0) then 33 | self.speed.x = self.speed.x * -1 34 | end 35 | if ((self.position.y + texture.height/2) > GetScreenHeight()) or ((self.position.y + texture.height/2 - 40) < 0) then 36 | self.speed.y = self.speed.y * -1 37 | end 38 | end 39 | 40 | -- Initialization 41 | ---------------------------------------------------------------------------------------- 42 | local screenWidth = 800 43 | local screenHeight = 450 44 | 45 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark") 46 | 47 | -- Load bunny texture 48 | local texBunny = LoadTexture("resources/wabbit_alpha.png") 49 | 50 | local bunnies = {} 51 | 52 | SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 53 | ---------------------------------------------------------------------------------------- 54 | 55 | -- Main game loop 56 | while not WindowShouldClose() do -- Detect window close button or ESC key 57 | -- Update 58 | ------------------------------------------------------------------------------------ 59 | if IsMouseButtonDown(MOUSE_LEFT_BUTTON) then 60 | -- Create more bunnies 61 | for i = 1, 100 do 62 | if #bunnies < MAX_BUNNIES then 63 | local speed = Vector2(GetRandomValue(-250, 250) / 60, GetRandomValue(-250, 250) / 60) 64 | local color = Color(GetRandomValue(50, 240), GetRandomValue(80, 240), GetRandomValue(100, 240), 255) 65 | --bunnies[#bunnies] = Bunny:new(nil, GetMousePosition(), speed, color) 66 | table.insert(bunnies, Bunny:new(GetMousePosition(), speed, color)) 67 | end 68 | end 69 | end 70 | 71 | -- Update bunnies 72 | for i = 1, #bunnies do 73 | bunnies[i]:update(texBunny) 74 | end 75 | ------------------------------------------------------------------------------------ 76 | 77 | -- Draw 78 | ------------------------------------------------------------------------------------ 79 | BeginDrawing(); 80 | 81 | ClearBackground(RAYWHITE); 82 | 83 | for i = 1, #bunnies do 84 | -- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), 85 | -- a draw call is launched and buffer starts being filled again; 86 | -- before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... 87 | -- Process of sending data is costly and it could happen that GPU data has not been completely 88 | -- processed for drawing while new data is tried to be sent (updating current in-use buffers) 89 | -- it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies 90 | DrawTexture(texBunny, math.floor(bunnies[i].position.x), math.floor(bunnies[i].position.y), bunnies[i].color); 91 | end 92 | 93 | DrawRectangle(0, 0, screenWidth, 40, BLACK) 94 | DrawText("bunnies: " .. #bunnies, 120, 10, 20, GREEN) 95 | DrawText("batched draw calls: " .. (1 + #bunnies / MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON) 96 | -- DrawText(FormatText("bunnies: %i", #bunnies), 120, 10, 20, GREEN) 97 | -- DrawText(FormatText("batched draw calls: %i", 1 + #bunnies/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON) 98 | 99 | DrawFPS(10, 10) 100 | 101 | EndDrawing() 102 | ------------------------------------------------------------------------------------ 103 | end 104 | 105 | -- De-Initialization 106 | ---------------------------------------------------------------------------------------- 107 | 108 | UnloadTexture(texBunny) -- Unload bunny texture 109 | 110 | CloseWindow() -- Close window and OpenGL context 111 | ---------------------------------------------------------------------------------------- 112 | -------------------------------------------------------------------------------- /examples/textures/textures_image_drawing.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Image loading and drawing on it 4 | -- 5 | -- NOTE: Images are loaded in CPU memory (RAM) textures are loaded in GPU memory (VRAM) 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing") 20 | 21 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 22 | 23 | local cat = LoadImage("resources/cat.png") -- Load image in CPU memory (RAM) 24 | cat = ImageCrop(cat, Rectangle(100, 10, 280, 380)) -- Crop an image piece 25 | cat = ImageFlipHorizontal(cat) -- Flip cropped image horizontally 26 | cat = ImageResize(cat, 150, 200) -- Resize flipped-cropped image 27 | 28 | local parrots = LoadImage("resources/parrots.png") -- Load image in CPU memory (RAM) 29 | 30 | -- Draw one image over the other with a scaling of 1.5f 31 | parrots = ImageDraw(parrots, cat, Rectangle(0, 0, cat.width, cat.height), Rectangle(30, 40, cat.width*1.5, cat.height*1.5)) 32 | parrots = ImageCrop(parrots, Rectangle(0, 50, parrots.width, parrots.height - 100)) -- Crop resulting image 33 | 34 | UnloadImage(cat) -- Unload image from RAM 35 | 36 | local texture = LoadTextureFromImage(parrots) -- Image converted to texture, uploaded to GPU memory (VRAM) 37 | UnloadImage(parrots) -- Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM 38 | 39 | SetTargetFPS(60) 40 | ------------------------------------------------------------------------------------------- 41 | 42 | -- Main game loop 43 | while not WindowShouldClose() do -- Detect window close button or ESC key 44 | -- Update 45 | --------------------------------------------------------------------------------------- 46 | -- TODO: Update your variables here 47 | --------------------------------------------------------------------------------------- 48 | 49 | -- Draw 50 | --------------------------------------------------------------------------------------- 51 | BeginDrawing() 52 | 53 | ClearBackground(RAYWHITE) 54 | 55 | DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE) 56 | DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY) 57 | 58 | DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY) 59 | DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY) 60 | 61 | EndDrawing() 62 | --------------------------------------------------------------------------------------- 63 | end 64 | 65 | -- De-Initialization 66 | ------------------------------------------------------------------------------------------- 67 | UnloadTexture(texture) -- Texture unloading 68 | 69 | CloseWindow() -- Close window and OpenGL context 70 | ------------------------------------------------------------------------------------------- 71 | -------------------------------------------------------------------------------- /examples/textures/textures_image_loading.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Image loading and texture creation 4 | -- 5 | -- NOTE: Images are loaded in CPU memory (RAM) textures are loaded in GPU memory (VRAM) 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading") 20 | 21 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 22 | 23 | local image = LoadImage("resources/raylib_logo.png") -- Loaded in CPU memory (RAM) 24 | local texture = LoadTextureFromImage(image) -- Image converted to texture, GPU memory (VRAM) 25 | 26 | UnloadImage(image) -- Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM 27 | ------------------------------------------------------------------------------------------- 28 | 29 | -- Main game loop 30 | while not WindowShouldClose() do -- Detect window close button or ESC key 31 | -- Update 32 | --------------------------------------------------------------------------------------- 33 | -- TODO: Update your variables here 34 | --------------------------------------------------------------------------------------- 35 | 36 | -- Draw 37 | --------------------------------------------------------------------------------------- 38 | BeginDrawing() 39 | 40 | ClearBackground(RAYWHITE) 41 | 42 | DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE) 43 | 44 | DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY) 45 | 46 | EndDrawing() 47 | --------------------------------------------------------------------------------------- 48 | end 49 | 50 | -- De-Initialization 51 | ------------------------------------------------------------------------------------------- 52 | UnloadTexture(texture) -- Texture unloading 53 | 54 | CloseWindow() -- Close window and OpenGL context 55 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/textures/textures_logo_raylib.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Texture loading and drawing 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing") 18 | 19 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 20 | local texture = LoadTexture("resources/raylib_logo.png") -- Texture loading 21 | ------------------------------------------------------------------------------------------- 22 | 23 | -- Main game loop 24 | while not WindowShouldClose() do -- Detect window close button or ESC key 25 | -- Update 26 | --------------------------------------------------------------------------------------- 27 | -- TODO: Update your variables here 28 | --------------------------------------------------------------------------------------- 29 | 30 | -- Draw 31 | --------------------------------------------------------------------------------------- 32 | BeginDrawing() 33 | 34 | ClearBackground(RAYWHITE) 35 | 36 | DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE) 37 | 38 | DrawText("this IS a texture!", 360, 370, 10, GRAY) 39 | 40 | EndDrawing() 41 | --------------------------------------------------------------------------------------- 42 | end 43 | 44 | -- De-Initialization 45 | ------------------------------------------------------------------------------------------- 46 | UnloadTexture(texture) -- Texture unloading 47 | 48 | CloseWindow() -- Close window and OpenGL context 49 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/textures/textures_particles_blending.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib example - particles trail blending 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | MAX_PARTICLES = 200 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles trail blending") 20 | 21 | -- Particles pool, reuse them! 22 | local mouseTail = {} 23 | 24 | -- Initialize particles 25 | for i = 1, MAX_PARTICLES do 26 | mouseTail[i] = {} 27 | mouseTail[i].position = Vector2(0, 0) 28 | mouseTail[i].color = Color(GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255) 29 | mouseTail[i].alpha = 1.0 30 | mouseTail[i].size = GetRandomValue(1, 30)/20.0 31 | mouseTail[i].rotation = GetRandomValue(0, 360) 32 | mouseTail[i].active = false 33 | end 34 | 35 | local gravity = 3.0 36 | 37 | local smoke = LoadTexture("resources/smoke.png") 38 | 39 | local blending = BLEND_ALPHA 40 | 41 | SetTargetFPS(60) 42 | ------------------------------------------------------------------------------------------- 43 | 44 | -- Main game loop 45 | while not WindowShouldClose() do -- Detect window close button or ESC key 46 | -- Update 47 | --------------------------------------------------------------------------------------- 48 | 49 | -- Activate one particle every frame and Update active particles 50 | -- NOTE: Particles initial position should be mouse position when activated 51 | -- NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0) 52 | -- NOTE: When a particle disappears, active = false and it can be reused. 53 | for i = 1, MAX_PARTICLES do 54 | if (not mouseTail[i].active) then 55 | mouseTail[i].active = true 56 | mouseTail[i].alpha = 1.0 57 | mouseTail[i].position = GetMousePosition() 58 | break 59 | end 60 | end 61 | 62 | for i = 1, MAX_PARTICLES do 63 | if (mouseTail[i].active) then 64 | mouseTail[i].position.y = mouseTail[i].position.y + gravity 65 | mouseTail[i].alpha = mouseTail[i].alpha - 0.01 66 | 67 | if (mouseTail[i].alpha <= 0.0) then mouseTail[i].active = false end 68 | 69 | mouseTail[i].rotation = mouseTail[i].rotation + 5.0 70 | end 71 | end 72 | 73 | if (IsKeyPressed(KEY_SPACE)) then 74 | if (blending == BLEND_ALPHA) then blending = BLEND_ADDITIVE 75 | else blending = BLEND_ALPHA end 76 | end 77 | --------------------------------------------------------------------------------------- 78 | 79 | -- Draw 80 | --------------------------------------------------------------------------------------- 81 | BeginDrawing() 82 | 83 | ClearBackground(DARKGRAY) 84 | 85 | BeginBlendMode(blending) 86 | 87 | -- Draw active particles 88 | for i = 1, MAX_PARTICLES do 89 | if (mouseTail[i].active) then 90 | DrawTexturePro(smoke, Rectangle(0, 0, smoke.width, smoke.height), 91 | Rectangle(mouseTail[i].position.x, mouseTail[i].position.y, 92 | smoke.width*mouseTail[i].size//1, smoke.height*mouseTail[i].size//1), 93 | Vector2(smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2), 94 | mouseTail[i].rotation, Fade(mouseTail[i].color, mouseTail[i].alpha)) end 95 | end 96 | 97 | EndBlendMode() 98 | 99 | DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK) 100 | 101 | if (blending == BLEND_ALPHA) then DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK) 102 | else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE) end 103 | 104 | EndDrawing() 105 | --------------------------------------------------------------------------------------- 106 | end 107 | 108 | -- De-Initialization 109 | ------------------------------------------------------------------------------------------- 110 | UnloadTexture(smoke) 111 | 112 | CloseWindow() -- Close window and OpenGL context 113 | ------------------------------------------------------------------------------------------- 114 | -------------------------------------------------------------------------------- /examples/textures/textures_raw_data.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Load textures from raw data 4 | -- 5 | -- NOTE: Images are loaded in CPU memory (RAM) textures are loaded in GPU memory (VRAM) 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | --#include -- Required for malloc() and free() 15 | 16 | -- Initialization 17 | ------------------------------------------------------------------------------------------- 18 | local screenWidth = 800 19 | local screenHeight = 450 20 | 21 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data") 22 | 23 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 24 | 25 | -- Load RAW image data (512x512, 32bit RGBA, no file header) 26 | local fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, TextureFormat.UNCOMPRESSED_R8G8B8A8, 0) 27 | local fudesumi = LoadTextureFromImage(fudesumiRaw) -- Upload CPU (RAM) image to GPU (VRAM) 28 | UnloadImage(fudesumiRaw) -- Unload CPU (RAM) image data 29 | 30 | -- Generate a checked texture by code (1024x1024 pixels) 31 | local width = 1024 32 | local height = 1024 33 | 34 | -- Dynamic memory allocation to store pixels data (Color type) 35 | local pixels = {} 36 | 37 | for y = 1, height do 38 | for x = 1, width do 39 | if ((((x - 1)/32+(y - 1)//32)//1)%2 == 0) then pixels[(y - 1)*height + x] = ORANGE 40 | else pixels[(y - 1)*height + x] = GOLD end 41 | end 42 | end 43 | 44 | -- Load pixels data into an image structure and create texture 45 | local checkedIm = LoadImageEx(pixels, width, height) 46 | local checked = LoadTextureFromImage(checkedIm) 47 | UnloadImage(checkedIm) -- Unload CPU (RAM) image data 48 | 49 | -- Dynamic memory must be freed after using it 50 | --free(pixels) -- Unload CPU (RAM) pixels data 51 | ------------------------------------------------------------------------------------------- 52 | 53 | -- Main game loop 54 | while not WindowShouldClose() do -- Detect window close button or ESC key 55 | -- Update 56 | --------------------------------------------------------------------------------------- 57 | -- TODO: Update your variables here 58 | --------------------------------------------------------------------------------------- 59 | 60 | -- Draw 61 | --------------------------------------------------------------------------------------- 62 | BeginDrawing() 63 | 64 | ClearBackground(RAYWHITE) 65 | 66 | DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.3)) 67 | DrawTexture(fudesumi, 430, -30, WHITE) 68 | 69 | DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN) 70 | DrawText("GENERATED by CODE", 72, 164, 30, BROWN) 71 | DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN) 72 | 73 | DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN) 74 | 75 | EndDrawing() 76 | --------------------------------------------------------------------------------------- 77 | end 78 | 79 | -- De-Initialization 80 | ------------------------------------------------------------------------------------------- 81 | UnloadTexture(fudesumi) -- Texture unloading 82 | UnloadTexture(checked) -- Texture unloading 83 | 84 | CloseWindow() -- Close window and OpenGL context 85 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/textures/textures_rectangle.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Texture loading and drawing a part defined by a rectangle 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | local MAX_FRAME_SPEED = 14 13 | local MIN_FRAME_SPEED = 1 14 | 15 | -- Initialization 16 | ------------------------------------------------------------------------------------------- 17 | local screenWidth = 800 18 | local screenHeight = 450 19 | 20 | InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle") 21 | 22 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 23 | local scarfy = LoadTexture("resources/scarfy.png") -- Texture loading 24 | 25 | local position = Vector2(350.0, 280.0) 26 | local frameRec = Rectangle(0, 0, scarfy.width/6, scarfy.height) 27 | local currentFrame = 0 28 | 29 | local framesCounter = 0 30 | local framesSpeed = 8 -- Number of spritesheet frames shown by second 31 | 32 | SetTargetFPS(60); -- Set our game to run at 60 frames-per-second 33 | ------------------------------------------------------------------------------------------- 34 | 35 | -- Main game loop 36 | while not WindowShouldClose() do -- Detect window close button or ESC key 37 | -- Update 38 | --------------------------------------------------------------------------------------- 39 | framesCounter = framesCounter + 1 40 | 41 | if (framesCounter >= (60/framesSpeed)) then 42 | framesCounter = 0 43 | currentFrame = currentFrame + 1 44 | 45 | if (currentFrame > 5) then currentFrame = 0 end 46 | 47 | frameRec.x = currentFrame*scarfy.width/6 48 | end 49 | 50 | if (IsKeyPressed(KEY_RIGHT)) then framesSpeed = framesSpeed + 1 51 | elseif (IsKeyPressed(KEY_LEFT)) then framesSpeed = framesSpeed - 1 end 52 | 53 | if (framesSpeed > MAX_FRAME_SPEED) then framesSpeed = MAX_FRAME_SPEED 54 | elseif (framesSpeed < MIN_FRAME_SPEED) then framesSpeed = MIN_FRAME_SPEED end 55 | --------------------------------------------------------------------------------------- 56 | 57 | -- Draw 58 | --------------------------------------------------------------------------------------- 59 | BeginDrawing() 60 | 61 | ClearBackground(RAYWHITE) 62 | 63 | DrawTexture(scarfy, 15, 40, WHITE) 64 | DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME) 65 | 66 | DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED) 67 | 68 | DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY) 69 | DrawText(string.format("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY) 70 | DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY) 71 | 72 | for i = 1, MAX_FRAME_SPEED do 73 | if (i <= framesSpeed) then DrawRectangle(250 + 21*i, 205, 20, 20, RED) end 74 | DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON) 75 | end 76 | 77 | DrawTextureRec(scarfy, frameRec, position, WHITE) -- Draw part of the texture 78 | 79 | DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY) 80 | 81 | EndDrawing() 82 | --------------------------------------------------------------------------------------- 83 | end 84 | 85 | -- De-Initialization 86 | ------------------------------------------------------------------------------------------- 87 | UnloadTexture(scarfy) -- Texture unloading 88 | 89 | CloseWindow() -- Close window and OpenGL context 90 | ------------------------------------------------------------------------------------------- 91 | -------------------------------------------------------------------------------- /examples/textures/textures_srcrec_dstrec.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Texture source and destination rectangles 4 | -- 5 | -- This example has been created using raylib 1.6 (www.raylib.com) 6 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | -- 8 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 9 | -- 10 | ------------------------------------------------------------------------------------------- 11 | 12 | -- Initialization 13 | ------------------------------------------------------------------------------------------- 14 | local screenWidth = 800 15 | local screenHeight = 450 16 | 17 | InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles") 18 | 19 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 20 | local scarfy = LoadTexture("resources/scarfy.png") -- Texture loading 21 | 22 | local frameWidth = scarfy.width/6 23 | local frameHeight = scarfy.height 24 | 25 | -- NOTE: Source rectangle (part of the texture to use for drawing) 26 | local sourceRec = Rectangle(0, 0, frameWidth, frameHeight) 27 | 28 | -- NOTE: Destination rectangle (screen rectangle where drawing part of texture) 29 | local destRec = Rectangle(screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2) 30 | 31 | -- NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size 32 | local origin = Vector2(frameWidth, frameHeight) 33 | 34 | local rotation = 0 35 | 36 | SetTargetFPS(60) 37 | ------------------------------------------------------------------------------------------- 38 | 39 | -- Main game loop 40 | while not WindowShouldClose() do -- Detect window close button or ESC key 41 | -- Update 42 | --------------------------------------------------------------------------------------- 43 | rotation = rotation + 1 44 | --------------------------------------------------------------------------------------- 45 | 46 | -- Draw 47 | --------------------------------------------------------------------------------------- 48 | BeginDrawing() 49 | 50 | ClearBackground(RAYWHITE) 51 | 52 | -- NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw 53 | -- sourceRec defines the part of the texture we use for drawing 54 | -- destRec defines the rectangle where our texture part will fit (scaling it to fit) 55 | -- origin defines the point of the texture used as reference for rotation and scaling 56 | -- rotation defines the texture rotation (using origin as rotation point) 57 | DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE) 58 | 59 | DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY) 60 | DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY) 61 | 62 | DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY) 63 | 64 | EndDrawing() 65 | --------------------------------------------------------------------------------------- 66 | end 67 | 68 | -- De-Initialization 69 | ------------------------------------------------------------------------------------------- 70 | UnloadTexture(scarfy) -- Texture unloading 71 | 72 | CloseWindow() -- Close window and OpenGL context 73 | ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/textures/textures_to_image.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------- 2 | -- 3 | -- raylib [textures] example - Retrieve image data from texture: GetTextureData() 4 | -- 5 | -- NOTE: Images are loaded in CPU memory (RAM) textures are loaded in GPU memory (VRAM) 6 | -- 7 | -- This example has been created using raylib 1.6 (www.raylib.com) 8 | -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | -- 10 | -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) 11 | -- 12 | ------------------------------------------------------------------------------------------- 13 | 14 | -- Initialization 15 | ------------------------------------------------------------------------------------------- 16 | local screenWidth = 800 17 | local screenHeight = 450 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image") 20 | 21 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 22 | 23 | local image = LoadImage("resources/raylib_logo.png") -- Load image data into CPU memory (RAM) 24 | local texture = LoadTextureFromImage(image) -- Image converted to texture, GPU memory (RAM -> VRAM) 25 | UnloadImage(image) -- Unload image data from CPU memory (RAM) 26 | 27 | image = GetTextureData(texture) -- Retrieve image data from GPU memory (VRAM -> RAM) 28 | UnloadTexture(texture) -- Unload texture from GPU memory (VRAM) 29 | 30 | texture = LoadTextureFromImage(image) -- Recreate texture from retrieved image data (RAM -> VRAM) 31 | UnloadImage(image) -- Unload retrieved image data from CPU memory (RAM) 32 | ------------------------------------------------------------------------------------------- 33 | 34 | -- Main game loop 35 | while not WindowShouldClose() do -- Detect window close button or ESC key 36 | -- Update 37 | --------------------------------------------------------------------------------------- 38 | -- TODO: Update your variables here 39 | --------------------------------------------------------------------------------------- 40 | 41 | -- Draw 42 | --------------------------------------------------------------------------------------- 43 | BeginDrawing() 44 | 45 | ClearBackground(RAYWHITE) 46 | 47 | DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE) 48 | 49 | DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY) 50 | 51 | EndDrawing() 52 | --------------------------------------------------------------------------------------- 53 | end 54 | 55 | -- De-Initialization 56 | ------------------------------------------------------------------------------------------- 57 | UnloadTexture(texture) -- Texture unloading 58 | 59 | CloseWindow() -- Close window and OpenGL context 60 | ------------------------------------------------------------------------------------------- 61 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # raylib-lua-sol.hpp include 2 | 3 | add_library(raylib-lua-sol-hpp INTERFACE) 4 | target_include_directories(raylib-lua-sol-hpp INTERFACE . ) 5 | file(COPY 6 | raylib-lua-sol.hpp 7 | raylib-lua-sol-rlgl.hpp 8 | raylib-lua-sol-raymath.hpp 9 | DESTINATION .) 10 | -------------------------------------------------------------------------------- /logo/raylib-lua-sol_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobLoach/raylib-lua-sol/dd02dd2612fadb935fbecbfdbc885ce32ae22307/logo/raylib-lua-sol_256x256.png -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_test( 2 | NAME raylib-lua-sol-tests 3 | COMMAND raylib-lua-sol 4 | ${CMAKE_CURRENT_SOURCE_DIR}/raylib-lua-sol-tests.lua) 5 | -------------------------------------------------------------------------------- /tests/raylib-lua-sol-tests.lua: -------------------------------------------------------------------------------- 1 | local function describe(name, descriptor) 2 | local errors = {} 3 | local successes = {} 4 | function it(spec_line, spec) 5 | local status = xpcall(spec, function (err) 6 | table.insert(errors, string.format("\t%s\n\t\t%s\n", spec_line, err)) 7 | end) 8 | if status then 9 | table.insert(successes, string.format("\t%s\n", spec_line)) 10 | end 11 | end 12 | local status = xpcall(descriptor, function (err) 13 | table.insert(errors, err) 14 | end, it) 15 | print(name) 16 | if #successes > 0 then 17 | print('Successes:') 18 | print(table.concat(successes)) 19 | end 20 | if #errors > 0 then 21 | print('Failures:') 22 | print(table.concat(errors)) 23 | TraceLog(LOG_ERROR, 'Error count: ' .. #errors) 24 | end 25 | end 26 | 27 | describe('raylib-lua-sol Tests', function (it) 28 | it('Functions', function() 29 | assert(IsWindowFullscreen() == false, 'IsWindowFullscreen() should be false') 30 | assert(GetFileExtension('something.lua') == '.lua', 'GetFileExtension("something.lua") should return "lua"') 31 | end) 32 | 33 | it('Enumerations', function () 34 | assert(FLAG_FULLSCREEN_MODE == 2, "FLAG_FULLSCREEN_MODE should equal 2") 35 | end) 36 | 37 | it('Structs', function () 38 | local rect = Rectangle(10, 20, 30, 40) 39 | assert(rect.width == 30, "Rectangle width should be 30") 40 | rect.width = 500 41 | assert(rect.width == 500, "Rectangle width should be 500") 42 | 43 | local vec = Vector2(30, 40) 44 | assert(vec.x == 30) 45 | end) 46 | 47 | it ('Color', function () 48 | assert(RAYWHITE.r == 245, "RAYWHITE should have 245 red") 49 | 50 | local c = Color(100, 100, 100, 255) 51 | assert(c.g == 100, "c.g should be 100") 52 | end) 53 | 54 | it('rlgl', function () 55 | assert(MAX_MATERIAL_MAPS == 12, "MAX_MATERIAL_MAPS should be 12") 56 | end) 57 | end) 58 | --------------------------------------------------------------------------------