├── README.md ├── examples ├── audio │ ├── audio_music_stream.nim │ ├── module_playing.nim │ ├── multichannel_sound.nim │ ├── raw_stream.nim │ └── resources │ │ ├── guitar_noodling.ogg │ │ ├── mini1111.xm │ │ ├── sound.wav │ │ └── tanatana.ogg ├── core │ ├── camera_2d.nim │ ├── camera_3d_first_person.nim │ ├── input_keys.nim │ └── picking_3d.nim ├── models │ ├── geometric_shapes.nim │ ├── rlgl_solar_system.nim │ └── waving_cubes.nim ├── original │ └── basic.nim ├── shaders │ ├── palette_switch.nim │ ├── raymarching.nim │ └── resources │ │ └── shaders │ │ └── glsl330 │ │ ├── palette_switch.fs │ │ └── raymarching.fs ├── shapes │ ├── bouncing_ball.nim │ ├── draw_ring.nim │ └── following_eyes.nim ├── text │ ├── format_text.nim │ ├── input_box.nim │ └── rectangle_bound.nim └── textures │ ├── image_processing.nim │ ├── particles_blending.nim │ ├── raw_data.nim │ └── resources │ ├── fudesumi.raw │ ├── parrots.png │ └── smoke.png ├── lib ├── FileSaver.min.js └── coffeescript.js ├── main.html └── res └── grixel.ttf /README.md: -------------------------------------------------------------------------------- 1 | # :.Sum.: 2 | __Raylib Forever__ is a fully automated [Nim](http://nim-lang) includefiles provider for [raylib](https://github.com/raysan5/raylib) and associated libraries. 3 | Developed in pure frustration it was designed to counterweight other **4** attempts to make actual wrapper. 4 | 5 | # :.Featuræ.: 6 | * Uses sheer power of your browser (and thought) to deliver includes for latest existing version. 7 | * Faithful code conversion: enums to enums, all naming conventions staying as-is. 8 | * Only known Nim binding to wrap [raygui](https://github.com/raysan5/raygui) (linked as pre-compiled [lib](https://github.com/Guevara-chan/Raylib-Forever/releases/tag/aux)). 9 | * Standalone converter [script](https://gist.github.com/Guevara-chan/2d10691e0146aae4c96ff534978529f8) in [CoffeeScript 2](http://coffeescript.org/), usable under [Node.js](https://nodejs.org/). 10 | * [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) and [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) submodules support. 11 | 12 | # :.Compatibility.: 13 | __Raylib Forever__ webpage was best tested with *Chrome 80* and [Electron](https://electronjs.org/), which is used to develop it. 14 | It should work on any non-mechanical teapot that provides `fetch` and ES2019, though. 15 | 16 | # :.Brief samples of raylib+nim union.: 17 | ![image](https://user-images.githubusercontent.com/8768470/74151688-c3258500-4c1d-11ea-8a50-f37dc0db4ada.png) 18 | -------------------------------------------------------------------------------- /examples/audio/audio_music_stream.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [audio] example - Music playing (streaming) 4 | # 5 | # This example has been created using raylib 1.3 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Copyright (c) 2015 Ramon Santamaria (@raysan5) 9 | # /Converted in 2*20 by Guevara-chan. 10 | # 11 | #******************************************************************************************* 12 | 13 | import raylib 14 | 15 | # Initialization 16 | # -------------------------------------------------------------------------------------- 17 | const screenWidth = 800 18 | const screenHeight = 450 19 | 20 | InitWindow screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)" 21 | 22 | InitAudioDevice() # Initialize audio device 23 | 24 | let music = LoadMusicStream("resources/guitar_noodling.ogg") # Load WAV audio file 25 | 26 | PlayMusicStream(music) 27 | 28 | var 29 | timePlayed = 0.0 30 | pause = false 31 | 32 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 33 | # -------------------------------------------------------------------------------------- 34 | 35 | # Main game loop 36 | while not WindowShouldClose(): # Detect window close button or ESC key 37 | # Update 38 | # ---------------------------------------------------------------------------------- 39 | music.UpdateMusicStream() 40 | 41 | if KEY_SPACE.IsKeyPressed(): 42 | music.StopMusicStream() 43 | music.PlayMusicStream() 44 | 45 | if KEY_P.IsKeyPressed(): 46 | pause = not pause 47 | if pause: music.PauseMusicStream() 48 | else: music.ResumeMusicStream() 49 | 50 | timePlayed = music.GetMusicTimePlayed()/music.GetMusicTimeLength()*400 51 | 52 | if timePlayed > 400: music.StopMusicStream() 53 | # ---------------------------------------------------------------------------------- 54 | 55 | # Draw 56 | # ---------------------------------------------------------------------------------- 57 | BeginDrawing() 58 | 59 | ClearBackground(RAYWHITE) 60 | 61 | DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY) 62 | 63 | DrawRectangle(200, 200, 400, 12, LIGHTGRAY) 64 | DrawRectangle(200, 200, (int)timePlayed, 12, MAROON) 65 | DrawRectangleLines(200, 200, 400, 12, GRAY) 66 | 67 | DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY) 68 | DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY) 69 | 70 | EndDrawing() 71 | # ---------------------------------------------------------------------------------- 72 | 73 | # De-Initialization 74 | # -------------------------------------------------------------------------------------- 75 | 76 | music.UnloadMusicStream() # Unload music stream buffers from RAM 77 | 78 | CloseAudioDevice() # Close audio device 79 | 80 | CloseWindow() # Close window and OpenGL context 81 | # -------------------------------------------------------------------------------------- 82 | -------------------------------------------------------------------------------- /examples/audio/module_playing.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [audio] example - Module playing (streaming) 4 | # 5 | # This example has been created using raylib 1.5 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Copyright (c) 2016 Ramon Santamaria (@raysan5) 9 | # /Converted in 2*20 by Guevara-chan. 10 | # 11 | #******************************************************************************************* 12 | 13 | import raylib, lenientops 14 | 15 | const MAX_CIRCLES = 64 16 | 17 | type CircleWave = object 18 | position: Vector2 19 | radius: float 20 | alpha: float 21 | speed: float 22 | color: Color 23 | 24 | # Initialization 25 | # -------------------------------------------------------------------------------------- 26 | const screenWidth = 800 27 | const screenHeight = 450 28 | 29 | SetConfigFlags FLAG_MSAA_4X_HINT.uint32 # NOTE: Try to enable MSAA 4X 30 | 31 | InitWindow screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)" 32 | 33 | InitAudioDevice() # Initialize audio device 34 | 35 | let colors = [ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE] 36 | 37 | # Creates ome circles for visual effect 38 | var circles: array[MAX_CIRCLES, CircleWave] 39 | 40 | for i in (MAX_CIRCLES-1).countdown 0: 41 | circles[i].alpha = 0.0f; 42 | circles[i].radius = GetRandomValue(10, 40).float 43 | circles[i].position.x = GetRandomValue(circles[i].radius.int, screenWidth - circles[i].radius.int).float 44 | circles[i].position.y = GetRandomValue(circles[i].radius.int, screenHeight - circles[i].radius.int).float 45 | circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f 46 | circles[i].color = colors[GetRandomValue(0, 13)] 47 | 48 | let music = LoadMusicStream("resources/mini1111.xm") 49 | 50 | PlayMusicStream music 51 | 52 | var 53 | timePlayed = 0.0f 54 | pause = false 55 | 56 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 57 | # -------------------------------------------------------------------------------------- 58 | 59 | # Main game loop 60 | while not WindowShouldClose(): # Detect window close button or ESC key 61 | 62 | # Update 63 | # ---------------------------------------------------------------------------------- 64 | UpdateMusicStream music # Update music buffer with new stream data 65 | 66 | # Restart music playing (stop and play) 67 | if IsKeyPressed(KEY_SPACE): 68 | StopMusicStream music 69 | PlayMusicStream music 70 | 71 | # Pause/Resume music playing 72 | if IsKeyPressed(KEY_P): 73 | pause = not pause 74 | if pause: PauseMusicStream music 75 | else: ResumeMusicStream music 76 | 77 | # Get timePlayed scaled to bar dimensions 78 | timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*(screenWidth - 40) 79 | 80 | # Color circles animation 81 | for i in (MAX_CIRCLES-1).countdown 0: 82 | if pause: break 83 | circles[i].alpha += circles[i].speed; 84 | circles[i].radius += circles[i].speed*10.0f; 85 | 86 | if circles[i].alpha > 1.0f: circles[i].speed *= -1 87 | 88 | if (circles[i].alpha <= 0.0f): 89 | circles[i].alpha = 0.0f; 90 | circles[i].radius = GetRandomValue(10, 40).float 91 | circles[i].position.x = GetRandomValue(circles[i].radius.int, screenWidth - circles[i].radius.int).float 92 | circles[i].position.y = GetRandomValue(circles[i].radius.int, screenHeight - circles[i].radius.int).float 93 | circles[i].color = colors[GetRandomValue(0, 13)]; 94 | circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f; 95 | # ---------------------------------------------------------------------------------- 96 | 97 | # Draw 98 | # ---------------------------------------------------------------------------------- 99 | BeginDrawing() 100 | 101 | ClearBackground(RAYWHITE) 102 | 103 | for i in (MAX_CIRCLES-1).countdown 0: 104 | DrawCircleV circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha) 105 | 106 | # Draw time bar 107 | DrawRectangle 20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY 108 | DrawRectangle 20, screenHeight - 20 - 12, timePlayed.int, 12, MAROON 109 | DrawRectangleLines 20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY 110 | 111 | EndDrawing() 112 | # ---------------------------------------------------------------------------------- 113 | 114 | # De-Initialization 115 | # -------------------------------------------------------------------------------------- 116 | UnloadMusicStream music # Unload music stream buffers from RAM 117 | 118 | CloseAudioDevice() # Close audio device (music streaming is automatically stopped) 119 | 120 | CloseWindow() # Close window and OpenGL context 121 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/audio/multichannel_sound.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [audio] example - Multichannel sound playing 4 | # 5 | # This example has been created using raylib 2.6 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5) 9 | # 10 | # Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5) 11 | # /Converted in 2*20 by Guevara-chan. 12 | # 13 | #******************************************************************************************* 14 | 15 | import raylib 16 | 17 | # Initialization 18 | # -------------------------------------------------------------------------------------- 19 | const screenWidth = 800 20 | const screenHeight = 450 21 | 22 | InitWindow screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing" 23 | 24 | InitAudioDevice() # Initialize audio device 25 | 26 | let 27 | fxWav = LoadSound("resources/sound.wav") # Load WAV audio file 28 | fxOgg = LoadSound("resources/tanatana.ogg") # Load OGG audio file 29 | 30 | SetSoundVolume fxWav, 0.2 31 | 32 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 33 | # -------------------------------------------------------------------------------------- 34 | 35 | # Main game loop 36 | while not WindowShouldClose(): # Detect window close button or ESC key 37 | # Update 38 | # ---------------------------------------------------------------------------------- 39 | if IsKeyPressed(KEY_ENTER): PlaySoundMulti fxWav # Play a new wav sound instance 40 | if IsKeyPressed(KEY_SPACE): PlaySoundMulti fxOgg # Play a new ogg sound instance 41 | # ---------------------------------------------------------------------------------- 42 | 43 | # Draw 44 | # ---------------------------------------------------------------------------------- 45 | BeginDrawing() 46 | 47 | ClearBackground RAYWHITE 48 | 49 | DrawText "MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY 50 | DrawText "Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY 51 | DrawText "Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY 52 | 53 | DrawText TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED 54 | 55 | EndDrawing() 56 | # ---------------------------------------------------------------------------------- 57 | 58 | # De-Initialization 59 | # -------------------------------------------------------------------------------------- 60 | StopSoundMulti() # We must stop the buffer pool before unloading 61 | 62 | UnloadSound fxWav # Unload sound data 63 | UnloadSound fxOgg # Unload sound data 64 | 65 | CloseAudioDevice() # Close audio device 66 | 67 | CloseWindow() # Close window and OpenGL context 68 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/audio/raw_stream.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [audio] example - Raw audio 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 | # Example created by Ramon Santamaria (@raysan5) and reviewed by James Hofmann (@triplefox) 9 | # 10 | # Copyright (c) 2015-2019 Ramon Santamaria (@raysan5) and James Hofmann (@triplefox) 11 | # /Converted in 2*20 by Guevara-chan. 12 | # 13 | #******************************************************************************************* 14 | 15 | import raylib, math, lenientops 16 | 17 | const MAX_SAMPLES = 512 18 | const MAX_SAMPLES_PER_UPDATE = 4096 19 | 20 | # Initialization 21 | # -------------------------------------------------------------------------------------- 22 | const screenWidth = 800 23 | const screenHeight = 450 24 | 25 | InitWindow screenWidth, screenHeight, "raylib [audio] example - raw audio streaming" 26 | 27 | InitAudioDevice() # Initialize audio device 28 | 29 | # Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) 30 | let stream = InitAudioStream(22050, 16, 1) 31 | 32 | # Buffer for the single cycle waveform we are synthesizing 33 | var data: array[MAX_SAMPLES, uint16] 34 | 35 | # Frame buffer, describing the waveform when repeated over the course of a frame 36 | var writeBuf: array[MAX_SAMPLES_PER_UPDATE, uint16] 37 | 38 | PlayAudioStream stream # Start processing stream buffer (no data loaded currently) 39 | 40 | # Position read in to determine next frequency 41 | var mousePosition = Vector2(x: -100.0f, y: -100.0f) 42 | 43 | # Cycles per second (hz) 44 | var frequency = 440.0f 45 | 46 | # Previous value, used to test if sine needs to be rewritten, and to smoothly modulate frequency 47 | var oldFrequency = 1.0f 48 | 49 | # Cursor to read and copy the samples of the sine wave buffer 50 | var readCursor = 0 51 | 52 | # Computed size in samples of the sine wave 53 | var waveLength = 1 54 | 55 | var position = Vector2() 56 | 57 | 30.SetTargetFPS # Set our game to run at 30 frames-per-second 58 | # -------------------------------------------------------------------------------------- 59 | 60 | # Main game loop 61 | while not WindowShouldClose(): # Detect window close button or ESC key 62 | # Update 63 | # ---------------------------------------------------------------------------------- 64 | 65 | # Sample mouse input. 66 | mousePosition = GetMousePosition() 67 | 68 | if IsMouseButtonDown(MOUSE_LEFT_BUTTON): frequency = 40.0f + (mousePosition.y).float 69 | 70 | # Rewrite the sine wave. 71 | # Compute two cycles to allow the buffer padding, simplifying any modulation, resampling, etc. 72 | if frequency != oldFrequency: 73 | # Compute wavelength. Limit size in both directions. 74 | let oldWavelength = waveLength 75 | waveLength = (22050/frequency).int 76 | if waveLength > MAX_SAMPLES div 2: waveLength = MAX_SAMPLES div 2 77 | if waveLength < 1: waveLength = 1 78 | 79 | # Write sine wave. 80 | for i in 0.. readLength: writeLength = readLength 100 | 101 | # Write the slice 102 | echo writeCursor 103 | copyMem cast[pointer](cast[int](writeBuf.addr)+writeCursor), cast[pointer](cast[int](data.addr)+readCursor), 104 | writeLength*sizeof(uint16) 105 | 106 | # Update cursors and loop audio 107 | readCursor = (readCursor + writeLength) %% waveLength 108 | 109 | writeCursor += writeLength 110 | 111 | # Copy finished frame to audio stream 112 | UpdateAudioStream stream, writeBuf.addr, MAX_SAMPLES_PER_UPDATE 113 | # ---------------------------------------------------------------------------------- 114 | 115 | # Draw 116 | # ---------------------------------------------------------------------------------- 117 | BeginDrawing() 118 | 119 | ClearBackground RAYWHITE 120 | 121 | DrawText TextFormat("sine frequency: %i",(int)frequency), GetScreenWidth() - 220, 10, 20, RED 122 | DrawText "click mouse button to change frequency", 10, 10, 20, DARKGRAY 123 | 124 | # Draw the current buffer state proportionate to the screen 125 | for i in 0.. 40: camera.rotation = 40 61 | elif camera.rotation < -40: camera.rotation = -40 62 | # Camera zoom controls 63 | camera.zoom += GetMouseWheelMove().float * 0.05 64 | if camera.zoom > 3.0: camera.zoom = 3.0 65 | elif camera.zoom < 0.1: camera.zoom = 0.1 66 | # Camera reset (zoom and rotation) 67 | if IsKeyPressed(KEY_R): 68 | camera.zoom = 1.0 69 | camera.rotation = 0.0 70 | #---------------------------------------------------------------------------------- 71 | # Draw 72 | #---------------------------------------------------------------------------------- 73 | BeginDrawing() 74 | ClearBackground RAYWHITE 75 | BeginMode2D camera 76 | DrawRectangle -6000, 320, 13000, 8000, DARKGRAY 77 | for i in 0..= MAX_PALETTES: currentPalette = 0 100 | elif currentPalette < 0: currentPalette = MAX_PALETTES - 1 101 | 102 | # Send new value to the shader to be used on drawing. 103 | # NOTE: We are sending RGB triplets w/o the alpha channel 104 | SetShaderValueV shader, paletteLoc, palettes[currentPalette].addr, UNIFORM_IVEC3, COLORS_PER_PALETTE 105 | # ---------------------------------------------------------------------------------- 106 | 107 | # Draw 108 | # ---------------------------------------------------------------------------------- 109 | BeginDrawing() 110 | 111 | ClearBackground RAYWHITE 112 | 113 | BeginShaderMode shader 114 | 115 | for i in 0..", 10, 10, 30, DARKBLUE 123 | DrawText "CURRENT PALETTE:", 60, 15, 20, RAYWHITE 124 | DrawText paletteText[currentPalette], 300, 15, 20, RED 125 | 126 | DrawFPS 700, 15 127 | 128 | EndDrawing() 129 | # ---------------------------------------------------------------------------------- 130 | 131 | # De-Initialization 132 | # -------------------------------------------------------------------------------------- 133 | UnloadShader shader # Unload shader 134 | 135 | CloseWindow() # Close window and OpenGL context 136 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shaders/raymarching.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [shaders] example - Raymarching shapes generation 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 2.0 (www.raylib.com) 13 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 14 | # 15 | # Copyright (c) 2018 Ramon Santamaria (@raysan5) 16 | # /Converted in 2*20 by Guevara-chan. 17 | # 18 | #******************************************************************************************* 19 | 20 | import raylib 21 | const GLSL_VERSION = 330 22 | 23 | # Initialization 24 | # -------------------------------------------------------------------------------------- 25 | var 26 | screenWidth = 800 27 | screenHeight = 450 28 | 29 | SetConfigFlags FLAG_WINDOW_RESIZABLE.uint32 30 | InitWindow screenWidth, screenHeight, "raylib [shaders] example - raymarching shapes" 31 | 32 | var camera = Camera() 33 | camera.position = Vector3(x: 2.5f, y: 2.5f, z: 3.0f) # Camera position 34 | camera.target = Vector3(x: 0.0f, y: 0.0f, z: 0.7f) # Camera looking at point 35 | camera.up = Vector3(x: 0.0f, y: 1.0f, z: 0.0f) # Camera up vector (rotation towards target) 36 | camera.fovy = 65.0f # Camera field-of-view Y 37 | 38 | SetCameraMode camera, CAMERA_FREE # Set camera mode 39 | 40 | # Load raymarching shader 41 | # NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader 42 | let 43 | shader = LoadShader(nil, TextFormat("resources/shaders/glsl%i/raymarching.fs", GLSL_VERSION)) 44 | 45 | # Get shader locations for required uniforms 46 | viewEyeLoc = GetShaderLocation(shader, "viewEye") 47 | viewCenterLoc = GetShaderLocation(shader, "viewCenter") 48 | runTimeLoc = GetShaderLocation(shader, "runTime") 49 | resolutionLoc = GetShaderLocation(shader, "resolution") 50 | 51 | var resolution = [screenWidth.float32, screenHeight.float32] 52 | SetShaderValue shader, resolutionLoc, resolution.addr, UNIFORM_VEC2 53 | 54 | var runTime = 0.0f 55 | 56 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 57 | # -------------------------------------------------------------------------------------- 58 | 59 | # Main game loop 60 | while not WindowShouldClose(): # Detect window close button or ESC key 61 | # Check if screen is resized 62 | # ---------------------------------------------------------------------------------- 63 | if IsWindowResized(): 64 | screenWidth = GetScreenWidth() 65 | screenHeight = GetScreenHeight() 66 | resolution = [screenWidth.float32, screenHeight.float32] 67 | SetShaderValue shader, resolutionLoc, resolution.addr, UNIFORM_VEC2 68 | 69 | # Update 70 | # ---------------------------------------------------------------------------------- 71 | camera.addr.UpdateCamera # Update camera 72 | 73 | var 74 | cameraPos = [camera.position.x, camera.position.y, camera.position.z] 75 | cameraTarget = [camera.target.x, camera.target.y, camera.target.z] 76 | 77 | deltaTime = GetFrameTime() 78 | runTime += deltaTime 79 | 80 | # Set shader required uniform values 81 | SetShaderValue shader, viewEyeLoc, cameraPos.addr, UNIFORM_VEC3 82 | SetShaderValue shader, viewCenterLoc, cameraTarget.addr, UNIFORM_VEC3 83 | SetShaderValue shader, runTimeLoc, runTime.addr, UNIFORM_FLOAT 84 | # ---------------------------------------------------------------------------------- 85 | 86 | # Draw 87 | # ---------------------------------------------------------------------------------- 88 | BeginDrawing() 89 | 90 | ClearBackground RAYWHITE 91 | 92 | # We only draw a white full-screen rectangle, 93 | # frame is generated in shader using raymarching 94 | BeginShaderMode shader 95 | DrawRectangle 0, 0, screenWidth, screenHeight, WHITE 96 | EndShaderMode() 97 | 98 | DrawText "(c) Raymarching shader by Iñigo Quilez. MIT License.", screenWidth - 280, screenHeight - 20, 10, BLACK 99 | 100 | EndDrawing() 101 | # ---------------------------------------------------------------------------------- 102 | 103 | # De-Initialization 104 | # -------------------------------------------------------------------------------------- 105 | UnloadShader shader # Unload shader 106 | 107 | CloseWindow() # Close window and OpenGL context 108 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/palette_switch.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | const int colors = 8; 4 | 5 | // Input fragment attributes (from fragment shader) 6 | in vec2 fragTexCoord; 7 | in vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform ivec3 palette[colors]; 12 | 13 | // Output fragment color 14 | out vec4 finalColor; 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord)*fragColor; 20 | 21 | // Convert the (normalized) texel color RED component (GB would work, too) 22 | // to the palette index by scaling up from [0, 1] to [0, 255]. 23 | int index = int(texelColor.r*255.0); 24 | ivec3 color = palette[index]; 25 | 26 | // Calculate final fragment color. Note that the palette color components 27 | // are defined in the range [0, 255] and need to be normalized to [0, 1] 28 | // for OpenGL to work. 29 | finalColor = vec4(color/255.0, texelColor.a); 30 | } 31 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/raymarching.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Output fragment color 8 | out vec4 finalColor; 9 | 10 | uniform vec3 viewEye; 11 | uniform vec3 viewCenter; 12 | uniform float runTime; 13 | uniform vec2 resolution; 14 | 15 | // The MIT License 16 | // Copyright © 2013 Inigo Quilez 17 | // Permission is hereby granted, free of charge, to any person obtaining a copy 18 | // of this software and associated documentation files (the "Software"), to deal 19 | // in the Software without restriction, including without limitation the rights 20 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | // copies of the Software, and to permit persons to whom the Software is 22 | // furnished to do so, subject to the following conditions: 23 | 24 | // The above copyright notice and this permission notice shall be included in all 25 | // copies or substantial portions of the Software. 26 | 27 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 | // SOFTWARE. 34 | 35 | // A list of useful distance function to simple primitives, and an example on how to 36 | // do some interesting boolean operations, repetition and displacement. 37 | // 38 | // More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm 39 | 40 | #define AA 1 // make this 1 is your machine is too slow 41 | 42 | //------------------------------------------------------------------ 43 | 44 | float sdPlane( vec3 p ) 45 | { 46 | return p.y; 47 | } 48 | 49 | float sdSphere( vec3 p, float s ) 50 | { 51 | return length(p)-s; 52 | } 53 | 54 | float sdBox( vec3 p, vec3 b ) 55 | { 56 | vec3 d = abs(p) - b; 57 | return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); 58 | } 59 | 60 | float sdEllipsoid( in vec3 p, in vec3 r ) 61 | { 62 | return (length( p/r ) - 1.0) * min(min(r.x,r.y),r.z); 63 | } 64 | 65 | float udRoundBox( vec3 p, vec3 b, float r ) 66 | { 67 | return length(max(abs(p)-b,0.0))-r; 68 | } 69 | 70 | float sdTorus( vec3 p, vec2 t ) 71 | { 72 | return length( vec2(length(p.xz)-t.x,p.y) )-t.y; 73 | } 74 | 75 | float sdHexPrism( vec3 p, vec2 h ) 76 | { 77 | vec3 q = abs(p); 78 | #if 0 79 | return max(q.z-h.y,max((q.x*0.866025+q.y*0.5),q.y)-h.x); 80 | #else 81 | float d1 = q.z-h.y; 82 | float d2 = max((q.x*0.866025+q.y*0.5),q.y)-h.x; 83 | return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.); 84 | #endif 85 | } 86 | 87 | float sdCapsule( vec3 p, vec3 a, vec3 b, float r ) 88 | { 89 | vec3 pa = p-a, ba = b-a; 90 | float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); 91 | return length( pa - ba*h ) - r; 92 | } 93 | 94 | float sdEquilateralTriangle( in vec2 p ) 95 | { 96 | const float k = sqrt(3.0); 97 | p.x = abs(p.x) - 1.0; 98 | p.y = p.y + 1.0/k; 99 | if( p.x + k*p.y > 0.0 ) p = vec2( p.x - k*p.y, -k*p.x - p.y )/2.0; 100 | p.x += 2.0 - 2.0*clamp( (p.x+2.0)/2.0, 0.0, 1.0 ); 101 | return -length(p)*sign(p.y); 102 | } 103 | 104 | float sdTriPrism( vec3 p, vec2 h ) 105 | { 106 | vec3 q = abs(p); 107 | float d1 = q.z-h.y; 108 | #if 1 109 | // distance bound 110 | float d2 = max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5; 111 | #else 112 | // correct distance 113 | h.x *= 0.866025; 114 | float d2 = sdEquilateralTriangle(p.xy/h.x)*h.x; 115 | #endif 116 | return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.); 117 | } 118 | 119 | float sdCylinder( vec3 p, vec2 h ) 120 | { 121 | vec2 d = abs(vec2(length(p.xz),p.y)) - h; 122 | return min(max(d.x,d.y),0.0) + length(max(d,0.0)); 123 | } 124 | 125 | float sdCone( in vec3 p, in vec3 c ) 126 | { 127 | vec2 q = vec2( length(p.xz), p.y ); 128 | float d1 = -q.y-c.z; 129 | float d2 = max( dot(q,c.xy), q.y); 130 | return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.); 131 | } 132 | 133 | float sdConeSection( in vec3 p, in float h, in float r1, in float r2 ) 134 | { 135 | float d1 = -p.y - h; 136 | float q = p.y - h; 137 | float si = 0.5*(r1-r2)/h; 138 | float d2 = max( sqrt( dot(p.xz,p.xz)*(1.0-si*si)) + q*si - r2, q ); 139 | return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.); 140 | } 141 | 142 | float sdPryamid4(vec3 p, vec3 h ) // h = { cos a, sin a, height } 143 | { 144 | // Tetrahedron = Octahedron - Cube 145 | float box = sdBox( p - vec3(0,-2.0*h.z,0), vec3(2.0*h.z) ); 146 | 147 | float d = 0.0; 148 | d = max( d, abs( dot(p, vec3( -h.x, h.y, 0 )) )); 149 | d = max( d, abs( dot(p, vec3( h.x, h.y, 0 )) )); 150 | d = max( d, abs( dot(p, vec3( 0, h.y, h.x )) )); 151 | d = max( d, abs( dot(p, vec3( 0, h.y,-h.x )) )); 152 | float octa = d - h.z; 153 | return max(-box,octa); // Subtraction 154 | } 155 | 156 | float length2( vec2 p ) 157 | { 158 | return sqrt( p.x*p.x + p.y*p.y ); 159 | } 160 | 161 | float length6( vec2 p ) 162 | { 163 | p = p*p*p; p = p*p; 164 | return pow( p.x + p.y, 1.0/6.0 ); 165 | } 166 | 167 | float length8( vec2 p ) 168 | { 169 | p = p*p; p = p*p; p = p*p; 170 | return pow( p.x + p.y, 1.0/8.0 ); 171 | } 172 | 173 | float sdTorus82( vec3 p, vec2 t ) 174 | { 175 | vec2 q = vec2(length2(p.xz)-t.x,p.y); 176 | return length8(q)-t.y; 177 | } 178 | 179 | float sdTorus88( vec3 p, vec2 t ) 180 | { 181 | vec2 q = vec2(length8(p.xz)-t.x,p.y); 182 | return length8(q)-t.y; 183 | } 184 | 185 | float sdCylinder6( vec3 p, vec2 h ) 186 | { 187 | return max( length6(p.xz)-h.x, abs(p.y)-h.y ); 188 | } 189 | 190 | //------------------------------------------------------------------ 191 | 192 | float opS( float d1, float d2 ) 193 | { 194 | return max(-d2,d1); 195 | } 196 | 197 | vec2 opU( vec2 d1, vec2 d2 ) 198 | { 199 | return (d1.x0.0 ) tmax = min( tmax, tp1 ); 253 | float tp2 = (1.6-ro.y)/rd.y; if( tp2>0.0 ) { if( ro.y>1.6 ) tmin = max( tmin, tp2 ); 254 | else tmax = min( tmax, tp2 ); } 255 | #endif 256 | 257 | float t = tmin; 258 | float m = -1.0; 259 | for( int i=0; i<64; i++ ) 260 | { 261 | float precis = 0.0005*t; 262 | vec2 res = map( ro+rd*t ); 263 | if( res.xtmax ) break; 264 | t += res.x; 265 | m = res.y; 266 | } 267 | 268 | if( t>tmax ) m=-1.0; 269 | return vec2( t, m ); 270 | } 271 | 272 | 273 | float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax ) 274 | { 275 | float res = 1.0; 276 | float t = mint; 277 | for( int i=0; i<16; i++ ) 278 | { 279 | float h = map( ro + rd*t ).x; 280 | res = min( res, 8.0*h/t ); 281 | t += clamp( h, 0.02, 0.10 ); 282 | if( h<0.001 || t>tmax ) break; 283 | } 284 | return clamp( res, 0.0, 1.0 ); 285 | } 286 | 287 | vec3 calcNormal( in vec3 pos ) 288 | { 289 | vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; 290 | return normalize( e.xyy*map( pos + e.xyy ).x + 291 | e.yyx*map( pos + e.yyx ).x + 292 | e.yxy*map( pos + e.yxy ).x + 293 | e.xxx*map( pos + e.xxx ).x ); 294 | /* 295 | vec3 eps = vec3( 0.0005, 0.0, 0.0 ); 296 | vec3 nor = vec3( 297 | map(pos+eps.xyy).x - map(pos-eps.xyy).x, 298 | map(pos+eps.yxy).x - map(pos-eps.yxy).x, 299 | map(pos+eps.yyx).x - map(pos-eps.yyx).x ); 300 | return normalize(nor); 301 | */ 302 | } 303 | 304 | float calcAO( in vec3 pos, in vec3 nor ) 305 | { 306 | float occ = 0.0; 307 | float sca = 1.0; 308 | for( int i=0; i<5; i++ ) 309 | { 310 | float hr = 0.01 + 0.12*float(i)/4.0; 311 | vec3 aopos = nor * hr + pos; 312 | float dd = map( aopos ).x; 313 | occ += -(dd-hr)*sca; 314 | sca *= 0.95; 315 | } 316 | return clamp( 1.0 - 3.0*occ, 0.0, 1.0 ); 317 | } 318 | 319 | // http://iquilezles.org/www/articles/checkerfiltering/checkerfiltering.htm 320 | float checkersGradBox( in vec2 p ) 321 | { 322 | // filter kernel 323 | vec2 w = fwidth(p) + 0.001; 324 | // analytical integral (box filter) 325 | vec2 i = 2.0*(abs(fract((p-0.5*w)*0.5)-0.5)-abs(fract((p+0.5*w)*0.5)-0.5))/w; 326 | // xor pattern 327 | return 0.5 - 0.5*i.x*i.y; 328 | } 329 | 330 | vec3 render( in vec3 ro, in vec3 rd ) 331 | { 332 | vec3 col = vec3(0.7, 0.9, 1.0) +rd.y*0.8; 333 | vec2 res = castRay(ro,rd); 334 | float t = res.x; 335 | float m = res.y; 336 | if( m>-0.5 ) 337 | { 338 | vec3 pos = ro + t*rd; 339 | vec3 nor = calcNormal( pos ); 340 | vec3 ref = reflect( rd, nor ); 341 | 342 | // material 343 | col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) ); 344 | if( m<1.5 ) 345 | { 346 | 347 | float f = checkersGradBox( 5.0*pos.xz ); 348 | col = 0.3 + f*vec3(0.1); 349 | } 350 | 351 | // lighting 352 | float occ = calcAO( pos, nor ); 353 | vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) ); 354 | vec3 hal = normalize( lig-rd ); 355 | float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 ); 356 | float dif = clamp( dot( nor, lig ), 0.0, 1.0 ); 357 | float bac = clamp( dot( nor, normalize(vec3(-lig.x,0.0,-lig.z))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0); 358 | float dom = smoothstep( -0.1, 0.1, ref.y ); 359 | float fre = pow( clamp(1.0+dot(nor,rd),0.0,1.0), 2.0 ); 360 | 361 | dif *= calcSoftshadow( pos, lig, 0.02, 2.5 ); 362 | dom *= calcSoftshadow( pos, ref, 0.02, 2.5 ); 363 | 364 | float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)* 365 | dif * 366 | (0.04 + 0.96*pow( clamp(1.0+dot(hal,rd),0.0,1.0), 5.0 )); 367 | 368 | vec3 lin = vec3(0.0); 369 | lin += 1.30*dif*vec3(1.00,0.80,0.55); 370 | lin += 0.40*amb*vec3(0.40,0.60,1.00)*occ; 371 | lin += 0.50*dom*vec3(0.40,0.60,1.00)*occ; 372 | lin += 0.50*bac*vec3(0.25,0.25,0.25)*occ; 373 | lin += 0.25*fre*vec3(1.00,1.00,1.00)*occ; 374 | col = col*lin; 375 | col += 10.00*spe*vec3(1.00,0.90,0.70); 376 | 377 | col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) ); 378 | } 379 | 380 | return vec3( clamp(col,0.0,1.0) ); 381 | } 382 | 383 | mat3 setCamera( in vec3 ro, in vec3 ta, float cr ) 384 | { 385 | vec3 cw = normalize(ta-ro); 386 | vec3 cp = vec3(sin(cr), cos(cr),0.0); 387 | vec3 cu = normalize( cross(cw,cp) ); 388 | vec3 cv = normalize( cross(cu,cw) ); 389 | return mat3( cu, cv, cw ); 390 | } 391 | 392 | void main() 393 | { 394 | vec3 tot = vec3(0.0); 395 | #if AA>1 396 | for( int m=0; m1 425 | } 426 | tot /= float(AA*AA); 427 | #endif 428 | 429 | finalColor = vec4( tot, 1.0 ); 430 | } -------------------------------------------------------------------------------- /examples/shapes/bouncing_ball.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [shapes] example - bouncing ball 4 | # 5 | # This example has been created using raylib 1.0 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Copyright (c) 2013 Ramon Santamaria (@raysan5) 9 | # /Converted in 2*20 by Guevara-chan. 10 | # 11 | #******************************************************************************************* 12 | 13 | import raylib, lenientops 14 | 15 | # Initialization 16 | # --------------------------------------------------------- 17 | const screenWidth = 800 18 | const screenHeight = 450 19 | 20 | InitWindow screenWidth, screenHeight, "raylib [shapes] example - bouncing ball" 21 | 22 | var 23 | ballPosition = Vector2(x: GetScreenWidth()/2, y: GetScreenHeight()/2) 24 | ballSpeed = Vector2(x: 5.0f, y: 4.0f) 25 | ballRadius = 20.0 26 | 27 | pause = false 28 | framesCounter = 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(): # Detect window close button or ESC key 35 | # Update 36 | # ----------------------------------------------------- 37 | if KEY_SPACE.IsKeyPressed: pause = not pause 38 | 39 | if not pause: 40 | ballPosition.x += ballSpeed.x 41 | ballPosition.y += ballSpeed.y 42 | 43 | # Check walls collision for bouncing 44 | if (ballPosition.x >= (GetScreenWidth() - ballRadius)) or (ballPosition.x <= ballRadius): ballSpeed.x *= -1.0f 45 | if (ballPosition.y >= (GetScreenHeight() - ballRadius)) or (ballPosition.y <= ballRadius): ballSpeed.y *= -1.0f 46 | else: framesCounter.inc 47 | # ----------------------------------------------------- 48 | 49 | # Draw 50 | # ----------------------------------------------------- 51 | BeginDrawing() 52 | 53 | ClearBackground RAYWHITE 54 | 55 | DrawCircleV ballPosition, ballRadius, MAROON 56 | DrawText "PRESS SPACE to PAUSE BALL MOVEMENT", 10, GetScreenHeight() - 25, 20, LIGHTGRAY 57 | 58 | # On pause, we draw a blinking message 59 | if pause and ((framesCounter div 30) %% 2).bool: DrawText "PAUSED", 350, 200, 30, GRAY 60 | 61 | DrawFPS 10, 10 62 | 63 | EndDrawing() 64 | # ----------------------------------------------------- 65 | 66 | # De-Initialization 67 | # --------------------------------------------------------- 68 | CloseWindow() # Close window and OpenGL context 69 | # --------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shapes/draw_ring.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [shapes] example - draw ring (with gui options) 4 | # 5 | # This example has been created using raylib 2.5 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) 9 | # 10 | # Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) 11 | # /Converted in 2*20 by Guevara-chan. 12 | # 13 | #******************************************************************************************* 14 | 15 | import raylib, raygui 16 | 17 | # Initialization 18 | # -------------------------------------------------------------------------------------- 19 | const screenWidth = 800 20 | const screenHeight = 450 21 | 22 | InitWindow screenWidth, screenHeight, "raylib [shapes] example - draw ring" 23 | 24 | var 25 | center = Vector2(x: (GetScreenWidth() - 300) / 2, y: GetScreenHeight() / 2) 26 | 27 | innerRadius = 80.0f 28 | outerRadius = 190.0f 29 | 30 | startAngle = 0.0 31 | endAngle = 360.0 32 | segments = 0 33 | 34 | drawRing = true 35 | drawRingLines = false 36 | drawCircleLines = false 37 | 38 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 39 | # -------------------------------------------------------------------------------------- 40 | 41 | # Main game loop 42 | while not WindowShouldClose(): # Detect window close button or ESC key 43 | # Update 44 | # ---------------------------------------------------------------------------------- 45 | # NOTE: All variables update happens inside GUI control functions 46 | # ---------------------------------------------------------------------------------- 47 | 48 | # Draw 49 | # ---------------------------------------------------------------------------------- 50 | BeginDrawing() 51 | 52 | ClearBackground RAYWHITE 53 | 54 | DrawLine 500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f) 55 | DrawRectangle 500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f) 56 | 57 | if drawRing: DrawRing center,innerRadius,outerRadius,startAngle.int,endAngle.int,segments,Fade(MAROON, 0.3) 58 | if drawRingLines: DrawRingLines center,innerRadius,outerRadius,startAngle.int,endAngle.int,segments,Fade(BLACK, 0.4) 59 | if drawCircleLines: DrawCircleSectorLines center,outerRadius,startAngle.int,endAngle.int,segments,Fade(BLACK, 0.4) 60 | 61 | # Draw GUI controls 62 | # ------------------------------------------------------------------------------ 63 | startAngle = GuiSliderBar(Rectangle(x: 600, y: 40, width: 120, height: 20), "StartAngle", "", startAngle, -450,450) 64 | endAngle = GuiSliderBar(Rectangle(x: 600, y: 70, width: 120, height: 20), "EndAngle", "", endAngle, -450,450) 65 | 66 | innerRadius = GuiSliderBar(Rectangle(x: 600, y: 140, width: 120, height: 20), "InnerRadius", "", innerRadius, 0,100) 67 | outerRadius = GuiSliderBar(Rectangle(x: 600, y: 170, width: 120, height: 20), "OuterRadius", "", outerRadius, 0,200) 68 | 69 | segments = GuiSliderBar(Rectangle(x: 600, y: 240, width: 120, height: 20), "Segments", "", segments.float, 0,100).int 70 | 71 | drawRing = GuiCheckBox(Rectangle(x: 600, y: 320, width: 20, height: 20), "Draw Ring", drawRing) 72 | drawRingLines = GuiCheckBox(Rectangle(x: 600, y: 350, width: 20, height: 20), "Draw RingLines", drawRingLines) 73 | drawCircleLines = GuiCheckBox(Rectangle(x: 600, y: 380, width: 20, height: 20), "Draw CircleLines", drawCircleLines) 74 | # ------------------------------------------------------------------------------ 75 | 76 | DrawText TextFormat("MODE: %s", (if segments >= 4: "MANUAL" else: "AUTO")), 600, 270, 10, 77 | (if segments >= 4: MAROON else: DARKGRAY) 78 | 79 | DrawFPS 10, 10 80 | 81 | EndDrawing() 82 | # ---------------------------------------------------------------------------------- 83 | 84 | # De-Initialization 85 | # -------------------------------------------------------------------------------------- 86 | CloseWindow() # Close window and OpenGL context 87 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/shapes/following_eyes.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [shapes] example - following eyes 4 | # 5 | # This example has been created using raylib 2.5 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) 9 | # /Converted in 2*20 by Guevara-chan. 10 | # 11 | #******************************************************************************************* 12 | 13 | import raylib, math 14 | 15 | # Initialization 16 | # -------------------------------------------------------------------------------------- 17 | const screenWidth = 800 18 | const screenHeight = 450 19 | 20 | InitWindow screenWidth, screenHeight, "raylib [shapes] example - following eyes" 21 | 22 | var 23 | scleraLeftPosition = Vector2(x: GetScreenWidth()/2 - 100, y: GetScreenHeight()/2) 24 | scleraRightPosition = Vector2(x: GetScreenWidth()/2 + 100, y: GetScreenHeight()/2) 25 | scleraRadius = 80.0 26 | 27 | irisLeftPosition = Vector2(x: GetScreenWidth()/2 - 100, y: GetScreenHeight()/2) 28 | irisRightPosition = Vector2(x: GetScreenWidth()/2 + 100, y: GetScreenHeight()/2) 29 | irisRadius = 24.0 30 | 31 | angle = 0.0f 32 | dx = 0.0f 33 | dy = 0.0f 34 | dxx = 0.0f 35 | dyy = 0.0f 36 | 37 | SetTargetFPS 60 # Set our game to run at 60 frames-per-second 38 | # -------------------------------------------------------------------------------------- 39 | 40 | # Main game loop 41 | while not WindowShouldClose(): # Detect window close button or ESC key 42 | # Update 43 | # ---------------------------------------------------------------------------------- 44 | irisLeftPosition = GetMousePosition() 45 | irisRightPosition = GetMousePosition() 46 | 47 | # Check not inside the left eye sclera 48 | if not CheckCollisionPointCircle(irisLeftPosition, scleraLeftPosition, scleraRadius - 20): 49 | dx = irisLeftPosition.x - scleraLeftPosition.x; 50 | dy = irisLeftPosition.y - scleraLeftPosition.y; 51 | 52 | angle = arctan2(dy, dx) 53 | 54 | dxx = (scleraRadius - irisRadius)*angle.cos 55 | dyy = (scleraRadius - irisRadius)*angle.sin 56 | 57 | irisLeftPosition.x = scleraLeftPosition.x + dxx 58 | irisLeftPosition.y = scleraLeftPosition.y + dyy 59 | 60 | # Check not inside the right eye sclera 61 | if not CheckCollisionPointCircle(irisRightPosition, scleraRightPosition, scleraRadius - 20): 62 | dx = irisRightPosition.x - scleraRightPosition.x 63 | dy = irisRightPosition.y - scleraRightPosition.y 64 | 65 | angle = arctan2(dy, dx) 66 | 67 | dxx = (scleraRadius - irisRadius)*angle.cos 68 | dyy = (scleraRadius - irisRadius)*angle.sin 69 | 70 | irisRightPosition.x = scleraRightPosition.x + dxx 71 | irisRightPosition.y = scleraRightPosition.y + dyy 72 | # ---------------------------------------------------------------------------------- 73 | 74 | # Draw 75 | # ---------------------------------------------------------------------------------- 76 | BeginDrawing() 77 | 78 | ClearBackground RAYWHITE 79 | 80 | DrawCircleV scleraLeftPosition, scleraRadius, LIGHTGRAY 81 | DrawCircleV irisLeftPosition, irisRadius, BROWN 82 | DrawCircleV irisLeftPosition, 10, BLACK 83 | 84 | DrawCircleV scleraRightPosition, scleraRadius, LIGHTGRAY 85 | DrawCircleV irisRightPosition, irisRadius, DARKGREEN 86 | DrawCircleV irisRightPosition, 10, BLACK 87 | 88 | DrawFPS 10, 10 89 | 90 | EndDrawing() 91 | # ---------------------------------------------------------------------------------- 92 | 93 | # De-Initialization 94 | # -------------------------------------------------------------------------------------- 95 | CloseWindow() # Close window and OpenGL context 96 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/text/format_text.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [text] example - Text formatting 4 | # 5 | # This example has been created using raylib 1.1 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Copyright (c) 2014 Ramon Santamaria (@raysan5) 9 | # /Converted in 2*20 by Guevara-chan. 10 | # 11 | #******************************************************************************************* 12 | 13 | import raylib 14 | 15 | # Initialization 16 | # -------------------------------------------------------------------------------------- 17 | const screenWidth = 800 18 | const screenHeight = 450 19 | 20 | InitWindow screenWidth, screenHeight, "raylib [text] example - text formatting" 21 | 22 | let 23 | score = 100020 24 | hiscore = 200450 25 | lives = 5 26 | 27 | SetTargetFPS(60) # Set our game to run at 60 frames-per-second 28 | # -------------------------------------------------------------------------------------- 29 | 30 | # Main game loop 31 | while not WindowShouldClose(): # Detect window close button or ESC key 32 | # Update 33 | # ---------------------------------------------------------------------------------- 34 | # TODO: Update your variables here 35 | # ---------------------------------------------------------------------------------- 36 | 37 | # Draw 38 | # ---------------------------------------------------------------------------------- 39 | BeginDrawing() 40 | 41 | ClearBackground RAYWHITE 42 | 43 | DrawText TextFormat("Score: %08i", score), 200, 80, 20, RED 44 | 45 | DrawText TextFormat("HiScore: %08i", hiscore), 200, 120, 20, GREEN 46 | 47 | DrawText TextFormat("Lives: %02i", lives), 200, 160, 40, BLUE 48 | 49 | DrawText TextFormat("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK 50 | 51 | EndDrawing() 52 | # ---------------------------------------------------------------------------------- 53 | 54 | # De-Initialization 55 | # -------------------------------------------------------------------------------------- 56 | CloseWindow() # Close window and OpenGL context 57 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/text/input_box.nim: -------------------------------------------------------------------------------- 1 | #****************************************************************************************** 2 | # 3 | # raylib [text] 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) 2017 Ramon Santamaria (@raysan5) 9 | # /Converted in 2*20 by Guevara-chan. 10 | # 11 | #******************************************************************************************* 12 | 13 | include raylib 14 | 15 | const MAX_INPUT_CHARS = 9 16 | 17 | # Initialization 18 | # -------------------------------------------------------------------------------------- 19 | const screenWidth = 800 20 | const screenHeight = 450 21 | 22 | InitWindow screenWidth, screenHeight, "raylib [text] example - input box" 23 | 24 | var 25 | name: array[MAX_INPUT_CHARS+1, char] # NOTE: One extra space required for line ending char '\0' 26 | letterCount = 0 27 | 28 | textBox = Rectangle(x: screenWidth/2 - 100, y: 180, width: 225, height: 50) 29 | mouseOnText = false 30 | 31 | framesCounter = 0 32 | 33 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 34 | # -------------------------------------------------------------------------------------- 35 | 36 | # Main game loop 37 | while not WindowShouldClose():# Detect window close button or ESC key 38 | # Update 39 | # ---------------------------------------------------------------------------------- 40 | mouseOnText = CheckCollisionPointRec(GetMousePosition(), textBox) 41 | 42 | if mouseOnText: 43 | # Get pressed key (character) on the queue 44 | var key = GetKeyPressed() 45 | 46 | # Check if more characters have been pressed on the same frame 47 | while key > 0: 48 | # NOTE: Only allow keys in range [32..125] 49 | if key >= 32 and key <= 125 and letterCount < MAX_INPUT_CHARS: 50 | name[letterCount] = key.char 51 | letterCount.inc 52 | key = GetKeyPressed() # Check next character in the queue 53 | 54 | if KEY_BACKSPACE.IsKeyPressed: 55 | letterCount.dec 56 | if letterCount < 0: letterCount = 0 57 | name[letterCount] = '\0' 58 | 59 | if mouseOnText: framesCounter.inc else: framesCounter = 0 60 | # ---------------------------------------------------------------------------------- 61 | 62 | # Draw 63 | # ---------------------------------------------------------------------------------- 64 | BeginDrawing() 65 | 66 | ClearBackground RAYWHITE 67 | 68 | DrawText "PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY 69 | 70 | DrawRectangleRec textBox, LIGHTGRAY 71 | if mouseOnText: DrawRectangleLines textBox.x.int, textBox.y.int, textBox.width.int, textBox.height.int, RED 72 | else: DrawRectangleLines textBox.x.int, textBox.y.int, textBox.width.int, textBox.height.int, DARKGRAY 73 | 74 | let namestr = cast[cstring](addr name[0]) 75 | DrawText $namestr, textBox.x.int + 5, textBox.y.int + 8, 40, MAROON 76 | 77 | DrawText TextFormat("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY 78 | 79 | if mouseOnText: 80 | if letterCount < MAX_INPUT_CHARS: 81 | # Draw blinking underscore char 82 | if (framesCounter div 20)%%2 == 0: 83 | DrawText "_", textBox.x.int + 8 + MeasureText(namestr, 40), textBox.y.int + 12, 40, MAROON 84 | else: DrawText "Press BACKSPACE to delete chars...", 230, 300, 20, GRAY 85 | 86 | EndDrawing() 87 | # ---------------------------------------------------------------------------------- 88 | 89 | # De-Initialization 90 | # -------------------------------------------------------------------------------------- 91 | CloseWindow() # Close window and OpenGL context 92 | # -------------------------------------------------------------------------------------- 93 | 94 | # Check if any key is pressed 95 | # NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126 96 | proc IsAnyKeyPressed(): bool = 97 | var 98 | keyPressed = false 99 | key = GetKeyPressed() 100 | 101 | if key >= 32 and key <= 126: keyPressed = true 102 | 103 | return keyPressed -------------------------------------------------------------------------------- /examples/text/rectangle_bound.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [text] example - Draw text inside a rectangle 4 | # 5 | # This example has been created using raylib 2.3 (www.raylib.com) 6 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 7 | # 8 | # Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) 9 | # 10 | # Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) 11 | # /Converted in 2*20 by Guevara-chan. 12 | # 13 | #******************************************************************************************* 14 | 15 | import raylib 16 | 17 | # Initialization 18 | # -------------------------------------------------------------------------------------- 19 | const screenWidth = 800 20 | const screenHeight = 450 21 | 22 | InitWindow screenWidth, screenHeight, "raylib [text] example - draw text inside a rectangle" 23 | 24 | let text = "Text cannot escape\tthis container\t...word wrap also works when active so here's" & 25 | "a long text for testing.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod" & 26 | "tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet risus nullam eget felis eget." 27 | 28 | var 29 | resizing = false 30 | wordWrap = true 31 | 32 | container = Rectangle(x: 25, y: 25, width: screenWidth - 50, height: screenHeight - 250) 33 | resizer = Rectangle(x: container.x+container.width-17, y: container.y+container.height-17, width: 14, height: 14) 34 | 35 | # Minimum width and heigh for the container rectangle 36 | const minWidth = 60 37 | const minHeight = 60 38 | const maxWidth = screenWidth - 50 39 | const maxHeight = screenHeight - 160 40 | 41 | var 42 | lastMouse = Vector2(x: 0.0f, y: 0.0f) # Stores last mouse coordinates 43 | borderColor = MAROON # Container border color 44 | font = GetFontDefault() # Get default system font 45 | 46 | 60.SetTargetFPS # Set our game to run at 60 frames-per-second 47 | # -------------------------------------------------------------------------------------- 48 | 49 | # Main game loop 50 | while not WindowShouldClose(): # Detect window close button or ESC key 51 | # Update 52 | # ---------------------------------------------------------------------------------- 53 | if IsKeyPressed(KEY_SPACE): wordWrap = not wordWrap 54 | 55 | let mouse = GetMousePosition() 56 | 57 | # Check if the mouse is inside the container and toggle border color 58 | if CheckCollisionPointRec(mouse, container): borderColor = Fade(MAROON, 0.4f) 59 | elif not resizing: borderColor = MAROON 60 | 61 | # Container resizing logic 62 | if resizing: 63 | if IsMouseButtonReleased(MOUSE_LEFT_BUTTON): resizing = false 64 | 65 | let width = container.width + (mouse.x - lastMouse.x) 66 | container.width = if width > minWidth: (if width < maxWidth: width else: maxWidth) else: minWidth 67 | 68 | let height = container.height + (mouse.y - lastMouse.y) 69 | container.height = if height > minHeight: (if height < maxHeight: height else: maxHeight) else: minHeight 70 | else: 71 | # Check if we're resizing 72 | if IsMouseButtonDown(MOUSE_LEFT_BUTTON) and CheckCollisionPointRec(mouse, resizer): resizing = true 73 | 74 | # Move resizer rectangle properly 75 | resizer.x = container.x + container.width - 17 76 | resizer.y = container.y + container.height - 17 77 | 78 | lastMouse = mouse # Update mouse 79 | # ---------------------------------------------------------------------------------- 80 | 81 | # Draw 82 | # ---------------------------------------------------------------------------------- 83 | BeginDrawing() 84 | 85 | ClearBackground RAYWHITE 86 | 87 | DrawRectangleLinesEx container, 3, borderColor # Draw container border 88 | 89 | # Draw text in container (add some padding) 90 | DrawTextRec font, text, 91 | Rectangle(x: container.x + 4, y: container.y + 4, width: container.width-4, height: container.height-4), 92 | 20.0f, 2.0f, wordWrap, GRAY 93 | 94 | DrawRectangleRec resizer, borderColor # Draw the resize box 95 | 96 | # Draw bottom info 97 | DrawRectangle 0, screenHeight - 54, screenWidth, 54, GRAY 98 | DrawRectangleRec Rectangle(x: 382, y: screenHeight - 34, width: 12, height: 12), MAROON 99 | 100 | DrawText "Word Wrap: ", 313, screenHeight-115, 20, BLACK 101 | if wordWrap: DrawText "ON", 447, screenHeight - 115, 20, RED 102 | else: DrawText "OFF", 447, screenHeight - 115, 20, BLACK 103 | 104 | DrawText "Press [SPACE] to toggle word wrap", 218, screenHeight - 86, 20, GRAY 105 | 106 | DrawText "Click hold & drag the to resize the container", 155, screenHeight - 38, 20, RAYWHITE 107 | 108 | EndDrawing() 109 | # ---------------------------------------------------------------------------------- 110 | 111 | # De-Initialization 112 | # -------------------------------------------------------------------------------------- 113 | CloseWindow() # Close window and OpenGL context 114 | # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /examples/textures/image_processing.nim: -------------------------------------------------------------------------------- 1 | #******************************************************************************************* 2 | # 3 | # raylib [textures] example - Image processing 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.4 (www.raylib.com) 8 | # raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 9 | # 10 | # Copyright (c) 2016 Ramon Santamaria (@raysan5) 11 | # /Converted in 2*20 by Guevara-chan. 12 | # 13 | #******************************************************************************************* 14 | 15 | import raylib, system/[ansi_c] 16 | 17 | const NUM_PROCESSES = 8 18 | 19 | type ImageProcess = enum 20 | NONE = 0 21 | COLOR_GRAYSCALE 22 | COLOR_TINT 23 | COLOR_INVERT 24 | COLOR_CONTRAST 25 | COLOR_BRIGHTNESS 26 | FLIP_VERTICAL 27 | FLIP_HORIZONTAL 28 | 29 | const processText = [ 30 | "NO PROCESSING", 31 | "COLOR GRAYSCALE", 32 | "COLOR TINT", 33 | "COLOR INVERT", 34 | "COLOR CONTRAST", 35 | "COLOR BRIGHTNESS", 36 | "FLIP VERTICAL", 37 | "FLIP HORIZONTAL" 38 | ] 39 | 40 | # Initialization 41 | # -------------------------------------------------------------------------------------- 42 | const screenWidth = 800 43 | const screenHeight = 450 44 | 45 | InitWindow screenWidth, screenHeight, "raylib [textures] example - image processing" 46 | 47 | # NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 48 | 49 | var image = LoadImage("resources/parrots.png") # Loaded in CPU memory (RAM) 50 | ImageFormat image.addr, UNCOMPRESSED_R8G8B8A8 # Format image to RGBA 32bit (required for texture update) <-- ISSUE 51 | let texture = LoadTextureFromImage image # Image converted to texture, GPU memory (VRAM) 52 | 53 | var 54 | currentProcess = NONE 55 | textureReload = false 56 | selectRecs: array[NUM_PROCESSES, Rectangle] 57 | 58 | for i in 0.. 2 | 3 | 4 | 5 | ◢.Raylib Forever.◣ 6 | 7 | 8 | 9 | 17 | 18 | 19 | raylib official site 20 | (C) Guevara-chan 21 | /examples/ 22 | #binaries 23 |
..:Reload ?:..
24 | 25 | 26 | -------------------------------------------------------------------------------- /res/grixel.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guevara-chan/Raylib-Forever/4839cf046e59dbde2b460398ce2a10fc3fa1ba22/res/grixel.ttf --------------------------------------------------------------------------------