diff --git a/CHANGELOG b/CHANGELOG index 87052478c..8b51d7999 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,21 +11,25 @@ NOTE: It includes some interesting new features and is a stepping stone towards raylib future. HUGE changes: -[rlua] LUA BINDING: Complete raylib LUA binding, all raylib functions ported to LUA plus the +60 code examples. -[audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing. FLAC support added. +[rlua] LUA BINDING: Complete raylib LUA binding, ALL raylib functions ported to LUA plus the +60 code examples. +[audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing, +20 new functions added. [physac] COMPLETE REWRITE: Improved performance, functionality and simplified usage, moved to own repository and added multiple examples! -other changes: +Other changes: [core] Corrected issue on OSX with HighDPI display [core] Added flag to allow resizable window [core] Allow no default font loading [core] Corrected old issue with mouse buttons on web [core] Improved gamepad support, unified across platforms +[core] Gamepad id functionality: GetGamepadName(), IsGamepadName() +[core] Gamepad buttons/axis checking functionality: [core] Reviewed Android key inputs system, unified with desktop [rlgl] Redesigned lighting shader system -[rlgl] Reviewed UpdateVrTracking() and rlglLoadRenderTexture() [rlgl] Updated standard shader for better performance +[rlgl] Support alpha on framebuffer: rlglLoadRenderTexture() +[rlgl] Reviewed UpdateVrTracking() to update camera +[rlgl] Added IsVrSimulator() to check for VR simulator [shapes] Corrected issue on DrawPolyEx() [textures] Simplified supported image formats support [textures] Improved text drawing within an image: ImageDrawText() @@ -33,17 +37,18 @@ other changes: [textures] Support textures filtering: SetTextureFilter() [textures] Support textures wrap modes: SetTextureWrap() [text] Improved TTF spritefont generation: LoadSpriteFontTTF() -[text] Improved AngelCode fonts support -[text] Reviewed spacing formatting +[text] Improved AngelCode fonts support (unordered chars) [text] Added TraceLog info on image spritefont loading [text] Improved text measurement: MeasureTextEx() [models] Improved OBJ loading flexibility +[models] Reviewed functions: DrawLine3D(), DrawCircle3D() [models] Removed function: ResolveCollisionCubicmap() [camera] Redesigned camera system and ported to header-only +[camera] Removed function: UpdateCameraPlayer() [gestures] Redesigned gestures module to header-only [audio] Simplified Music loading and playing system [audio] Added trace on audio device closing -[audio] Reviewed Wave struct for reter flexivility +[audio] Reviewed Wave struct, improved flexibility [audio] Support sound data update: UpdateSound() [audio] Added support for FLAC audio loading/streaming [raygui] Removed raygui from raylib repo (moved to own repo) @@ -52,8 +57,8 @@ other changes: [build] Support shared/dynamic raylib compilation [*] Updated LibOVR to SDK version 1.8 [*] Updated games to latest raylib version -[*] Improved Android support [*] Improved examples and added new ones +[*] Improved Android support ----------------------------------------------- Release: raylib 1.5.0 (18 July 2016) diff --git a/README.md b/README.md index df1fa0ff9..6d0323500 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,9 @@ On November 2016, only 4 months after raylib 1.5, arrives raylib 1.6. This new v Complete raylib LUA binding. All raylib functions plus the +60 code examples have been ported to LUA, now LUA users can enjoy coding videogames in LUA while using all the internal power of raylib. This addition also open the doors to LUA scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to LUA scripts while keep using raylib functionality. -Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added to allow raw audio processing and playing. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more! +Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added (+20 new functions) to allow raw audio processing and streaming. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more! + +Physac module has been moved to its own repository and it has been improved A LOT, actually, library has been completely rewritten from scratch by @victorfisac, multiple samples have been added together with countless new features to match current standard 2D physic libraries. Results are amazing! Camera and gestures modules have been reviewed, highly simplified and ported to single-file header-only libraries for easier portability and usage flexibility. Consequently, camera system usage has been simplified in all examples. @@ -168,8 +170,6 @@ Improved Gamepad support on Windows and Raspberry Pi with the addition of new fu Improved textures and text functionality, adding new functions for texture filtering control and better TTF/AngelCode fonts loading and generation support. -Physac module has been moved to its own repository and it has been improved A LOT, actually, library has been completely rewritten by @victorfisac, multiple samples have been added and countless new features to match current standard 2D physic libraries. - Build system improvement. Added support for raylib dynamic library generation (raylib.dll) for users that prefer dynamic library linking. Also thinking on advance users, it has been added pre-configured Visual Studio C++ 2015 solution with raylib project and C/C++ examples for users that prefer that professional IDE and compiler. New examples, new functions, complete code-base review, multiple bugs corrected... this is raylib 1.6. Enjoy making games. diff --git a/examples/Makefile b/examples/Makefile index 378f5edfd..710e97c47 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,6 +2,8 @@ # # raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten) # +# NOTE: By default examples are compiled using raylib static library and OpenAL Soft shared library +# # Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event @@ -26,6 +28,9 @@ # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop() PLATFORM ?= PLATFORM_DESKTOP +# define NO to use OpenAL Soft as static library (shared by default) +SHARED_OPENAL ?= YES + # determine PLATFORM_OS in case PLATFORM_DESKTOP selected ifeq ($(PLATFORM),PLATFORM_DESKTOP) # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows @@ -62,12 +67,13 @@ endif # define compiler flags: # -O2 defines optimization level +# -s strip unnecessary data from build # -Wall turns on most, but not all, compiler warnings # -std=c99 use standard C from 1999 revision ifeq ($(PLATFORM),PLATFORM_RPI) - CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline + CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline else - CFLAGS = -O2 -Wall -std=c99 + CFLAGS = -O2 -s -Wall -std=c99 endif ifeq ($(PLATFORM),PLATFORM_WEB) CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources @@ -151,7 +157,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) else # libraries for Windows desktop compiling # NOTE: GLFW3 and OpenAL Soft libraries should be installed - LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32 + LIBS = -lraylib -lglfw3 -lopengl32 -lgdi32 + # if static OpenAL Soft required, define the corresponding libs + ifeq ($(SHARED_OPENAL),NO) + LIBS += -lopenal32 -lwinmm + CFLAGS += -Wl,-allow-multiple-definition + else + LIBS += -lopenal32dll + endif endif endif endif @@ -215,6 +228,8 @@ EXAMPLES = \ text_format_text \ text_font_select \ text_writing_anim \ + text_ttf_loading \ + text_bmfont_unordered \ models_geometric_shapes \ models_box_collisions \ models_billboard \ @@ -230,6 +245,11 @@ EXAMPLES = \ audio_music_stream \ audio_module_playing \ audio_raw_stream \ + physics_demo \ + physics_friction \ + physics_movement \ + physics_restitution \ + physics_shatter \ fix_dylib \ @@ -400,6 +420,14 @@ text_font_select: text_font_select.c text_writing_anim: text_writing_anim.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) +# compile [text] example - text ttf loading +text_ttf_loading: text_ttf_loading.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + +# compile [text] example - text bmfont unordered +text_bmfont_unordered: text_bmfont_unordered.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + # compile [models] example - basic geometric 3d shapes models_geometric_shapes: models_geometric_shapes.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) @@ -464,6 +492,26 @@ audio_module_playing: audio_module_playing.c audio_raw_stream: audio_raw_stream.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) +# compile [physac] example - physics demo +physics_demo: physics_demo.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS) + +# compile [physac] example - physics friction +physics_friction: physics_friction.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS) + +# compile [physac] example - physics movement +physics_movement: physics_movement.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS) + +# compile [physac] example - physics restitution +physics_restitution: physics_restitution.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS) + +# compile [physac] example - physics shatter +physics_shatter: physics_shatter.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS) + # fix dylib install path name for each executable (MAC) fix_dylib: ifeq ($(PLATFORM_OS),OSX) diff --git a/examples/audio_module_playing.c b/examples/audio_module_playing.c index 7da3579cc..a9ee46193 100644 --- a/examples/audio_module_playing.c +++ b/examples/audio_module_playing.c @@ -30,6 +30,8 @@ int main() int screenWidth = 800; int screenHeight = 450; + SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X + InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)"); InitAudioDevice(); // Initialize audio device @@ -49,13 +51,6 @@ int main() circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f; circles[i].color = colors[GetRandomValue(0, 13)]; } - - // Load postprocessing bloom shader - Shader shader = LoadShader("resources/shaders/glsl330/base.vs", - "resources/shaders/glsl330/bloom.fs"); - - // Create a RenderTexture2D to be used for render to texture - RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); Music xm = LoadMusicStream("resources/audio/mini1111.xm"); @@ -117,28 +112,17 @@ int main() //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(BLACK); + ClearBackground(WHITE); - BeginTextureMode(target); // Enable drawing to texture - - for (int i = MAX_CIRCLES - 1; i >= 0; i--) - { - DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)); - } - - EndTextureMode(); // End drawing to texture (now we have a texture available for next passes) + for (int i = MAX_CIRCLES - 1; i >= 0; i--) + { + DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)); + } - BeginShaderMode(shader); - - // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); - - EndShaderMode(); - // Draw time bar DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY); DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON); - DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE); + DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -146,9 +130,6 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadRenderTexture(target); // Unload render texture - UnloadMusicStream(xm); // Unload music stream buffers from RAM CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) diff --git a/examples/audio_module_playing.lua b/examples/audio_module_playing.lua index 3c5ad6410..7c675424c 100644 --- a/examples/audio_module_playing.lua +++ b/examples/audio_module_playing.lua @@ -37,13 +37,6 @@ for i = MAX_CIRCLES, 1, -1 do circles[i].color = colors[GetRandomValue(1, 14)] end --- Load postprocessing bloom shader -local shader = LoadShader("resources/shaders/glsl330/base.vs", - "resources/shaders/glsl330/bloom.fs") - --- Create a RenderTexture2D to be used for render to texture -local target = LoadRenderTexture(screenWidth, screenHeight) - local xm = LoadMusicStream("resources/audio/mini1111.xm") PlayMusicStream(xm) @@ -83,22 +76,11 @@ while not WindowShouldClose() do -- Detect window close button or ESC key --------------------------------------------------------------------------------------- BeginDrawing() - ClearBackground(BLACK) + ClearBackground(RAYWHITE) - BeginTextureMode(target) -- Enable drawing to texture - - for i = MAX_CIRCLES, 1, -1 do - DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)) - end - - EndTextureMode() -- End drawing to texture (now we have a texture available for next passes) - - BeginShaderMode(shader) - - -- NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, Rectangle(0, 0, target.texture.width, -target.texture.height), Vector2(0, 0), WHITE) - - EndShaderMode() + for i = MAX_CIRCLES, 1, -1 do + DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)) + end -- Draw time bar DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY) @@ -111,10 +93,7 @@ end -- De-Initialization ------------------------------------------------------------------------------------------- -UnloadShader(shader) -- Unload shader -UnloadRenderTexture(target) -- Unload render texture - -UnloadMusicStream(xm) -- Unload music stream buffers from RAM +UnloadMusicStream(xm) -- Unload music stream buffers from RAM CloseAudioDevice() -- Close audio device (music streaming is automatically stopped) diff --git a/examples/audio_module_playing.png b/examples/audio_module_playing.png index 7c2e469f6..8bde9879d 100644 Binary files a/examples/audio_module_playing.png and b/examples/audio_module_playing.png differ diff --git a/examples/audio_raw_stream.png b/examples/audio_raw_stream.png new file mode 100644 index 000000000..344f4a710 Binary files /dev/null and b/examples/audio_raw_stream.png differ diff --git a/examples/audio_standalone.c b/examples/audio_standalone.c index c716faedb..7688b881c 100644 --- a/examples/audio_standalone.c +++ b/examples/audio_standalone.c @@ -32,6 +32,8 @@ int main() { + // Initialization + //-------------------------------------------------------------------------------------- unsigned char key; InitAudioDevice(); @@ -43,7 +45,9 @@ int main() PlayMusicStream(music); printf("\nPress s or d to play sounds...\n"); - + //-------------------------------------------------------------------------------------- + + // Main loop while (key != KEY_ESCAPE) { if (kbhit()) key = getch(); @@ -63,15 +67,15 @@ int main() UpdateMusicStream(music); } + // De-Initialization + //-------------------------------------------------------------------------------------- UnloadSound(fxWav); // Unload sound data UnloadSound(fxOgg); // Unload sound data UnloadMusicStream(music); // Unload music stream data CloseAudioDevice(); - - printf("\n\nPress ENTER to close..."); - getchar(); + //-------------------------------------------------------------------------------------- return 0; } \ No newline at end of file diff --git a/examples/core_3d_camera_first_person.lua b/examples/core_3d_camera_first_person.lua index 800c3c2a1..22ccdc5c5 100644 --- a/examples/core_3d_camera_first_person.lua +++ b/examples/core_3d_camera_first_person.lua @@ -19,7 +19,7 @@ local screenHeight = 450 InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person") -- Define the camera to look into our 3d world (position, target, up vector) -local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 60.0) +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) -- Generates some random columns local heights = {} @@ -34,17 +34,16 @@ end local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position -SetCameraMode(CameraMode.FIRST_PERSON) -- Set a first person camera mode -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FIRST_PERSON) -- Set a first person camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera, playerPosition = UpdateCameraPlayer(camera, playerPosition) -- Update camera and player position + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/core_3d_camera_free.lua b/examples/core_3d_camera_free.lua index 244aad6b8..57fa7a12f 100644 --- a/examples/core_3d_camera_free.lua +++ b/examples/core_3d_camera_free.lua @@ -18,26 +18,23 @@ InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free") -- Define the camera to look into our 3d world local camera = {} -camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position +camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) camera.fovy = 45.0 -- Camera field-of-view Y local cubePosition = Vector3(0.0, 0.0, 0.0) -SetCameraMode(CameraMode.FREE) -- Set a free camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/core_3d_picking.lua b/examples/core_3d_picking.lua index 1adee67c1..230f5756f 100644 --- a/examples/core_3d_picking.lua +++ b/examples/core_3d_picking.lua @@ -30,18 +30,16 @@ local ray = Ray(Vector3(0, 0, 0), Vector3(0, 0, 0)) -- Picking line ray local collision = false -SetCameraMode(CameraMode.FREE) -- Set a free camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then -- NOTE: This function is NOT WORKING properly! diff --git a/examples/core_drop_files.c b/examples/core_drop_files.c index 5eea35f3c..5c1501b83 100644 --- a/examples/core_drop_files.c +++ b/examples/core_drop_files.c @@ -23,7 +23,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); int count = 0; - char **droppedFiles; + char **droppedFiles = { 0 }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- diff --git a/examples/core_input_gamepad.lua b/examples/core_input_gamepad.lua index 78d9b84e8..ade3f00f8 100644 --- a/examples/core_input_gamepad.lua +++ b/examples/core_input_gamepad.lua @@ -19,8 +19,8 @@ local screenHeight = 450 InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input") -local ballPosition = Vector2(screenWidth/2, screenHeight/2) -local gamepadMovement = Vector2(0, 0) +local texPs3Pad = LoadTexture("resources/ps3.png") +local texXboxPad = LoadTexture("resources/xbox.png") SetTargetFPS(60) -- Set target frames-per-second ------------------------------------------------------------------------------------------- @@ -29,18 +29,7 @@ SetTargetFPS(60) -- Set target frames-per-second while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then - gamepadMovement.x = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X) - gamepadMovement.y = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y) - - ballPosition.x = ballPosition.x + gamepadMovement.x - ballPosition.y = ballPosition.y - gamepadMovement.y - - if (IsGamepadButtonPressed(GAMEPAD.PLAYER1, GAMEPAD.BUTTON_A)) then - ballPosition.x = screenWidth/2 - ballPosition.y = screenHeight/2 - end - end + -- ... --------------------------------------------------------------------------------------- -- Draw @@ -49,9 +38,117 @@ while not WindowShouldClose() do -- Detect window close button or ESC key ClearBackground(RAYWHITE) - DrawText("move the ball with gamepad", 10, 10, 20, DARKGRAY) + if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then + DrawText(string.format("GP1: %s", GetGamepadName(GAMEPAD.PLAYER1)), 10, 10, 10, BLACK) - DrawCircleV(ballPosition, 50, MAROON) + if (IsGamepadName(GAMEPAD.PLAYER1, "Xbox 360 Controller")) then + DrawTexture(texXboxPad, 0, 0, DARKGRAY) + + -- Draw buttons: xbox home + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_HOME)) then DrawCircle(394, 89, 19, RED) end + + -- Draw buttons: basic + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_START)) then DrawCircle(436, 150, 9, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_SELECT)) then DrawCircle(352, 150, 9, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_X)) then DrawCircle(501, 151, 15, BLUE) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_A)) then DrawCircle(536, 187, 15, LIME) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_B)) then DrawCircle(572, 151, 15, MAROON) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_Y)) then DrawCircle(536, 115, 15, GOLD) end + + -- Draw buttons: d-pad + DrawRectangle(317, 202, 19, 71, BLACK) + DrawRectangle(293, 228, 69, 19, BLACK) + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_UP)) then DrawRectangle(317, 202, 19, 26, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_DOWN)) then DrawRectangle(317, 202 + 45, 19, 26, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LEFT)) then DrawRectangle(292, 228, 25, 19, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RIGHT)) then DrawRectangle(292 + 44, 228, 26, 19, RED) end + + -- Draw buttons: left-right back + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LB)) then DrawCircle(259, 61, 20, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RB)) then DrawCircle(536, 61, 20, RED) end + + -- Draw axis: left joystick + DrawCircle(259, 152, 39, BLACK) + DrawCircle(259, 152, 34, LIGHTGRAY) + DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)*20), + 152 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)*20), 25, BLACK) + + -- Draw axis: right joystick + DrawCircle(461, 237, 38, BLACK) + DrawCircle(461, 237, 33, LIGHTGRAY) + DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_X)*20), + 237 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_Y)*20), 25, BLACK) + + -- Draw axis: left-right triggers + DrawRectangle(170, 30, 15, 70, GRAY) + DrawRectangle(604, 30, 15, 70, GRAY) + DrawRectangle(170, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT))/2.0)*70), RED) + DrawRectangle(604, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT))/2.0)*70), RED) + + --DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT)), 10, 40, 10, BLACK) + --DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT)), 10, 60, 10, BLACK) + elseif (IsGamepadName(GAMEPAD.PLAYER1, "PLAYSTATION(R)3 Controller")) then + DrawTexture(texPs3Pad, 0, 0, DARKGRAY) + + -- Draw buttons: ps + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_PS)) then DrawCircle(396, 222, 13, RED) end + + -- Draw buttons: basic + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SELECT)) then DrawRectangle(328, 170, 32, 13, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_START)) then DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_TRIANGLE)) then DrawCircle(557, 144, 13, LIME) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CIRCLE)) then DrawCircle(586, 173, 13, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CROSS)) then DrawCircle(557, 203, 13, VIOLET) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SQUARE)) then DrawCircle(527, 173, 13, PINK) end + + -- Draw buttons: d-pad + DrawRectangle(225, 132, 24, 84, BLACK) + DrawRectangle(195, 161, 84, 25, BLACK) + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_UP)) then DrawRectangle(225, 132, 24, 29, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_DOWN)) then DrawRectangle(225, 132 + 54, 24, 30, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_LEFT)) then DrawRectangle(195, 161, 30, 25, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_RIGHT)) then DrawRectangle(195 + 54, 161, 30, 25, RED) end + + -- Draw buttons: left-right back buttons + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_L1)) then DrawCircle(239, 82, 20, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_R1)) then DrawCircle(557, 82, 20, RED) end + + -- Draw axis: left joystick + DrawCircle(319, 255, 35, BLACK) + DrawCircle(319, 255, 31, LIGHTGRAY) + DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_X)*20), + 255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_Y)*20), 25, BLACK) + + -- Draw axis: right joystick + DrawCircle(475, 255, 35, BLACK) + DrawCircle(475, 255, 31, LIGHTGRAY) + DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_X)*20), + 255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_Y)*20), 25, BLACK) + + -- Draw axis: left-right triggers + DrawRectangle(169, 48, 15, 70, GRAY) + DrawRectangle(611, 48, 15, 70, GRAY) + DrawRectangle(169, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_L2))/2.0)*70), RED) + DrawRectangle(611, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_R2))/2.0)*70), RED) + else + DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY) + + -- TODO: Draw generic gamepad + end + + DrawText(string.format("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD.PLAYER1)), 10, 50, 10, MAROON) + + for i = 1, GetGamepadAxisCount(GAMEPAD.PLAYER1) do -- Iterate along all the rectangles + DrawText(string.format("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD.PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY) + end + + if (GetGamepadButtonPressed() ~= -1) then DrawText(string.format("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED) + else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY) end + else + DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY) + + DrawTexture(texXboxPad, 0, 0, LIGHTGRAY) + end EndDrawing() --------------------------------------------------------------------------------------- @@ -59,5 +156,8 @@ end -- De-Initialization ------------------------------------------------------------------------------------------- -CloseWindow() -- Close window and OpenGL context +UnloadTexture(texPs3Pad) -- Unload gamepad texture +UnloadTexture(texXboxPad) -- Unload gamepad texture + +CloseWindow() -- Close window and OpenGL context ------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/examples/core_input_gamepad.png b/examples/core_input_gamepad.png index f7e556584..5996eece5 100644 Binary files a/examples/core_input_gamepad.png and b/examples/core_input_gamepad.png differ diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 7276e3def..eb628cd76 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -47,10 +47,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode) - else UpdateVrTracking(&camera); // Update camera with device tracking data + if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode) + else if (IsVrDeviceReady()) UpdateVrTracking(&camera); // Update camera with device tracking data - if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode + if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core_world_screen.lua b/examples/core_world_screen.lua index 51f2cdbf0..48b617dd3 100644 --- a/examples/core_world_screen.lua +++ b/examples/core_world_screen.lua @@ -23,10 +23,7 @@ local cubePosition = Vector3(0.0, 0.0, 0.0) local cubeScreenPosition = Vector2(0, 0) -SetCameraMode(CameraMode.FREE) -- Set a free camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ---------------------------------------------------------------------------------------- @@ -35,7 +32,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per- while not WindowShouldClose() do -- Detect window close button or ESC key -- Update ------------------------------------------------------------------------------------ - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera -- Calculate cube screen space position (with a little offset to be in top) cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera) diff --git a/examples/models_billboard.lua b/examples/models_billboard.lua index 457198e61..9d81f6ce2 100644 --- a/examples/models_billboard.lua +++ b/examples/models_billboard.lua @@ -22,19 +22,16 @@ local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0. local bill = LoadTexture("resources/billboard.png") -- Our texture billboard local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/models_cubicmap.lua b/examples/models_cubicmap.lua index bae3bac21..79faafc95 100644 --- a/examples/models_cubicmap.lua +++ b/examples/models_cubicmap.lua @@ -31,18 +31,16 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/models_heightmap.lua b/examples/models_heightmap.lua index 4240f8b70..efcbfb4b8 100644 --- a/examples/models_heightmap.lua +++ b/examples/models_heightmap.lua @@ -27,17 +27,16 @@ local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (d UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ---------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/physics_basic_rigidbody.c b/examples/physics_basic_rigidbody.c deleted file mode 100644 index 87316a981..000000000 --- a/examples/physics_basic_rigidbody.c +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************************* -* -* raylib [physac] example - Basic rigidbody -* -* This example has been created using raylib 1.5 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* NOTE: -* Physac requires multi-threading, when InitPhysics() a second thread is created to manage -* physics calculations. To accomplish that, physac uses pthread Win32 library that can be -* found inside raylib/src/external/pthread directory. -* -* Add pthread library when compiling physac example: -* gcc -o $(NAME_PART).exe $(FILE_NAME) $(RAYLIB_DIR)\raylib_icon -L../src/external/pthread/lib \ -* -I../src -I../src/external/pthread/include -lraylib -lglfw3 -lopengl32 -lgdi32 -lpthreadGC2 -std=c99 -Wall -* -* Note that pthreadGC2.dll must be also copied to project directory! -* -* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#define PHYSAC_IMPLEMENTATION -#include "physac.h" - -#define MOVE_VELOCITY 5 -#define JUMP_VELOCITY 30 - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [physac] example - basic rigidbody"); - InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module - - // Debug variables - bool isDebug = false; - - // Create rectangle physic object - PhysicBody rectangle = CreatePhysicBody((Vector2){ screenWidth*0.25f, screenHeight/2 }, 0.0f, (Vector2){ 75, 50 }); - rectangle->rigidbody.enabled = true; // Enable physic object rigidbody behaviour - rectangle->rigidbody.applyGravity = true; - rectangle->rigidbody.friction = 0.1f; - rectangle->rigidbody.bounciness = 6.0f; - - // Create square physic object - PhysicBody square = CreatePhysicBody((Vector2){ screenWidth*0.75f, screenHeight/2 }, 0.0f, (Vector2){ 50, 50 }); - square->rigidbody.enabled = true; // Enable physic object rigidbody behaviour - square->rigidbody.applyGravity = true; - square->rigidbody.friction = 0.1f; - - // Create walls physic objects - PhysicBody floor = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.95f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 }); - PhysicBody leftWall = CreatePhysicBody((Vector2){ 0.0f, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight }); - PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight }); - PhysicBody roof = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.05f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 }); - - // Create pplatform physic object - PhysicBody platform = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.7f }, 0.0f, (Vector2){ screenWidth*0.25f, 20 }); - - SetTargetFPS(60); - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // Check rectangle movement inputs - if (IsKeyPressed('W')) rectangle->rigidbody.velocity.y = JUMP_VELOCITY; - if (IsKeyDown('A')) rectangle->rigidbody.velocity.x = -MOVE_VELOCITY; - else if (IsKeyDown('D')) rectangle->rigidbody.velocity.x = MOVE_VELOCITY; - - // Check square movement inputs - if (IsKeyDown(KEY_UP) && square->rigidbody.isGrounded) square->rigidbody.velocity.y = JUMP_VELOCITY; - if (IsKeyDown(KEY_LEFT)) square->rigidbody.velocity.x = -MOVE_VELOCITY; - else if (IsKeyDown(KEY_RIGHT)) square->rigidbody.velocity.x = MOVE_VELOCITY; - - // Check debug switch input - if (IsKeyPressed('P')) isDebug = !isDebug; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // Draw floor, roof and walls rectangles - DrawRectangleRec(TransformToRectangle(floor->transform), DARKGRAY); // Convert transform values to rectangle data type variable - DrawRectangleRec(TransformToRectangle(leftWall->transform), DARKGRAY); - DrawRectangleRec(TransformToRectangle(rightWall->transform), DARKGRAY); - DrawRectangleRec(TransformToRectangle(roof->transform), DARKGRAY); - - // Draw middle platform rectangle - DrawRectangleRec(TransformToRectangle(platform->transform), DARKGRAY); - - // Draw physic objects - DrawRectangleRec(TransformToRectangle(rectangle->transform), RED); - DrawRectangleRec(TransformToRectangle(square->transform), BLUE); - - // Draw collider lines if debug is enabled - if (isDebug) - { - DrawRectangleLines(floor->collider.bounds.x, floor->collider.bounds.y, floor->collider.bounds.width, floor->collider.bounds.height, GREEN); - DrawRectangleLines(leftWall->collider.bounds.x, leftWall->collider.bounds.y, leftWall->collider.bounds.width, leftWall->collider.bounds.height, GREEN); - DrawRectangleLines(rightWall->collider.bounds.x, rightWall->collider.bounds.y, rightWall->collider.bounds.width, rightWall->collider.bounds.height, GREEN); - DrawRectangleLines(roof->collider.bounds.x, roof->collider.bounds.y, roof->collider.bounds.width, roof->collider.bounds.height, GREEN); - DrawRectangleLines(platform->collider.bounds.x, platform->collider.bounds.y, platform->collider.bounds.width, platform->collider.bounds.height, GREEN); - DrawRectangleLines(rectangle->collider.bounds.x, rectangle->collider.bounds.y, rectangle->collider.bounds.width, rectangle->collider.bounds.height, GREEN); - DrawRectangleLines(square->collider.bounds.x, square->collider.bounds.y, square->collider.bounds.width, square->collider.bounds.height, GREEN); - } - - // Draw help message - DrawText("Use WASD to move rectangle and ARROWS to move square", screenWidth/2 - MeasureText("Use WASD to move rectangle and ARROWS to move square", 20)/2, screenHeight*0.075f, 20, LIGHTGRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics (including all loaded objects) - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} \ No newline at end of file diff --git a/examples/physics_basic_rigidbody.png b/examples/physics_basic_rigidbody.png deleted file mode 100644 index 52f265acf..000000000 Binary files a/examples/physics_basic_rigidbody.png and /dev/null differ diff --git a/examples/physics_demo.c b/examples/physics_demo.c new file mode 100644 index 000000000..bed7c94d3 --- /dev/null +++ b/examples/physics_demo.c @@ -0,0 +1,122 @@ +/******************************************************************************************* +* +* Physac - Physics demo +* +* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* +* Copyright (c) 2016 Victor Fisac +* +********************************************************************************************/ + +#include "raylib.h" + +#define PHYSAC_IMPLEMENTATION +#include "..\src\physac.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo"); + SetTargetFPS(60); + + // Physac logo drawing position + int logoX = screenWidth - MeasureText("Physac", 30) - 10; + int logoY = 15; + + // Initialize physics and default physics bodies + InitPhysics(); + + // Create floor rectangle physics body + PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10); + floor->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + + // Create obstacle circle physics body + PhysicsBody circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10); + circle->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed('R')) // Reset physics input + { + ResetPhysics(); + + floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10); + floor->enabled = false; + + circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10); + circle->enabled = false; + } + + // Physics body creation inputs + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10); + else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10); + + // Destroy falling physics bodies + int bodiesCount = GetPhysicsBodiesCount(); + for (int i = bodiesCount - 1; i >= 0; i--) + { + PhysicsBody body = GetPhysicsBody(i); + if (body != NULL && (body->position.y > screenHeight*2)) DestroyPhysicsBody(body); + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(BLACK); + + DrawFPS(screenWidth - 90, screenHeight - 30); + + // Draw created physics bodies + bodiesCount = GetPhysicsBodiesCount(); + for (int i = 0; i < bodiesCount; i++) + { + PhysicsBody body = GetPhysicsBody(i); + + if (body != NULL) + { + int vertexCount = GetPhysicsShapeVerticesCount(i); + for (int j = 0; j < vertexCount; j++) + { + // Get physics bodies shape vertices to draw lines + // Note: GetPhysicsShapeVertex() already calculates rotation transformations + Vector2 vertexA = GetPhysicsShapeVertex(body, j); + + int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape + Vector2 vertexB = GetPhysicsShapeVertex(body, jj); + + DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions + } + } + } + + DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE); + DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE); + DrawText("Press 'R' to reset example", 10, 40, 10, WHITE); + + DrawText("Physac", logoX, logoY, 30, WHITE); + DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/physics_demo.png b/examples/physics_demo.png new file mode 100644 index 000000000..12dc7e724 Binary files /dev/null and b/examples/physics_demo.png differ diff --git a/examples/physics_forces.c b/examples/physics_forces.c deleted file mode 100644 index e45cb44cc..000000000 --- a/examples/physics_forces.c +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************************* -* -* raylib [physac] example - Forces -* -* This example has been created using raylib 1.5 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* NOTE: -* Physac requires multi-threading, when InitPhysics() a second thread is created to manage -* physics calculations. To accomplish that, physac uses pthread Win32 library that can be -* found inside raylib/src/external/pthread directory. -* -* Add pthread library when compiling physac example: -* gcc -o $(NAME_PART).exe $(FILE_NAME) $(RAYLIB_DIR)\raylib_icon -L../src/external/pthread/lib \ -* -I../src -I../src/external/pthread/include -lraylib -lglfw3 -lopengl32 -lgdi32 -lpthreadGC2 -std=c99 -Wall -* -* Note that pthreadGC2.dll must be also copied to project directory! -* -* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#define PHYSAC_IMPLEMENTATION -#include "physac.h" - -#define FORCE_AMOUNT 5.0f -#define FORCE_RADIUS 150 -#define LINE_LENGTH 75 -#define TRIANGLE_LENGTH 12 - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [physac] example - forces"); - InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module - - // Global variables - Vector2 mousePosition; - bool isDebug = false; - - // Create rectangle physic objects - PhysicBody rectangles[3]; - for (int i = 0; i < 3; i++) - { - rectangles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) }, 0.0f, (Vector2){ 50, 50 }); - rectangles[i]->rigidbody.enabled = true; // Enable physic object rigidbody behaviour - rectangles[i]->rigidbody.friction = 0.1f; - } - - // Create circles physic objects - // NOTE: when creating circle physic objects, transform.scale must be { 0, 0 } and object radius must be defined in collider.radius and use this value to draw the circle. - PhysicBody circles[3]; - for (int i = 0; i < 3; i++) - { - circles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) }, 0.0f, (Vector2){ 0, 0 }); - circles[i]->rigidbody.enabled = true; // Enable physic object rigidbody behaviour - circles[i]->rigidbody.friction = 0.1f; - circles[i]->collider.type = COLLIDER_CIRCLE; - circles[i]->collider.radius = 25; - } - - // Create walls physic objects - PhysicBody leftWall = CreatePhysicBody((Vector2){ -25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight }); - PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth + 25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight }); - PhysicBody topWall = CreatePhysicBody((Vector2){ screenWidth/2, -25 }, 0.0f, (Vector2){ screenWidth, 50 }); - PhysicBody bottomWall = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight + 25 }, 0.0f, (Vector2){ screenWidth, 50 }); - - SetTargetFPS(60); - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - - // Update mouse position value - mousePosition = GetMousePosition(); - - // Check force input - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ApplyForceAtPosition(mousePosition, FORCE_AMOUNT, FORCE_RADIUS); - - // Check reset input - if (IsKeyPressed('R')) - { - // Reset rectangle physic objects positions - for (int i = 0; i < 3; i++) - { - rectangles[i]->transform.position = (Vector2){ screenWidth/4*(i+1) - rectangles[i]->transform.scale.x/2, (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) - rectangles[i]->transform.scale.y/2 }; - rectangles[i]->rigidbody.velocity =(Vector2){ 0.0f, 0.0f }; - } - - // Reset circles physic objects positions - for (int i = 0; i < 3; i++) - { - circles[i]->transform.position = (Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) }; - circles[i]->rigidbody.velocity =(Vector2){ 0.0f, 0.0f }; - } - } - - // Check debug switch input - if (IsKeyPressed('P')) isDebug = !isDebug; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // Draw rectangles - for (int i = 0; i < 3; i++) - { - // Convert transform values to rectangle data type variable - DrawRectangleRec(TransformToRectangle(rectangles[i]->transform), RED); - if (isDebug) DrawRectangleLines(rectangles[i]->collider.bounds.x, rectangles[i]->collider.bounds.y, rectangles[i]->collider.bounds.width, rectangles[i]->collider.bounds.height, GREEN); - - // Draw force radius - DrawCircleLines(mousePosition.x, mousePosition.y, FORCE_RADIUS, BLACK); - - // Draw direction lines - if (CheckCollisionPointCircle((Vector2){ rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 }, mousePosition, FORCE_RADIUS)) - { - Vector2 direction = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2 - mousePosition.x, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 - mousePosition.y }; - float angle = atan2l(direction.y, direction.x); - - // Calculate arrow start and end positions - Vector2 startPosition = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 }; - Vector2 endPosition = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2 + (cos(angle)*LINE_LENGTH), rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 + (sin(angle)*LINE_LENGTH) }; - - // Draw arrow line - DrawLineV(startPosition, endPosition, BLACK); - - // Draw arrow triangle - DrawTriangleLines((Vector2){ endPosition.x - cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y - sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH }, - (Vector2){ endPosition.x + cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y + sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH }, - (Vector2){ endPosition.x + cos(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2, endPosition.y + sin(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2 }, BLACK); - } - } - - // Draw circles - for (int i = 0; i < 3; i++) - { - DrawCircleV(circles[i]->transform.position, circles[i]->collider.radius, BLUE); - if (isDebug) DrawCircleLines(circles[i]->transform.position.x, circles[i]->transform.position.y, circles[i]->collider.radius, GREEN); - - // Draw force radius - DrawCircleLines(mousePosition.x, mousePosition.y, FORCE_RADIUS, BLACK); - - // Draw direction lines - if (CheckCollisionPointCircle((Vector2){ circles[i]->transform.position.x, circles[i]->transform.position.y }, mousePosition, FORCE_RADIUS)) - { - Vector2 direction = { circles[i]->transform.position.x - mousePosition.x, circles[i]->transform.position.y - mousePosition.y }; - float angle = atan2l(direction.y, direction.x); - - // Calculate arrow start and end positions - Vector2 startPosition = { circles[i]->transform.position.x, circles[i]->transform.position.y }; - Vector2 endPosition = { circles[i]->transform.position.x + (cos(angle)*LINE_LENGTH), circles[i]->transform.position.y + (sin(angle)*LINE_LENGTH) }; - - // Draw arrow line - DrawLineV(startPosition, endPosition, BLACK); - - // Draw arrow triangle - DrawTriangleLines((Vector2){ endPosition.x - cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y - sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH }, - (Vector2){ endPosition.x + cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y + sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH }, - (Vector2){ endPosition.x + cos(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2, endPosition.y + sin(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2 }, BLACK); - } - } - - // Draw help messages - DrawText("Use LEFT MOUSE BUTTON to apply a force", screenWidth/2 - MeasureText("Use LEFT MOUSE BUTTON to apply a force", 20)/2, screenHeight*0.075f, 20, LIGHTGRAY); - DrawText("Use R to reset objects position", screenWidth/2 - MeasureText("Use R to reset objects position", 20)/2, screenHeight*0.875f, 20, GRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics module - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} \ No newline at end of file diff --git a/examples/physics_forces.png b/examples/physics_forces.png deleted file mode 100644 index 832bdbd9e..000000000 Binary files a/examples/physics_forces.png and /dev/null differ diff --git a/examples/physics_friction.c b/examples/physics_friction.c new file mode 100644 index 000000000..28d3c4b8c --- /dev/null +++ b/examples/physics_friction.c @@ -0,0 +1,136 @@ +/******************************************************************************************* +* +* Physac - Physics friction +* +* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* +* Copyright (c) 2016 Victor Fisac +* +********************************************************************************************/ + +#include "raylib.h" + +#define PHYSAC_IMPLEMENTATION +#include "..\src\physac.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction"); + SetTargetFPS(60); + + // Physac logo drawing position + int logoX = screenWidth - MeasureText("Physac", 30) - 10; + int logoY = 15; + + // Initialize physics and default physics bodies + InitPhysics(); + + // Create floor rectangle physics body + PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10); + floor->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + PhysicsBody wall = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight*0.8f }, 10, 80, 10); + wall->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + + // Create left ramp physics body + PhysicsBody rectLeft = CreatePhysicsBodyRectangle((Vector2){ 25, screenHeight - 5 }, 250, 250, 10); + rectLeft->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + SetPhysicsBodyRotation(rectLeft, 30*DEG2RAD); + + // Create right ramp physics body + PhysicsBody rectRight = CreatePhysicsBodyRectangle((Vector2){ screenWidth - 25, screenHeight - 5 }, 250, 250, 10); + rectRight->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + SetPhysicsBodyRotation(rectRight, 330*DEG2RAD); + + // Create dynamic physics bodies + PhysicsBody bodyA = CreatePhysicsBodyRectangle((Vector2){ 35, screenHeight*0.6f }, 40, 40, 10); + bodyA->staticFriction = 0.1f; + bodyA->dynamicFriction = 0.1f; + SetPhysicsBodyRotation(bodyA, 30*DEG2RAD); + + PhysicsBody bodyB = CreatePhysicsBodyRectangle((Vector2){ screenWidth - 35, screenHeight*0.6f }, 40, 40, 10); + bodyB->staticFriction = 1; + bodyB->dynamicFriction = 1; + SetPhysicsBodyRotation(bodyB, 330*DEG2RAD); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed('R')) // Reset physics input + { + // Reset dynamic physics bodies position, velocity and rotation + bodyA->position = (Vector2){ 35, screenHeight*0.6f }; + bodyA->velocity = (Vector2){ 0, 0 }; + bodyA->angularVelocity = 0; + SetPhysicsBodyRotation(bodyA, 30*DEG2RAD); + + bodyB->position = (Vector2){ screenWidth - 35, screenHeight*0.6f }; + bodyB->velocity = (Vector2){ 0, 0 }; + bodyB->angularVelocity = 0; + SetPhysicsBodyRotation(bodyB, 330*DEG2RAD); + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(BLACK); + + DrawFPS(screenWidth - 90, screenHeight - 30); + + // Draw created physics bodies + int bodiesCount = GetPhysicsBodiesCount(); + for (int i = 0; i < bodiesCount; i++) + { + PhysicsBody body = GetPhysicsBody(i); + + if (body != NULL) + { + int vertexCount = GetPhysicsShapeVerticesCount(i); + for (int j = 0; j < vertexCount; j++) + { + // Get physics bodies shape vertices to draw lines + // Note: GetPhysicsShapeVertex() already calculates rotation transformations + Vector2 vertexA = GetPhysicsShapeVertex(body, j); + + int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape + Vector2 vertexB = GetPhysicsShapeVertex(body, jj); + + DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions + } + } + } + + DrawRectangle(0, screenHeight - 49, screenWidth, 49, BLACK); + + DrawText("Friction amount", (screenWidth - MeasureText("Friction amount", 30))/2, 75, 30, WHITE); + DrawText("0.1", bodyA->position.x - MeasureText("0.1", 20)/2, bodyA->position.y - 7, 20, WHITE); + DrawText("1", bodyB->position.x - MeasureText("1", 20)/2, bodyB->position.y - 7, 20, WHITE); + + DrawText("Press 'R' to reset example", 10, 10, 10, WHITE); + + DrawText("Physac", logoX, logoY, 30, WHITE); + DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/physics_friction.png b/examples/physics_friction.png new file mode 100644 index 000000000..e791ec2b9 Binary files /dev/null and b/examples/physics_friction.png differ diff --git a/examples/physics_movement.c b/examples/physics_movement.c new file mode 100644 index 000000000..ca18f3dfc --- /dev/null +++ b/examples/physics_movement.c @@ -0,0 +1,122 @@ +/******************************************************************************************* +* +* Physac - Physics movement +* +* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* +* Copyright (c) 2016 Victor Fisac +* +********************************************************************************************/ + +#include "raylib.h" + +#define PHYSAC_IMPLEMENTATION +#include "..\src\physac.h" + +#define VELOCITY 0.5f + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics movement"); + SetTargetFPS(60); + + // Physac logo drawing position + int logoX = screenWidth - MeasureText("Physac", 30) - 10; + int logoY = 15; + + // Initialize physics and default physics bodies + InitPhysics(); + + // Create floor and walls rectangle physics body + PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10); + PhysicsBody platformLeft = CreatePhysicsBodyRectangle((Vector2){ screenWidth*0.25f, screenHeight*0.6f }, screenWidth*0.25f, 10, 10); + PhysicsBody platformRight = CreatePhysicsBodyRectangle((Vector2){ screenWidth*0.75f, screenHeight*0.6f }, screenWidth*0.25f, 10, 10); + PhysicsBody wallLeft = CreatePhysicsBodyRectangle((Vector2){ -5, screenHeight/2 }, 10, screenHeight, 10); + PhysicsBody wallRight = CreatePhysicsBodyRectangle((Vector2){ screenWidth + 5, screenHeight/2 }, 10, screenHeight, 10); + + // Disable dynamics to floor and walls physics bodies + floor->enabled = false; + platformLeft->enabled = false; + platformRight->enabled = false; + wallLeft->enabled = false; + wallRight->enabled = false; + + // Create movement physics body + PhysicsBody body = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight/2 }, 50, 50, 1); + body->freezeOrient = true; // Constrain body rotation to avoid little collision torque amounts + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed('R')) // Reset physics input + { + // Reset movement physics body position, velocity and rotation + body->position = (Vector2){ screenWidth/2, screenHeight/2 }; + body->velocity = (Vector2){ 0, 0 }; + SetPhysicsBodyRotation(body, 0); + } + + // Horizontal movement input + if (IsKeyDown(KEY_RIGHT)) body->velocity.x = VELOCITY; + else if (IsKeyDown(KEY_LEFT)) body->velocity.x = -VELOCITY; + + // Vertical movement input checking if player physics body is grounded + if (IsKeyDown(KEY_UP) && body->isGrounded) body->velocity.y = -VELOCITY*4; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(BLACK); + + DrawFPS(screenWidth - 90, screenHeight - 30); + + // Draw created physics bodies + int bodiesCount = GetPhysicsBodiesCount(); + for (int i = 0; i < bodiesCount; i++) + { + PhysicsBody body = GetPhysicsBody(i); + + int vertexCount = GetPhysicsShapeVerticesCount(i); + for (int j = 0; j < vertexCount; j++) + { + // Get physics bodies shape vertices to draw lines + // Note: GetPhysicsShapeVertex() already calculates rotation transformations + Vector2 vertexA = GetPhysicsShapeVertex(body, j); + + int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape + Vector2 vertexB = GetPhysicsShapeVertex(body, jj); + + DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions + } + } + + DrawText("Use 'ARROWS' to move player", 10, 10, 10, WHITE); + DrawText("Press 'R' to reset example", 10, 30, 10, WHITE); + + DrawText("Physac", logoX, logoY, 30, WHITE); + DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/physics_movement.png b/examples/physics_movement.png new file mode 100644 index 000000000..a88a7d79f Binary files /dev/null and b/examples/physics_movement.png differ diff --git a/examples/physics_restitution.c b/examples/physics_restitution.c new file mode 100644 index 000000000..3543db69c --- /dev/null +++ b/examples/physics_restitution.c @@ -0,0 +1,115 @@ +/******************************************************************************************* +* +* Physac - Physics restitution +* +* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* +* Copyright (c) 2016 Victor Fisac +* +********************************************************************************************/ + +#include "raylib.h" + +#define PHYSAC_IMPLEMENTATION +#include "..\src\physac.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution"); + SetTargetFPS(60); + + // Physac logo drawing position + int logoX = screenWidth - MeasureText("Physac", 30) - 10; + int logoY = 15; + + // Initialize physics and default physics bodies + InitPhysics(); + + // Create floor rectangle physics body + PhysicsBody floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10); + floor->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + floor->restitution = 1; + + // Create circles physics body + PhysicsBody circleA = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.25f, screenHeight/2 }, 30, 10); + circleA->restitution = 0; + PhysicsBody circleB = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.5f, screenHeight/2 }, 30, 10); + circleB->restitution = 0.5f; + PhysicsBody circleC = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.75f, screenHeight/2 }, 30, 10); + circleC->restitution = 1; + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed('R')) // Reset physics input + { + // Reset circles physics bodies position and velocity + circleA->position = (Vector2){ screenWidth*0.25f, screenHeight/2 }; + circleA->velocity = (Vector2){ 0, 0 }; + circleB->position = (Vector2){ screenWidth*0.5f, screenHeight/2 }; + circleB->velocity = (Vector2){ 0, 0 }; + circleC->position = (Vector2){ screenWidth*0.75f, screenHeight/2 }; + circleC->velocity = (Vector2){ 0, 0 }; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(BLACK); + + DrawFPS(screenWidth - 90, screenHeight - 30); + + // Draw created physics bodies + int bodiesCount = GetPhysicsBodiesCount(); + for (int i = 0; i < bodiesCount; i++) + { + PhysicsBody body = GetPhysicsBody(i); + + int vertexCount = GetPhysicsShapeVerticesCount(i); + for (int j = 0; j < vertexCount; j++) + { + // Get physics bodies shape vertices to draw lines + // Note: GetPhysicsShapeVertex() already calculates rotation transformations + Vector2 vertexA = GetPhysicsShapeVertex(body, j); + + int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape + Vector2 vertexB = GetPhysicsShapeVertex(body, jj); + + DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions + } + } + + DrawText("Restitution amount", (screenWidth - MeasureText("Restitution amount", 30))/2, 75, 30, WHITE); + DrawText("0", circleA->position.x - MeasureText("0", 20)/2, circleA->position.y - 7, 20, WHITE); + DrawText("0.5", circleB->position.x - MeasureText("0.5", 20)/2, circleB->position.y - 7, 20, WHITE); + DrawText("1", circleC->position.x - MeasureText("1", 20)/2, circleC->position.y - 7, 20, WHITE); + + DrawText("Press 'R' to reset example", 10, 10, 10, WHITE); + + DrawText("Physac", logoX, logoY, 30, WHITE); + DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/physics_restitution.png b/examples/physics_restitution.png new file mode 100644 index 000000000..8ec4b3f32 Binary files /dev/null and b/examples/physics_restitution.png differ diff --git a/examples/physics_shatter.c b/examples/physics_shatter.c new file mode 100644 index 000000000..2cb9d1952 --- /dev/null +++ b/examples/physics_shatter.c @@ -0,0 +1,107 @@ +/******************************************************************************************* +* +* Physac - Body shatter +* +* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* +* Copyright (c) 2016 Victor Fisac +* +********************************************************************************************/ + +#include "raylib.h" + +#define PHYSAC_IMPLEMENTATION +#include "..\src\physac.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter"); + SetTargetFPS(60); + + // Physac logo drawing position + int logoX = screenWidth - MeasureText("Physac", 30) - 10; + int logoY = 15; + + // Initialize physics and default physics bodies + InitPhysics(); + SetPhysicsGravity(0, 0); + + // Create random polygon physics body to shatter + PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed('R')) // Reset physics input + { + ResetPhysics(); + + // Create random polygon physics body to shatter + body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + } + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input + { + // Note: some values need to be stored in variables due to asynchronous changes during main thread + int count = GetPhysicsBodiesCount(); + for (int i = count - 1; i >= 0; i--) + { + PhysicsBody currentBody = GetPhysicsBody(i); + if (currentBody != NULL) PhysicsShatter(currentBody, GetMousePosition(), 10/currentBody->inverseMass); + } + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(BLACK); + + // Draw created physics bodies + int bodiesCount = GetPhysicsBodiesCount(); + for (int i = 0; i < bodiesCount; i++) + { + PhysicsBody currentBody = GetPhysicsBody(i); + + int vertexCount = GetPhysicsShapeVerticesCount(i); + for (int j = 0; j < vertexCount; j++) + { + // Get physics bodies shape vertices to draw lines + // Note: GetPhysicsShapeVertex() already calculates rotation transformations + Vector2 vertexA = GetPhysicsShapeVertex(currentBody, j); + + int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape + Vector2 vertexB = GetPhysicsShapeVertex(currentBody, jj); + + DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions + } + } + + DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, WHITE); + + DrawText("Physac", logoX, logoY, 30, WHITE); + DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/physics_shatter.png b/examples/physics_shatter.png new file mode 100644 index 000000000..68f9a1b7d Binary files /dev/null and b/examples/physics_shatter.png differ diff --git a/examples/resources/fonts/KAISG.ttf b/examples/resources/fonts/KAISG.ttf new file mode 100644 index 000000000..04478b25c Binary files /dev/null and b/examples/resources/fonts/KAISG.ttf differ diff --git a/examples/resources/fonts/pixantiqua.fnt b/examples/resources/fonts/pixantiqua.fnt new file mode 100644 index 000000000..971b9b0bc --- /dev/null +++ b/examples/resources/fonts/pixantiqua.fnt @@ -0,0 +1,188 @@ +info face="PixAntiqua" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=2,2,2,2 spacing=2,2 outline=0 +common lineHeight=32 base=27 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4 +page id=0 file="pixantiqua_0.png" +chars count=184 +char id=32 x=9 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=33 x=391 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=34 x=240 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=35 x=468 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=36 x=152 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=37 x=176 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=38 x=303 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=39 x=495 y=266 width=8 height=36 xoffset=-3 yoffset=-2 xadvance=5 page=0 chnl=15 +char id=40 x=256 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=199 x=432 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=200 x=126 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=201 x=147 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=202 x=288 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=203 x=189 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=204 x=468 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=205 x=486 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=206 x=0 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=207 x=72 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=208 x=329 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=209 x=277 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=210 x=182 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=211 x=26 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=41 x=272 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=42 x=288 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=43 x=414 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=44 x=378 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=45 x=414 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=46 x=443 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=47 x=392 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=48 x=485 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=49 x=450 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=50 x=21 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=51 x=42 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=59 x=456 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=60 x=168 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=61 x=309 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=62 x=336 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=63 x=315 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=64 x=364 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=65 x=390 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=66 x=120 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=67 x=144 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=68 x=168 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=69 x=294 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=52 x=488 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=53 x=63 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=54 x=24 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=55 x=48 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=56 x=72 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=57 x=96 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=58 x=404 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=70 x=252 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=71 x=192 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=72 x=78 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=78 x=78 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=79 x=355 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=80 x=264 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=81 x=381 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=82 x=288 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=83 x=312 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=91 x=144 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=92 x=108 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=93 x=304 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=94 x=34 y=0 width=32 height=36 xoffset=-3 yoffset=-2 xadvance=29 page=0 chnl=15 +char id=95 x=231 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=96 x=442 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=97 x=408 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=98 x=432 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=99 x=210 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=84 x=336 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=85 x=360 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=86 x=0 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=87 x=68 y=0 width=30 height=36 xoffset=-3 yoffset=-2 xadvance=27 page=0 chnl=15 +char id=88 x=26 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=89 x=384 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=90 x=84 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=100 x=456 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=101 x=480 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=102 x=54 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=103 x=0 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=104 x=24 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=105 x=469 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=106 x=18 y=266 width=16 height=36 xoffset=-8 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=107 x=48 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=108 x=417 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=109 x=161 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=110 x=72 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=111 x=96 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=117 x=192 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=118 x=216 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=119 x=248 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=120 x=240 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=121 x=264 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=122 x=288 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=123 x=432 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=124 x=365 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=125 x=378 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=126 x=393 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=127 x=132 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=160 x=0 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=161 x=352 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=162 x=351 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=163 x=336 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=165 x=360 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=167 x=384 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=169 x=433 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=170 x=224 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=171 x=105 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=172 x=0 y=0 width=32 height=36 xoffset=-3 yoffset=-2 xadvance=29 page=0 chnl=15 +char id=173 x=494 y=38 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=174 x=52 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=175 x=52 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=176 x=126 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=177 x=435 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=178 x=320 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=179 x=336 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=181 x=459 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=112 x=120 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=113 x=144 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=114 x=396 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=115 x=168 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=116 x=36 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=182 x=408 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=183 x=498 y=190 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=185 x=192 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=186 x=208 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=187 x=477 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=191 x=456 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=192 x=407 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=193 x=234 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=194 x=416 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=195 x=156 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=196 x=130 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=197 x=104 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=198 x=190 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=212 x=0 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=213 x=338 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=214 x=312 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=215 x=357 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=216 x=286 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=217 x=456 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=218 x=480 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=219 x=0 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=220 x=24 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=221 x=48 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=222 x=260 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=223 x=72 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=224 x=96 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=225 x=120 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=226 x=144 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=227 x=168 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=228 x=192 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=229 x=216 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=230 x=219 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=231 x=372 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=73 x=90 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=74 x=216 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=75 x=240 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=76 x=273 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=77 x=100 y=0 width=30 height=36 xoffset=-3 yoffset=-2 xadvance=27 page=0 chnl=15 +char id=232 x=312 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=233 x=240 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=234 x=264 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=235 x=104 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=236 x=430 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=237 x=482 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=238 x=160 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=239 x=176 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=240 x=128 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=241 x=200 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=242 x=224 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=243 x=248 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=244 x=272 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=245 x=296 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=246 x=320 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=247 x=330 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=248 x=208 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=249 x=344 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=250 x=368 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=251 x=416 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=252 x=440 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=253 x=464 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=254 x=0 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=255 x=0 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 diff --git a/examples/resources/fonts/pixantiqua_0.png b/examples/resources/fonts/pixantiqua_0.png new file mode 100644 index 000000000..2aa2870f3 Binary files /dev/null and b/examples/resources/fonts/pixantiqua_0.png differ diff --git a/examples/rlua_execute_file.c b/examples/rlua_execute_file.c index 717203130..a91ce42fe 100644 --- a/examples/rlua_execute_file.c +++ b/examples/rlua_execute_file.c @@ -7,7 +7,8 @@ * Compile example using: * gcc -o $(NAME_PART).exe $(FILE_NAME) $(RAYLIB_DIR)\raylib_icon / * -I../src -I../src/external/lua/include -L../src/external/lua/lib / -* -lraylib -lglfw3 -lopengl32 -lopenal32 -llua53 -lgdi32 -std=c99 +* -lraylib -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -llua53 / +* -std=c99 -Wl,-allow-multiple-definition -Wl,--subsystem,windows * * This example has been created using raylib 1.6 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -28,7 +29,7 @@ int main() InitLuaDevice(); //-------------------------------------------------------------------------------------- - // ExecuteLuaFile("core_basic_window.lua"); // OK! + ExecuteLuaFile("core_basic_window.lua"); // OK! // ExecuteLuaFile("core_input_keys.lua"); // OK! // ExecuteLuaFile("core_input_mouse.lua"); // OK! // ExecuteLuaFile("core_mouse_wheel.lua"); // OK! @@ -65,6 +66,8 @@ int main() // ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText() // ExecuteLuaFile("text_font_select.lua"); // OK! // ExecuteLuaFile("text_writing_anim.lua"); // OK! + // ExecuteLuaFile("text_ttf_loading.lua"); // ISSUE: Attempt to index a SpriteFont value (local 'font') + // ExecuteLuaFile("text_bmfont_unordered.lua"); // OK! // ExecuteLuaFile("models_geometric_shapes.lua"); // OK! // ExecuteLuaFile("models_box_collisions.lua"); // OK! // ExecuteLuaFile("models_billboard.lua"); // OK! @@ -80,7 +83,7 @@ int main() // ExecuteLuaFile("audio_music_stream.lua"); // OK! // ExecuteLuaFile("audio_module_playing.lua"); // OK! // ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream() - + // De-Initialization //-------------------------------------------------------------------------------------- CloseLuaDevice(); // Close Lua device and free resources diff --git a/examples/shaders_custom_uniform.lua b/examples/shaders_custom_uniform.lua index 3a8bbae5f..dafd3b848 100644 --- a/examples/shaders_custom_uniform.lua +++ b/examples/shaders_custom_uniform.lua @@ -47,15 +47,13 @@ local swirlCenter = { screenWidth/2, screenHeight/2 } local target = LoadRenderTexture(screenWidth, screenHeight) -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- local mousePosition = GetMousePosition() @@ -66,7 +64,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key -- Send new value to the shader to be used on drawing SetShaderValue(shader, swirlCenterLoc, swirlCenter) - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw @@ -75,13 +73,13 @@ while not WindowShouldClose() do -- Detect window close button or ESC key ClearBackground(RAYWHITE) - BeginTextureMode(target) -- Enable drawing to texture + BeginTextureMode(target) -- Enable drawing to texture Begin3dMode(camera) DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture - DrawGrid(10, 1.0) -- Draw a grid + DrawGrid(10, 1.0) -- Draw a grid End3dMode() diff --git a/examples/shaders_model_shader.c b/examples/shaders_model_shader.c index 26de49221..51e9c1b39 100644 --- a/examples/shaders_model_shader.c +++ b/examples/shaders_model_shader.c @@ -42,7 +42,7 @@ int main() Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode + SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -52,7 +52,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/shaders_model_shader.lua b/examples/shaders_model_shader.lua index d1436a7e5..38f0fd307 100644 --- a/examples/shaders_model_shader.lua +++ b/examples/shaders_model_shader.lua @@ -39,9 +39,7 @@ dwarf.material.texDiffuse = texture -- Bind texture to model local position = Vector3(0.0, 0.0, 0.0) -- Set model position -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- @@ -50,7 +48,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-pe while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_postprocessing.lua b/examples/shaders_postprocessing.lua index f20f31ec5..7dfac816a 100644 --- a/examples/shaders_postprocessing.lua +++ b/examples/shaders_postprocessing.lua @@ -41,18 +41,16 @@ local shader = LoadShader("resources/shaders/glsl330/base.vs", local target = LoadRenderTexture(screenWidth, screenHeight) -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_standard_lighting.lua b/examples/shaders_standard_lighting.lua index 2f3700ffb..1d4dcfcf1 100644 --- a/examples/shaders_standard_lighting.lua +++ b/examples/shaders_standard_lighting.lua @@ -60,18 +60,16 @@ pointLight.diffuse = Color(100, 100, 255, 255) pointLight.radius = 3.0 -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/text_bmfont_unordered.c b/examples/text_bmfont_unordered.c new file mode 100644 index 000000000..b29c5f8b6 --- /dev/null +++ b/examples/text_bmfont_unordered.c @@ -0,0 +1,65 @@ +/******************************************************************************************* +* +* raylib [text] example - BMFont unordered chars loading and drawing +* +* This example has been created using raylib 1.4 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2016 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing"); + + // NOTE: Using chars outside the [32..127] limits! + // NOTE: If a character is not found in the font, it just renders a space + const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"; + + // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) + SpriteFont font = LoadSpriteFont("resources/fonts/pixantiqua.fnt"); // BMFont (AngelCode) + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update variables here... + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY); + DrawText(FormatText("Font base size: %i", font.size), 40, 80, 20, GRAY); + DrawText(FormatText("Font chars number: %i", font.numChars), 40, 110, 20, GRAY); + + DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.size, 0, MAROON); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadSpriteFont(font); // AngelCode SpriteFont unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/text_bmfont_unordered.lua b/examples/text_bmfont_unordered.lua new file mode 100644 index 000000000..f324ca196 --- /dev/null +++ b/examples/text_bmfont_unordered.lua @@ -0,0 +1,57 @@ +------------------------------------------------------------------------------------------- +-- +-- raylib [text] example - BMFont unordered chars loading and drawing +-- +-- This example has been created using raylib 1.6 (www.raylib.com) +-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +-- +-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) +-- +------------------------------------------------------------------------------------------- + +-- Initialization +------------------------------------------------------------------------------------------- +local screenWidth = 800 +local screenHeight = 450 + +InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing") + +-- NOTE: Using chars outside the [32..127] limits! +-- NOTE: If a character is not found in the font, it just renders a space +local msg = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ" + +-- NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) +local font = LoadSpriteFont("resources/fonts/pixantiqua.fnt") -- BMFont (AngelCode) + +SetTargetFPS(60) +------------------------------------------------------------------------------------------- + +-- Main game loop +while not WindowShouldClose() do -- Detect window close button or ESC key + -- Update + --------------------------------------------------------------------------------------- + -- TODO: Update variables here... + --------------------------------------------------------------------------------------- + + -- Draw + --------------------------------------------------------------------------------------- + BeginDrawing() + + ClearBackground(RAYWHITE) + + DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY) + DrawText(string.format("Font base size: %i", font.size), 40, 80, 20, GRAY) + DrawText(string.format("Font chars number: %i", font.numChars), 40, 110, 20, GRAY) + + DrawTextEx(font, msg, Vector2(40, 180), font.size, 0, MAROON) + + EndDrawing() + --------------------------------------------------------------------------------------- +end + +-- De-Initialization +------------------------------------------------------------------------------------------- +UnloadSpriteFont(font) -- AngelCode SpriteFont unloading + +CloseWindow() -- Close window and OpenGL context +------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/examples/text_bmfont_unordered.png b/examples/text_bmfont_unordered.png new file mode 100644 index 000000000..c67675675 Binary files /dev/null and b/examples/text_bmfont_unordered.png differ diff --git a/examples/text_ttf_loading.c b/examples/text_ttf_loading.c new file mode 100644 index 000000000..918209dd6 --- /dev/null +++ b/examples/text_ttf_loading.c @@ -0,0 +1,130 @@ +/******************************************************************************************* +* +* raylib [text] example - TTF loading and usage +* +* This example has been created using raylib 1.3.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); + + const char msg[50] = "TTF SpriteFont"; + + // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) + + // TTF SpriteFont loading with custom generation parameters + SpriteFont font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0); + + // Generate mipmap levels to use trilinear filtering + // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR + GenTextureMipmaps(&font.texture); + + float fontSize = font.size; + Vector2 fontPosition = { 40, screenHeight/2 + 50 }; + Vector2 textSize; + + SetTextureFilter(font.texture, FILTER_POINT); + int currentFontFilter = 0; // FILTER_POINT + + int count = 0; + char **droppedFiles; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + fontSize += GetMouseWheelMove()*4.0f; + + // Choose font texture filter method + if (IsKeyPressed(KEY_ONE)) + { + SetTextureFilter(font.texture, FILTER_POINT); + currentFontFilter = 0; + } + else if (IsKeyPressed(KEY_TWO)) + { + SetTextureFilter(font.texture, FILTER_BILINEAR); + currentFontFilter = 1; + } + else if (IsKeyPressed(KEY_THREE)) + { + // NOTE: Trilinear filter won't be noticed on 2D drawing + SetTextureFilter(font.texture, FILTER_TRILINEAR); + currentFontFilter = 2; + } + + textSize = MeasureTextEx(font, msg, fontSize, 0); + + if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; + else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; + + // Load a dropped TTF file dynamically (at current fontSize) + if (IsFileDropped()) + { + droppedFiles = GetDroppedFiles(&count); + + if (count == 1) // Only support one ttf file dropped + { + UnloadSpriteFont(font); + font = LoadSpriteFontTTF(droppedFiles[0], fontSize, 0, 0); + ClearDroppedFiles(); + } + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY); + DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY); + DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY); + DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY); + + DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK); + + // TODO: It seems texSize measurement is not accurate due to chars offsets... + //DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED); + + DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY); + DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY); + DrawText(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY); + DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY); + + if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK); + else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK); + else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadSpriteFont(font); // SpriteFont unloading + + ClearDroppedFiles(); // Clear internal buffers + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/text_ttf_loading.lua b/examples/text_ttf_loading.lua new file mode 100644 index 000000000..26443212b --- /dev/null +++ b/examples/text_ttf_loading.lua @@ -0,0 +1,118 @@ +------------------------------------------------------------------------------------------- +-- +-- raylib [text] example - TTF loading and usage +-- +-- This example has been created using raylib 1.6 (www.raylib.com) +-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +-- +-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) +-- +------------------------------------------------------------------------------------------- + +-- Initialization +------------------------------------------------------------------------------------------- +local screenWidth = 800; +local screenHeight = 450; + +InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading") + +local msg = "TTF SpriteFont" + +-- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) + +-- TTF SpriteFont loading with custom generation parameters +local font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0) + +-- Generate mipmap levels to use trilinear filtering +-- NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR +--font.texture = GenTextureMipmaps(font.texture) -- ISSUE: attempt to index a SpriteFont value (local 'font') + +local fontSize = font.size +local fontPosition = Vector2(40, screenHeight/2 + 50) +local textSize + +SetTextureFilter(font.texture, TextureFilter.POINT) +local currentFontFilter = 0 -- Default: FILTER_POINT + +local count = 0 +local droppedFiles + +SetTargetFPS(60) +------------------------------------------------------------------------------------------- + +-- Main game loop +while not WindowShouldClose() do -- Detect window close button or ESC key + -- Update + --------------------------------------------------------------------------------------- + fontSize = fontSize + GetMouseWheelMove()*4.0 + + -- Choose font texture filter method + if (IsKeyPressed(KEY.ONE)) then + SetTextureFilter(font.texture, TextureFilter.POINT) + currentFontFilter = 0 + elseif (IsKeyPressed(KEY.TWO)) then + SetTextureFilter(font.texture, TextureFilter.BILINEAR) + currentFontFilter = 1 + elseif (IsKeyPressed(KEY.THREE)) then + -- NOTE: Trilinear filter won't be noticed on 2D drawing + SetTextureFilter(font.texture, TextureFilter.TRILINEAR) + currentFontFilter = 2 + end + + textSize = MeasureTextEx(font, msg, fontSize, 0) + + if (IsKeyDown(KEY.LEFT)) then fontPosition.x = fontPosition.x - 10 + elseif (IsKeyDown(KEY.RIGHT)) then fontPosition.x = fontPosition.x + 10 + end + + -- Load a dropped TTF file dynamically (at current fontSize) + if (IsFileDropped()) then + droppedFiles = GetDroppedFiles() + count = #droppedFiles + + if (count == 1) then -- Only support one ttf file dropped + UnloadSpriteFont(font) + font = LoadSpriteFontTTF(droppedFiles[1], fontSize, 0, 0) + ClearDroppedFiles() + end + end + --------------------------------------------------------------------------------------- + + -- Draw + --------------------------------------------------------------------------------------- + BeginDrawing() + + ClearBackground(RAYWHITE) + + DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY) + DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY) + DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY) + DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY) + + DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK) + + -- TODO: It seems texSize measurement is not accurate due to chars offsets... + --DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED) + + DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY) + DrawText(string.format("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY) + DrawText(string.format("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY) + DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY) + + if (currentFontFilter == 0) then DrawText("POINT", 570, 400, 20, BLACK) + elseif (currentFontFilter == 1) then DrawText("BILINEAR", 570, 400, 20, BLACK) + elseif (currentFontFilter == 2) then DrawText("TRILINEAR", 570, 400, 20, BLACK) + end + + EndDrawing() + --------------------------------------------------------------------------------------- +end + +-- De-Initialization +------------------------------------------------------------------------------------------- +UnloadSpriteFont(font) -- SpriteFont unloading + +ClearDroppedFiles() -- Clear internal buffers + +CloseWindow() -- Close window and OpenGL context +------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/examples/text_ttf_loading.png b/examples/text_ttf_loading.png new file mode 100644 index 000000000..29ea263ac Binary files /dev/null and b/examples/text_ttf_loading.png differ diff --git a/games/drturtle/makefile b/games/drturtle/makefile index f9efd3e85..0a45e18a6 100644 --- a/games/drturtle/makefile +++ b/games/drturtle/makefile @@ -112,8 +112,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # libraries for Debian GNU/Linux desktop compiling # requires the following packages: # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal - endif + LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread -ldl + # on XWindow could require also below libraries, just uncomment + #LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor + else ifeq ($(PLATFORM_OS),OSX) # libraries for OS X 10.9 desktop compiling # requires the following packages: @@ -124,6 +126,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: GLFW3 and OpenAL Soft libraries should be installed LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 endif + endif endif ifeq ($(PLATFORM),PLATFORM_RPI) # libraries for Raspberry Pi compiling diff --git a/games/just_do/makefile b/games/just_do/makefile index 5cca9df5b..1a971081d 100644 --- a/games/just_do/makefile +++ b/games/just_do/makefile @@ -117,8 +117,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # libraries for Debian GNU/Linux desktop compiling # requires the following packages: # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal - endif + LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread -ldl + # on XWindow could require also below libraries, just uncomment + #LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor + else ifeq ($(PLATFORM_OS),OSX) # libraries for OS X 10.9 desktop compiling # requires the following packages: @@ -129,6 +131,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: GLFW3 and OpenAL Soft libraries should be installed LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 endif + endif endif ifeq ($(PLATFORM),PLATFORM_RPI) # libraries for Raspberry Pi compiling diff --git a/games/raylib_demo/makefile b/games/raylib_demo/makefile index a4435bb0b..0c22261c2 100644 --- a/games/raylib_demo/makefile +++ b/games/raylib_demo/makefile @@ -117,7 +117,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # libraries for Debian GNU/Linux desktop compiling # requires the following packages: # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread + LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread -ldl # on XWindow could require also below libraries, just uncomment #LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor else diff --git a/games/skully_escape/makefile b/games/skully_escape/makefile index d47760d3a..967c3da70 100644 --- a/games/skully_escape/makefile +++ b/games/skully_escape/makefile @@ -114,8 +114,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # libraries for Debian GNU/Linux desktop compiling # requires the following packages: # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal - endif + LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread -ldl + # on XWindow could require also below libraries, just uncomment + #LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor + else ifeq ($(PLATFORM_OS),OSX) # libraries for OS X 10.9 desktop compiling # requires the following packages: @@ -126,6 +128,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: GLFW3 and OpenAL Soft libraries should be installed LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 endif + endif endif ifeq ($(PLATFORM),PLATFORM_RPI) # libraries for Raspberry Pi compiling diff --git a/release/android/armeabi/libraylib.a b/release/android/armeabi/libraylib.a index 3ee2746da..39975a6ba 100644 Binary files a/release/android/armeabi/libraylib.a and b/release/android/armeabi/libraylib.a differ diff --git a/release/android/raylib.h b/release/android/raylib.h index fee6aa910..d28b07a35 100644 --- a/release/android/raylib.h +++ b/release/android/raylib.h @@ -1,42 +1,44 @@ /********************************************************************************************** * -* raylib 1.5.0 (www.raylib.com) +* raylib 1.6.0 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,15 +79,19 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) +#if defined(_WIN32) && defined(BUILDING_DLL) + #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL +#elif defined(_WIN32) && defined(RAYLIB_DLL) + #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL +#else + #define RLAPI // We are building or using raylib as a static library (or Linux shared library) #endif //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -93,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -165,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -181,21 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons -// NOTE: Adjusted for a PS3 USB Controller -#define GAMEPAD_BUTTON_A 2 -#define GAMEPAD_BUTTON_B 1 -#define GAMEPAD_BUTTON_X 3 -#define GAMEPAD_BUTTON_Y 4 -#define GAMEPAD_BUTTON_R1 7 -#define GAMEPAD_BUTTON_R2 5 -#define GAMEPAD_BUTTON_L1 6 -#define GAMEPAD_BUTTON_L2 8 -#define GAMEPAD_BUTTON_SELECT 9 -#define GAMEPAD_BUTTON_START 10 +// Gamepad Buttons/Axis + +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 +#define GAMEPAD_PS3_BUTTON_SELECT 9 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -206,62 +230,67 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 +// NOTE: MSC C++ compiler does not support compound literals (C99 feature) +// Plain structures in C++ (without constructors) can be initialized from { } initializers. +#ifdef __cplusplus + #define CLITERAL +#else + #define CLITERAL (Color) +#endif // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background -#define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray -#define GRAY (Color){ 130, 130, 130, 255 } // Gray -#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray -#define YELLOW (Color){ 253, 249, 0, 255 } // Yellow -#define GOLD (Color){ 255, 203, 0, 255 } // Gold -#define ORANGE (Color){ 255, 161, 0, 255 } // Orange -#define PINK (Color){ 255, 109, 194, 255 } // Pink -#define RED (Color){ 230, 41, 55, 255 } // Red -#define MAROON (Color){ 190, 33, 55, 255 } // Maroon -#define GREEN (Color){ 0, 228, 48, 255 } // Green -#define LIME (Color){ 0, 158, 47, 255 } // Lime -#define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green -#define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue -#define BLUE (Color){ 0, 121, 241, 255 } // Blue -#define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue -#define PURPLE (Color){ 200, 122, 255, 255 } // Purple -#define VIOLET (Color){ 135, 60, 190, 255 } // Violet -#define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple -#define BEIGE (Color){ 211, 176, 131, 255 } // Beige -#define BROWN (Color){ 127, 106, 79, 255 } // Brown -#define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown +#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray +#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray +#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray +#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow +#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold +#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange +#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink +#define RED CLITERAL{ 230, 41, 55, 255 } // Red +#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon +#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green +#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime +#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green +#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue +#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue +#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue +#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple +#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet +#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple +#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige +#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown +#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown -#define WHITE (Color){ 255, 255, 255, 255 } // White -#define BLACK (Color){ 0, 0, 0, 255 } // Black -#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) -#define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta -#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) +#define WHITE CLITERAL{ 255, 255, 255, 255 } // White +#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black +#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) +#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta +#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -278,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -397,7 +423,7 @@ typedef struct Mesh { // Shader type (generic shader) typedef struct Shader { unsigned int id; // Shader program id - + // Vertex attributes locations (default locations) int vertexLoc; // Vertex attribute location point (default-location = 0) int texcoordLoc; // Texcoord attribute location point (default-location = 1) @@ -408,8 +434,10 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) - + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) + // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1) @@ -423,11 +451,11 @@ typedef struct Material { Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc) Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) - + Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color - + float glossiness; // Glossiness level (Ranges from 0 to 1000) } Material; @@ -443,14 +471,14 @@ typedef struct LightData { unsigned int id; // Light unique id bool enabled; // Light enabled int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - + Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) - + Color diffuse; // Light diffuse color float intensity; // Light intensity level - + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; @@ -463,21 +491,38 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { + unsigned int sampleCount; // Number of samples + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) void *data; // Buffer data pointer - unsigned int dataSize; // Data size in bytes - unsigned int sampleRate; // Samples per second to be played - short bitsPerSample; // Sample size in bits - short channels; } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + +// Music type (file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +typedef struct MusicData *Music; + +// Audio stream type +// NOTE: Useful to create custom audio streams not bound to a specific file +typedef struct AudioStream { + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) + + int format; // OpenAL audio format specifier + unsigned int source; // OpenAL audio source id + unsigned int buffers[2]; // OpenAL audio buffers (double buffering) +} AudioStream; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -501,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -520,20 +580,14 @@ typedef enum { GESTURE_PINCH_OUT = 512 } Gestures; -// Touch action (fingers or mouse) -typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; - -// Gesture events -// NOTE: MAX_TOUCH_POINTS fixed to 2 -typedef struct GestureEvent { - int touchAction; - int pointCount; - int pointerId[MAX_TOUCH_POINTS]; - Vector2 position[MAX_TOUCH_POINTS]; -} GestureEvent; - // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -561,352 +615,362 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif -void CloseWindow(void); // Close Window and Terminate Context -bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) -int GetScreenWidth(void); // Get current screen width -int GetScreenHeight(void); // Get current screen height +RLAPI void CloseWindow(void); // Close Window and Terminate Context +RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI int GetScreenWidth(void); // Get current screen width +RLAPI int GetScreenHeight(void); // Get current screen height -void ShowCursor(void); // Shows cursor -void HideCursor(void); // Hides cursor -bool IsCursorHidden(void); // Returns true if cursor is not visible -void EnableCursor(void); // Enables cursor -void DisableCursor(void); // Disables cursor +#if !defined(PLATFORM_ANDROID) +RLAPI void ShowCursor(void); // Shows cursor +RLAPI void HideCursor(void); // Hides cursor +RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor +RLAPI void DisableCursor(void); // Disables cursor +#endif -void ClearBackground(Color color); // Sets Background Color -void BeginDrawing(void); // Setup drawing canvas to start drawing -void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Sets Background Color +RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) -void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -void End2dMode(void); // Ends 2D mode custom camera usage -void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) -void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode -void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing -void EndTextureMode(void); // Ends drawing to render texture +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera +RLAPI void End2dMode(void); // Ends 2D mode custom camera usage +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode +RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing +RLAPI void EndTextureMode(void); // Ends drawing to render texture -Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position -Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) +RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) -void SetTargetFPS(int fps); // Set target FPS (maximum) -float GetFPS(void); // Returns current FPS -float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) +RLAPI float GetFPS(void); // Returns current FPS +RLAPI float GetFrameTime(void); // Returns time in seconds for one frame -Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value -int GetHexValue(Color color); // Returns hexadecimal value for a Color -float *ColorToFloat(Color color); // Converts Color to float array and normalizes -float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color +RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes +RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array +RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) -Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f +RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) +RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -void SetConfigFlags(char flags); // Setup some window configuration flags -void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -bool IsFileDropped(void); // Check if a file have been dropped into window -char **GetDroppedFiles(int *count); // Retrieve dropped files into window -void ClearDroppedFiles(void); // Clear dropped files paths buffer +RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) +RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -bool IsKeyPressed(int key); // Detect if a key has been pressed once -bool IsKeyDown(int key); // Detect if a key is being pressed -bool IsKeyReleased(int key); // Detect if a key has been released once -bool IsKeyUp(int key); // Detect if a key is NOT being pressed -int GetKeyPressed(void); // Get latest key pressed -void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once +RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed +RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once +RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed +RLAPI int GetKeyPressed(void); // Get latest key pressed +RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once -bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed -bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once -bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id +RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once +RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed +RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once +RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once -bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once -bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed -int GetMouseX(void); // Returns mouse position X -int GetMouseY(void); // Returns mouse position Y -Vector2 GetMousePosition(void); // Returns mouse position XY -void SetMousePosition(Vector2 position); // Set mouse position XY -int GetMouseWheelMove(void); // Returns mouse wheel movement Y +RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once +RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed +RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once +RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed +RLAPI int GetMouseX(void); // Returns mouse position X +RLAPI int GetMouseY(void); // Returns mouse position Y +RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY +RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y -int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) -int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) -Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) - -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif +RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) +RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) +RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ -void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags -bool IsGestureDetected(int gesture); // Check if a gesture have been detected -void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures -void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents()) - -int GetTouchPointsCount(void); // Get touch points count -int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds -Vector2 GetGestureDragVector(void); // Get gesture drag vector -float GetGestureDragAngle(void); // Get gesture drag angle -Vector2 GetGesturePinchVector(void); // Get gesture pinch delta -float GetGesturePinchAngle(void); // Get gesture pinch angle +RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags +RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected +RLAPI int GetGestureDetected(void); // Get latest detected gesture +RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector +RLAPI float GetGestureDragAngle(void); // Get gesture drag angle +RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta +RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode -void SetCameraPosition(Vector3 position); // Set internal camera position -void SetCameraTarget(Vector3 target); // Set internal camera target -void SetCameraFovy(float fovy); // Set internal camera field-of-view-y - -void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) -void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) -void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - -void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) +RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) +RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) +RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) +RLAPI void SetCameraMoveControls(int frontKey, int backKey, + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ -void DrawPixel(int posX, int posY, Color color); // Draw a pixel -void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) -void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line -void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) -void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle -void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) -void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline -void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle -void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle -void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle -void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline -void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) -void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points -void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines +RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel +RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) +RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line +RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) +RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle +RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle +RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline +RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle +RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) +RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline +RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle +RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline +RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) +RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points +RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines -bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles -bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle -Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision -bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle -bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle -bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle +RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ -Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) -Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) -Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file -Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) -Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory -Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory -Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D LoadTextureFromImage(Image image); // Load a texture from image data -RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering -void UnloadImage(Image image); // Unload image from CPU memory (RAM) -void UnloadTexture(Texture2D texture); // Unload texture from GPU memory -void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory -Color *GetImageData(Image image); // Get pixel data from image as a Color struct array -Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image -void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) -void ImageFormat(Image *image, int newFormat); // Convert image data to desired format -void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) -Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) -void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image -void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) -void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) -void ImageFlipVertical(Image *image); // Flip image vertically -void ImageFlipHorizontal(Image *image); // Flip image horizontally -void ImageColorTint(Image *image, Color color); // Modify image color: tint -void ImageColorInvert(Image *image); // Modify image color: invert -void ImageColorGrayscale(Image *image); // Modify image color: grayscale -void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) -void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) +RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) +RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file +RLAPI Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) +RLAPI Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory +RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory +RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) +RLAPI Texture2D LoadTextureFromImage(Image image); // Load a texture from image data +RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering +RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM) +RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory +RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory +RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) +RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image +RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) +RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) +RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image +RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) +RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) +RLAPI void ImageFlipVertical(Image *image); // Flip image vertically +RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally +RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint +RLAPI void ImageColorInvert(Image *image); // Modify image color: invert +RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale +RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) +RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode -void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D -void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 +RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters +RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ -SpriteFont GetDefaultFont(void); // Get the default SpriteFont -SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory -void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory +RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont +RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters +RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory -void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters - int fontSize, int spacing, Color tint); -int MeasureText(const char *text, int fontSize); // Measure string width for default font -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters + float fontSize, int spacing, Color tint); +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner -const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' -const char *SubText(const char *text, int position, int length); // Get a piece of a text string +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' +RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube -void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) -void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured -void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere -void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters -void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires -void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone -void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires -void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ -void DrawRay(Ray ray, Color color); // Draw a ray line -void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) -void DrawGizmo(Vector3 position); // Draw simple gizmo -void DrawLight(Light light); // Draw light in 3D world -void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space -//DrawTorus(), DrawTeapot() are useless... +RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube +RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) +RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires +RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured +RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere +RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters +RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires +RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone +RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ +RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line +RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) +RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo +RLAPI void DrawLight(Light light); // Draw light in 3D world +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) -Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) -Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) -Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model -Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) -void UnloadModel(Model model); // Unload 3d model from memory +RLAPI Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) +RLAPI Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) +RLAPI Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) +RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model +RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) +RLAPI void UnloadModel(Model model); // Unload 3d model from memory -Material LoadMaterial(const char *fileName); // Load material data (from file) -Material LoadDefaultMaterial(void); // Load default material (uses default models shader) -Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) -void UnloadMaterial(Material material); // Unload material textures from VRAM +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) +RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) +RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) +RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM -void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) -void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters -void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) -void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters -void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) +RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) +RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) +RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters +RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec + +RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits +RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres +RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes +RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere +RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere +RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection +RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits -bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres -bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes -bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere -bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere -bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection -bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations -void UnloadShader(Shader shader); // Unload a custom shader from memory +RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations +RLAPI void UnloadShader(Shader shader); // Unload a custom shader from memory -Shader GetDefaultShader(void); // Get default shader -Shader GetStandardShader(void); // Get standard shader -Texture2D GetDefaultTexture(void); // Get default texture +RLAPI Shader GetDefaultShader(void); // Get default shader +RLAPI Shader GetStandardShader(void); // Get standard shader +RLAPI Texture2D GetDefaultTexture(void); // Get default texture -int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location -void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) -void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) -void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location +RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) +RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) +RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) -void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) -void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) +RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) +RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -void BeginShaderMode(Shader shader); // Begin custom shader drawing -void EndShaderMode(void); // End custom shader drawing (use default shader) -void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) -void EndBlendMode(void); // End blending mode (reset to default: alpha blending) +RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing +RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) +RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) +RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) -Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DestroyLight(Light light); // Destroy a light and take it out of the list +RLAPI Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool +RLAPI void DestroyLight(Light light); // Destroy a light and take it out of the list //------------------------------------------------------------------------------------ // VR experience Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -void InitVrDevice(int vdDevice); // Init VR device -void CloseVrDevice(void); // Close VR device -void UpdateVrTracking(void); // Update VR tracking (position and orientation) -void BeginVrDrawing(void); // Begin VR drawing configuration -void EndVrDrawing(void); // End VR drawing process (and desktop mirror) -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) +RLAPI void InitVrDevice(int vdDevice); // Init VR device +RLAPI void CloseVrDevice(void); // Close VR device +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera +RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ -void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +RLAPI void InitAudioDevice(void); // Initialize audio device and context +RLAPI void CloseAudioDevice(void); // Close the audio device and context +RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory -Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) -void UnloadSound(Sound sound); // Unload sound -void PlaySound(Sound sound); // Play a sound -void PauseSound(Sound sound); // Pause a sound -void StopSound(Sound sound); // Stop playing a sound -bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing -void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) -void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory +RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data +RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data +RLAPI void UnloadSound(Sound sound); // Unload sound +RLAPI void PlaySound(Sound sound); // Play a sound +RLAPI void PauseSound(Sound sound); // Pause a sound +RLAPI void ResumeSound(Sound sound); // Resume a paused sound +RLAPI void StopSound(Sound sound); // Stop playing a sound +RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing +RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) +RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI void UnloadMusicStream(Music music); // Unload music stream +RLAPI void PlayMusicStream(Music music); // Start music playing +RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming +RLAPI void StopMusicStream(Music music); // Stop music playing +RLAPI void PauseMusicStream(Music music); // Pause music playing +RLAPI void ResumeMusicStream(Music music); // Resume playing paused music +RLAPI bool IsMusicPlaying(Music music); // Check if music is playing +RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) +RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) +RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) +RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -int PlayMusicStream(int index, char *fileName); // Start music playing (open stream) -void UpdateMusicStream(int index); // Updates buffers for music streaming -void StopMusicStream(int index); // Stop music playing (close stream) -void PauseMusicStream(int index); // Pause music playing -void ResumeMusicStream(int index); // Resume playing paused music -bool IsMusicPlaying(int index); // Check if music is playing -void SetMusicVolume(int index, float volume); // Set volume for music (1.0 is max level) -void SetMusicPitch(int index, float pitch); // Set pitch for a music (1.0 is base level) -float GetMusicTimeLength(int index); // Get current music time length (in seconds) -float GetMusicTimePlayed(int index); // Get current music time played (in seconds) -int GetMusicStreamCount(void); // Get number of streams loaded +RLAPI AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) +RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data +RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory +RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill +RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream +RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream +RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream +RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream #ifdef __cplusplus } diff --git a/release/html5/libraylib.bc b/release/html5/libraylib.bc index 5a26136be..4a7b8fa8b 100644 Binary files a/release/html5/libraylib.bc and b/release/html5/libraylib.bc differ diff --git a/release/html5/raylib.h b/release/html5/raylib.h index fee6aa910..d28b07a35 100644 --- a/release/html5/raylib.h +++ b/release/html5/raylib.h @@ -1,42 +1,44 @@ /********************************************************************************************** * -* raylib 1.5.0 (www.raylib.com) +* raylib 1.6.0 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,15 +79,19 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) +#if defined(_WIN32) && defined(BUILDING_DLL) + #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL +#elif defined(_WIN32) && defined(RAYLIB_DLL) + #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL +#else + #define RLAPI // We are building or using raylib as a static library (or Linux shared library) #endif //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -93,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -165,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -181,21 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons -// NOTE: Adjusted for a PS3 USB Controller -#define GAMEPAD_BUTTON_A 2 -#define GAMEPAD_BUTTON_B 1 -#define GAMEPAD_BUTTON_X 3 -#define GAMEPAD_BUTTON_Y 4 -#define GAMEPAD_BUTTON_R1 7 -#define GAMEPAD_BUTTON_R2 5 -#define GAMEPAD_BUTTON_L1 6 -#define GAMEPAD_BUTTON_L2 8 -#define GAMEPAD_BUTTON_SELECT 9 -#define GAMEPAD_BUTTON_START 10 +// Gamepad Buttons/Axis + +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 +#define GAMEPAD_PS3_BUTTON_SELECT 9 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -206,62 +230,67 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 +// NOTE: MSC C++ compiler does not support compound literals (C99 feature) +// Plain structures in C++ (without constructors) can be initialized from { } initializers. +#ifdef __cplusplus + #define CLITERAL +#else + #define CLITERAL (Color) +#endif // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background -#define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray -#define GRAY (Color){ 130, 130, 130, 255 } // Gray -#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray -#define YELLOW (Color){ 253, 249, 0, 255 } // Yellow -#define GOLD (Color){ 255, 203, 0, 255 } // Gold -#define ORANGE (Color){ 255, 161, 0, 255 } // Orange -#define PINK (Color){ 255, 109, 194, 255 } // Pink -#define RED (Color){ 230, 41, 55, 255 } // Red -#define MAROON (Color){ 190, 33, 55, 255 } // Maroon -#define GREEN (Color){ 0, 228, 48, 255 } // Green -#define LIME (Color){ 0, 158, 47, 255 } // Lime -#define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green -#define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue -#define BLUE (Color){ 0, 121, 241, 255 } // Blue -#define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue -#define PURPLE (Color){ 200, 122, 255, 255 } // Purple -#define VIOLET (Color){ 135, 60, 190, 255 } // Violet -#define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple -#define BEIGE (Color){ 211, 176, 131, 255 } // Beige -#define BROWN (Color){ 127, 106, 79, 255 } // Brown -#define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown +#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray +#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray +#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray +#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow +#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold +#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange +#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink +#define RED CLITERAL{ 230, 41, 55, 255 } // Red +#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon +#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green +#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime +#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green +#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue +#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue +#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue +#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple +#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet +#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple +#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige +#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown +#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown -#define WHITE (Color){ 255, 255, 255, 255 } // White -#define BLACK (Color){ 0, 0, 0, 255 } // Black -#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) -#define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta -#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) +#define WHITE CLITERAL{ 255, 255, 255, 255 } // White +#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black +#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) +#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta +#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -278,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -397,7 +423,7 @@ typedef struct Mesh { // Shader type (generic shader) typedef struct Shader { unsigned int id; // Shader program id - + // Vertex attributes locations (default locations) int vertexLoc; // Vertex attribute location point (default-location = 0) int texcoordLoc; // Texcoord attribute location point (default-location = 1) @@ -408,8 +434,10 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) - + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) + // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1) @@ -423,11 +451,11 @@ typedef struct Material { Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc) Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) - + Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color - + float glossiness; // Glossiness level (Ranges from 0 to 1000) } Material; @@ -443,14 +471,14 @@ typedef struct LightData { unsigned int id; // Light unique id bool enabled; // Light enabled int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - + Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) - + Color diffuse; // Light diffuse color float intensity; // Light intensity level - + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; @@ -463,21 +491,38 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { + unsigned int sampleCount; // Number of samples + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) void *data; // Buffer data pointer - unsigned int dataSize; // Data size in bytes - unsigned int sampleRate; // Samples per second to be played - short bitsPerSample; // Sample size in bits - short channels; } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + +// Music type (file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +typedef struct MusicData *Music; + +// Audio stream type +// NOTE: Useful to create custom audio streams not bound to a specific file +typedef struct AudioStream { + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) + + int format; // OpenAL audio format specifier + unsigned int source; // OpenAL audio source id + unsigned int buffers[2]; // OpenAL audio buffers (double buffering) +} AudioStream; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -501,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -520,20 +580,14 @@ typedef enum { GESTURE_PINCH_OUT = 512 } Gestures; -// Touch action (fingers or mouse) -typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; - -// Gesture events -// NOTE: MAX_TOUCH_POINTS fixed to 2 -typedef struct GestureEvent { - int touchAction; - int pointCount; - int pointerId[MAX_TOUCH_POINTS]; - Vector2 position[MAX_TOUCH_POINTS]; -} GestureEvent; - // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -561,352 +615,362 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif -void CloseWindow(void); // Close Window and Terminate Context -bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) -int GetScreenWidth(void); // Get current screen width -int GetScreenHeight(void); // Get current screen height +RLAPI void CloseWindow(void); // Close Window and Terminate Context +RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI int GetScreenWidth(void); // Get current screen width +RLAPI int GetScreenHeight(void); // Get current screen height -void ShowCursor(void); // Shows cursor -void HideCursor(void); // Hides cursor -bool IsCursorHidden(void); // Returns true if cursor is not visible -void EnableCursor(void); // Enables cursor -void DisableCursor(void); // Disables cursor +#if !defined(PLATFORM_ANDROID) +RLAPI void ShowCursor(void); // Shows cursor +RLAPI void HideCursor(void); // Hides cursor +RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor +RLAPI void DisableCursor(void); // Disables cursor +#endif -void ClearBackground(Color color); // Sets Background Color -void BeginDrawing(void); // Setup drawing canvas to start drawing -void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Sets Background Color +RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) -void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -void End2dMode(void); // Ends 2D mode custom camera usage -void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) -void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode -void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing -void EndTextureMode(void); // Ends drawing to render texture +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera +RLAPI void End2dMode(void); // Ends 2D mode custom camera usage +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode +RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing +RLAPI void EndTextureMode(void); // Ends drawing to render texture -Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position -Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) +RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) -void SetTargetFPS(int fps); // Set target FPS (maximum) -float GetFPS(void); // Returns current FPS -float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) +RLAPI float GetFPS(void); // Returns current FPS +RLAPI float GetFrameTime(void); // Returns time in seconds for one frame -Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value -int GetHexValue(Color color); // Returns hexadecimal value for a Color -float *ColorToFloat(Color color); // Converts Color to float array and normalizes -float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color +RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes +RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array +RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) -Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f +RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) +RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -void SetConfigFlags(char flags); // Setup some window configuration flags -void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -bool IsFileDropped(void); // Check if a file have been dropped into window -char **GetDroppedFiles(int *count); // Retrieve dropped files into window -void ClearDroppedFiles(void); // Clear dropped files paths buffer +RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) +RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -bool IsKeyPressed(int key); // Detect if a key has been pressed once -bool IsKeyDown(int key); // Detect if a key is being pressed -bool IsKeyReleased(int key); // Detect if a key has been released once -bool IsKeyUp(int key); // Detect if a key is NOT being pressed -int GetKeyPressed(void); // Get latest key pressed -void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once +RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed +RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once +RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed +RLAPI int GetKeyPressed(void); // Get latest key pressed +RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once -bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed -bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once -bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id +RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once +RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed +RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once +RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once -bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once -bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed -int GetMouseX(void); // Returns mouse position X -int GetMouseY(void); // Returns mouse position Y -Vector2 GetMousePosition(void); // Returns mouse position XY -void SetMousePosition(Vector2 position); // Set mouse position XY -int GetMouseWheelMove(void); // Returns mouse wheel movement Y +RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once +RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed +RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once +RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed +RLAPI int GetMouseX(void); // Returns mouse position X +RLAPI int GetMouseY(void); // Returns mouse position Y +RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY +RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y -int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) -int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) -Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) - -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif +RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) +RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) +RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ -void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags -bool IsGestureDetected(int gesture); // Check if a gesture have been detected -void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures -void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents()) - -int GetTouchPointsCount(void); // Get touch points count -int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds -Vector2 GetGestureDragVector(void); // Get gesture drag vector -float GetGestureDragAngle(void); // Get gesture drag angle -Vector2 GetGesturePinchVector(void); // Get gesture pinch delta -float GetGesturePinchAngle(void); // Get gesture pinch angle +RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags +RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected +RLAPI int GetGestureDetected(void); // Get latest detected gesture +RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector +RLAPI float GetGestureDragAngle(void); // Get gesture drag angle +RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta +RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode -void SetCameraPosition(Vector3 position); // Set internal camera position -void SetCameraTarget(Vector3 target); // Set internal camera target -void SetCameraFovy(float fovy); // Set internal camera field-of-view-y - -void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) -void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) -void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - -void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) +RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) +RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) +RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) +RLAPI void SetCameraMoveControls(int frontKey, int backKey, + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ -void DrawPixel(int posX, int posY, Color color); // Draw a pixel -void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) -void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line -void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) -void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle -void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) -void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline -void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle -void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle -void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle -void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline -void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) -void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points -void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines +RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel +RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) +RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line +RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) +RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle +RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle +RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline +RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle +RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) +RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline +RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle +RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline +RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) +RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points +RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines -bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles -bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle -Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision -bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle -bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle -bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle +RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ -Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) -Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) -Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file -Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) -Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory -Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory -Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D LoadTextureFromImage(Image image); // Load a texture from image data -RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering -void UnloadImage(Image image); // Unload image from CPU memory (RAM) -void UnloadTexture(Texture2D texture); // Unload texture from GPU memory -void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory -Color *GetImageData(Image image); // Get pixel data from image as a Color struct array -Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image -void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) -void ImageFormat(Image *image, int newFormat); // Convert image data to desired format -void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) -Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) -void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image -void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) -void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) -void ImageFlipVertical(Image *image); // Flip image vertically -void ImageFlipHorizontal(Image *image); // Flip image horizontally -void ImageColorTint(Image *image, Color color); // Modify image color: tint -void ImageColorInvert(Image *image); // Modify image color: invert -void ImageColorGrayscale(Image *image); // Modify image color: grayscale -void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) -void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) +RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) +RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file +RLAPI Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) +RLAPI Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory +RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory +RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) +RLAPI Texture2D LoadTextureFromImage(Image image); // Load a texture from image data +RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering +RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM) +RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory +RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory +RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) +RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image +RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) +RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) +RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image +RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) +RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) +RLAPI void ImageFlipVertical(Image *image); // Flip image vertically +RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally +RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint +RLAPI void ImageColorInvert(Image *image); // Modify image color: invert +RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale +RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) +RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode -void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D -void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 +RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters +RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ -SpriteFont GetDefaultFont(void); // Get the default SpriteFont -SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory -void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory +RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont +RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters +RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory -void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters - int fontSize, int spacing, Color tint); -int MeasureText(const char *text, int fontSize); // Measure string width for default font -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters + float fontSize, int spacing, Color tint); +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner -const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' -const char *SubText(const char *text, int position, int length); // Get a piece of a text string +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' +RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube -void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) -void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured -void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere -void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters -void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires -void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone -void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires -void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ -void DrawRay(Ray ray, Color color); // Draw a ray line -void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) -void DrawGizmo(Vector3 position); // Draw simple gizmo -void DrawLight(Light light); // Draw light in 3D world -void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space -//DrawTorus(), DrawTeapot() are useless... +RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube +RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) +RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires +RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured +RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere +RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters +RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires +RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone +RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ +RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line +RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) +RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo +RLAPI void DrawLight(Light light); // Draw light in 3D world +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) -Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) -Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) -Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model -Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) -void UnloadModel(Model model); // Unload 3d model from memory +RLAPI Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) +RLAPI Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) +RLAPI Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) +RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model +RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) +RLAPI void UnloadModel(Model model); // Unload 3d model from memory -Material LoadMaterial(const char *fileName); // Load material data (from file) -Material LoadDefaultMaterial(void); // Load default material (uses default models shader) -Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) -void UnloadMaterial(Material material); // Unload material textures from VRAM +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) +RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) +RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) +RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM -void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) -void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters -void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) -void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters -void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) +RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) +RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) +RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters +RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec + +RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits +RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres +RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes +RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere +RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere +RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection +RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits -bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres -bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes -bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere -bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere -bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection -bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations -void UnloadShader(Shader shader); // Unload a custom shader from memory +RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations +RLAPI void UnloadShader(Shader shader); // Unload a custom shader from memory -Shader GetDefaultShader(void); // Get default shader -Shader GetStandardShader(void); // Get standard shader -Texture2D GetDefaultTexture(void); // Get default texture +RLAPI Shader GetDefaultShader(void); // Get default shader +RLAPI Shader GetStandardShader(void); // Get standard shader +RLAPI Texture2D GetDefaultTexture(void); // Get default texture -int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location -void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) -void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) -void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location +RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) +RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) +RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) -void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) -void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) +RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) +RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -void BeginShaderMode(Shader shader); // Begin custom shader drawing -void EndShaderMode(void); // End custom shader drawing (use default shader) -void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) -void EndBlendMode(void); // End blending mode (reset to default: alpha blending) +RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing +RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) +RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) +RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) -Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DestroyLight(Light light); // Destroy a light and take it out of the list +RLAPI Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool +RLAPI void DestroyLight(Light light); // Destroy a light and take it out of the list //------------------------------------------------------------------------------------ // VR experience Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -void InitVrDevice(int vdDevice); // Init VR device -void CloseVrDevice(void); // Close VR device -void UpdateVrTracking(void); // Update VR tracking (position and orientation) -void BeginVrDrawing(void); // Begin VR drawing configuration -void EndVrDrawing(void); // End VR drawing process (and desktop mirror) -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) +RLAPI void InitVrDevice(int vdDevice); // Init VR device +RLAPI void CloseVrDevice(void); // Close VR device +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera +RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ -void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +RLAPI void InitAudioDevice(void); // Initialize audio device and context +RLAPI void CloseAudioDevice(void); // Close the audio device and context +RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory -Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) -void UnloadSound(Sound sound); // Unload sound -void PlaySound(Sound sound); // Play a sound -void PauseSound(Sound sound); // Pause a sound -void StopSound(Sound sound); // Stop playing a sound -bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing -void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) -void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory +RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data +RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data +RLAPI void UnloadSound(Sound sound); // Unload sound +RLAPI void PlaySound(Sound sound); // Play a sound +RLAPI void PauseSound(Sound sound); // Pause a sound +RLAPI void ResumeSound(Sound sound); // Resume a paused sound +RLAPI void StopSound(Sound sound); // Stop playing a sound +RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing +RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) +RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI void UnloadMusicStream(Music music); // Unload music stream +RLAPI void PlayMusicStream(Music music); // Start music playing +RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming +RLAPI void StopMusicStream(Music music); // Stop music playing +RLAPI void PauseMusicStream(Music music); // Pause music playing +RLAPI void ResumeMusicStream(Music music); // Resume playing paused music +RLAPI bool IsMusicPlaying(Music music); // Check if music is playing +RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) +RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) +RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) +RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -int PlayMusicStream(int index, char *fileName); // Start music playing (open stream) -void UpdateMusicStream(int index); // Updates buffers for music streaming -void StopMusicStream(int index); // Stop music playing (close stream) -void PauseMusicStream(int index); // Pause music playing -void ResumeMusicStream(int index); // Resume playing paused music -bool IsMusicPlaying(int index); // Check if music is playing -void SetMusicVolume(int index, float volume); // Set volume for music (1.0 is max level) -void SetMusicPitch(int index, float pitch); // Set pitch for a music (1.0 is base level) -float GetMusicTimeLength(int index); // Get current music time length (in seconds) -float GetMusicTimePlayed(int index); // Get current music time played (in seconds) -int GetMusicStreamCount(void); // Get number of streams loaded +RLAPI AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) +RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data +RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory +RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill +RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream +RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream +RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream +RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream #ifdef __cplusplus } diff --git a/release/linux/libraylib.a b/release/linux/libraylib.a deleted file mode 100644 index 81002beb5..000000000 Binary files a/release/linux/libraylib.a and /dev/null differ diff --git a/release/linux/libraylib.so b/release/linux/libraylib.so deleted file mode 100755 index dc759cd4a..000000000 Binary files a/release/linux/libraylib.so and /dev/null differ diff --git a/release/linux/raylib.h b/release/linux/raylib.h index fee6aa910..d28b07a35 100644 --- a/release/linux/raylib.h +++ b/release/linux/raylib.h @@ -1,42 +1,44 @@ /********************************************************************************************** * -* raylib 1.5.0 (www.raylib.com) +* raylib 1.6.0 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,15 +79,19 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) +#if defined(_WIN32) && defined(BUILDING_DLL) + #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL +#elif defined(_WIN32) && defined(RAYLIB_DLL) + #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL +#else + #define RLAPI // We are building or using raylib as a static library (or Linux shared library) #endif //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -93,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -165,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -181,21 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons -// NOTE: Adjusted for a PS3 USB Controller -#define GAMEPAD_BUTTON_A 2 -#define GAMEPAD_BUTTON_B 1 -#define GAMEPAD_BUTTON_X 3 -#define GAMEPAD_BUTTON_Y 4 -#define GAMEPAD_BUTTON_R1 7 -#define GAMEPAD_BUTTON_R2 5 -#define GAMEPAD_BUTTON_L1 6 -#define GAMEPAD_BUTTON_L2 8 -#define GAMEPAD_BUTTON_SELECT 9 -#define GAMEPAD_BUTTON_START 10 +// Gamepad Buttons/Axis + +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 +#define GAMEPAD_PS3_BUTTON_SELECT 9 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -206,62 +230,67 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 +// NOTE: MSC C++ compiler does not support compound literals (C99 feature) +// Plain structures in C++ (without constructors) can be initialized from { } initializers. +#ifdef __cplusplus + #define CLITERAL +#else + #define CLITERAL (Color) +#endif // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background -#define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray -#define GRAY (Color){ 130, 130, 130, 255 } // Gray -#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray -#define YELLOW (Color){ 253, 249, 0, 255 } // Yellow -#define GOLD (Color){ 255, 203, 0, 255 } // Gold -#define ORANGE (Color){ 255, 161, 0, 255 } // Orange -#define PINK (Color){ 255, 109, 194, 255 } // Pink -#define RED (Color){ 230, 41, 55, 255 } // Red -#define MAROON (Color){ 190, 33, 55, 255 } // Maroon -#define GREEN (Color){ 0, 228, 48, 255 } // Green -#define LIME (Color){ 0, 158, 47, 255 } // Lime -#define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green -#define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue -#define BLUE (Color){ 0, 121, 241, 255 } // Blue -#define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue -#define PURPLE (Color){ 200, 122, 255, 255 } // Purple -#define VIOLET (Color){ 135, 60, 190, 255 } // Violet -#define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple -#define BEIGE (Color){ 211, 176, 131, 255 } // Beige -#define BROWN (Color){ 127, 106, 79, 255 } // Brown -#define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown +#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray +#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray +#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray +#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow +#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold +#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange +#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink +#define RED CLITERAL{ 230, 41, 55, 255 } // Red +#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon +#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green +#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime +#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green +#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue +#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue +#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue +#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple +#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet +#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple +#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige +#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown +#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown -#define WHITE (Color){ 255, 255, 255, 255 } // White -#define BLACK (Color){ 0, 0, 0, 255 } // Black -#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) -#define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta -#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) +#define WHITE CLITERAL{ 255, 255, 255, 255 } // White +#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black +#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) +#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta +#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -278,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -397,7 +423,7 @@ typedef struct Mesh { // Shader type (generic shader) typedef struct Shader { unsigned int id; // Shader program id - + // Vertex attributes locations (default locations) int vertexLoc; // Vertex attribute location point (default-location = 0) int texcoordLoc; // Texcoord attribute location point (default-location = 1) @@ -408,8 +434,10 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) - + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) + // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1) @@ -423,11 +451,11 @@ typedef struct Material { Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc) Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) - + Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color - + float glossiness; // Glossiness level (Ranges from 0 to 1000) } Material; @@ -443,14 +471,14 @@ typedef struct LightData { unsigned int id; // Light unique id bool enabled; // Light enabled int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - + Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) - + Color diffuse; // Light diffuse color float intensity; // Light intensity level - + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; @@ -463,21 +491,38 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { + unsigned int sampleCount; // Number of samples + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) void *data; // Buffer data pointer - unsigned int dataSize; // Data size in bytes - unsigned int sampleRate; // Samples per second to be played - short bitsPerSample; // Sample size in bits - short channels; } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + +// Music type (file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +typedef struct MusicData *Music; + +// Audio stream type +// NOTE: Useful to create custom audio streams not bound to a specific file +typedef struct AudioStream { + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) + + int format; // OpenAL audio format specifier + unsigned int source; // OpenAL audio source id + unsigned int buffers[2]; // OpenAL audio buffers (double buffering) +} AudioStream; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -501,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -520,20 +580,14 @@ typedef enum { GESTURE_PINCH_OUT = 512 } Gestures; -// Touch action (fingers or mouse) -typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; - -// Gesture events -// NOTE: MAX_TOUCH_POINTS fixed to 2 -typedef struct GestureEvent { - int touchAction; - int pointCount; - int pointerId[MAX_TOUCH_POINTS]; - Vector2 position[MAX_TOUCH_POINTS]; -} GestureEvent; - // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -561,352 +615,362 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif -void CloseWindow(void); // Close Window and Terminate Context -bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) -int GetScreenWidth(void); // Get current screen width -int GetScreenHeight(void); // Get current screen height +RLAPI void CloseWindow(void); // Close Window and Terminate Context +RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI int GetScreenWidth(void); // Get current screen width +RLAPI int GetScreenHeight(void); // Get current screen height -void ShowCursor(void); // Shows cursor -void HideCursor(void); // Hides cursor -bool IsCursorHidden(void); // Returns true if cursor is not visible -void EnableCursor(void); // Enables cursor -void DisableCursor(void); // Disables cursor +#if !defined(PLATFORM_ANDROID) +RLAPI void ShowCursor(void); // Shows cursor +RLAPI void HideCursor(void); // Hides cursor +RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor +RLAPI void DisableCursor(void); // Disables cursor +#endif -void ClearBackground(Color color); // Sets Background Color -void BeginDrawing(void); // Setup drawing canvas to start drawing -void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Sets Background Color +RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) -void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -void End2dMode(void); // Ends 2D mode custom camera usage -void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) -void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode -void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing -void EndTextureMode(void); // Ends drawing to render texture +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera +RLAPI void End2dMode(void); // Ends 2D mode custom camera usage +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode +RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing +RLAPI void EndTextureMode(void); // Ends drawing to render texture -Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position -Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) +RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) -void SetTargetFPS(int fps); // Set target FPS (maximum) -float GetFPS(void); // Returns current FPS -float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) +RLAPI float GetFPS(void); // Returns current FPS +RLAPI float GetFrameTime(void); // Returns time in seconds for one frame -Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value -int GetHexValue(Color color); // Returns hexadecimal value for a Color -float *ColorToFloat(Color color); // Converts Color to float array and normalizes -float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color +RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes +RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array +RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) -Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f +RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) +RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -void SetConfigFlags(char flags); // Setup some window configuration flags -void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -bool IsFileDropped(void); // Check if a file have been dropped into window -char **GetDroppedFiles(int *count); // Retrieve dropped files into window -void ClearDroppedFiles(void); // Clear dropped files paths buffer +RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) +RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -bool IsKeyPressed(int key); // Detect if a key has been pressed once -bool IsKeyDown(int key); // Detect if a key is being pressed -bool IsKeyReleased(int key); // Detect if a key has been released once -bool IsKeyUp(int key); // Detect if a key is NOT being pressed -int GetKeyPressed(void); // Get latest key pressed -void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once +RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed +RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once +RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed +RLAPI int GetKeyPressed(void); // Get latest key pressed +RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once -bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed -bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once -bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id +RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once +RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed +RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once +RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once -bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once -bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed -int GetMouseX(void); // Returns mouse position X -int GetMouseY(void); // Returns mouse position Y -Vector2 GetMousePosition(void); // Returns mouse position XY -void SetMousePosition(Vector2 position); // Set mouse position XY -int GetMouseWheelMove(void); // Returns mouse wheel movement Y +RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once +RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed +RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once +RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed +RLAPI int GetMouseX(void); // Returns mouse position X +RLAPI int GetMouseY(void); // Returns mouse position Y +RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY +RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y -int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) -int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) -Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) - -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif +RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) +RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) +RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ -void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags -bool IsGestureDetected(int gesture); // Check if a gesture have been detected -void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures -void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents()) - -int GetTouchPointsCount(void); // Get touch points count -int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds -Vector2 GetGestureDragVector(void); // Get gesture drag vector -float GetGestureDragAngle(void); // Get gesture drag angle -Vector2 GetGesturePinchVector(void); // Get gesture pinch delta -float GetGesturePinchAngle(void); // Get gesture pinch angle +RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags +RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected +RLAPI int GetGestureDetected(void); // Get latest detected gesture +RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector +RLAPI float GetGestureDragAngle(void); // Get gesture drag angle +RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta +RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode -void SetCameraPosition(Vector3 position); // Set internal camera position -void SetCameraTarget(Vector3 target); // Set internal camera target -void SetCameraFovy(float fovy); // Set internal camera field-of-view-y - -void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) -void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) -void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - -void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) +RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) +RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) +RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) +RLAPI void SetCameraMoveControls(int frontKey, int backKey, + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ -void DrawPixel(int posX, int posY, Color color); // Draw a pixel -void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) -void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line -void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) -void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle -void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) -void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline -void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle -void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle -void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle -void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline -void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) -void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points -void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines +RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel +RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) +RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line +RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) +RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle +RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle +RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline +RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle +RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) +RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline +RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle +RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline +RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) +RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points +RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines -bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles -bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle -Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision -bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle -bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle -bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle +RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ -Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) -Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) -Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file -Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) -Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory -Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory -Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D LoadTextureFromImage(Image image); // Load a texture from image data -RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering -void UnloadImage(Image image); // Unload image from CPU memory (RAM) -void UnloadTexture(Texture2D texture); // Unload texture from GPU memory -void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory -Color *GetImageData(Image image); // Get pixel data from image as a Color struct array -Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image -void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) -void ImageFormat(Image *image, int newFormat); // Convert image data to desired format -void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) -Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) -void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image -void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) -void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) -void ImageFlipVertical(Image *image); // Flip image vertically -void ImageFlipHorizontal(Image *image); // Flip image horizontally -void ImageColorTint(Image *image, Color color); // Modify image color: tint -void ImageColorInvert(Image *image); // Modify image color: invert -void ImageColorGrayscale(Image *image); // Modify image color: grayscale -void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) -void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) +RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) +RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file +RLAPI Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) +RLAPI Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory +RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory +RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) +RLAPI Texture2D LoadTextureFromImage(Image image); // Load a texture from image data +RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering +RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM) +RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory +RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory +RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) +RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image +RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) +RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) +RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image +RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) +RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) +RLAPI void ImageFlipVertical(Image *image); // Flip image vertically +RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally +RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint +RLAPI void ImageColorInvert(Image *image); // Modify image color: invert +RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale +RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) +RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode -void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D -void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 +RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters +RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ -SpriteFont GetDefaultFont(void); // Get the default SpriteFont -SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory -void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory +RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont +RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters +RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory -void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters - int fontSize, int spacing, Color tint); -int MeasureText(const char *text, int fontSize); // Measure string width for default font -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters + float fontSize, int spacing, Color tint); +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner -const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' -const char *SubText(const char *text, int position, int length); // Get a piece of a text string +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' +RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube -void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) -void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured -void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere -void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters -void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires -void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone -void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires -void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ -void DrawRay(Ray ray, Color color); // Draw a ray line -void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) -void DrawGizmo(Vector3 position); // Draw simple gizmo -void DrawLight(Light light); // Draw light in 3D world -void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space -//DrawTorus(), DrawTeapot() are useless... +RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube +RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) +RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires +RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured +RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere +RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters +RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires +RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone +RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ +RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line +RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) +RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo +RLAPI void DrawLight(Light light); // Draw light in 3D world +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) -Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) -Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) -Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model -Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) -void UnloadModel(Model model); // Unload 3d model from memory +RLAPI Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) +RLAPI Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) +RLAPI Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) +RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model +RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) +RLAPI void UnloadModel(Model model); // Unload 3d model from memory -Material LoadMaterial(const char *fileName); // Load material data (from file) -Material LoadDefaultMaterial(void); // Load default material (uses default models shader) -Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) -void UnloadMaterial(Material material); // Unload material textures from VRAM +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) +RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) +RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) +RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM -void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) -void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters -void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) -void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters -void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) +RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) +RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) +RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters +RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec + +RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits +RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres +RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes +RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere +RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere +RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection +RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits -bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres -bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes -bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere -bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere -bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection -bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations -void UnloadShader(Shader shader); // Unload a custom shader from memory +RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations +RLAPI void UnloadShader(Shader shader); // Unload a custom shader from memory -Shader GetDefaultShader(void); // Get default shader -Shader GetStandardShader(void); // Get standard shader -Texture2D GetDefaultTexture(void); // Get default texture +RLAPI Shader GetDefaultShader(void); // Get default shader +RLAPI Shader GetStandardShader(void); // Get standard shader +RLAPI Texture2D GetDefaultTexture(void); // Get default texture -int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location -void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) -void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) -void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location +RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) +RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) +RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) -void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) -void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) +RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) +RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -void BeginShaderMode(Shader shader); // Begin custom shader drawing -void EndShaderMode(void); // End custom shader drawing (use default shader) -void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) -void EndBlendMode(void); // End blending mode (reset to default: alpha blending) +RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing +RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) +RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) +RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) -Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DestroyLight(Light light); // Destroy a light and take it out of the list +RLAPI Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool +RLAPI void DestroyLight(Light light); // Destroy a light and take it out of the list //------------------------------------------------------------------------------------ // VR experience Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -void InitVrDevice(int vdDevice); // Init VR device -void CloseVrDevice(void); // Close VR device -void UpdateVrTracking(void); // Update VR tracking (position and orientation) -void BeginVrDrawing(void); // Begin VR drawing configuration -void EndVrDrawing(void); // End VR drawing process (and desktop mirror) -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) +RLAPI void InitVrDevice(int vdDevice); // Init VR device +RLAPI void CloseVrDevice(void); // Close VR device +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera +RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ -void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +RLAPI void InitAudioDevice(void); // Initialize audio device and context +RLAPI void CloseAudioDevice(void); // Close the audio device and context +RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory -Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) -void UnloadSound(Sound sound); // Unload sound -void PlaySound(Sound sound); // Play a sound -void PauseSound(Sound sound); // Pause a sound -void StopSound(Sound sound); // Stop playing a sound -bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing -void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) -void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory +RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data +RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data +RLAPI void UnloadSound(Sound sound); // Unload sound +RLAPI void PlaySound(Sound sound); // Play a sound +RLAPI void PauseSound(Sound sound); // Pause a sound +RLAPI void ResumeSound(Sound sound); // Resume a paused sound +RLAPI void StopSound(Sound sound); // Stop playing a sound +RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing +RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) +RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI void UnloadMusicStream(Music music); // Unload music stream +RLAPI void PlayMusicStream(Music music); // Start music playing +RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming +RLAPI void StopMusicStream(Music music); // Stop music playing +RLAPI void PauseMusicStream(Music music); // Pause music playing +RLAPI void ResumeMusicStream(Music music); // Resume playing paused music +RLAPI bool IsMusicPlaying(Music music); // Check if music is playing +RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) +RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) +RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) +RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -int PlayMusicStream(int index, char *fileName); // Start music playing (open stream) -void UpdateMusicStream(int index); // Updates buffers for music streaming -void StopMusicStream(int index); // Stop music playing (close stream) -void PauseMusicStream(int index); // Pause music playing -void ResumeMusicStream(int index); // Resume playing paused music -bool IsMusicPlaying(int index); // Check if music is playing -void SetMusicVolume(int index, float volume); // Set volume for music (1.0 is max level) -void SetMusicPitch(int index, float pitch); // Set pitch for a music (1.0 is base level) -float GetMusicTimeLength(int index); // Get current music time length (in seconds) -float GetMusicTimePlayed(int index); // Get current music time played (in seconds) -int GetMusicStreamCount(void); // Get number of streams loaded +RLAPI AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) +RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data +RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory +RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill +RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream +RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream +RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream +RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream #ifdef __cplusplus } diff --git a/release/osx/libraylib.a b/release/osx/libraylib.a deleted file mode 100644 index 32ca7a24e..000000000 Binary files a/release/osx/libraylib.a and /dev/null differ diff --git a/release/osx/raylib.h b/release/osx/raylib.h index fee6aa910..d28b07a35 100644 --- a/release/osx/raylib.h +++ b/release/osx/raylib.h @@ -1,42 +1,44 @@ /********************************************************************************************** * -* raylib 1.5.0 (www.raylib.com) +* raylib 1.6.0 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,15 +79,19 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) +#if defined(_WIN32) && defined(BUILDING_DLL) + #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL +#elif defined(_WIN32) && defined(RAYLIB_DLL) + #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL +#else + #define RLAPI // We are building or using raylib as a static library (or Linux shared library) #endif //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -93,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -165,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -181,21 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons -// NOTE: Adjusted for a PS3 USB Controller -#define GAMEPAD_BUTTON_A 2 -#define GAMEPAD_BUTTON_B 1 -#define GAMEPAD_BUTTON_X 3 -#define GAMEPAD_BUTTON_Y 4 -#define GAMEPAD_BUTTON_R1 7 -#define GAMEPAD_BUTTON_R2 5 -#define GAMEPAD_BUTTON_L1 6 -#define GAMEPAD_BUTTON_L2 8 -#define GAMEPAD_BUTTON_SELECT 9 -#define GAMEPAD_BUTTON_START 10 +// Gamepad Buttons/Axis + +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 +#define GAMEPAD_PS3_BUTTON_SELECT 9 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -206,62 +230,67 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 +// NOTE: MSC C++ compiler does not support compound literals (C99 feature) +// Plain structures in C++ (without constructors) can be initialized from { } initializers. +#ifdef __cplusplus + #define CLITERAL +#else + #define CLITERAL (Color) +#endif // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background -#define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray -#define GRAY (Color){ 130, 130, 130, 255 } // Gray -#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray -#define YELLOW (Color){ 253, 249, 0, 255 } // Yellow -#define GOLD (Color){ 255, 203, 0, 255 } // Gold -#define ORANGE (Color){ 255, 161, 0, 255 } // Orange -#define PINK (Color){ 255, 109, 194, 255 } // Pink -#define RED (Color){ 230, 41, 55, 255 } // Red -#define MAROON (Color){ 190, 33, 55, 255 } // Maroon -#define GREEN (Color){ 0, 228, 48, 255 } // Green -#define LIME (Color){ 0, 158, 47, 255 } // Lime -#define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green -#define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue -#define BLUE (Color){ 0, 121, 241, 255 } // Blue -#define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue -#define PURPLE (Color){ 200, 122, 255, 255 } // Purple -#define VIOLET (Color){ 135, 60, 190, 255 } // Violet -#define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple -#define BEIGE (Color){ 211, 176, 131, 255 } // Beige -#define BROWN (Color){ 127, 106, 79, 255 } // Brown -#define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown +#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray +#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray +#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray +#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow +#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold +#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange +#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink +#define RED CLITERAL{ 230, 41, 55, 255 } // Red +#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon +#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green +#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime +#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green +#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue +#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue +#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue +#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple +#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet +#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple +#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige +#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown +#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown -#define WHITE (Color){ 255, 255, 255, 255 } // White -#define BLACK (Color){ 0, 0, 0, 255 } // Black -#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) -#define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta -#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) +#define WHITE CLITERAL{ 255, 255, 255, 255 } // White +#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black +#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) +#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta +#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -278,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -397,7 +423,7 @@ typedef struct Mesh { // Shader type (generic shader) typedef struct Shader { unsigned int id; // Shader program id - + // Vertex attributes locations (default locations) int vertexLoc; // Vertex attribute location point (default-location = 0) int texcoordLoc; // Texcoord attribute location point (default-location = 1) @@ -408,8 +434,10 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) - + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) + // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1) @@ -423,11 +451,11 @@ typedef struct Material { Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc) Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) - + Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color - + float glossiness; // Glossiness level (Ranges from 0 to 1000) } Material; @@ -443,14 +471,14 @@ typedef struct LightData { unsigned int id; // Light unique id bool enabled; // Light enabled int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - + Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) - + Color diffuse; // Light diffuse color float intensity; // Light intensity level - + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; @@ -463,21 +491,38 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { + unsigned int sampleCount; // Number of samples + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) void *data; // Buffer data pointer - unsigned int dataSize; // Data size in bytes - unsigned int sampleRate; // Samples per second to be played - short bitsPerSample; // Sample size in bits - short channels; } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + +// Music type (file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +typedef struct MusicData *Music; + +// Audio stream type +// NOTE: Useful to create custom audio streams not bound to a specific file +typedef struct AudioStream { + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) + + int format; // OpenAL audio format specifier + unsigned int source; // OpenAL audio source id + unsigned int buffers[2]; // OpenAL audio buffers (double buffering) +} AudioStream; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -501,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -520,20 +580,14 @@ typedef enum { GESTURE_PINCH_OUT = 512 } Gestures; -// Touch action (fingers or mouse) -typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; - -// Gesture events -// NOTE: MAX_TOUCH_POINTS fixed to 2 -typedef struct GestureEvent { - int touchAction; - int pointCount; - int pointerId[MAX_TOUCH_POINTS]; - Vector2 position[MAX_TOUCH_POINTS]; -} GestureEvent; - // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -561,352 +615,362 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif -void CloseWindow(void); // Close Window and Terminate Context -bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) -int GetScreenWidth(void); // Get current screen width -int GetScreenHeight(void); // Get current screen height +RLAPI void CloseWindow(void); // Close Window and Terminate Context +RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI int GetScreenWidth(void); // Get current screen width +RLAPI int GetScreenHeight(void); // Get current screen height -void ShowCursor(void); // Shows cursor -void HideCursor(void); // Hides cursor -bool IsCursorHidden(void); // Returns true if cursor is not visible -void EnableCursor(void); // Enables cursor -void DisableCursor(void); // Disables cursor +#if !defined(PLATFORM_ANDROID) +RLAPI void ShowCursor(void); // Shows cursor +RLAPI void HideCursor(void); // Hides cursor +RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor +RLAPI void DisableCursor(void); // Disables cursor +#endif -void ClearBackground(Color color); // Sets Background Color -void BeginDrawing(void); // Setup drawing canvas to start drawing -void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Sets Background Color +RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) -void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -void End2dMode(void); // Ends 2D mode custom camera usage -void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) -void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode -void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing -void EndTextureMode(void); // Ends drawing to render texture +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera +RLAPI void End2dMode(void); // Ends 2D mode custom camera usage +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode +RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing +RLAPI void EndTextureMode(void); // Ends drawing to render texture -Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position -Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) +RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) -void SetTargetFPS(int fps); // Set target FPS (maximum) -float GetFPS(void); // Returns current FPS -float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) +RLAPI float GetFPS(void); // Returns current FPS +RLAPI float GetFrameTime(void); // Returns time in seconds for one frame -Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value -int GetHexValue(Color color); // Returns hexadecimal value for a Color -float *ColorToFloat(Color color); // Converts Color to float array and normalizes -float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color +RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes +RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array +RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) -Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f +RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) +RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -void SetConfigFlags(char flags); // Setup some window configuration flags -void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -bool IsFileDropped(void); // Check if a file have been dropped into window -char **GetDroppedFiles(int *count); // Retrieve dropped files into window -void ClearDroppedFiles(void); // Clear dropped files paths buffer +RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) +RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -bool IsKeyPressed(int key); // Detect if a key has been pressed once -bool IsKeyDown(int key); // Detect if a key is being pressed -bool IsKeyReleased(int key); // Detect if a key has been released once -bool IsKeyUp(int key); // Detect if a key is NOT being pressed -int GetKeyPressed(void); // Get latest key pressed -void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once +RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed +RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once +RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed +RLAPI int GetKeyPressed(void); // Get latest key pressed +RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once -bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed -bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once -bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id +RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once +RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed +RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once +RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once -bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once -bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed -int GetMouseX(void); // Returns mouse position X -int GetMouseY(void); // Returns mouse position Y -Vector2 GetMousePosition(void); // Returns mouse position XY -void SetMousePosition(Vector2 position); // Set mouse position XY -int GetMouseWheelMove(void); // Returns mouse wheel movement Y +RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once +RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed +RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once +RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed +RLAPI int GetMouseX(void); // Returns mouse position X +RLAPI int GetMouseY(void); // Returns mouse position Y +RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY +RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y -int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) -int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) -Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) - -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif +RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) +RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) +RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ -void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags -bool IsGestureDetected(int gesture); // Check if a gesture have been detected -void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures -void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents()) - -int GetTouchPointsCount(void); // Get touch points count -int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds -Vector2 GetGestureDragVector(void); // Get gesture drag vector -float GetGestureDragAngle(void); // Get gesture drag angle -Vector2 GetGesturePinchVector(void); // Get gesture pinch delta -float GetGesturePinchAngle(void); // Get gesture pinch angle +RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags +RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected +RLAPI int GetGestureDetected(void); // Get latest detected gesture +RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector +RLAPI float GetGestureDragAngle(void); // Get gesture drag angle +RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta +RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode -void SetCameraPosition(Vector3 position); // Set internal camera position -void SetCameraTarget(Vector3 target); // Set internal camera target -void SetCameraFovy(float fovy); // Set internal camera field-of-view-y - -void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) -void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) -void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - -void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) +RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) +RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) +RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) +RLAPI void SetCameraMoveControls(int frontKey, int backKey, + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ -void DrawPixel(int posX, int posY, Color color); // Draw a pixel -void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) -void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line -void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) -void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle -void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) -void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline -void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle -void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle -void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle -void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline -void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) -void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points -void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines +RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel +RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) +RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line +RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) +RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle +RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle +RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline +RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle +RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) +RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline +RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle +RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline +RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) +RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points +RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines -bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles -bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle -Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision -bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle -bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle -bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle +RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ -Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) -Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) -Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file -Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) -Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory -Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory -Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D LoadTextureFromImage(Image image); // Load a texture from image data -RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering -void UnloadImage(Image image); // Unload image from CPU memory (RAM) -void UnloadTexture(Texture2D texture); // Unload texture from GPU memory -void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory -Color *GetImageData(Image image); // Get pixel data from image as a Color struct array -Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image -void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) -void ImageFormat(Image *image, int newFormat); // Convert image data to desired format -void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) -Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) -void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image -void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) -void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) -void ImageFlipVertical(Image *image); // Flip image vertically -void ImageFlipHorizontal(Image *image); // Flip image horizontally -void ImageColorTint(Image *image, Color color); // Modify image color: tint -void ImageColorInvert(Image *image); // Modify image color: invert -void ImageColorGrayscale(Image *image); // Modify image color: grayscale -void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) -void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) +RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) +RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file +RLAPI Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) +RLAPI Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory +RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory +RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) +RLAPI Texture2D LoadTextureFromImage(Image image); // Load a texture from image data +RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering +RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM) +RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory +RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory +RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) +RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image +RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) +RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) +RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image +RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) +RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) +RLAPI void ImageFlipVertical(Image *image); // Flip image vertically +RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally +RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint +RLAPI void ImageColorInvert(Image *image); // Modify image color: invert +RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale +RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) +RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode -void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D -void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 +RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters +RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ -SpriteFont GetDefaultFont(void); // Get the default SpriteFont -SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory -void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory +RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont +RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters +RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory -void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters - int fontSize, int spacing, Color tint); -int MeasureText(const char *text, int fontSize); // Measure string width for default font -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters + float fontSize, int spacing, Color tint); +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner -const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' -const char *SubText(const char *text, int position, int length); // Get a piece of a text string +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' +RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube -void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) -void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured -void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere -void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters -void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires -void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone -void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires -void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ -void DrawRay(Ray ray, Color color); // Draw a ray line -void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) -void DrawGizmo(Vector3 position); // Draw simple gizmo -void DrawLight(Light light); // Draw light in 3D world -void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space -//DrawTorus(), DrawTeapot() are useless... +RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube +RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) +RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires +RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured +RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere +RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters +RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires +RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone +RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ +RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line +RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) +RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo +RLAPI void DrawLight(Light light); // Draw light in 3D world +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) -Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) -Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) -Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model -Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) -void UnloadModel(Model model); // Unload 3d model from memory +RLAPI Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) +RLAPI Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) +RLAPI Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) +RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model +RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) +RLAPI void UnloadModel(Model model); // Unload 3d model from memory -Material LoadMaterial(const char *fileName); // Load material data (from file) -Material LoadDefaultMaterial(void); // Load default material (uses default models shader) -Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) -void UnloadMaterial(Material material); // Unload material textures from VRAM +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) +RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) +RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) +RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM -void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) -void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters -void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) -void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters -void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) +RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) +RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) +RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters +RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec + +RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits +RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres +RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes +RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere +RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere +RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection +RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits -bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres -bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes -bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere -bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere -bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection -bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations -void UnloadShader(Shader shader); // Unload a custom shader from memory +RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations +RLAPI void UnloadShader(Shader shader); // Unload a custom shader from memory -Shader GetDefaultShader(void); // Get default shader -Shader GetStandardShader(void); // Get standard shader -Texture2D GetDefaultTexture(void); // Get default texture +RLAPI Shader GetDefaultShader(void); // Get default shader +RLAPI Shader GetStandardShader(void); // Get standard shader +RLAPI Texture2D GetDefaultTexture(void); // Get default texture -int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location -void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) -void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) -void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location +RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) +RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) +RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) -void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) -void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) +RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) +RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -void BeginShaderMode(Shader shader); // Begin custom shader drawing -void EndShaderMode(void); // End custom shader drawing (use default shader) -void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) -void EndBlendMode(void); // End blending mode (reset to default: alpha blending) +RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing +RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) +RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) +RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) -Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DestroyLight(Light light); // Destroy a light and take it out of the list +RLAPI Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool +RLAPI void DestroyLight(Light light); // Destroy a light and take it out of the list //------------------------------------------------------------------------------------ // VR experience Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -void InitVrDevice(int vdDevice); // Init VR device -void CloseVrDevice(void); // Close VR device -void UpdateVrTracking(void); // Update VR tracking (position and orientation) -void BeginVrDrawing(void); // Begin VR drawing configuration -void EndVrDrawing(void); // End VR drawing process (and desktop mirror) -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) +RLAPI void InitVrDevice(int vdDevice); // Init VR device +RLAPI void CloseVrDevice(void); // Close VR device +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera +RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ -void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +RLAPI void InitAudioDevice(void); // Initialize audio device and context +RLAPI void CloseAudioDevice(void); // Close the audio device and context +RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory -Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) -void UnloadSound(Sound sound); // Unload sound -void PlaySound(Sound sound); // Play a sound -void PauseSound(Sound sound); // Pause a sound -void StopSound(Sound sound); // Stop playing a sound -bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing -void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) -void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory +RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data +RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data +RLAPI void UnloadSound(Sound sound); // Unload sound +RLAPI void PlaySound(Sound sound); // Play a sound +RLAPI void PauseSound(Sound sound); // Pause a sound +RLAPI void ResumeSound(Sound sound); // Resume a paused sound +RLAPI void StopSound(Sound sound); // Stop playing a sound +RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing +RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) +RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI void UnloadMusicStream(Music music); // Unload music stream +RLAPI void PlayMusicStream(Music music); // Start music playing +RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming +RLAPI void StopMusicStream(Music music); // Stop music playing +RLAPI void PauseMusicStream(Music music); // Pause music playing +RLAPI void ResumeMusicStream(Music music); // Resume playing paused music +RLAPI bool IsMusicPlaying(Music music); // Check if music is playing +RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) +RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) +RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) +RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -int PlayMusicStream(int index, char *fileName); // Start music playing (open stream) -void UpdateMusicStream(int index); // Updates buffers for music streaming -void StopMusicStream(int index); // Stop music playing (close stream) -void PauseMusicStream(int index); // Pause music playing -void ResumeMusicStream(int index); // Resume playing paused music -bool IsMusicPlaying(int index); // Check if music is playing -void SetMusicVolume(int index, float volume); // Set volume for music (1.0 is max level) -void SetMusicPitch(int index, float pitch); // Set pitch for a music (1.0 is base level) -float GetMusicTimeLength(int index); // Get current music time length (in seconds) -float GetMusicTimePlayed(int index); // Get current music time played (in seconds) -int GetMusicStreamCount(void); // Get number of streams loaded +RLAPI AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) +RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data +RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory +RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill +RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream +RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream +RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream +RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream #ifdef __cplusplus } diff --git a/release/rpi/libraylib.a b/release/rpi/libraylib.a index 522e02bd5..f3d41d506 100644 Binary files a/release/rpi/libraylib.a and b/release/rpi/libraylib.a differ diff --git a/release/rpi/raylib.h b/release/rpi/raylib.h index fee6aa910..d28b07a35 100644 --- a/release/rpi/raylib.h +++ b/release/rpi/raylib.h @@ -1,42 +1,44 @@ /********************************************************************************************** * -* raylib 1.5.0 (www.raylib.com) +* raylib 1.6.0 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,15 +79,19 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) +#if defined(_WIN32) && defined(BUILDING_DLL) + #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL +#elif defined(_WIN32) && defined(RAYLIB_DLL) + #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL +#else + #define RLAPI // We are building or using raylib as a static library (or Linux shared library) #endif //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -93,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -165,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -181,21 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons -// NOTE: Adjusted for a PS3 USB Controller -#define GAMEPAD_BUTTON_A 2 -#define GAMEPAD_BUTTON_B 1 -#define GAMEPAD_BUTTON_X 3 -#define GAMEPAD_BUTTON_Y 4 -#define GAMEPAD_BUTTON_R1 7 -#define GAMEPAD_BUTTON_R2 5 -#define GAMEPAD_BUTTON_L1 6 -#define GAMEPAD_BUTTON_L2 8 -#define GAMEPAD_BUTTON_SELECT 9 -#define GAMEPAD_BUTTON_START 10 +// Gamepad Buttons/Axis + +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 +#define GAMEPAD_PS3_BUTTON_SELECT 9 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -206,62 +230,67 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 +// NOTE: MSC C++ compiler does not support compound literals (C99 feature) +// Plain structures in C++ (without constructors) can be initialized from { } initializers. +#ifdef __cplusplus + #define CLITERAL +#else + #define CLITERAL (Color) +#endif // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background -#define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray -#define GRAY (Color){ 130, 130, 130, 255 } // Gray -#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray -#define YELLOW (Color){ 253, 249, 0, 255 } // Yellow -#define GOLD (Color){ 255, 203, 0, 255 } // Gold -#define ORANGE (Color){ 255, 161, 0, 255 } // Orange -#define PINK (Color){ 255, 109, 194, 255 } // Pink -#define RED (Color){ 230, 41, 55, 255 } // Red -#define MAROON (Color){ 190, 33, 55, 255 } // Maroon -#define GREEN (Color){ 0, 228, 48, 255 } // Green -#define LIME (Color){ 0, 158, 47, 255 } // Lime -#define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green -#define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue -#define BLUE (Color){ 0, 121, 241, 255 } // Blue -#define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue -#define PURPLE (Color){ 200, 122, 255, 255 } // Purple -#define VIOLET (Color){ 135, 60, 190, 255 } // Violet -#define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple -#define BEIGE (Color){ 211, 176, 131, 255 } // Beige -#define BROWN (Color){ 127, 106, 79, 255 } // Brown -#define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown +#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray +#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray +#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray +#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow +#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold +#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange +#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink +#define RED CLITERAL{ 230, 41, 55, 255 } // Red +#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon +#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green +#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime +#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green +#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue +#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue +#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue +#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple +#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet +#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple +#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige +#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown +#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown -#define WHITE (Color){ 255, 255, 255, 255 } // White -#define BLACK (Color){ 0, 0, 0, 255 } // Black -#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) -#define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta -#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) +#define WHITE CLITERAL{ 255, 255, 255, 255 } // White +#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black +#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) +#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta +#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -278,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -397,7 +423,7 @@ typedef struct Mesh { // Shader type (generic shader) typedef struct Shader { unsigned int id; // Shader program id - + // Vertex attributes locations (default locations) int vertexLoc; // Vertex attribute location point (default-location = 0) int texcoordLoc; // Texcoord attribute location point (default-location = 1) @@ -408,8 +434,10 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) - + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) + // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1) @@ -423,11 +451,11 @@ typedef struct Material { Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc) Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) - + Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color - + float glossiness; // Glossiness level (Ranges from 0 to 1000) } Material; @@ -443,14 +471,14 @@ typedef struct LightData { unsigned int id; // Light unique id bool enabled; // Light enabled int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - + Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) - + Color diffuse; // Light diffuse color float intensity; // Light intensity level - + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; @@ -463,21 +491,38 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { + unsigned int sampleCount; // Number of samples + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) void *data; // Buffer data pointer - unsigned int dataSize; // Data size in bytes - unsigned int sampleRate; // Samples per second to be played - short bitsPerSample; // Sample size in bits - short channels; } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + +// Music type (file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +typedef struct MusicData *Music; + +// Audio stream type +// NOTE: Useful to create custom audio streams not bound to a specific file +typedef struct AudioStream { + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) + + int format; // OpenAL audio format specifier + unsigned int source; // OpenAL audio source id + unsigned int buffers[2]; // OpenAL audio buffers (double buffering) +} AudioStream; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -501,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -520,20 +580,14 @@ typedef enum { GESTURE_PINCH_OUT = 512 } Gestures; -// Touch action (fingers or mouse) -typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; - -// Gesture events -// NOTE: MAX_TOUCH_POINTS fixed to 2 -typedef struct GestureEvent { - int touchAction; - int pointCount; - int pointerId[MAX_TOUCH_POINTS]; - Vector2 position[MAX_TOUCH_POINTS]; -} GestureEvent; - // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -561,352 +615,362 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif -void CloseWindow(void); // Close Window and Terminate Context -bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) -int GetScreenWidth(void); // Get current screen width -int GetScreenHeight(void); // Get current screen height +RLAPI void CloseWindow(void); // Close Window and Terminate Context +RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI int GetScreenWidth(void); // Get current screen width +RLAPI int GetScreenHeight(void); // Get current screen height -void ShowCursor(void); // Shows cursor -void HideCursor(void); // Hides cursor -bool IsCursorHidden(void); // Returns true if cursor is not visible -void EnableCursor(void); // Enables cursor -void DisableCursor(void); // Disables cursor +#if !defined(PLATFORM_ANDROID) +RLAPI void ShowCursor(void); // Shows cursor +RLAPI void HideCursor(void); // Hides cursor +RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor +RLAPI void DisableCursor(void); // Disables cursor +#endif -void ClearBackground(Color color); // Sets Background Color -void BeginDrawing(void); // Setup drawing canvas to start drawing -void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Sets Background Color +RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) -void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -void End2dMode(void); // Ends 2D mode custom camera usage -void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) -void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode -void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing -void EndTextureMode(void); // Ends drawing to render texture +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera +RLAPI void End2dMode(void); // Ends 2D mode custom camera usage +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode +RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing +RLAPI void EndTextureMode(void); // Ends drawing to render texture -Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position -Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) +RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) -void SetTargetFPS(int fps); // Set target FPS (maximum) -float GetFPS(void); // Returns current FPS -float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) +RLAPI float GetFPS(void); // Returns current FPS +RLAPI float GetFrameTime(void); // Returns time in seconds for one frame -Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value -int GetHexValue(Color color); // Returns hexadecimal value for a Color -float *ColorToFloat(Color color); // Converts Color to float array and normalizes -float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color +RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes +RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array +RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) -Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f +RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) +RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -void SetConfigFlags(char flags); // Setup some window configuration flags -void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -bool IsFileDropped(void); // Check if a file have been dropped into window -char **GetDroppedFiles(int *count); // Retrieve dropped files into window -void ClearDroppedFiles(void); // Clear dropped files paths buffer +RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) +RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -bool IsKeyPressed(int key); // Detect if a key has been pressed once -bool IsKeyDown(int key); // Detect if a key is being pressed -bool IsKeyReleased(int key); // Detect if a key has been released once -bool IsKeyUp(int key); // Detect if a key is NOT being pressed -int GetKeyPressed(void); // Get latest key pressed -void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once +RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed +RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once +RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed +RLAPI int GetKeyPressed(void); // Get latest key pressed +RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once -bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed -bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once -bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id +RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once +RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed +RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once +RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once -bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once -bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed -int GetMouseX(void); // Returns mouse position X -int GetMouseY(void); // Returns mouse position Y -Vector2 GetMousePosition(void); // Returns mouse position XY -void SetMousePosition(Vector2 position); // Set mouse position XY -int GetMouseWheelMove(void); // Returns mouse wheel movement Y +RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once +RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed +RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once +RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed +RLAPI int GetMouseX(void); // Returns mouse position X +RLAPI int GetMouseY(void); // Returns mouse position Y +RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY +RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y -int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) -int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) -Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) - -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif +RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) +RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) +RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ -void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags -bool IsGestureDetected(int gesture); // Check if a gesture have been detected -void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures -void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents()) - -int GetTouchPointsCount(void); // Get touch points count -int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds -Vector2 GetGestureDragVector(void); // Get gesture drag vector -float GetGestureDragAngle(void); // Get gesture drag angle -Vector2 GetGesturePinchVector(void); // Get gesture pinch delta -float GetGesturePinchAngle(void); // Get gesture pinch angle +RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags +RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected +RLAPI int GetGestureDetected(void); // Get latest detected gesture +RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector +RLAPI float GetGestureDragAngle(void); // Get gesture drag angle +RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta +RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode -void SetCameraPosition(Vector3 position); // Set internal camera position -void SetCameraTarget(Vector3 target); // Set internal camera target -void SetCameraFovy(float fovy); // Set internal camera field-of-view-y - -void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) -void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) -void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - -void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) +RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) +RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) +RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) +RLAPI void SetCameraMoveControls(int frontKey, int backKey, + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ -void DrawPixel(int posX, int posY, Color color); // Draw a pixel -void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) -void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line -void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) -void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle -void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) -void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline -void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle -void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle -void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle -void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline -void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) -void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points -void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines +RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel +RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) +RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line +RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) +RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle +RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle +RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline +RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle +RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) +RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline +RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle +RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline +RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) +RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points +RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines -bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles -bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle -Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision -bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle -bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle -bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle +RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ -Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) -Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) -Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file -Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) -Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory -Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory -Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D LoadTextureFromImage(Image image); // Load a texture from image data -RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering -void UnloadImage(Image image); // Unload image from CPU memory (RAM) -void UnloadTexture(Texture2D texture); // Unload texture from GPU memory -void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory -Color *GetImageData(Image image); // Get pixel data from image as a Color struct array -Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image -void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) -void ImageFormat(Image *image, int newFormat); // Convert image data to desired format -void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) -Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) -void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image -void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) -void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) -void ImageFlipVertical(Image *image); // Flip image vertically -void ImageFlipHorizontal(Image *image); // Flip image horizontally -void ImageColorTint(Image *image, Color color); // Modify image color: tint -void ImageColorInvert(Image *image); // Modify image color: invert -void ImageColorGrayscale(Image *image); // Modify image color: grayscale -void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) -void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) +RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) +RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file +RLAPI Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) +RLAPI Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory +RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory +RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) +RLAPI Texture2D LoadTextureFromImage(Image image); // Load a texture from image data +RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering +RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM) +RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory +RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory +RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) +RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image +RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) +RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) +RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image +RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) +RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) +RLAPI void ImageFlipVertical(Image *image); // Flip image vertically +RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally +RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint +RLAPI void ImageColorInvert(Image *image); // Modify image color: invert +RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale +RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) +RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode -void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D -void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 +RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters +RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ -SpriteFont GetDefaultFont(void); // Get the default SpriteFont -SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory -void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory +RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont +RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters +RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory -void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters - int fontSize, int spacing, Color tint); -int MeasureText(const char *text, int fontSize); // Measure string width for default font -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters + float fontSize, int spacing, Color tint); +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner -const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' -const char *SubText(const char *text, int position, int length); // Get a piece of a text string +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' +RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube -void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) -void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured -void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere -void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters -void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires -void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone -void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires -void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ -void DrawRay(Ray ray, Color color); // Draw a ray line -void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) -void DrawGizmo(Vector3 position); // Draw simple gizmo -void DrawLight(Light light); // Draw light in 3D world -void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space -//DrawTorus(), DrawTeapot() are useless... +RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube +RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) +RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires +RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured +RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere +RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters +RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires +RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone +RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ +RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line +RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) +RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo +RLAPI void DrawLight(Light light); // Draw light in 3D world +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) -Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) -Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) -Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model -Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) -void UnloadModel(Model model); // Unload 3d model from memory +RLAPI Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) +RLAPI Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) +RLAPI Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) +RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model +RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) +RLAPI void UnloadModel(Model model); // Unload 3d model from memory -Material LoadMaterial(const char *fileName); // Load material data (from file) -Material LoadDefaultMaterial(void); // Load default material (uses default models shader) -Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) -void UnloadMaterial(Material material); // Unload material textures from VRAM +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) +RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) +RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) +RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM -void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) -void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters -void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) -void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters -void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) +RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) +RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) +RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters +RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec + +RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits +RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres +RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes +RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere +RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere +RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection +RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits -bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres -bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes -bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere -bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere -bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection -bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations -void UnloadShader(Shader shader); // Unload a custom shader from memory +RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations +RLAPI void UnloadShader(Shader shader); // Unload a custom shader from memory -Shader GetDefaultShader(void); // Get default shader -Shader GetStandardShader(void); // Get standard shader -Texture2D GetDefaultTexture(void); // Get default texture +RLAPI Shader GetDefaultShader(void); // Get default shader +RLAPI Shader GetStandardShader(void); // Get standard shader +RLAPI Texture2D GetDefaultTexture(void); // Get default texture -int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location -void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) -void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) -void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location +RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) +RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) +RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) -void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) -void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) +RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) +RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -void BeginShaderMode(Shader shader); // Begin custom shader drawing -void EndShaderMode(void); // End custom shader drawing (use default shader) -void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) -void EndBlendMode(void); // End blending mode (reset to default: alpha blending) +RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing +RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) +RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) +RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) -Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DestroyLight(Light light); // Destroy a light and take it out of the list +RLAPI Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool +RLAPI void DestroyLight(Light light); // Destroy a light and take it out of the list //------------------------------------------------------------------------------------ // VR experience Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -void InitVrDevice(int vdDevice); // Init VR device -void CloseVrDevice(void); // Close VR device -void UpdateVrTracking(void); // Update VR tracking (position and orientation) -void BeginVrDrawing(void); // Begin VR drawing configuration -void EndVrDrawing(void); // End VR drawing process (and desktop mirror) -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) +RLAPI void InitVrDevice(int vdDevice); // Init VR device +RLAPI void CloseVrDevice(void); // Close VR device +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera +RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ -void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +RLAPI void InitAudioDevice(void); // Initialize audio device and context +RLAPI void CloseAudioDevice(void); // Close the audio device and context +RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory -Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) -void UnloadSound(Sound sound); // Unload sound -void PlaySound(Sound sound); // Play a sound -void PauseSound(Sound sound); // Pause a sound -void StopSound(Sound sound); // Stop playing a sound -bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing -void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) -void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory +RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data +RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data +RLAPI void UnloadSound(Sound sound); // Unload sound +RLAPI void PlaySound(Sound sound); // Play a sound +RLAPI void PauseSound(Sound sound); // Pause a sound +RLAPI void ResumeSound(Sound sound); // Resume a paused sound +RLAPI void StopSound(Sound sound); // Stop playing a sound +RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing +RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) +RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI void UnloadMusicStream(Music music); // Unload music stream +RLAPI void PlayMusicStream(Music music); // Start music playing +RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming +RLAPI void StopMusicStream(Music music); // Stop music playing +RLAPI void PauseMusicStream(Music music); // Pause music playing +RLAPI void ResumeMusicStream(Music music); // Resume playing paused music +RLAPI bool IsMusicPlaying(Music music); // Check if music is playing +RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) +RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) +RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) +RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -int PlayMusicStream(int index, char *fileName); // Start music playing (open stream) -void UpdateMusicStream(int index); // Updates buffers for music streaming -void StopMusicStream(int index); // Stop music playing (close stream) -void PauseMusicStream(int index); // Pause music playing -void ResumeMusicStream(int index); // Resume playing paused music -bool IsMusicPlaying(int index); // Check if music is playing -void SetMusicVolume(int index, float volume); // Set volume for music (1.0 is max level) -void SetMusicPitch(int index, float pitch); // Set pitch for a music (1.0 is base level) -float GetMusicTimeLength(int index); // Get current music time length (in seconds) -float GetMusicTimePlayed(int index); // Get current music time played (in seconds) -int GetMusicStreamCount(void); // Get number of streams loaded +RLAPI AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) +RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data +RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory +RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill +RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream +RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream +RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream +RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream #ifdef __cplusplus } diff --git a/release/win32/mingw32/libraylib.a b/release/win32/mingw32/libraylib.a index 6e9db0d2f..e0136aed7 100644 Binary files a/release/win32/mingw32/libraylib.a and b/release/win32/mingw32/libraylib.a differ diff --git a/release/win32/mingw32/libraylibdll.a b/release/win32/mingw32/libraylibdll.a new file mode 100644 index 000000000..c0b544054 Binary files /dev/null and b/release/win32/mingw32/libraylibdll.a differ diff --git a/release/win32/raylib.h b/release/win32/raylib.h index fee6aa910..d28b07a35 100644 --- a/release/win32/raylib.h +++ b/release/win32/raylib.h @@ -1,42 +1,44 @@ /********************************************************************************************** * -* raylib 1.5.0 (www.raylib.com) +* raylib 1.6.0 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,15 +79,19 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) +#if defined(_WIN32) && defined(BUILDING_DLL) + #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL +#elif defined(_WIN32) && defined(RAYLIB_DLL) + #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL +#else + #define RLAPI // We are building or using raylib as a static library (or Linux shared library) #endif //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -93,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -165,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -181,21 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons -// NOTE: Adjusted for a PS3 USB Controller -#define GAMEPAD_BUTTON_A 2 -#define GAMEPAD_BUTTON_B 1 -#define GAMEPAD_BUTTON_X 3 -#define GAMEPAD_BUTTON_Y 4 -#define GAMEPAD_BUTTON_R1 7 -#define GAMEPAD_BUTTON_R2 5 -#define GAMEPAD_BUTTON_L1 6 -#define GAMEPAD_BUTTON_L2 8 -#define GAMEPAD_BUTTON_SELECT 9 -#define GAMEPAD_BUTTON_START 10 +// Gamepad Buttons/Axis + +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 +#define GAMEPAD_PS3_BUTTON_SELECT 9 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -206,62 +230,67 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 +// NOTE: MSC C++ compiler does not support compound literals (C99 feature) +// Plain structures in C++ (without constructors) can be initialized from { } initializers. +#ifdef __cplusplus + #define CLITERAL +#else + #define CLITERAL (Color) +#endif // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background -#define LIGHTGRAY (Color){ 200, 200, 200, 255 } // Light Gray -#define GRAY (Color){ 130, 130, 130, 255 } // Gray -#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray -#define YELLOW (Color){ 253, 249, 0, 255 } // Yellow -#define GOLD (Color){ 255, 203, 0, 255 } // Gold -#define ORANGE (Color){ 255, 161, 0, 255 } // Orange -#define PINK (Color){ 255, 109, 194, 255 } // Pink -#define RED (Color){ 230, 41, 55, 255 } // Red -#define MAROON (Color){ 190, 33, 55, 255 } // Maroon -#define GREEN (Color){ 0, 228, 48, 255 } // Green -#define LIME (Color){ 0, 158, 47, 255 } // Lime -#define DARKGREEN (Color){ 0, 117, 44, 255 } // Dark Green -#define SKYBLUE (Color){ 102, 191, 255, 255 } // Sky Blue -#define BLUE (Color){ 0, 121, 241, 255 } // Blue -#define DARKBLUE (Color){ 0, 82, 172, 255 } // Dark Blue -#define PURPLE (Color){ 200, 122, 255, 255 } // Purple -#define VIOLET (Color){ 135, 60, 190, 255 } // Violet -#define DARKPURPLE (Color){ 112, 31, 126, 255 } // Dark Purple -#define BEIGE (Color){ 211, 176, 131, 255 } // Beige -#define BROWN (Color){ 127, 106, 79, 255 } // Brown -#define DARKBROWN (Color){ 76, 63, 47, 255 } // Dark Brown +#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray +#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray +#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray +#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow +#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold +#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange +#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink +#define RED CLITERAL{ 230, 41, 55, 255 } // Red +#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon +#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green +#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime +#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green +#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue +#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue +#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue +#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple +#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet +#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple +#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige +#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown +#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown -#define WHITE (Color){ 255, 255, 255, 255 } // White -#define BLACK (Color){ 0, 0, 0, 255 } // Black -#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) -#define MAGENTA (Color){ 255, 0, 255, 255 } // Magenta -#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) +#define WHITE CLITERAL{ 255, 255, 255, 255 } // White +#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black +#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) +#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta +#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -278,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -397,7 +423,7 @@ typedef struct Mesh { // Shader type (generic shader) typedef struct Shader { unsigned int id; // Shader program id - + // Vertex attributes locations (default locations) int vertexLoc; // Vertex attribute location point (default-location = 0) int texcoordLoc; // Texcoord attribute location point (default-location = 1) @@ -408,8 +434,10 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) - + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) + // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1) @@ -423,11 +451,11 @@ typedef struct Material { Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc) Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) - + Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color - + float glossiness; // Glossiness level (Ranges from 0 to 1000) } Material; @@ -443,14 +471,14 @@ typedef struct LightData { unsigned int id; // Light unique id bool enabled; // Light enabled int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT - + Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) - + Color diffuse; // Light diffuse color float intensity; // Light intensity level - + float coneAngle; // Light cone max angle: LIGHT_SPOT } LightData, *Light; @@ -463,21 +491,38 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { + unsigned int sampleCount; // Number of samples + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) void *data; // Buffer data pointer - unsigned int dataSize; // Data size in bytes - unsigned int sampleRate; // Samples per second to be played - short bitsPerSample; // Sample size in bits - short channels; } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + +// Music type (file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +typedef struct MusicData *Music; + +// Audio stream type +// NOTE: Useful to create custom audio streams not bound to a specific file +typedef struct AudioStream { + unsigned int sampleRate; // Frequency (samples per second) + unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int channels; // Number of channels (1-mono, 2-stereo) + + int format; // OpenAL audio format specifier + unsigned int source; // OpenAL audio source id + unsigned int buffers[2]; // OpenAL audio buffers (double buffering) +} AudioStream; + // Texture formats // NOTE: Support depends on OpenGL version and platform typedef enum { @@ -501,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -520,20 +580,14 @@ typedef enum { GESTURE_PINCH_OUT = 512 } Gestures; -// Touch action (fingers or mouse) -typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction; - -// Gesture events -// NOTE: MAX_TOUCH_POINTS fixed to 2 -typedef struct GestureEvent { - int touchAction; - int pointCount; - int pointerId[MAX_TOUCH_POINTS]; - Vector2 position[MAX_TOUCH_POINTS]; -} GestureEvent; - // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -561,352 +615,362 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif -void CloseWindow(void); // Close Window and Terminate Context -bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) -int GetScreenWidth(void); // Get current screen width -int GetScreenHeight(void); // Get current screen height +RLAPI void CloseWindow(void); // Close Window and Terminate Context +RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI int GetScreenWidth(void); // Get current screen width +RLAPI int GetScreenHeight(void); // Get current screen height -void ShowCursor(void); // Shows cursor -void HideCursor(void); // Hides cursor -bool IsCursorHidden(void); // Returns true if cursor is not visible -void EnableCursor(void); // Enables cursor -void DisableCursor(void); // Disables cursor +#if !defined(PLATFORM_ANDROID) +RLAPI void ShowCursor(void); // Shows cursor +RLAPI void HideCursor(void); // Hides cursor +RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor +RLAPI void DisableCursor(void); // Disables cursor +#endif -void ClearBackground(Color color); // Sets Background Color -void BeginDrawing(void); // Setup drawing canvas to start drawing -void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Sets Background Color +RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) -void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -void End2dMode(void); // Ends 2D mode custom camera usage -void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) -void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode -void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing -void EndTextureMode(void); // Ends drawing to render texture +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera +RLAPI void End2dMode(void); // Ends 2D mode custom camera usage +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode +RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing +RLAPI void EndTextureMode(void); // Ends drawing to render texture -Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position -Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) +RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) -void SetTargetFPS(int fps); // Set target FPS (maximum) -float GetFPS(void); // Returns current FPS -float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) +RLAPI float GetFPS(void); // Returns current FPS +RLAPI float GetFrameTime(void); // Returns time in seconds for one frame -Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value -int GetHexValue(Color color); // Returns hexadecimal value for a Color -float *ColorToFloat(Color color); // Converts Color to float array and normalizes -float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color +RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes +RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array +RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) -Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f +RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) +RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -void SetConfigFlags(char flags); // Setup some window configuration flags -void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -bool IsFileDropped(void); // Check if a file have been dropped into window -char **GetDroppedFiles(int *count); // Retrieve dropped files into window -void ClearDroppedFiles(void); // Clear dropped files paths buffer +RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) +RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -bool IsKeyPressed(int key); // Detect if a key has been pressed once -bool IsKeyDown(int key); // Detect if a key is being pressed -bool IsKeyReleased(int key); // Detect if a key has been released once -bool IsKeyUp(int key); // Detect if a key is NOT being pressed -int GetKeyPressed(void); // Get latest key pressed -void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once +RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed +RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once +RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed +RLAPI int GetKeyPressed(void); // Get latest key pressed +RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) -bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once -bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed -bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once -bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id +RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once +RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed +RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once +RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis -bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once -bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once -bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed -int GetMouseX(void); // Returns mouse position X -int GetMouseY(void); // Returns mouse position Y -Vector2 GetMousePosition(void); // Returns mouse position XY -void SetMousePosition(Vector2 position); // Set mouse position XY -int GetMouseWheelMove(void); // Returns mouse wheel movement Y +RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once +RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed +RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once +RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed +RLAPI int GetMouseX(void); // Returns mouse position X +RLAPI int GetMouseY(void); // Returns mouse position Y +RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY +RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y -int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) -int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) -Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) - -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif +RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) +RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) +RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ -void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags -bool IsGestureDetected(int gesture); // Check if a gesture have been detected -void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures -void UpdateGestures(void); // Update gestures detected (called automatically in PollInputEvents()) - -int GetTouchPointsCount(void); // Get touch points count -int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds -Vector2 GetGestureDragVector(void); // Get gesture drag vector -float GetGestureDragAngle(void); // Get gesture drag angle -Vector2 GetGesturePinchVector(void); // Get gesture pinch delta -float GetGesturePinchAngle(void); // Get gesture pinch angle +RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags +RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected +RLAPI int GetGestureDetected(void); // Get latest detected gesture +RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector +RLAPI float GetGestureDragAngle(void); // Get gesture drag angle +RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta +RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode -void SetCameraPosition(Vector3 position); // Set internal camera position -void SetCameraTarget(Vector3 target); // Set internal camera target -void SetCameraFovy(float fovy); // Set internal camera field-of-view-y - -void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) -void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) -void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - -void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) +RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) +RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) +RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) +RLAPI void SetCameraMoveControls(int frontKey, int backKey, + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ -void DrawPixel(int posX, int posY, Color color); // Draw a pixel -void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) -void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line -void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) -void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle -void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) -void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline -void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle -void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle -void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle -void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline -void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) -void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points -void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines +RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel +RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version) +RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line +RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) +RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle +RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle +RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline +RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle +RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) +RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline +RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle +RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline +RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) +RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points +RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines -bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles -bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle -Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision -bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle -bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle -bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle +RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ -Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) -Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) -Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file -Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) -Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory -Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory -Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D LoadTextureFromImage(Image image); // Load a texture from image data -RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering -void UnloadImage(Image image); // Unload image from CPU memory (RAM) -void UnloadTexture(Texture2D texture); // Unload texture from GPU memory -void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory -Color *GetImageData(Image image); // Get pixel data from image as a Color struct array -Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image -void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) -void ImageFormat(Image *image, int newFormat); // Convert image data to desired format -void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) -Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) -void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image -void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) -void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) -void ImageFlipVertical(Image *image); // Flip image vertically -void ImageFlipHorizontal(Image *image); // Flip image horizontally -void ImageColorTint(Image *image, Color color); // Modify image color: tint -void ImageColorInvert(Image *image); // Modify image color: invert -void ImageColorGrayscale(Image *image); // Modify image color: grayscale -void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) -void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI Image LoadImage(const char *fileName); // Load an image into CPU memory (RAM) +RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image data from Color array data (RGBA - 32bit) +RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image data from RAW file +RLAPI Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) +RLAPI Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory +RLAPI Texture2D LoadTextureEx(void *data, int width, int height, int textureFormat); // Load a texture from raw data into GPU memory +RLAPI Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) +RLAPI Texture2D LoadTextureFromImage(Image image); // Load a texture from image data +RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load a texture to be used for rendering +RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM) +RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory +RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory +RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) +RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image +RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) +RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) +RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image +RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) +RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination) +RLAPI void ImageFlipVertical(Image *image); // Flip image vertically +RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally +RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint +RLAPI void ImageColorInvert(Image *image); // Modify image color: invert +RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale +RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) +RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode -void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D -void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 +RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters +RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ -SpriteFont GetDefaultFont(void); // Get the default SpriteFont -SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory -void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory +RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont +RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters +RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory -void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters - int fontSize, int spacing, Color tint); -int MeasureText(const char *text, int fontSize); // Measure string width for default font -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters + float fontSize, int spacing, Color tint); +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner -const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' -const char *SubText(const char *text, int position, int length); // Get a piece of a text string +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' +RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube -void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) -void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float lenght, Color color); // Draw cube textured -void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere -void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters -void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires -void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone -void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires -void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ -void DrawRay(Ray ray, Color color); // Draw a ray line -void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) -void DrawGizmo(Vector3 position); // Draw simple gizmo -void DrawLight(Light light); // Draw light in 3D world -void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space -//DrawTorus(), DrawTeapot() are useless... +RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space +RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube +RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) +RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires +RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured +RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere +RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters +RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires +RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone +RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires +RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ +RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line +RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) +RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo +RLAPI void DrawLight(Light light); // Draw light in 3D world +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) -Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) -Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) -Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model -Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) -void UnloadModel(Model model); // Unload 3d model from memory +RLAPI Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) +RLAPI Model LoadModelEx(Mesh data, bool dynamic); // Load a 3d model (from mesh data) +RLAPI Model LoadModelFromRES(const char *rresName, int resId); // Load a 3d model from rRES file (raylib Resource) +RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a heightmap image as a 3d model +RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) +RLAPI void UnloadModel(Model model); // Unload 3d model from memory -Material LoadMaterial(const char *fileName); // Load material data (from file) -Material LoadDefaultMaterial(void); // Load default material (uses default models shader) -Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) -void UnloadMaterial(Material material); // Unload material textures from VRAM +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) +RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) +RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) +RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM -void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) -void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters -void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) -void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters -void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) +RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) +RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) +RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters +RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec + +RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits +RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres +RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes +RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere +RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere +RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection +RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits -bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres -bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes -bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere -bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere -bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection -bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations -void UnloadShader(Shader shader); // Unload a custom shader from memory +RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations +RLAPI void UnloadShader(Shader shader); // Unload a custom shader from memory -Shader GetDefaultShader(void); // Get default shader -Shader GetStandardShader(void); // Get standard shader -Texture2D GetDefaultTexture(void); // Get default texture +RLAPI Shader GetDefaultShader(void); // Get default shader +RLAPI Shader GetStandardShader(void); // Get standard shader +RLAPI Texture2D GetDefaultTexture(void); // Get default texture -int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location -void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) -void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) -void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location +RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) +RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) +RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) -void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) -void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) +RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) +RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -void BeginShaderMode(Shader shader); // Begin custom shader drawing -void EndShaderMode(void); // End custom shader drawing (use default shader) -void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) -void EndBlendMode(void); // End blending mode (reset to default: alpha blending) +RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing +RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) +RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) +RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) -Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool -void DestroyLight(Light light); // Destroy a light and take it out of the list +RLAPI Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool +RLAPI void DestroyLight(Light light); // Destroy a light and take it out of the list //------------------------------------------------------------------------------------ // VR experience Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 //------------------------------------------------------------------------------------ -void InitVrDevice(int vdDevice); // Init VR device -void CloseVrDevice(void); // Close VR device -void UpdateVrTracking(void); // Update VR tracking (position and orientation) -void BeginVrDrawing(void); // Begin VR drawing configuration -void EndVrDrawing(void); // End VR drawing process (and desktop mirror) -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) +RLAPI void InitVrDevice(int vdDevice); // Init VR device +RLAPI void CloseVrDevice(void); // Close VR device +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera +RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ -void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) -bool IsAudioDeviceReady(void); // True if call to InitAudioDevice() was successful and CloseAudioDevice() has not been called yet +RLAPI void InitAudioDevice(void); // Initialize audio device and context +RLAPI void CloseAudioDevice(void); // Close the audio device and context +RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory -Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data -Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) -void UnloadSound(Sound sound); // Unload sound -void PlaySound(Sound sound); // Play a sound -void PauseSound(Sound sound); // Pause a sound -void StopSound(Sound sound); // Stop playing a sound -bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing -void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) -void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory +RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data +RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data +RLAPI void UnloadSound(Sound sound); // Unload sound +RLAPI void PlaySound(Sound sound); // Play a sound +RLAPI void PauseSound(Sound sound); // Pause a sound +RLAPI void ResumeSound(Sound sound); // Resume a paused sound +RLAPI void StopSound(Sound sound); // Stop playing a sound +RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing +RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) +RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file +RLAPI void UnloadMusicStream(Music music); // Unload music stream +RLAPI void PlayMusicStream(Music music); // Start music playing +RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming +RLAPI void StopMusicStream(Music music); // Stop music playing +RLAPI void PauseMusicStream(Music music); // Pause music playing +RLAPI void ResumeMusicStream(Music music); // Resume playing paused music +RLAPI bool IsMusicPlaying(Music music); // Check if music is playing +RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) +RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) +RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) +RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -int PlayMusicStream(int index, char *fileName); // Start music playing (open stream) -void UpdateMusicStream(int index); // Updates buffers for music streaming -void StopMusicStream(int index); // Stop music playing (close stream) -void PauseMusicStream(int index); // Pause music playing -void ResumeMusicStream(int index); // Resume playing paused music -bool IsMusicPlaying(int index); // Check if music is playing -void SetMusicVolume(int index, float volume); // Set volume for music (1.0 is max level) -void SetMusicPitch(int index, float pitch); // Set pitch for a music (1.0 is base level) -float GetMusicTimeLength(int index); // Get current music time length (in seconds) -float GetMusicTimePlayed(int index); // Get current music time played (in seconds) -int GetMusicStreamCount(void); // Get number of streams loaded +RLAPI AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) +RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data +RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory +RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill +RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream +RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream +RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream +RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream #ifdef __cplusplus } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index c094ad967..000000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -cmake_minimum_required (VERSION 3.0) -project (raylib) -SET(PLATFORM_TO_USE "PLATFORM_DESKTOP" CACHE STRING "Platform to compile for") -SET_PROPERTY(CACHE PLATFORM_TO_USE PROPERTY STRINGS PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB) - -set(CMAKE_C_FLAGS "-O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces") - -IF(${PLATFORM_TO_USE} MATCHES "PLATFORM_DESKTOP") - - add_definitions(-DPLATFORM_DESKTOP, -DGRAPHICS_API_OPENGL_33) - include_directories("." "external/" "external/openal_soft/include" "external/glfw3/include") - -ENDIF() - -IF(${PLATFORM_TO_USE} MATCHES "PLATFORM_RPI") - - add_definitions(-DPLATFORM_RPI, -GRAPHICS_API_OPENGL_ES2) - include_directories("." "external/" "/opt/vc/include" "/opt/vc/include/interface/vmcs_host/linux" "/opt/vc/include/interface/vcos/pthreads") - -ENDIF() - -IF(${PLATFORM_TO_USE} MATCHES "PLATFORM_WEB") - - add_definitions(-DPLATFORM_WEB, -GRAPHICS_API_OPENGL_ES2) - include_directories("." "external/" "external/openal_soft/include" "external/glfw3/include") - -ENDIF() - - -file(GLOB SOURCES "*.c" "external/*.c") -add_library(raylib STATIC ${SOURCES}) -install(TARGETS raylib DESTINATION ../lib/) \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index ee3f0c12a..2e2631897 100644 --- a/src/Makefile +++ b/src/Makefile @@ -38,6 +38,14 @@ PLATFORM ?= PLATFORM_DESKTOP # define YES if you want shared/dynamic version of library instead of static (default) SHARED ?= NO +# define NO to use OpenAL Soft as static library (or shared by default) +SHARED_OPENAL ?= YES + +# on PLATFORM_WEB force OpenAL Soft shared library +ifeq ($(PLATFORM),PLATFORM_WEB) + SHARED_OPENAL ?= YES +endif + # determine if the file has root access (only for installing raylib) # "whoami" prints the name of the user that calls him (so, if it is the root # user, "whoami" prints "root"). @@ -99,11 +107,20 @@ CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces ifeq ($(SHARED),YES) CFLAGS += -fPIC SHAREDFLAG = BUILDING_DLL - SHAREDLIBS = -Lexternal/glfw3/lib/win32 -Lexternal/openal_soft/lib/win32 -lglfw3 -lopenal32 -lgdi32 + SHAREDLIBS = -Lexternal/glfw3/lib/win32 -Lexternal/openal_soft/lib/win32 -lglfw3 -lgdi32 else SHAREDFLAG = BUILDING_STATIC endif +# if static OpenAL Soft required, define the corresponding flags +ifeq ($(SHARED_OPENAL),NO) + SHAREDLIBS += -lopenal32 -lwinmm + SHAREDOPENALFLAG = AL_LIBTYPE_STATIC +else + SHAREDLIBS += -lopenal32dll + SHAREDOPENALFLAG = SHARED_OPENAL +endif + #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes # define any directories containing required header files @@ -165,12 +182,17 @@ else endif ifeq ($(PLATFORM_OS),WINDOWS) $(CC) -shared -o $(OUTPUT_PATH)/raylib.dll $(OBJS) $(SHAREDLIBS) -Wl,--out-implib,$(OUTPUT_PATH)/libraylibdll.a - @echo "raylib dynamic library (raylib.dll) and MSVC required import library (libraylibdll.a) generated!" + @echo "raylib dynamic library (raylib.dll) and import library (libraylibdll.a) generated!" endif else # compile raylib static library for desktop platforms. ar rcs $(OUTPUT_PATH)/libraylib.a $(OBJS) @echo "libraylib.a generated (static library)!" + ifeq ($(SHARED_OPENAL),NO) + @echo "expected OpenAL Soft static library linking" + else + @echo "expected OpenAL Soft shared library linking" + endif endif endif @@ -202,7 +224,7 @@ models.o : models.c raylib.h rlgl.h raymath.h # compile audio module audio.o : audio.c raylib.h - $(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG) + $(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG) -D$(SHAREDOPENALFLAG) # compile stb_vorbis library external/stb_vorbis.o: external/stb_vorbis.c external/stb_vorbis.h diff --git a/src/audio.c b/src/audio.c index 3684e10a1..49aca4b01 100644 --- a/src/audio.c +++ b/src/audio.c @@ -2,18 +2,22 @@ * * raylib.audio * -* Basic functions to manage Audio: +* This module provides basic functionality to work with audio: * Manage audio device (init/close) -* Load and Unload audio files +* Load and Unload audio files (WAV, OGG, FLAC, XM, MOD) * Play/Stop/Pause/Resume loaded audio * Manage mixing channels * Manage raw audio context * -* Uses external lib: -* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html) -* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/) -* jar_xm - XM module file loading -* jar_mod - MOD audio file loading +* External libs: +* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html) +* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/) +* jar_xm - XM module file loading +* jar_mod - MOD audio file loading +* dr_flac - FLAC audio file loading +* +* Module Configuration Flags: +* AUDIO_STANDALONE - Use this module as standalone library (independently of raylib) * * Many thanks to Joshua Reisenauer (github: @kd7tck) for the following additions: * XM audio module support (jar_xm) @@ -21,6 +25,7 @@ * Mixing channels support * Raw audio context support * +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -44,8 +49,11 @@ #if defined(AUDIO_STANDALONE) #include "audio.h" + #include // Required for: va_list, va_start(), vfprintf(), va_end() #else #include "raylib.h" + #include "utils.h" // Required for: DecompressData() + // NOTE: Includes Android fopen() function map #endif #include "AL/al.h" // OpenAL basic header @@ -63,13 +71,6 @@ #define AL_FORMAT_STEREO_FLOAT32 0x10011 #endif -#if defined(AUDIO_STANDALONE) - #include // Required for: va_list, va_start(), vfprintf(), va_end() -#else - #include "utils.h" // Required for: DecompressData() - // NOTE: Includes Android fopen() function map -#endif - //#define STB_VORBIS_HEADER_ONLY #include "external/stb_vorbis.h" // OGG loading functions @@ -117,7 +118,7 @@ typedef struct MusicData { bool loop; // Repeat music after finish (loop) unsigned int totalSamples; // Total number of samples unsigned int samplesLeft; // Number of samples left to end -} MusicData, *Music; +} MusicData; #if defined(AUDIO_STANDALONE) typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType; diff --git a/src/audio.h b/src/audio.h index 923492ca5..2b3c59335 100644 --- a/src/audio.h +++ b/src/audio.h @@ -2,18 +2,19 @@ * * raylib.audio * -* Basic functions to manage Audio: +* This module provides basic functionality to work with audio: * Manage audio device (init/close) -* Load and Unload audio files +* Load and Unload audio files (WAV, OGG, FLAC, XM, MOD) * Play/Stop/Pause/Resume loaded audio * Manage mixing channels * Manage raw audio context * -* Uses external lib: -* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html) -* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/) -* jar_xm - XM module file loading -* jar_mod - MOD audio file loading +* External libs: +* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html) +* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/) +* jar_xm - XM module file loading +* jar_mod - MOD audio file loading +* dr_flac - FLAC audio file loading * * Many thanks to Joshua Reisenauer (github: @kd7tck) for the following additions: * XM audio module support (jar_xm) @@ -21,6 +22,7 @@ * Mixing channels support * Raw audio context support * +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -60,12 +62,6 @@ #endif #endif -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { unsigned int sampleCount; // Number of samples @@ -75,9 +71,16 @@ typedef struct Wave { void *data; // Buffer data pointer } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + // Music type (file streaming from memory) // NOTE: Anything longer than ~10 seconds should be streamed -typedef struct Music *Music; +typedef struct MusicData *Music; // Audio stream type // NOTE: Useful to create custom audio streams not bound to a specific file @@ -104,13 +107,16 @@ extern "C" { // Prevents name mangling of functions // Module Functions Declaration //---------------------------------------------------------------------------------- void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) +void CloseAudioDevice(void); // Close the audio device and context bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory +Wave LoadWave(const char *fileName); // Load wave data from file into RAM +Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +Sound LoadSound(const char *fileName); // Load sound to memory Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +void UnloadWave(Wave wave); // Unload wave data void UnloadSound(Sound sound); // Unload sound void PlaySound(Sound sound); // Play a sound void PauseSound(Sound sound); // Pause a sound @@ -119,12 +125,15 @@ void StopSound(Sound sound); // Stop playing bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) - -Music LoadMusicStream(char *fileName); // Load music stream from file +void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +Wave WaveCopy(Wave wave); // Copy a wave to a new wave +void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +Music LoadMusicStream(const char *fileName); // Load music stream from file void UnloadMusicStream(Music music); // Unload music stream -void PlayMusicStream(Music music); // Start music playing (open stream) +void PlayMusicStream(Music music); // Start music playing void UpdateMusicStream(Music music); // Updates buffers for music streaming -void StopMusicStream(Music music); // Stop music playing (close stream) +void StopMusicStream(Music music); // Stop music playing void PauseMusicStream(Music music); // Pause music playing void ResumeMusicStream(Music music); // Resume playing paused music bool IsMusicPlaying(Music music); // Check if music is playing @@ -133,9 +142,9 @@ void SetMusicPitch(Music music, float pitch); // Set pitch for float GetMusicTimeLength(Music music); // Get music time length (in seconds) float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -AudioStream InitAudioStream(unsigned int sampleRate, - unsigned int sampleSize, - unsigned int channels); // Init audio stream (to stream audio pcm data) +AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data void CloseAudioStream(AudioStream stream); // Close audio stream and free memory bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill diff --git a/src/core.c b/src/core.c index 8e15eb96e..241772ecf 100644 --- a/src/core.c +++ b/src/core.c @@ -4,24 +4,25 @@ * * Basic functions to manage windows, OpenGL context and input on multiple platforms * -* The following platforms are supported: -* PLATFORM_DESKTOP - Windows, Linux, Mac (OSX) -* PLATFORM_ANDROID - Only OpenGL ES 2.0 devices -* PLATFORM_RPI - Rapsberry Pi (tested on Raspbian) -* PLATFORM_WEB - Emscripten, HTML5 -* Oculus Rift CV1 (with desktop mirror) - View [rlgl] module to enable it +* The following platforms are supported: Windows, Linux, Mac (OSX), Android, Raspberry Pi, HTML5, Oculus Rift CV1 * -* On PLATFORM_DESKTOP, the external lib GLFW3 (www.glfw.com) is used to manage graphic -* device, OpenGL context and input on multiple operating systems (Windows, Linux, OSX). -* -* On PLATFORM_ANDROID, graphic device is managed by EGL and input system by Android activity. -* -* On PLATFORM_RPI, graphic device is managed by EGL and input system is coded in raw mode. +* External libs: +* GLFW3 - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX) +* raymath - 3D math functionality (Vector3, Matrix, Quaternion) +* camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person) +* gestures - Gestures system for touch-ready devices (or simulated from mouse inputs) * * Module Configuration Flags: +* PLATFORM_DESKTOP - Windows, Linux, Mac (OSX) +* PLATFORM_ANDROID - Android (only OpenGL ES 2.0 devices), graphic device is managed by EGL and input system by Android activity. +* PLATFORM_RPI - Rapsberry Pi (tested on Raspbian), graphic device is managed by EGL and input system is coded in raw mode. +* PLATFORM_WEB - HTML5 (using emscripten compiler) * * RL_LOAD_DEFAULT_FONT - Use external module functions to load default raylib font (module: text) * +* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for render mirror - View [rlgl] module to enable it +* +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -667,7 +668,7 @@ void Begin3dMode(Camera camera) { rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) - if (IsVrDeviceReady()) BeginVrDrawing(); + if (IsVrDeviceReady() || IsVrSimulator()) BeginVrDrawing(); rlMatrixMode(RL_PROJECTION); // Switch to projection matrix @@ -697,7 +698,7 @@ void End3dMode(void) { rlglDraw(); // Process internal buffers (update + draw) - if (IsVrDeviceReady()) EndVrDrawing(); + if (IsVrDeviceReady() || IsVrSimulator()) EndVrDrawing(); rlMatrixMode(RL_PROJECTION); // Switch to projection matrix rlPopMatrix(); // Restore previous matrix (PROJECTION) from matrix stack @@ -1174,12 +1175,14 @@ bool IsGamepadAvailable(int gamepad) bool IsGamepadName(int gamepad, const char *name) { bool result = false; + +#if !defined(PLATFORM_ANDROID) const char *gamepadName = NULL; - + if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad); - if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0); - +#endif + return result; } @@ -1975,7 +1978,11 @@ static void PollInputEvents(void) previousMouseWheelY = currentMouseWheelY; currentMouseWheelY = 0; - +#endif + +// NOTE: GLFW3 joystick functionality not available in web +// TODO: Support joysticks using emscripten API +#if defined(PLATFORM_DESKTOP) // Check if gamepads are ready // NOTE: We do it here in case of disconection for (int i = 0; i < MAX_GAMEPADS; i++) diff --git a/src/external/stb_image.h b/src/external/stb_image.h index ce87646df..5572a8807 100644 --- a/src/external/stb_image.h +++ b/src/external/stb_image.h @@ -390,7 +390,7 @@ publish, and distribute this file as you see fit. #define STBI_NO_HDR // RaySan: not required by raylib -#define STBI_NO_SIMD // RaySan: issues when compiling with GCC 4.7.2 +//#define STBI_NO_SIMD // RaySan: issues when compiling with GCC 4.7.2 #ifndef STBI_NO_STDIO #include @@ -398,7 +398,7 @@ publish, and distribute this file as you see fit. // NOTE: Added to work with raylib on Android #if defined(PLATFORM_ANDROID) - #include "utils.h" // Android fopen function map + #include "utils.h" // RaySan: Android fopen function map #endif #define STBI_VERSION 1 diff --git a/src/models.c b/src/models.c index b7e36b8a0..48f8b8131 100644 --- a/src/models.c +++ b/src/models.c @@ -4,6 +4,12 @@ * * Basic functions to draw 3d shapes and load/draw 3d models (.OBJ) * +* External libs: +* rlgl - raylib OpenGL abstraction layer +* +* Module Configuration Flags: +* ... +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -34,8 +40,7 @@ #include // Required for: strcmp() #include // Required for: sin(), cos() -#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2 -#include "raymath.h" // Matrix data type and Matrix functions +#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 //---------------------------------------------------------------------------------- // Defines and Macros @@ -76,11 +81,11 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) } // Draw a circle in 3D world space -void DrawCircle3D(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color) +void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color) { rlPushMatrix(); rlTranslatef(center.x, center.y, center.z); - rlRotatef(rotationAngle, rotation.x, rotation.y, rotation.z); + rlRotatef(rotationAngle, rotationAxis.x, rotationAxis.y, rotationAxis.z); rlBegin(RL_LINES); for (int i = 0; i < 360; i += 10) @@ -579,9 +584,9 @@ void DrawLight(Light light) { DrawSphereWires(light->position, 0.3f*light->intensity, 8, 8, (light->enabled ? light->diffuse : GRAY)); - DrawCircle3D(light->position, light->radius, 0.0f, (Vector3){ 0, 0, 0 }, (light->enabled ? light->diffuse : GRAY)); - DrawCircle3D(light->position, light->radius, 90.0f, (Vector3){ 1, 0, 0 }, (light->enabled ? light->diffuse : GRAY)); - DrawCircle3D(light->position, light->radius, 90.0f, (Vector3){ 0, 1, 0 }, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, light->radius, (Vector3){ 0, 0, 0 }, 0.0f, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, light->radius, (Vector3){ 1, 0, 0 }, 90.0f, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, light->radius, (Vector3){ 0, 1, 0 },90.0f, (light->enabled ? light->diffuse : GRAY)); } break; case LIGHT_DIRECTIONAL: { @@ -597,7 +602,7 @@ void DrawLight(Light light) Vector3 dir = VectorSubtract(light->target, light->position); VectorNormalize(&dir); - DrawCircle3D(light->position, 0.5f, 0.0f, dir, (light->enabled ? light->diffuse : GRAY)); + DrawCircle3D(light->position, 0.5f, dir, 0.0f, (light->enabled ? light->diffuse : GRAY)); //DrawCylinderWires(light->position, 0.0f, 0.3f*light->coneAngle/50, 0.6f, 5, (light->enabled ? light->diffuse : GRAY)); DrawCubeWires(light->target, 0.3f, 0.3f, 0.3f, (light->enabled ? light->diffuse : GRAY)); @@ -1812,6 +1817,7 @@ static Material LoadMTL(const char *fileName) char buffer[MAX_BUFFER_SIZE]; Vector3 color = { 1.0f, 1.0f, 1.0f }; char mapFileName[128]; + int result = 0; FILE *mtlFile; @@ -1896,13 +1902,13 @@ static Material LoadMTL(const char *fileName) { if (buffer[5] == 'd') // map_Kd string Diffuse color texture map. { - sscanf(buffer, "map_Kd %s", mapFileName); - if (mapFileName != NULL) material.texDiffuse = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Kd %s", mapFileName); + if (result != EOF) material.texDiffuse = LoadTexture(mapFileName); } else if (buffer[5] == 's') // map_Ks string Specular color texture map. { - sscanf(buffer, "map_Ks %s", mapFileName); - if (mapFileName != NULL) material.texSpecular = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Ks %s", mapFileName); + if (result != EOF) material.texSpecular = LoadTexture(mapFileName); } else if (buffer[5] == 'a') // map_Ka string Ambient color texture map. { @@ -1911,13 +1917,13 @@ static Material LoadMTL(const char *fileName) } break; case 'B': // map_Bump string Bump texture map. { - sscanf(buffer, "map_Bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'b': // map_bump string Bump texture map. { - sscanf(buffer, "map_bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "map_bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'd': // map_d string Opacity texture map. { @@ -1941,8 +1947,8 @@ static Material LoadMTL(const char *fileName) } break; case 'b': // bump string Bump texture map { - sscanf(buffer, "bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d { diff --git a/src/physac.h b/src/physac.h index dd4c41269..e807ffa6a 100644 --- a/src/physac.h +++ b/src/physac.h @@ -1,8 +1,11 @@ /********************************************************************************************** * -* physac 1.0 - 2D Physics library for raylib (https://github.com/raysan5/raylib) +* Physac - 2D Physics library for videogames * -* // TODO: Description... +* Description: Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop +* to simluate physics. A physics step contains the following phases: get collision information, apply dynamics, +* collision solving and position correction. It uses a very simple struct for physic bodies with a position vector +* to be used in any 3D rendering API. * * CONFIGURATION: * @@ -24,30 +27,21 @@ * internally in the library and input management and drawing functions must be provided by * the user (check library implementation for further details). * +* #define PHYSAC_DEBUG +* Traces log messages when creating and destroying physics bodies and detects errors in physics +* calculations and reference exceptions; it is useful for debug purposes +* * #define PHYSAC_MALLOC() * #define PHYSAC_FREE() * You can define your own malloc/free implementation replacing stdlib.h malloc()/free() functions. * Otherwise it will include stdlib.h and use the C standard library malloc()/free() function. -* -* LIMITATIONS: * -* - There is a limit of 256 physic objects. -* - Physics behaviour can be unexpected using bounciness or friction values out of 0.0f - 1.0f range. -* - The module is limited to 2D axis oriented physics. -* - Physics colliders must be rectangle or circle shapes (there is not a custom polygon collider type). -* -* VERSIONS: -* -* 1.0 (14-Jun-2016) New module defines and fixed some delta time calculation bugs. -* 0.9 (09-Jun-2016) Module names review and converted to header-only. -* 0.8 (23-Mar-2016) Complete module redesign, steps-based for better physics resolution. -* 0.3 (13-Feb-2016) Reviewed to add PhysicObjects pool. -* 0.2 (03-Jan-2016) Improved physics calculations. -* 0.1 (30-Dec-2015) Initial release. +* VERY THANKS TO: +* - Ramón Santamaria (@raysan5) * * LICENSE: zlib/libpng * -* Copyright (c) 2016 Victor Fisac (main developer) and Ramon Santamaria +* Copyright (c) 2016 Victor Fisac * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -66,18 +60,18 @@ * **********************************************************************************************/ -#ifndef PHYSAC_H +#if !defined(PHYSAC_H) #define PHYSAC_H -#if !defined(RAYGUI_STANDALONE) - #include "raylib.h" -#endif - #define PHYSAC_STATIC -#ifdef PHYSAC_STATIC +// #define PHYSAC_NO_THREADS +// #define PHYSAC_STANDALONE +// #define PHYSAC_DEBUG + +#if defined(PHYSAC_STATIC) #define PHYSACDEF static // Functions just visible to module including this file #else - #ifdef __cplusplus + #if defined(__cplusplus) #define PHYSACDEF extern "C" // Functions visible from other files (no name mangling of functions in C++) #else #define PHYSACDEF extern // Functions visible from other files @@ -87,87 +81,141 @@ //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -// ... +#define PHYSAC_MAX_BODIES 64 +#define PHYSAC_MAX_MANIFOLDS 4096 +#define PHYSAC_MAX_VERTICES 24 +#define PHYSAC_CIRCLE_VERTICES 24 + +#define PHYSAC_DESIRED_DELTATIME 1.0/60.0 +#define PHYSAC_MAX_TIMESTEP 0.02 +#define PHYSAC_COLLISION_ITERATIONS 100 +#define PHYSAC_PENETRATION_ALLOWANCE 0.05f +#define PHYSAC_PENETRATION_CORRECTION 0.4f + +#define PHYSAC_PI 3.14159265358979323846 +#define PHYSAC_DEG2RAD (PHYSAC_PI/180.0f) + +#define PHYSAC_MALLOC(size) malloc(size) +#define PHYSAC_FREE(ptr) free(ptr) //---------------------------------------------------------------------------------- // Types and Structures Definition // NOTE: Below types are required for PHYSAC_STANDALONE usage //---------------------------------------------------------------------------------- #if defined(PHYSAC_STANDALONE) - #ifndef __cplusplus - // Boolean type - #ifndef true - typedef enum { false, true } bool; - #endif - #endif - // Vector2 type typedef struct Vector2 { float x; float y; } Vector2; - // Rectangle type - typedef struct Rectangle { - int x; - int y; - int width; - int height; - } Rectangle; + // Boolean type + #if !defined(_STDBOOL_H) + typedef enum { false, true } bool; + #define _STDBOOL_H + #endif #endif -typedef enum { COLLIDER_CIRCLE, COLLIDER_RECTANGLE } ColliderType; +typedef enum PhysicsShapeType { PHYSICS_CIRCLE, PHYSICS_POLYGON } PhysicsShapeType; -typedef struct Transform { - Vector2 position; - float rotation; // Radians (not used) - Vector2 scale; // Just for rectangle physic objects, for circle physic objects use collider radius and keep scale as { 0, 0 } -} Transform; +// Previously defined to be used in PhysicsShape struct as circular dependencies +typedef struct PhysicsBodyData *PhysicsBody; -typedef struct Rigidbody { - bool enabled; // Acts as kinematic state (collisions are calculated anyway) - float mass; - Vector2 acceleration; - Vector2 velocity; - bool applyGravity; - bool isGrounded; - float friction; // Normalized value - float bounciness; -} Rigidbody; +// Mat2 type (used for polygon shape rotation matrix) +typedef struct Mat2 +{ + float m00; + float m01; + float m10; + float m11; +} Mat2; -typedef struct Collider { - bool enabled; - ColliderType type; - Rectangle bounds; // Used for COLLIDER_RECTANGLE - int radius; // Used for COLLIDER_CIRCLE -} Collider; +typedef struct PolygonData { + unsigned int vertexCount; // Current used vertex and normals count + Vector2 vertices[PHYSAC_MAX_VERTICES]; // Polygon vertex positions vectors + Vector2 normals[PHYSAC_MAX_VERTICES]; // Polygon vertex normals vectors + Mat2 transform; // Vertices transform matrix 2x2 +} PolygonData; -typedef struct PhysicBodyData { - unsigned int id; - Transform transform; - Rigidbody rigidbody; - Collider collider; - bool enabled; -} PhysicBodyData, *PhysicBody; +typedef struct PhysicsShape { + PhysicsShapeType type; // Physics shape type (circle or polygon) + PhysicsBody body; // Shape physics body reference + float radius; // Circle shape radius (used for circle shapes) + PolygonData vertexData; // Polygon shape vertices position and normals data (just used for polygon shapes) +} PhysicsShape; + +typedef struct PhysicsBodyData { + unsigned int id; // Reference unique identifier + bool enabled; // Enabled dynamics state (collisions are calculated anyway) + Vector2 position; // Physics body shape pivot + Vector2 velocity; // Current linear velocity applied to position + Vector2 force; // Current linear force (reset to 0 every step) + float angularVelocity; // Current angular velocity applied to orient + float torque; // Current angular force (reset to 0 every step) + float orient; // Rotation in radians + float inertia; // Moment of inertia + float inverseInertia; // Inverse value of inertia + float mass; // Physics body mass + float inverseMass; // Inverse value of mass + float staticFriction; // Friction when the body has not movement (0 to 1) + float dynamicFriction; // Friction when the body has movement (0 to 1) + float restitution; // Restitution coefficient of the body (0 to 1) + bool useGravity; // Apply gravity force to dynamics + bool isGrounded; // Physics grounded on other body state + bool freezeOrient; // Physics rotation constraint + PhysicsShape shape; // Physics body shape information (type, radius, vertices, normals) +} PhysicsBodyData; + +typedef struct PhysicsManifoldData { + unsigned int id; // Reference unique identifier + PhysicsBody bodyA; // Manifold first physics body reference + PhysicsBody bodyB; // Manifold second physics body reference + float penetration; // Depth of penetration from collision + Vector2 normal; // Normal direction vector from 'a' to 'b' + Vector2 contacts[2]; // Points of contact during collision + unsigned int contactsCount; // Current collision number of contacts + float restitution; // Mixed restitution during collision + float dynamicFriction; // Mixed dynamic friction during collision + float staticFriction; // Mixed static friction during collision +} PhysicsManifoldData, *PhysicsManifold; + +#if defined(__cplusplus) +extern "C" { // Prevents name mangling of functions +#endif + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +//... //---------------------------------------------------------------------------------- // Module Functions Declaration //---------------------------------------------------------------------------------- -PHYSACDEF void InitPhysics(Vector2 gravity); // Initializes pointers array (just pointers, fixed size) -PHYSACDEF void* PhysicsThread(void *arg); // Physics calculations thread function -PHYSACDEF void ClosePhysics(); // Unitialize all physic objects and empty the objects pool +PHYSACDEF void InitPhysics(void); // Initializes physics values, pointers and creates physics loop thread +PHYSACDEF bool IsPhysicsEnabled(void); // Returns true if physics thread is currently enabled +PHYSACDEF void SetPhysicsGravity(float x, float y); // Sets physics global gravity force +PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); // Creates a new circle physics body with generic parameters +PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density); // Creates a new rectangle physics body with generic parameters +PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density); // Creates a new polygon physics body with generic parameters +PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force); // Adds a force to a physics body +PHYSACDEF void PhysicsAddTorque(PhysicsBody body, float amount); // Adds an angular force to a physics body +PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force); // Shatters a polygon shape physics body to little physics bodies with explosion force +PHYSACDEF int GetPhysicsBodiesCount(void); // Returns the current amount of created physics bodies +PHYSACDEF PhysicsBody GetPhysicsBody(int index); // Returns a physics body of the bodies pool at a specific index +PHYSACDEF int GetPhysicsShapeType(int index); // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) +PHYSACDEF int GetPhysicsShapeVerticesCount(int index); // Returns the amount of vertices of a physics body shape +PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex); // Returns transformed position of a body shape (body position + vertex transformed position) +PHYSACDEF void SetPhysicsBodyRotation(PhysicsBody body, float radians); // Sets physics body shape transform based on radians parameter +PHYSACDEF void DestroyPhysicsBody(PhysicsBody body); // Unitializes and destroy a physics body +PHYSACDEF void ResetPhysics(void); // Destroys created physics bodies and manifolds and resets global values +PHYSACDEF void ClosePhysics(void); // Unitializes physics pointers and closes physics loop thread -PHYSACDEF PhysicBody CreatePhysicBody(Vector2 position, float rotation, Vector2 scale); // Create a new physic body dinamically, initialize it and add to pool -PHYSACDEF void DestroyPhysicBody(PhysicBody pbody); // Destroy a specific physic body and take it out of the list - -PHYSACDEF void ApplyForce(PhysicBody pbody, Vector2 force); // Apply directional force to a physic body -PHYSACDEF void ApplyForceAtPosition(Vector2 position, float force, float radius); // Apply radial force to all physic objects in range - -PHYSACDEF Rectangle TransformToRectangle(Transform transform); // Convert Transform data type to Rectangle (position and scale) +#if defined(__cplusplus) +} +#endif #endif // PHYSAC_H - /*********************************************************************************** * * PHYSAC IMPLEMENTATION @@ -176,657 +224,1854 @@ PHYSACDEF Rectangle TransformToRectangle(Transform transform); #if defined(PHYSAC_IMPLEMENTATION) -// Check if custom malloc/free functions defined, if not, using standard ones -#if !defined(PHYSAC_MALLOC) - #include // Required for: malloc(), free() - - #define PHYSAC_MALLOC(size) malloc(size) - #define PHYSAC_FREE(ptr) free(ptr) +#if !defined(PHYSAC_NO_THREADS) + #include // Required for: pthread_t, pthread_create() #endif -#include // Required for: cos(), sin(), abs(), fminf() -#include // Required for typedef unsigned long long int uint64_t, used by hi-res timer - -#ifndef PHYSAC_NO_THREADS - #include // Required for: pthread_create() +#if defined(PHYSAC_DEBUG) + #include // Required for: printf() #endif -#if defined(PLATFORM_DESKTOP) +#include // Required for: malloc(), free(), srand(), rand() +#include // Required for: cosf(), sinf(), fabs(), sqrtf() + +#if defined(_WIN32) // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); -#elif defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) - #include // Required for: timespec - #include // Required for: clock_gettime() +#elif defined(__linux) + #include // Required for: timespec + #include // Required for: clock_gettime() #endif //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -#define MAX_PHYSIC_BODIES 256 // Maximum available physic bodies slots in bodies pool -#define PHYSICS_TIMESTEP 0.016666 // Physics fixed time step (1/fps) -#define PHYSICS_ACCURACY 0.0001f // Velocity subtract operations round filter (friction) -#define PHYSICS_ERRORPERCENT 0.001f // Collision resolve position fix +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) +#define PHYSAC_FLT_MAX 3.402823466e+38f +#define PHYSAC_EPSILON 0.000001f //---------------------------------------------------------------------------------- // Types and Structures Definition -// NOTE: Below types are required for PHYSAC_STANDALONE usage //---------------------------------------------------------------------------------- // ... //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -static bool physicsThreadEnabled = false; // Physics calculations thread exit control -static uint64_t baseTime; // Base time measure for hi-res timer -static double currentTime, previousTime; // Used to track timmings -static PhysicBody physicBodies[MAX_PHYSIC_BODIES]; // Physic bodies pool -static int physicBodiesCount; // Counts current enabled physic bodies -static Vector2 gravityForce; // Gravity force +#if !defined(PHYSAC_NO_THREADS) + static pthread_t physicsThreadId; // Physics thread id +#endif +static unsigned int usedMemory = 0; // Total allocated dynamic memory +static bool physicsThreadEnabled = false; // Physics thread enabled state +static double currentTime = 0; // Current time in milliseconds +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) + static double baseTime = 0; // Android and RPI platforms base time +#endif +static double startTime = 0; // Start time in milliseconds +static double deltaTime = 0; // Delta time used for physics steps +static double accumulator = 0; // Physics time step delta time accumulator +static unsigned int stepsCount = 0; // Total physics steps processed +static Vector2 gravityForce = { 0, 9.81f/1000 }; // Physics world gravity force +static PhysicsBody bodies[PHYSAC_MAX_BODIES]; // Physics bodies pointers array +static unsigned int physicsBodiesCount = 0; // Physics world current bodies counter +static PhysicsManifold contacts[PHYSAC_MAX_MANIFOLDS]; // Physics bodies pointers array +static unsigned int physicsManifoldsCount = 0; // Physics world current manifolds counter //---------------------------------------------------------------------------------- -// Module specific Functions Declaration +// Module Internal Functions Declaration //---------------------------------------------------------------------------------- -static void UpdatePhysics(double deltaTime); // Update physic objects, calculating physic behaviours and collisions detection -static void InitTimer(void); // Initialize hi-resolution timer -static double GetCurrentTime(void); // Time measure returned are microseconds -static float Vector2DotProduct(Vector2 v1, Vector2 v2); // Returns the dot product of two Vector2 -static float Vector2Length(Vector2 v); // Returns the length of a Vector2 +static PolygonData CreateRandomPolygon(float radius, int sides); // Creates a random polygon shape with max vertex distance from polygon pivot +static PolygonData CreateRectanglePolygon(Vector2 pos, Vector2 size); // Creates a rectangle polygon shape based on a min and max positions +static void *PhysicsLoop(void *arg); // Physics loop thread function +static void PhysicsStep(void); // Physics steps calculations (dynamics, collisions and position corrections) +static PhysicsManifold CreatePhysicsManifold(PhysicsBody a, PhysicsBody b); // Creates a new physics manifold to solve collision +static void DestroyPhysicsManifold(PhysicsManifold manifold); // Unitializes and destroys a physics manifold +static void SolvePhysicsManifold(PhysicsManifold manifold); // Solves a created physics manifold between two physics bodies +static void SolveCircleToCircle(PhysicsManifold manifold); // Solves collision between two circle shape physics bodies +static void SolveCircleToPolygon(PhysicsManifold manifold); // Solves collision between a circle to a polygon shape physics bodies +static void SolvePolygonToCircle(PhysicsManifold manifold); // Solves collision between a polygon to a circle shape physics bodies +static void SolvePolygonToPolygon(PhysicsManifold manifold); // Solves collision between two polygons shape physics bodies +static void IntegratePhysicsForces(PhysicsBody body); // Integrates physics forces into velocity +static void InitializePhysicsManifolds(PhysicsManifold manifold); // Initializes physics manifolds to solve collisions +static void IntegratePhysicsImpulses(PhysicsManifold manifold); // Integrates physics collisions impulses to solve collisions +static void IntegratePhysicsVelocity(PhysicsBody body); // Integrates physics velocity into position and forces +static void CorrectPhysicsPositions(PhysicsManifold manifold); // Corrects physics bodies positions based on manifolds collision information +static float FindAxisLeastPenetration(int *faceIndex, PhysicsShape shapeA, PhysicsShape shapeB); // Finds polygon shapes axis least penetration +static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, PhysicsShape inc, int index); // Finds two polygon shapes incident face +static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB); // Calculates clipping based on a normal and two faces +static bool BiasGreaterThan(float valueA, float valueB); // Check if values are between bias range +static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3); // Returns the barycenter of a triangle given by 3 points +static void InitTimer(void); // Initializes hi-resolution timer +static double GetCurrentTime(void); // Get current time in milliseconds +static int GetRandomNumber(int min, int max); // Returns a random number between min and max (both included) + +static void MathClamp(double *value, double min, double max); // Clamp a value in a range +static Vector2 MathCross(float value, Vector2 vector); // Returns the cross product of a vector and a value +static float MathCrossVector2(Vector2 v1, Vector2 v2); // Returns the cross product of two vectors +static float MathLenSqr(Vector2 vector); // Returns the len square root of a vector +static float MathDot(Vector2 v1, Vector2 v2); // Returns the dot product of two vectors +static inline float DistSqr(Vector2 v1, Vector2 v2); // Returns the square root of distance between two vectors +static void MathNormalize(Vector2 *vector); // Returns the normalized values of a vector +static Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Returns the sum of two given vectors +static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Returns the subtract of two given vectors + +static Mat2 Mat2Radians(float radians); // Creates a matrix 2x2 from a given radians value +static void Mat2Set(Mat2 *matrix, float radians); // Set values from radians to a created matrix 2x2 +static Mat2 Mat2Transpose(Mat2 matrix); // Returns the transpose of a given matrix 2x2 +static Vector2 Mat2MultiplyVector2(Mat2 matrix, Vector2 vector); // Multiplies a vector by a matrix 2x2 //---------------------------------------------------------------------------------- // Module Functions Definition //---------------------------------------------------------------------------------- - -// Initializes pointers array (just pointers, fixed size) -PHYSACDEF void InitPhysics(Vector2 gravity) +// Initializes physics values, pointers and creates physics loop thread +PHYSACDEF void InitPhysics(void) { - // Initialize physics variables - physicBodiesCount = 0; - gravityForce = gravity; - - #ifndef PHYSAC_NO_THREADS // NOTE: if defined, user will need to create a thread for PhysicsThread function manually - // Create physics thread - pthread_t tid; - pthread_create(&tid, NULL, &PhysicsThread, NULL); + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] physics module initialized successfully\n"); + #endif + + #if !defined(PHYSAC_NO_THREADS) + // NOTE: if defined, user will need to create a thread for PhysicsThread function manually + // Create physics thread using POSIXS thread libraries + pthread_create(&physicsThreadId, NULL, &PhysicsLoop, NULL); #endif } -// Unitialize all physic objects and empty the objects pool -PHYSACDEF void ClosePhysics() +// Returns true if physics thread is currently enabled +PHYSACDEF bool IsPhysicsEnabled(void) { - // Exit physics thread loop + return physicsThreadEnabled; +} + +// Sets physics global gravity force +PHYSACDEF void SetPhysicsGravity(float x, float y) +{ + gravityForce.x = x; + gravityForce.y = y; +} + +// Creates a new circle physics body with generic parameters +PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density) +{ + PhysicsBody newBody = CreatePhysicsBodyPolygon(pos, radius, PHYSAC_CIRCLE_VERTICES, density); + return newBody; + + /*PhysicsBody newBody = (PhysicsBody)PHYSAC_MALLOC(sizeof(PhysicsBodyData)); + usedMemory += sizeof(PhysicsBodyData); + + int newId = -1; + for (int i = 0; i < PHYSAC_MAX_BODIES; i++) + { + int currentId = i; + + // Check if current id already exist in other physics body + for (int k = 0; k < physicsBodiesCount; k++) + { + if (bodies[k]->id == currentId) + { + currentId++; + break; + } + } + + // If it is not used, use it as new physics body id + if (currentId == i) + { + newId = i; + break; + } + } + + if (newId != -1) + { + // Initialize new body with generic values + newBody->id = newId; + newBody->enabled = true; + newBody->position = pos; + newBody->velocity = (Vector2){ 0 }; + newBody->force = (Vector2){ 0 }; + newBody->angularVelocity = 0; + newBody->torque = 0; + newBody->orient = 0; + newBody->mass = PHYSAC_PI*radius*radius*density; + newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f); + newBody->inertia = newBody->mass*radius*radius; + newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f); + newBody->staticFriction = 0; + newBody->dynamicFriction = 0; + newBody->restitution = 0; + newBody->useGravity = true; + newBody->freezeOrient = false; + newBody->shape.type = PHYSICS_CIRCLE; + newBody->shape.body = newBody; + newBody->shape.radius = radius; + + // Add new body to bodies pointers array and update bodies count + bodies[physicsBodiesCount] = newBody; + physicsBodiesCount++; + + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] created circle physics body id %i\n", newBody->id); + #endif + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] new physics body creation failed because there is any available id to use\n"); + #endif + + return newBody;*/ +} + +// Creates a new rectangle physics body with generic parameters +PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density) +{ + PhysicsBody newBody = (PhysicsBody)PHYSAC_MALLOC(sizeof(PhysicsBodyData)); + usedMemory += sizeof(PhysicsBodyData); + + int newId = -1; + for (int i = 0; i < PHYSAC_MAX_BODIES; i++) + { + int currentId = i; + + // Check if current id already exist in other physics body + for (int k = 0; k < physicsBodiesCount; k++) + { + if (bodies[k]->id == currentId) + { + currentId++; + break; + } + } + + // If it is not used, use it as new physics body id + if (currentId == i) + { + newId = i; + break; + } + } + + if (newId != -1) + { + // Initialize new body with generic values + newBody->id = newId; + newBody->enabled = true; + newBody->position = pos; + newBody->velocity = (Vector2){ 0 }; + newBody->force = (Vector2){ 0 }; + newBody->angularVelocity = 0; + newBody->torque = 0; + newBody->orient = 0; + newBody->shape.type = PHYSICS_POLYGON; + newBody->shape.body = newBody; + newBody->shape.vertexData = CreateRectanglePolygon(pos, (Vector2){ width, height }); + + // Calculate centroid and moment of inertia + Vector2 center = { 0 }; + float area = 0; + float inertia = 0; + const float k = 1.0f/3.0f; + + for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++) + { + // Triangle vertices, third vertex implied as (0, 0) + Vector2 p1 = newBody->shape.vertexData.vertices[i]; + int nextIndex = (((i + 1) < newBody->shape.vertexData.vertexCount) ? (i + 1) : 0); + Vector2 p2 = newBody->shape.vertexData.vertices[nextIndex]; + + float D = MathCrossVector2(p1, p2); + float triangleArea = D/2; + + area += triangleArea; + + // Use area to weight the centroid average, not just vertex position + center.x += triangleArea*k*(p1.x + p2.x); + center.y += triangleArea*k*(p1.y + p2.y); + + float intx2 = p1.x*p1.x + p2.x*p1.x + p2.x*p2.x; + float inty2 = p1.y*p1.y + p2.y*p1.y + p2.y*p2.y; + inertia += (0.25f*k*D)*(intx2 + inty2); + } + + center.x *= 1.0f/area; + center.y *= 1.0f/area; + + // Translate vertices to centroid (make the centroid (0, 0) for the polygon in model space) + // Note: this is not really necessary + for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++) + { + newBody->shape.vertexData.vertices[i].x -= center.x; + newBody->shape.vertexData.vertices[i].y -= center.y; + } + + newBody->mass = density*area; + newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f); + newBody->inertia = density*inertia; + newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f); + newBody->staticFriction = 0.4f; + newBody->dynamicFriction = 0.2f; + newBody->restitution = 0; + newBody->useGravity = true; + newBody->isGrounded = false; + newBody->freezeOrient = false; + + // Add new body to bodies pointers array and update bodies count + bodies[physicsBodiesCount] = newBody; + physicsBodiesCount++; + + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] created polygon physics body id %i\n", newBody->id); + #endif + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] new physics body creation failed because there is any available id to use\n"); + #endif + + return newBody; +} + +// Creates a new polygon physics body with generic parameters +PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density) +{ + PhysicsBody newBody = (PhysicsBody)PHYSAC_MALLOC(sizeof(PhysicsBodyData)); + usedMemory += sizeof(PhysicsBodyData); + + int newId = -1; + for (int i = 0; i < PHYSAC_MAX_BODIES; i++) + { + int currentId = i; + + // Check if current id already exist in other physics body + for (int k = 0; k < physicsBodiesCount; k++) + { + if (bodies[k]->id == currentId) + { + currentId++; + break; + } + } + + // If it is not used, use it as new physics body id + if (currentId == i) + { + newId = i; + break; + } + } + + if (newId != -1) + { + // Initialize new body with generic values + newBody->id = newId; + newBody->enabled = true; + newBody->position = pos; + newBody->velocity = (Vector2){ 0 }; + newBody->force = (Vector2){ 0 }; + newBody->angularVelocity = 0; + newBody->torque = 0; + newBody->orient = 0; + newBody->shape.type = PHYSICS_POLYGON; + newBody->shape.body = newBody; + newBody->shape.vertexData = CreateRandomPolygon(radius, sides); + + // Calculate centroid and moment of inertia + Vector2 center = { 0 }; + float area = 0; + float inertia = 0; + const float alpha = 1.0f/3.0f; + + for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++) + { + // Triangle vertices, third vertex implied as (0, 0) + Vector2 position1 = newBody->shape.vertexData.vertices[i]; + int nextIndex = (((i + 1) < newBody->shape.vertexData.vertexCount) ? (i + 1) : 0); + Vector2 position2 = newBody->shape.vertexData.vertices[nextIndex]; + + float cross = MathCrossVector2(position1, position2); + float triangleArea = cross/2; + + area += triangleArea; + + // Use area to weight the centroid average, not just vertex position + center.x += triangleArea*alpha*(position1.x + position2.x); + center.y += triangleArea*alpha*(position1.y + position2.y); + + float intx2 = position1.x*position1.x + position2.x*position1.x + position2.x*position2.x; + float inty2 = position1.y*position1.y + position2.y*position1.y + position2.y*position2.y; + inertia += (0.25f*alpha*cross)*(intx2 + inty2); + } + + center.x *= 1.0f/area; + center.y *= 1.0f/area; + + // Translate vertices to centroid (make the centroid (0, 0) for the polygon in model space) + // Note: this is not really necessary + for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++) + { + newBody->shape.vertexData.vertices[i].x -= center.x; + newBody->shape.vertexData.vertices[i].y -= center.y; + } + + newBody->mass = density*area; + newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f); + newBody->inertia = density*inertia; + newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f); + newBody->staticFriction = 0.4f; + newBody->dynamicFriction = 0.2f; + newBody->restitution = 0; + newBody->useGravity = true; + newBody->isGrounded = false; + newBody->freezeOrient = false; + + // Add new body to bodies pointers array and update bodies count + bodies[physicsBodiesCount] = newBody; + physicsBodiesCount++; + + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] created polygon physics body id %i\n", newBody->id); + #endif + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] new physics body creation failed because there is any available id to use\n"); + #endif + + return newBody; +} + +// Adds a force to a physics body +PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force) +{ + if (body != NULL) body->force = Vector2Add(body->force, force); +} + +// Adds an angular force to a physics body +PHYSACDEF void PhysicsAddTorque(PhysicsBody body, float amount) +{ + if (body != NULL) body->torque += amount; +} + +// Shatters a polygon shape physics body to little physics bodies with explosion force +PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force) +{ + if (body != NULL) + { + if (body->shape.type == PHYSICS_POLYGON) + { + PolygonData vertexData = body->shape.vertexData; + bool collision = false; + + for (int i = 0; i < vertexData.vertexCount; i++) + { + Vector2 positionA = body->position; + Vector2 positionB = Mat2MultiplyVector2(vertexData.transform, Vector2Add(body->position, vertexData.vertices[i])); + int nextIndex = (((i + 1) < vertexData.vertexCount) ? (i + 1) : 0); + Vector2 positionC = Mat2MultiplyVector2(vertexData.transform, Vector2Add(body->position, vertexData.vertices[nextIndex])); + + // Check collision between each triangle + float alpha = ((positionB.y - positionC.y)*(position.x - positionC.x) + (positionC.x - positionB.x)*(position.y - positionC.y))/ + ((positionB.y - positionC.y)*(positionA.x - positionC.x) + (positionC.x - positionB.x)*(positionA.y - positionC.y)); + + float beta = ((positionC.y - positionA.y)*(position.x - positionC.x) + (positionA.x - positionC.x)*(position.y - positionC.y))/ + ((positionB.y - positionC.y)*(positionA.x - positionC.x) + (positionC.x - positionB.x)*(positionA.y - positionC.y)); + + float gamma = 1.0f - alpha - beta; + + if ((alpha > 0) && (beta > 0) & (gamma > 0)) + { + collision = true; + break; + } + } + + if (collision) + { + int count = vertexData.vertexCount; + Vector2 bodyPos = body->position; + Vector2 vertices[count]; + Mat2 trans = vertexData.transform; + for (int i = 0; i < count; i++) vertices[i] = vertexData.vertices[i]; + + // Destroy shattered physics body + DestroyPhysicsBody(body); + + for (int i = 0; i < count; i++) + { + int nextIndex = (((i + 1) < count) ? (i + 1) : 0); + Vector2 center = TriangleBarycenter(vertices[i], vertices[nextIndex], (Vector2){ 0, 0 }); + center = Vector2Add(bodyPos, center); + Vector2 offset = Vector2Subtract(center, bodyPos); + + PhysicsBody newBody = CreatePhysicsBodyPolygon(center, 10, 3, 10); // Create polygon physics body with relevant values + + PolygonData newData = { 0 }; + newData.vertexCount = 3; + newData.transform = trans; + + newData.vertices[0] = Vector2Subtract(vertices[i], offset); + newData.vertices[1] = Vector2Subtract(vertices[nextIndex], offset); + newData.vertices[2] = Vector2Subtract(position, center); + + // Separate vertices to avoid unnecessary physics collisions + newData.vertices[0].x *= 0.95f; + newData.vertices[0].y *= 0.95f; + newData.vertices[1].x *= 0.95f; + newData.vertices[1].y *= 0.95f; + newData.vertices[2].x *= 0.95f; + newData.vertices[2].y *= 0.95f; + + // Calculate polygon faces normals + for (int j = 0; j < newData.vertexCount; j++) + { + int nextVertex = (((j + 1) < newData.vertexCount) ? (j + 1) : 0); + Vector2 face = Vector2Subtract(newData.vertices[nextVertex], newData.vertices[j]); + + newData.normals[j] = (Vector2){ face.y, -face.x }; + MathNormalize(&newData.normals[j]); + } + + // Apply computed vertex data to new physics body shape + newBody->shape.vertexData = newData; + + // Calculate centroid and moment of inertia + center = (Vector2){ 0 }; + float area = 0; + float inertia = 0; + const float k = 1.0f/3.0f; + + for (int j = 0; j < newBody->shape.vertexData.vertexCount; j++) + { + // Triangle vertices, third vertex implied as (0, 0) + Vector2 p1 = newBody->shape.vertexData.vertices[j]; + int nextVertex = (((j + 1) < newBody->shape.vertexData.vertexCount) ? (j + 1) : 0); + Vector2 p2 = newBody->shape.vertexData.vertices[nextVertex]; + + float D = MathCrossVector2(p1, p2); + float triangleArea = D/2; + + area += triangleArea; + + // Use area to weight the centroid average, not just vertex position + center.x += triangleArea*k*(p1.x + p2.x); + center.y += triangleArea*k*(p1.y + p2.y); + + float intx2 = p1.x*p1.x + p2.x*p1.x + p2.x*p2.x; + float inty2 = p1.y*p1.y + p2.y*p1.y + p2.y*p2.y; + inertia += (0.25f*k*D)*(intx2 + inty2); + } + + center.x *= 1.0f/area; + center.y *= 1.0f/area; + + newBody->mass = area; + newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f); + newBody->inertia = inertia; + newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f); + + // Calculate explosion force direction + Vector2 pointA = newBody->position; + Vector2 pointB = Vector2Subtract(newData.vertices[1], newData.vertices[0]); + pointB.x /= 2; + pointB.y /= 2; + Vector2 forceDirection = Vector2Subtract(Vector2Add(pointA, Vector2Add(newData.vertices[0], pointB)), newBody->position); + MathNormalize(&forceDirection); + forceDirection.x *= force; + forceDirection.y *= force; + + // Apply force to new physics body + PhysicsAddForce(newBody, forceDirection); + } + } + } + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] error when trying to shatter a null reference physics body"); + #endif +} + +// Returns the current amount of created physics bodies +PHYSACDEF int GetPhysicsBodiesCount(void) +{ + return physicsBodiesCount; +} + +// Returns a physics body of the bodies pool at a specific index +PHYSACDEF PhysicsBody GetPhysicsBody(int index) +{ + if (index < physicsBodiesCount) + { + PhysicsBody body = bodies[index]; + if (body != NULL) return body; + else + { + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] error when trying to get a null reference physics body"); + #endif + + return NULL; + } + } + #if defined(PHYSAC_DEBUG) + else + { + printf("[PHYSAC] physics body index is out of bounds"); + return NULL; + } + #endif +} + +// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) +PHYSACDEF int GetPhysicsShapeType(int index) +{ + if (index < physicsBodiesCount) + { + PhysicsBody body = bodies[index]; + if (body != NULL) return body->shape.type; + #if defined(PHYSAC_DEBUG) + else + { + printf("[PHYSAC] error when trying to get a null reference physics body"); + return -1; + } + #endif + } + #if defined(PHYSAC_DEBUG) + else + { + printf("[PHYSAC] physics body index is out of bounds"); + return -1; + } + #endif +} + +// Returns the amount of vertices of a physics body shape +PHYSACDEF int GetPhysicsShapeVerticesCount(int index) +{ + if (index < physicsBodiesCount) + { + PhysicsBody body = bodies[index]; + if (body != NULL) + { + switch (body->shape.type) + { + case PHYSICS_CIRCLE: return PHYSAC_CIRCLE_VERTICES; break; + case PHYSICS_POLYGON: return body->shape.vertexData.vertexCount; break; + default: break; + } + } + #if defined(PHYSAC_DEBUG) + else + { + printf("[PHYSAC] error when trying to get a null reference physics body"); + return 0; + } + #endif + } + #if defined(PHYSAC_DEBUG) + else + { + printf("[PHYSAC] physics body index is out of bounds"); + return 0; + } + #endif +} + +// Returns transformed position of a body shape (body position + vertex transformed position) +PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex) +{ + Vector2 position = { 0 }; + + if (body != NULL) + { + switch (body->shape.type) + { + case PHYSICS_CIRCLE: + { + position.x = body->position.x + cosf(360/PHYSAC_CIRCLE_VERTICES*vertex*PHYSAC_DEG2RAD)*body->shape.radius; + position.y = body->position.y + sinf(360/PHYSAC_CIRCLE_VERTICES*vertex*PHYSAC_DEG2RAD)*body->shape.radius; + } break; + case PHYSICS_POLYGON: + { + PolygonData vertexData = body->shape.vertexData; + position = Vector2Add(body->position, Mat2MultiplyVector2(vertexData.transform, vertexData.vertices[vertex])); + } break; + default: break; + } + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] error when trying to get a null reference physics body"); + #endif + + return position; +} + +// Sets physics body shape transform based on radians parameter +PHYSACDEF void SetPhysicsBodyRotation(PhysicsBody body, float radians) +{ + if (body != NULL) + { + body->orient = radians; + + if (body->shape.type == PHYSICS_POLYGON) body->shape.vertexData.transform = Mat2Radians(radians); + } +} + +// Unitializes and destroys a physics body +PHYSACDEF void DestroyPhysicsBody(PhysicsBody body) +{ + if (body != NULL) + { + int id = body->id; + int index = -1; + + for (int i = 0; i < physicsBodiesCount; i++) + { + if (bodies[i]->id == id) + { + index = i; + break; + } + } + + #if defined(PHYSAC_DEBUG) + if (index == -1) printf("[PHYSAC] cannot find body id %i in pointers array\n", id); + #endif + + // Free body allocated memory + PHYSAC_FREE(bodies[index]); + usedMemory -= sizeof(PhysicsBodyData); + bodies[index] = NULL; + + // Reorder physics bodies pointers array and its catched index + for (int i = index; i < physicsBodiesCount; i++) + { + if ((i + 1) < physicsBodiesCount) bodies[i] = bodies[i + 1]; + } + + // Update physics bodies count + physicsBodiesCount--; + + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] destroyed physics body id %i\n", id); + #endif + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] error trying to destroy a null referenced body\n"); + #endif +} + +// Destroys created physics bodies and manifolds and resets global values +PHYSACDEF void ResetPhysics(void) +{ + // Unitialize physics bodies dynamic memory allocations + for (int i = physicsBodiesCount - 1; i >= 0; i--) + { + PhysicsBody body = bodies[i]; + + if (body != NULL) + { + PHYSAC_FREE(body); + body = NULL; + usedMemory -= sizeof(PhysicsBodyData); + } + } + + physicsBodiesCount = 0; + + // Unitialize physics manifolds dynamic memory allocations + for (int i = physicsManifoldsCount - 1; i >= 0; i--) + { + PhysicsManifold manifold = contacts[i]; + + if (manifold != NULL) + { + PHYSAC_FREE(manifold); + manifold = NULL; + usedMemory -= sizeof(PhysicsManifoldData); + } + } + + physicsManifoldsCount = 0; + + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] physics module reset successfully\n"); + #endif +} + +// Unitializes physics pointers and exits physics loop thread +PHYSACDEF void ClosePhysics(void) +{ + // Exit physics loop thread physicsThreadEnabled = false; - - // Free all dynamic memory allocations - for (int i = 0; i < physicBodiesCount; i++) PHYSAC_FREE(physicBodies[i]); - - // Reset enabled physic objects count - physicBodiesCount = 0; + + #if !defined(PHYSAC_NO_THREADS) + pthread_join(physicsThreadId, NULL); + #endif } -// Create a new physic body dinamically, initialize it and add to pool -PHYSACDEF PhysicBody CreatePhysicBody(Vector2 position, float rotation, Vector2 scale) +//---------------------------------------------------------------------------------- +// Module Internal Functions Definition +//---------------------------------------------------------------------------------- +// Creates a random polygon shape with max vertex distance from polygon pivot +static PolygonData CreateRandomPolygon(float radius, int sides) { - // Allocate dynamic memory - PhysicBody obj = (PhysicBody)PHYSAC_MALLOC(sizeof(PhysicBodyData)); - - // Initialize physic body values with generic values - obj->id = physicBodiesCount; - obj->enabled = true; - - obj->transform = (Transform){ (Vector2){ position.x - scale.x/2, position.y - scale.y/2 }, rotation, scale }; - - obj->rigidbody.enabled = false; - obj->rigidbody.mass = 1.0f; - obj->rigidbody.acceleration = (Vector2){ 0.0f, 0.0f }; - obj->rigidbody.velocity = (Vector2){ 0.0f, 0.0f }; - obj->rigidbody.applyGravity = false; - obj->rigidbody.isGrounded = false; - obj->rigidbody.friction = 0.0f; - obj->rigidbody.bounciness = 0.0f; - - obj->collider.enabled = true; - obj->collider.type = COLLIDER_RECTANGLE; - obj->collider.bounds = TransformToRectangle(obj->transform); - obj->collider.radius = 0.0f; - - // Add new physic body to the pointers array - physicBodies[physicBodiesCount] = obj; - - // Increase enabled physic bodies count - physicBodiesCount++; - - return obj; -} + PolygonData data = { 0 }; + data.vertexCount = sides; -// Destroy a specific physic body and take it out of the list -PHYSACDEF void DestroyPhysicBody(PhysicBody pbody) -{ - // Free dynamic memory allocation - PHYSAC_FREE(physicBodies[pbody->id]); - - // Remove *obj from the pointers array - for (int i = pbody->id; i < physicBodiesCount; i++) + float orient = GetRandomNumber(0, 360); + data.transform = Mat2Radians(orient*PHYSAC_DEG2RAD); + + // Calculate polygon vertices positions + for (int i = 0; i < data.vertexCount; i++) { - // Resort all the following pointers of the array - if ((i + 1) < physicBodiesCount) - { - physicBodies[i] = physicBodies[i + 1]; - physicBodies[i]->id = physicBodies[i + 1]->id; - } - else PHYSAC_FREE(physicBodies[i]); + data.vertices[i].x = cosf(360/sides*i*PHYSAC_DEG2RAD)*radius; + data.vertices[i].y = sinf(360/sides*i*PHYSAC_DEG2RAD)*radius; } - - // Decrease enabled physic bodies count - physicBodiesCount--; -} -// Apply directional force to a physic body -PHYSACDEF void ApplyForce(PhysicBody pbody, Vector2 force) -{ - if (pbody->rigidbody.enabled) + // Calculate polygon faces normals + for (int i = 0; i < data.vertexCount; i++) { - pbody->rigidbody.velocity.x += force.x/pbody->rigidbody.mass; - pbody->rigidbody.velocity.y += force.y/pbody->rigidbody.mass; + int nextIndex = (((i + 1) < sides) ? (i + 1) : 0); + Vector2 face = Vector2Subtract(data.vertices[nextIndex], data.vertices[i]); + + data.normals[i] = (Vector2){ face.y, -face.x }; + MathNormalize(&data.normals[i]); } + + return data; } -// Apply radial force to all physic objects in range -PHYSACDEF void ApplyForceAtPosition(Vector2 position, float force, float radius) +// Creates a rectangle polygon shape based on a min and max positions +static PolygonData CreateRectanglePolygon(Vector2 pos, Vector2 size) { - for (int i = 0; i < physicBodiesCount; i++) + PolygonData data = { 0 }; + + data.vertexCount = 4; + data.transform = Mat2Radians(0); + + // Calculate polygon vertices positions + data.vertices[0] = (Vector2){ pos.x + size.x/2, pos.y - size.y/2 }; + data.vertices[1] = (Vector2){ pos.x + size.x/2, pos.y + size.y/2 }; + data.vertices[2] = (Vector2){ pos.x - size.x/2, pos.y + size.y/2 }; + data.vertices[3] = (Vector2){ pos.x - size.x/2, pos.y - size.y/2 }; + + // Calculate polygon faces normals + for (int i = 0; i < data.vertexCount; i++) { - if (physicBodies[i]->rigidbody.enabled) - { - // Calculate direction and distance between force and physic body position - Vector2 distance = (Vector2){ physicBodies[i]->transform.position.x - position.x, physicBodies[i]->transform.position.y - position.y }; + int nextIndex = (((i + 1) < data.vertexCount) ? (i + 1) : 0); + Vector2 face = Vector2Subtract(data.vertices[nextIndex], data.vertices[i]); - if (physicBodies[i]->collider.type == COLLIDER_RECTANGLE) - { - distance.x += physicBodies[i]->transform.scale.x/2; - distance.y += physicBodies[i]->transform.scale.y/2; - } - - float distanceLength = Vector2Length(distance); - - // Check if physic body is in force range - if (distanceLength <= radius) - { - // Normalize force direction - distance.x /= distanceLength; - distance.y /= -distanceLength; - - // Calculate final force - Vector2 finalForce = { distance.x*force, distance.y*force }; - - // Apply force to the physic body - ApplyForce(physicBodies[i], finalForce); - } - } + data.normals[i] = (Vector2){ face.y, -face.x }; + MathNormalize(&data.normals[i]); } + + return data; } -// Convert Transform data type to Rectangle (position and scale) -PHYSACDEF Rectangle TransformToRectangle(Transform transform) +// Physics loop thread function +static void *PhysicsLoop(void *arg) { - return (Rectangle){transform.position.x, transform.position.y, transform.scale.x, transform.scale.y}; -} + #if defined(PHYSAC_DEBUG) + printf("[PHYSAC] physics thread created with successfully\n"); + #endif -// Physics calculations thread function -PHYSACDEF void* PhysicsThread(void *arg) -{ - // Initialize thread loop state + // Initialize physics loop thread values physicsThreadEnabled = true; - - // Initialize hi-resolution timer - InitTimer(); - - // Physics update loop - while (physicsThreadEnabled) - { - currentTime = GetCurrentTime(); - double deltaTime = (double)(currentTime - previousTime); - previousTime = currentTime; + accumulator = 0; - // Delta time value needs to be inverse multiplied by physics time step value (1/target fps) - UpdatePhysics(deltaTime/PHYSICS_TIMESTEP); + // Initialize high resolution timer + InitTimer(); + + // Physics update loop + while (physicsThreadEnabled) + { + // Calculate current time + currentTime = GetCurrentTime(); + + // Calculate current delta time + deltaTime = currentTime - startTime; + + // Store the time elapsed since the last frame began + accumulator += deltaTime; + + // Clamp accumulator to max time step to avoid bad performance + MathClamp(&accumulator, 0, PHYSAC_MAX_TIMESTEP); + + // Fixed time stepping loop + while (accumulator >= PHYSAC_DESIRED_DELTATIME) + { + PhysicsStep(); + accumulator -= deltaTime; + } + + // Record the starting of this frame + startTime = currentTime; } - + + // Unitialize physics manifolds dynamic memory allocations + for (int i = physicsManifoldsCount - 1; i >= 0; i--) DestroyPhysicsManifold(contacts[i]); + + // Unitialize physics bodies dynamic memory allocations + for (int i = physicsBodiesCount - 1; i >= 0; i--) DestroyPhysicsBody(bodies[i]); + + #if defined(PHYSAC_DEBUG) + if (physicsBodiesCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated bodies [MEMORY: %i bytes]\n", physicsBodiesCount, usedMemory); + else if (physicsManifoldsCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated manifolds [MEMORY: %i bytes]\n", physicsManifoldsCount, usedMemory); + else printf("[PHYSAC] physics module closed successfully\n"); + #endif + return NULL; } -//---------------------------------------------------------------------------------- -// Module specific Functions Definition -//---------------------------------------------------------------------------------- -// Initialize hi-resolution timer -static void InitTimer(void) +// Physics steps calculations (dynamics, collisions and position corrections) +static void PhysicsStep(void) { -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) - struct timespec now; + stepsCount++; - if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) // Success + // Clear previous generated collisions information + for (int i = physicsManifoldsCount - 1; i >= 0; i--) { - baseTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; + PhysicsManifold manifold = contacts[i]; + if (manifold != NULL) DestroyPhysicsManifold(manifold); } -#endif - previousTime = GetCurrentTime(); // Get time as double -} - -// Time measure returned are microseconds -static double GetCurrentTime(void) -{ - double time; - -#if defined(PLATFORM_DESKTOP) - unsigned long long int clockFrequency, currentTime; - - QueryPerformanceFrequency(&clockFrequency); - QueryPerformanceCounter(¤tTime); - - time = (double)((double)currentTime/(double)clockFrequency); -#endif - -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec; - - time = (double)(temp - baseTime)*1e-9; -#endif - - return time; -} - -// Returns the dot product of two Vector2 -static float Vector2DotProduct(Vector2 v1, Vector2 v2) -{ - float result; - - result = v1.x*v2.x + v1.y*v2.y; - - return result; -} - -static float Vector2Length(Vector2 v) -{ - float result; - - result = sqrt(v.x*v.x + v.y*v.y); - - return result; -} - -// Update physic objects, calculating physic behaviours and collisions detection -static void UpdatePhysics(double deltaTime) -{ - for (int i = 0; i < physicBodiesCount; i++) + // Generate new collision information + for (int i = 0; i < physicsBodiesCount; i++) { - if (physicBodies[i]->enabled) + PhysicsBody bodyA = bodies[i]; + + if (bodyA != NULL) { - // Update physic behaviour - if (physicBodies[i]->rigidbody.enabled) + for (int j = i + 1; j < physicsBodiesCount; j++) { - // Apply friction to acceleration in X axis - if (physicBodies[i]->rigidbody.acceleration.x > PHYSICS_ACCURACY) physicBodies[i]->rigidbody.acceleration.x -= physicBodies[i]->rigidbody.friction*deltaTime; - else if (physicBodies[i]->rigidbody.acceleration.x < PHYSICS_ACCURACY) physicBodies[i]->rigidbody.acceleration.x += physicBodies[i]->rigidbody.friction*deltaTime; - else physicBodies[i]->rigidbody.acceleration.x = 0.0f; - - // Apply friction to acceleration in Y axis - if (physicBodies[i]->rigidbody.acceleration.y > PHYSICS_ACCURACY) physicBodies[i]->rigidbody.acceleration.y -= physicBodies[i]->rigidbody.friction*deltaTime; - else if (physicBodies[i]->rigidbody.acceleration.y < PHYSICS_ACCURACY) physicBodies[i]->rigidbody.acceleration.y += physicBodies[i]->rigidbody.friction*deltaTime; - else physicBodies[i]->rigidbody.acceleration.y = 0.0f; - - // Apply friction to velocity in X axis - if (physicBodies[i]->rigidbody.velocity.x > PHYSICS_ACCURACY) physicBodies[i]->rigidbody.velocity.x -= physicBodies[i]->rigidbody.friction*deltaTime; - else if (physicBodies[i]->rigidbody.velocity.x < PHYSICS_ACCURACY) physicBodies[i]->rigidbody.velocity.x += physicBodies[i]->rigidbody.friction*deltaTime; - else physicBodies[i]->rigidbody.velocity.x = 0.0f; - - // Apply friction to velocity in Y axis - if (physicBodies[i]->rigidbody.velocity.y > PHYSICS_ACCURACY) physicBodies[i]->rigidbody.velocity.y -= physicBodies[i]->rigidbody.friction*deltaTime; - else if (physicBodies[i]->rigidbody.velocity.y < PHYSICS_ACCURACY) physicBodies[i]->rigidbody.velocity.y += physicBodies[i]->rigidbody.friction*deltaTime; - else physicBodies[i]->rigidbody.velocity.y = 0.0f; - - // Apply gravity to velocity - if (physicBodies[i]->rigidbody.applyGravity) + PhysicsBody bodyB = bodies[j]; + + if (bodyB != NULL) { - physicBodies[i]->rigidbody.velocity.x += gravityForce.x*deltaTime; - physicBodies[i]->rigidbody.velocity.y += gravityForce.y*deltaTime; - } - - // Apply acceleration to velocity - physicBodies[i]->rigidbody.velocity.x += physicBodies[i]->rigidbody.acceleration.x*deltaTime; - physicBodies[i]->rigidbody.velocity.y += physicBodies[i]->rigidbody.acceleration.y*deltaTime; - - // Apply velocity to position - physicBodies[i]->transform.position.x += physicBodies[i]->rigidbody.velocity.x*deltaTime; - physicBodies[i]->transform.position.y -= physicBodies[i]->rigidbody.velocity.y*deltaTime; - } - - // Update collision detection - if (physicBodies[i]->collider.enabled) - { - // Update collider bounds - physicBodies[i]->collider.bounds = TransformToRectangle(physicBodies[i]->transform); - - // Check collision with other colliders - for (int k = 0; k < physicBodiesCount; k++) - { - if (physicBodies[k]->collider.enabled && i != k) + if ((bodyA->inverseMass == 0) && (bodyB->inverseMass == 0)) continue; + + PhysicsManifold manifold = NULL; + if (bodyA->shape.type == PHYSICS_POLYGON && bodyB->shape.type == PHYSICS_CIRCLE) manifold = CreatePhysicsManifold(bodyB, bodyA); + else manifold = CreatePhysicsManifold(bodyA, bodyB); + SolvePhysicsManifold(manifold); + + if (manifold->contactsCount > 0) { - // Resolve physic collision - // NOTE: collision resolve is generic for all directions and conditions (no axis separated cases behaviours) - // and it is separated in rigidbody attributes resolve (velocity changes by impulse) and position correction (position overlap) - - // 1. Calculate collision normal - // ------------------------------------------------------------------------------------------------------------------------------------- - - // Define collision contact normal, direction and penetration depth - Vector2 contactNormal = { 0.0f, 0.0f }; - Vector2 direction = { 0.0f, 0.0f }; - float penetrationDepth = 0.0f; - - switch (physicBodies[i]->collider.type) - { - case COLLIDER_RECTANGLE: - { - switch (physicBodies[k]->collider.type) - { - case COLLIDER_RECTANGLE: - { - // Check if colliders are overlapped - if (CheckCollisionRecs(physicBodies[i]->collider.bounds, physicBodies[k]->collider.bounds)) - { - // Calculate direction vector from i to k - direction.x = (physicBodies[k]->transform.position.x + physicBodies[k]->transform.scale.x/2) - (physicBodies[i]->transform.position.x + physicBodies[i]->transform.scale.x/2); - direction.y = (physicBodies[k]->transform.position.y + physicBodies[k]->transform.scale.y/2) - (physicBodies[i]->transform.position.y + physicBodies[i]->transform.scale.y/2); - - // Define overlapping and penetration attributes - Vector2 overlap; - - // Calculate overlap on X axis - overlap.x = (physicBodies[i]->transform.scale.x + physicBodies[k]->transform.scale.x)/2 - abs(direction.x); - - // SAT test on X axis - if (overlap.x > 0.0f) - { - // Calculate overlap on Y axis - overlap.y = (physicBodies[i]->transform.scale.y + physicBodies[k]->transform.scale.y)/2 - abs(direction.y); - - // SAT test on Y axis - if (overlap.y > 0.0f) - { - // Find out which axis is axis of least penetration - if (overlap.y > overlap.x) - { - // Point towards k knowing that direction points from i to k - if (direction.x < 0.0f) contactNormal = (Vector2){ -1.0f, 0.0f }; - else contactNormal = (Vector2){ 1.0f, 0.0f }; - - // Update penetration depth for position correction - penetrationDepth = overlap.x; - } - else - { - // Point towards k knowing that direction points from i to k - if (direction.y < 0.0f) contactNormal = (Vector2){ 0.0f, 1.0f }; - else contactNormal = (Vector2){ 0.0f, -1.0f }; - - // Update penetration depth for position correction - penetrationDepth = overlap.y; - } - } - } - } - } break; - case COLLIDER_CIRCLE: - { - if (CheckCollisionCircleRec(physicBodies[k]->transform.position, physicBodies[k]->collider.radius, physicBodies[i]->collider.bounds)) - { - // Calculate direction vector between circles - direction.x = physicBodies[k]->transform.position.x - physicBodies[i]->transform.position.x + physicBodies[i]->transform.scale.x/2; - direction.y = physicBodies[k]->transform.position.y - physicBodies[i]->transform.position.y + physicBodies[i]->transform.scale.y/2; - - // Calculate closest point on rectangle to circle - Vector2 closestPoint = { 0.0f, 0.0f }; - if (direction.x > 0.0f) closestPoint.x = physicBodies[i]->collider.bounds.x + physicBodies[i]->collider.bounds.width; - else closestPoint.x = physicBodies[i]->collider.bounds.x; - - if (direction.y > 0.0f) closestPoint.y = physicBodies[i]->collider.bounds.y + physicBodies[i]->collider.bounds.height; - else closestPoint.y = physicBodies[i]->collider.bounds.y; - - // Check if the closest point is inside the circle - if (CheckCollisionPointCircle(closestPoint, physicBodies[k]->transform.position, physicBodies[k]->collider.radius)) - { - // Recalculate direction based on closest point position - direction.x = physicBodies[k]->transform.position.x - closestPoint.x; - direction.y = physicBodies[k]->transform.position.y - closestPoint.y; - float distance = Vector2Length(direction); - - // Calculate final contact normal - contactNormal.x = direction.x/distance; - contactNormal.y = -direction.y/distance; - - // Calculate penetration depth - penetrationDepth = physicBodies[k]->collider.radius - distance; - } - else - { - if (abs(direction.y) < abs(direction.x)) - { - // Calculate final contact normal - if (direction.y > 0.0f) - { - contactNormal = (Vector2){ 0.0f, -1.0f }; - penetrationDepth = fabs(physicBodies[i]->collider.bounds.y - physicBodies[k]->transform.position.y - physicBodies[k]->collider.radius); - } - else - { - contactNormal = (Vector2){ 0.0f, 1.0f }; - penetrationDepth = fabs(physicBodies[i]->collider.bounds.y - physicBodies[k]->transform.position.y + physicBodies[k]->collider.radius); - } - } - else - { - // Calculate final contact normal - if (direction.x > 0.0f) - { - contactNormal = (Vector2){ 1.0f, 0.0f }; - penetrationDepth = fabs(physicBodies[k]->transform.position.x + physicBodies[k]->collider.radius - physicBodies[i]->collider.bounds.x); - } - else - { - contactNormal = (Vector2){ -1.0f, 0.0f }; - penetrationDepth = fabs(physicBodies[i]->collider.bounds.x + physicBodies[i]->collider.bounds.width - physicBodies[k]->transform.position.x - physicBodies[k]->collider.radius); - } - } - } - } - } break; - } - } break; - case COLLIDER_CIRCLE: - { - switch (physicBodies[k]->collider.type) - { - case COLLIDER_RECTANGLE: - { - if (CheckCollisionCircleRec(physicBodies[i]->transform.position, physicBodies[i]->collider.radius, physicBodies[k]->collider.bounds)) - { - // Calculate direction vector between circles - direction.x = physicBodies[k]->transform.position.x + physicBodies[i]->transform.scale.x/2 - physicBodies[i]->transform.position.x; - direction.y = physicBodies[k]->transform.position.y + physicBodies[i]->transform.scale.y/2 - physicBodies[i]->transform.position.y; - - // Calculate closest point on rectangle to circle - Vector2 closestPoint = { 0.0f, 0.0f }; - if (direction.x > 0.0f) closestPoint.x = physicBodies[k]->collider.bounds.x + physicBodies[k]->collider.bounds.width; - else closestPoint.x = physicBodies[k]->collider.bounds.x; - - if (direction.y > 0.0f) closestPoint.y = physicBodies[k]->collider.bounds.y + physicBodies[k]->collider.bounds.height; - else closestPoint.y = physicBodies[k]->collider.bounds.y; - - // Check if the closest point is inside the circle - if (CheckCollisionPointCircle(closestPoint, physicBodies[i]->transform.position, physicBodies[i]->collider.radius)) - { - // Recalculate direction based on closest point position - direction.x = physicBodies[i]->transform.position.x - closestPoint.x; - direction.y = physicBodies[i]->transform.position.y - closestPoint.y; - float distance = Vector2Length(direction); - - // Calculate final contact normal - contactNormal.x = direction.x/distance; - contactNormal.y = -direction.y/distance; - - // Calculate penetration depth - penetrationDepth = physicBodies[k]->collider.radius - distance; - } - else - { - if (abs(direction.y) < abs(direction.x)) - { - // Calculate final contact normal - if (direction.y > 0.0f) - { - contactNormal = (Vector2){ 0.0f, -1.0f }; - penetrationDepth = fabs(physicBodies[k]->collider.bounds.y - physicBodies[i]->transform.position.y - physicBodies[i]->collider.radius); - } - else - { - contactNormal = (Vector2){ 0.0f, 1.0f }; - penetrationDepth = fabs(physicBodies[k]->collider.bounds.y - physicBodies[i]->transform.position.y + physicBodies[i]->collider.radius); - } - } - else - { - // Calculate final contact normal and penetration depth - if (direction.x > 0.0f) - { - contactNormal = (Vector2){ 1.0f, 0.0f }; - penetrationDepth = fabs(physicBodies[i]->transform.position.x + physicBodies[i]->collider.radius - physicBodies[k]->collider.bounds.x); - } - else - { - contactNormal = (Vector2){ -1.0f, 0.0f }; - penetrationDepth = fabs(physicBodies[k]->collider.bounds.x + physicBodies[k]->collider.bounds.width - physicBodies[i]->transform.position.x - physicBodies[i]->collider.radius); - } - } - } - } - } break; - case COLLIDER_CIRCLE: - { - // Check if colliders are overlapped - if (CheckCollisionCircles(physicBodies[i]->transform.position, physicBodies[i]->collider.radius, physicBodies[k]->transform.position, physicBodies[k]->collider.radius)) - { - // Calculate direction vector between circles - direction.x = physicBodies[k]->transform.position.x - physicBodies[i]->transform.position.x; - direction.y = physicBodies[k]->transform.position.y - physicBodies[i]->transform.position.y; - - // Calculate distance between circles - float distance = Vector2Length(direction); - - // Check if circles are not completely overlapped - if (distance != 0.0f) - { - // Calculate contact normal direction (Y axis needs to be flipped) - contactNormal.x = direction.x/distance; - contactNormal.y = -direction.y/distance; - } - else contactNormal = (Vector2){ 1.0f, 0.0f }; // Choose random (but consistent) values - } - } break; - default: break; - } - } break; - default: break; - } - - // Update rigidbody grounded state - if (physicBodies[i]->rigidbody.enabled) physicBodies[i]->rigidbody.isGrounded = (contactNormal.y < 0.0f); - - // 2. Calculate collision impulse - // ------------------------------------------------------------------------------------------------------------------------------------- - - // Calculate relative velocity - Vector2 relVelocity = { 0.0f, 0.0f }; - relVelocity.x = physicBodies[k]->rigidbody.velocity.x - physicBodies[i]->rigidbody.velocity.x; - relVelocity.y = physicBodies[k]->rigidbody.velocity.y - physicBodies[i]->rigidbody.velocity.y; - - // Calculate relative velocity in terms of the normal direction - float velAlongNormal = Vector2DotProduct(relVelocity, contactNormal); - - // Dot not resolve if velocities are separating - if (velAlongNormal <= 0.0f) - { - // Calculate minimum bounciness value from both objects - float e = fminf(physicBodies[i]->rigidbody.bounciness, physicBodies[k]->rigidbody.bounciness); - - // Calculate impulse scalar value - float j = -(1.0f + e)*velAlongNormal; - j /= 1.0f/physicBodies[i]->rigidbody.mass + 1.0f/physicBodies[k]->rigidbody.mass; - - // Calculate final impulse vector - Vector2 impulse = { j*contactNormal.x, j*contactNormal.y }; - - // Calculate collision mass ration - float massSum = physicBodies[i]->rigidbody.mass + physicBodies[k]->rigidbody.mass; - float ratio = 0.0f; - - // Apply impulse to current rigidbodies velocities if they are enabled - if (physicBodies[i]->rigidbody.enabled) - { - // Calculate inverted mass ration - ratio = physicBodies[i]->rigidbody.mass/massSum; - - // Apply impulse direction to velocity - physicBodies[i]->rigidbody.velocity.x -= impulse.x*ratio*(1.0f+physicBodies[i]->rigidbody.bounciness); - physicBodies[i]->rigidbody.velocity.y -= impulse.y*ratio*(1.0f+physicBodies[i]->rigidbody.bounciness); - } - - if (physicBodies[k]->rigidbody.enabled) - { - // Calculate inverted mass ration - ratio = physicBodies[k]->rigidbody.mass/massSum; - - // Apply impulse direction to velocity - physicBodies[k]->rigidbody.velocity.x += impulse.x*ratio*(1.0f+physicBodies[i]->rigidbody.bounciness); - physicBodies[k]->rigidbody.velocity.y += impulse.y*ratio*(1.0f+physicBodies[i]->rigidbody.bounciness); - } - - // 3. Correct colliders overlaping (transform position) - // --------------------------------------------------------------------------------------------------------------------------------- - - // Calculate transform position penetration correction - Vector2 posCorrection; - posCorrection.x = penetrationDepth/((1.0f/physicBodies[i]->rigidbody.mass) + (1.0f/physicBodies[k]->rigidbody.mass))*PHYSICS_ERRORPERCENT*contactNormal.x; - posCorrection.y = penetrationDepth/((1.0f/physicBodies[i]->rigidbody.mass) + (1.0f/physicBodies[k]->rigidbody.mass))*PHYSICS_ERRORPERCENT*contactNormal.y; - - // Fix transform positions - if (physicBodies[i]->rigidbody.enabled) - { - // Fix physic objects transform position - physicBodies[i]->transform.position.x -= 1.0f/physicBodies[i]->rigidbody.mass*posCorrection.x; - physicBodies[i]->transform.position.y += 1.0f/physicBodies[i]->rigidbody.mass*posCorrection.y; - - // Update collider bounds - physicBodies[i]->collider.bounds = TransformToRectangle(physicBodies[i]->transform); - - if (physicBodies[k]->rigidbody.enabled) - { - // Fix physic objects transform position - physicBodies[k]->transform.position.x += 1.0f/physicBodies[k]->rigidbody.mass*posCorrection.x; - physicBodies[k]->transform.position.y -= 1.0f/physicBodies[k]->rigidbody.mass*posCorrection.y; - - // Update collider bounds - physicBodies[k]->collider.bounds = TransformToRectangle(physicBodies[k]->transform); - } - } - } + // Create a new manifold with same information as previously solved manifold and add it to the manifolds pool last slot + PhysicsManifold newManifold = CreatePhysicsManifold(bodyA, bodyB); + newManifold->penetration = manifold->penetration; + newManifold->normal = manifold->normal; + newManifold->contacts[0] = manifold->contacts[0]; + newManifold->contacts[1] = manifold->contacts[1]; + newManifold->contactsCount = manifold->contactsCount; + newManifold->restitution = manifold->restitution; + newManifold->dynamicFriction = manifold->dynamicFriction; + newManifold->staticFriction = manifold->staticFriction; } } } } } + + // Integrate forces to physics bodies + for (int i = 0; i < physicsBodiesCount; i++) + { + PhysicsBody body = bodies[i]; + if (body != NULL) IntegratePhysicsForces(body); + } + + // Initialize physics manifolds to solve collisions + for (int i = 0; i < physicsManifoldsCount; i++) + { + PhysicsManifold manifold = contacts[i]; + if (manifold != NULL) InitializePhysicsManifolds(manifold); + } + + // Integrate physics collisions impulses to solve collisions + for (int i = 0; i < PHYSAC_COLLISION_ITERATIONS; i++) + { + for (int j = 0; j < physicsManifoldsCount; j++) + { + PhysicsManifold manifold = contacts[i]; + if (manifold != NULL) IntegratePhysicsImpulses(manifold); + } + } + + // Integrate velocity to physics bodies + for (int i = 0; i < physicsBodiesCount; i++) + { + PhysicsBody body = bodies[i]; + if (body != NULL) IntegratePhysicsVelocity(body); + } + + // Correct physics bodies positions based on manifolds collision information + for (int i = 0; i < physicsManifoldsCount; i++) + { + PhysicsManifold manifold = contacts[i]; + if (manifold != NULL) CorrectPhysicsPositions(manifold); + } + + // Clear physics bodies forces + for (int i = 0; i < physicsBodiesCount; i++) + { + PhysicsBody body = bodies[i]; + if (body != NULL) + { + body->force = (Vector2){ 0 }; + body->torque = 0; + } + } } -#endif // PHYSAC_IMPLEMENTATION \ No newline at end of file +// Creates a new physics manifold to solve collision +static PhysicsManifold CreatePhysicsManifold(PhysicsBody a, PhysicsBody b) +{ + PhysicsManifold newManifold = (PhysicsManifold)PHYSAC_MALLOC(sizeof(PhysicsManifoldData)); + usedMemory += sizeof(PhysicsManifoldData); + + int newId = -1; + for (int i = 0; i < PHYSAC_MAX_MANIFOLDS; i++) + { + int currentId = i; + + // Check if current id already exist in other physics body + for (int k = 0; k < physicsManifoldsCount; k++) + { + if (contacts[k]->id == currentId) + { + currentId++; + break; + } + } + + // If it is not used, use it as new physics body id + if (currentId == i) + { + newId = i; + break; + } + } + + if (newId != -1) + { + // Initialize new manifold with generic values + newManifold->id = newId; + newManifold->bodyA = a; + newManifold->bodyB = b; + newManifold->penetration = 0; + newManifold->normal = (Vector2){ 0 }; + newManifold->contacts[0] = (Vector2){ 0 }; + newManifold->contacts[1] = (Vector2){ 0 }; + newManifold->contactsCount = 0; + newManifold->restitution = 0; + newManifold->dynamicFriction = 0; + newManifold->staticFriction = 0; + + // Add new body to bodies pointers array and update bodies count + contacts[physicsManifoldsCount] = newManifold; + physicsManifoldsCount++; + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] new physics manifold creation failed because there is any available id to use\n"); + #endif + + return newManifold; +} + +// Unitializes and destroys a physics manifold +static void DestroyPhysicsManifold(PhysicsManifold manifold) +{ + if (manifold != NULL) + { + int id = manifold->id; + int index = -1; + + for (int i = 0; i < physicsManifoldsCount; i++) + { + if (contacts[i]->id == id) + { + index = i; + break; + } + } + + #if defined(PHYSAC_DEBUG) + if (index == -1) printf("[PHYSAC] cannot find manifold id %i in pointers array\n", id); + #endif + + // Free manifold allocated memory + PHYSAC_FREE(contacts[index]); + usedMemory -= sizeof(PhysicsManifoldData); + contacts[index] = NULL; + + // Reorder physics manifolds pointers array and its catched index + for (int i = index; i < physicsManifoldsCount; i++) + { + if ((i + 1) < physicsManifoldsCount) contacts[i] = contacts[i + 1]; + } + + // Update physics manifolds count + physicsManifoldsCount--; + } + #if defined(PHYSAC_DEBUG) + else printf("[PHYSAC] error trying to destroy a null referenced manifold\n"); + #endif +} + +// Solves a created physics manifold between two physics bodies +static void SolvePhysicsManifold(PhysicsManifold manifold) +{ + switch (manifold->bodyA->shape.type) + { + case PHYSICS_CIRCLE: + { + switch (manifold->bodyB->shape.type) + { + case PHYSICS_CIRCLE: SolveCircleToCircle(manifold); break; + case PHYSICS_POLYGON: SolveCircleToPolygon(manifold); break; + default: break; + } + } break; + case PHYSICS_POLYGON: + { + switch (manifold->bodyB->shape.type) + { + case PHYSICS_CIRCLE: SolvePolygonToCircle(manifold); break; + case PHYSICS_POLYGON: SolvePolygonToPolygon(manifold); break; + default: break; + } + } break; + default: break; + } + + // Update physics body grounded state if normal direction is downside + manifold->bodyB->isGrounded = (manifold->normal.y < 0); +} + +// Solves collision between two circle shape physics bodies +static void SolveCircleToCircle(PhysicsManifold manifold) +{ + PhysicsBody bodyA = manifold->bodyA; + PhysicsBody bodyB = manifold->bodyB; + + // Calculate translational vector, which is normal + Vector2 normal = Vector2Subtract(bodyB->position, bodyA->position); + + float distSqr = MathLenSqr(normal); + float radius = bodyA->shape.radius + bodyB->shape.radius; + + // Check if circles are not in contact + if (distSqr >= radius*radius) + { + manifold->contactsCount = 0; + return; + } + + float distance = sqrtf(distSqr); + manifold->contactsCount = 1; + + if (distance == 0) + { + manifold->penetration = bodyA->shape.radius; + manifold->normal = (Vector2){ 1, 0 }; + manifold->contacts[0] = bodyA->position; + } + else + { + manifold->penetration = radius - distance; + manifold->normal = (Vector2){ normal.x/distance, normal.y/distance }; // Faster than using MathNormalize() due to sqrt is already performed + manifold->contacts[0] = (Vector2){ manifold->normal.x*bodyA->shape.radius + bodyA->position.x, manifold->normal.y*bodyA->shape.radius + bodyA->position.y }; + } + + // Update physics body grounded state if normal direction is down + if (manifold->normal.y < 0) bodyA->isGrounded = true; +} + +// Solves collision between a circle to a polygon shape physics bodies +static void SolveCircleToPolygon(PhysicsManifold manifold) +{ + PhysicsBody bodyA = manifold->bodyA; + PhysicsBody bodyB = manifold->bodyB; + + manifold->contactsCount = 0; + + // Transform circle center to polygon transform space + Vector2 center = bodyA->position; + center = Mat2MultiplyVector2(Mat2Transpose(bodyB->shape.vertexData.transform), Vector2Subtract(center, bodyB->position)); + + // Find edge with minimum penetration + // It is the same concept as using support points in SolvePolygonToPolygon + float separation = -PHYSAC_FLT_MAX; + int faceNormal = 0; + PolygonData vertexData = bodyB->shape.vertexData; + + for (int i = 0; i < vertexData.vertexCount; i++) + { + float currentSeparation = MathDot(vertexData.normals[i], Vector2Subtract(center, vertexData.vertices[i])); + + if (currentSeparation > bodyA->shape.radius) return; + + if (currentSeparation > separation) + { + separation = currentSeparation; + faceNormal = i; + } + } + + // Grab face's vertices + Vector2 v1 = vertexData.vertices[faceNormal]; + int nextIndex = (((faceNormal + 1) < vertexData.vertexCount) ? (faceNormal + 1) : 0); + Vector2 v2 = vertexData.vertices[nextIndex]; + + // Check to see if center is within polygon + if (separation < PHYSAC_EPSILON) + { + manifold->contactsCount = 1; + Vector2 normal = Mat2MultiplyVector2(vertexData.transform, vertexData.normals[faceNormal]); + manifold->normal = (Vector2){ -normal.x, -normal.y }; + manifold->contacts[0] = (Vector2){ manifold->normal.x*bodyA->shape.radius + bodyA->position.x, manifold->normal.y*bodyA->shape.radius + bodyA->position.y }; + manifold->penetration = bodyA->shape.radius; + return; + } + + // Determine which voronoi region of the edge center of circle lies within + float dot1 = MathDot(Vector2Subtract(center, v1), Vector2Subtract(v2, v1)); + float dot2 = MathDot(Vector2Subtract(center, v2), Vector2Subtract(v1, v2)); + manifold->penetration = bodyA->shape.radius - separation; + + if (dot1 <= 0) // Closest to v1 + { + if (DistSqr(center, v1) > bodyA->shape.radius*bodyA->shape.radius) return; + + manifold->contactsCount = 1; + Vector2 normal = Vector2Subtract(v1, center); + normal = Mat2MultiplyVector2(vertexData.transform, normal); + MathNormalize(&normal); + manifold->normal = normal; + v1 = Mat2MultiplyVector2(vertexData.transform, v1); + v1 = Vector2Add(v1, bodyB->position); + manifold->contacts[0] = v1; + } + else if (dot2 <= 0) // Closest to v2 + { + if (DistSqr(center, v2) > bodyA->shape.radius*bodyA->shape.radius) return; + + manifold->contactsCount = 1; + Vector2 normal = Vector2Subtract(v2, center); + v2 = Mat2MultiplyVector2(vertexData.transform, v2); + v2 = Vector2Add(v2, bodyB->position); + manifold->contacts[0] = v2; + normal = Mat2MultiplyVector2(vertexData.transform, normal); + MathNormalize(&normal); + manifold->normal = normal; + } + else // Closest to face + { + Vector2 normal = vertexData.normals[faceNormal]; + + if (MathDot(Vector2Subtract(center, v1), normal) > bodyA->shape.radius) return; + + normal = Mat2MultiplyVector2(vertexData.transform, normal); + manifold->normal = (Vector2){ -normal.x, -normal.y }; + manifold->contacts[0] = (Vector2){ manifold->normal.x*bodyA->shape.radius + bodyA->position.x, manifold->normal.y*bodyA->shape.radius + bodyA->position.y }; + manifold->contactsCount = 1; + } +} + +// Solves collision between a polygon to a circle shape physics bodies +static void SolvePolygonToCircle(PhysicsManifold manifold) +{ + PhysicsBody bodyA = manifold->bodyA; + PhysicsBody bodyB = manifold->bodyB; + + manifold->bodyA = bodyB; + manifold->bodyB = bodyA; + SolveCircleToPolygon(manifold); + + manifold->normal.x *= -1; + manifold->normal.y *= -1; +} + +// Solves collision between two polygons shape physics bodies +static void SolvePolygonToPolygon(PhysicsManifold manifold) +{ + PhysicsShape bodyA = manifold->bodyA->shape; + PhysicsShape bodyB = manifold->bodyB->shape; + manifold->contactsCount = 0; + + // Check for separating axis with A shape's face planes + int faceA = 0; + float penetrationA = FindAxisLeastPenetration(&faceA, bodyA, bodyB); + if (penetrationA >= 0) return; + + // Check for separating axis with B shape's face planes + int faceB = 0; + float penetrationB = FindAxisLeastPenetration(&faceB, bodyB, bodyA); + if (penetrationB >= 0) return; + + int referenceIndex = 0; + bool flip = false; // Always point from A shape to B shape + + PhysicsShape refPoly; // Reference + PhysicsShape incPoly; // Incident + + // Determine which shape contains reference face + if (BiasGreaterThan(penetrationA, penetrationB)) + { + refPoly = bodyA; + incPoly = bodyB; + referenceIndex = faceA; + } + else + { + refPoly = bodyB; + incPoly = bodyA; + referenceIndex = faceB; + flip = true; + } + + // World space incident face + Vector2 incidentFace[2]; + FindIncidentFace(&incidentFace[0], &incidentFace[1], refPoly, incPoly, referenceIndex); + + // Setup reference face vertices + PolygonData refData = refPoly.vertexData; + Vector2 v1 = refData.vertices[referenceIndex]; + referenceIndex = (((referenceIndex + 1) < refData.vertexCount) ? (referenceIndex + 1) : 0); + Vector2 v2 = refData.vertices[referenceIndex]; + + // Transform vertices to world space + v1 = Mat2MultiplyVector2(refData.transform, v1); + v1 = Vector2Add(v1, refPoly.body->position); + v2 = Mat2MultiplyVector2(refData.transform, v2); + v2 = Vector2Add(v2, refPoly.body->position); + + // Calculate reference face side normal in world space + Vector2 sidePlaneNormal = Vector2Subtract(v2, v1); + MathNormalize(&sidePlaneNormal); + + // Orthogonalize + Vector2 refFaceNormal = { sidePlaneNormal.y, -sidePlaneNormal.x }; + float refC = MathDot(refFaceNormal, v1); + float negSide = MathDot(sidePlaneNormal, v1)*-1; + float posSide = MathDot(sidePlaneNormal, v2); + + // Clip incident face to reference face side planes (due to floating point error, possible to not have required points + if (Clip((Vector2){ -sidePlaneNormal.x, -sidePlaneNormal.y }, negSide, &incidentFace[0], &incidentFace[1]) < 2) return; + if (Clip(sidePlaneNormal, posSide, &incidentFace[0], &incidentFace[1]) < 2) return; + + // Flip normal if required + manifold->normal = (flip ? (Vector2){ -refFaceNormal.x, -refFaceNormal.y } : refFaceNormal); + + // Keep points behind reference face + int currentPoint = 0; // Clipped points behind reference face + float separation = MathDot(refFaceNormal, incidentFace[0]) - refC; + if (separation <= 0) + { + manifold->contacts[currentPoint] = incidentFace[0]; + manifold->penetration = -separation; + currentPoint++; + } + else manifold->penetration = 0; + + separation = MathDot(refFaceNormal, incidentFace[1]) - refC; + + if (separation <= 0) + { + manifold->contacts[currentPoint] = incidentFace[1]; + manifold->penetration += -separation; + currentPoint++; + + // Calculate total penetration average + manifold->penetration /= currentPoint; + } + + manifold->contactsCount = currentPoint; +} + +// Integrates physics forces into velocity +static void IntegratePhysicsForces(PhysicsBody body) +{ + if (body->inverseMass == 0 || !body->enabled) return; + + body->velocity.x += (body->force.x*body->inverseMass)*(deltaTime/2); + body->velocity.y += (body->force.y*body->inverseMass)*(deltaTime/2); + + if (body->useGravity) + { + body->velocity.x += gravityForce.x*(deltaTime/2); + body->velocity.y += gravityForce.y*(deltaTime/2); + } + + if (!body->freezeOrient) body->angularVelocity += body->torque*body->inverseInertia*(deltaTime/2); +} + +// Initializes physics manifolds to solve collisions +static void InitializePhysicsManifolds(PhysicsManifold manifold) +{ + PhysicsBody bodyA = manifold->bodyA; + PhysicsBody bodyB = manifold->bodyB; + + // Calculate average restitution, static and dynamic friction + manifold->restitution = sqrtf(bodyA->restitution*bodyB->restitution); + manifold->staticFriction = sqrtf(bodyA->staticFriction*bodyB->staticFriction); + manifold->dynamicFriction = sqrtf(bodyA->dynamicFriction*bodyB->dynamicFriction); + + for (int i = 0; i < 2; i++) + { + // Caculate radius from center of mass to contact + Vector2 radiusA = Vector2Subtract(manifold->contacts[i], bodyA->position); + Vector2 radiusB = Vector2Subtract(manifold->contacts[i], bodyB->position); + + Vector2 crossA = MathCross(bodyA->angularVelocity, radiusA); + Vector2 crossB = MathCross(bodyB->angularVelocity, radiusB); + + Vector2 radiusV = { 0 }; + radiusV.x = bodyB->velocity.x + crossB.x - bodyA->velocity.x - crossA.x; + radiusV.y = bodyB->velocity.y + crossB.y - bodyA->velocity.y - crossA.y; + + // Determine if we should perform a resting collision or not; + // The idea is if the only thing moving this object is gravity, then the collision should be performed without any restitution + if (MathLenSqr(radiusV) < (MathLenSqr((Vector2){ gravityForce.x*deltaTime, gravityForce.y*deltaTime }) + PHYSAC_EPSILON)) manifold->restitution = 0; + } +} + +// Integrates physics collisions impulses to solve collisions +static void IntegratePhysicsImpulses(PhysicsManifold manifold) +{ + PhysicsBody bodyA = manifold->bodyA; + PhysicsBody bodyB = manifold->bodyB; + + // Early out and positional correct if both objects have infinite mass + if (fabs(bodyA->inverseMass + bodyB->inverseMass) <= PHYSAC_EPSILON) + { + bodyA->velocity = (Vector2){ 0 }; + bodyB->velocity = (Vector2){ 0 }; + return; + } + + for (int i = 0; i < manifold->contactsCount; i++) + { + // Calculate radius from center of mass to contact + Vector2 radiusA = Vector2Subtract(manifold->contacts[i], bodyA->position); + Vector2 radiusB = Vector2Subtract(manifold->contacts[i], bodyB->position); + + // Calculate relative velocity + Vector2 radiusV = { 0 }; + radiusV.x = bodyB->velocity.x + MathCross(bodyB->angularVelocity, radiusB).x - bodyA->velocity.x - MathCross(bodyA->angularVelocity, radiusA).x; + radiusV.y = bodyB->velocity.y + MathCross(bodyB->angularVelocity, radiusB).y - bodyA->velocity.y - MathCross(bodyA->angularVelocity, radiusA).y; + + // Relative velocity along the normal + float contactVelocity = MathDot(radiusV, manifold->normal); + + // Do not resolve if velocities are separating + if (contactVelocity > 0) return; + + float raCrossN = MathCrossVector2(radiusA, manifold->normal); + float rbCrossN = MathCrossVector2(radiusB, manifold->normal); + + float inverseMassSum = bodyA->inverseMass + bodyB->inverseMass + (raCrossN*raCrossN)*bodyA->inverseInertia + (rbCrossN*rbCrossN)*bodyB->inverseInertia; + + // Calculate impulse scalar value + float impulse = -(1.0f + manifold->restitution)*contactVelocity; + impulse /= inverseMassSum; + impulse /= (float)manifold->contactsCount; + + // Apply impulse to each physics body + Vector2 impulseV = { manifold->normal.x*impulse, manifold->normal.y*impulse }; + + if (bodyA->enabled) + { + bodyA->velocity.x += bodyA->inverseMass*(-impulseV.x); + bodyA->velocity.y += bodyA->inverseMass*(-impulseV.y); + if (!bodyA->freezeOrient) bodyA->angularVelocity += bodyA->inverseInertia*MathCrossVector2(radiusA, (Vector2){ -impulseV.x, -impulseV.y }); + } + + if (bodyB->enabled) + { + bodyB->velocity.x += bodyB->inverseMass*(impulseV.x); + bodyB->velocity.y += bodyB->inverseMass*(impulseV.y); + if (!bodyB->freezeOrient) bodyB->angularVelocity += bodyB->inverseInertia*MathCrossVector2(radiusB, impulseV); + } + + // Apply friction impulse to each physics body + radiusV.x = bodyB->velocity.x + MathCross(bodyB->angularVelocity, radiusB).x - bodyA->velocity.x - MathCross(bodyA->angularVelocity, radiusA).x; + radiusV.y = bodyB->velocity.y + MathCross(bodyB->angularVelocity, radiusB).y - bodyA->velocity.y - MathCross(bodyA->angularVelocity, radiusA).y; + + Vector2 tangent = { radiusV.x - (manifold->normal.x*MathDot(radiusV, manifold->normal)), radiusV.y - (manifold->normal.y*MathDot(radiusV, manifold->normal)) }; + MathNormalize(&tangent); + + // Calculate impulse tangent magnitude + float impulseTangent = -MathDot(radiusV, tangent); + impulseTangent /= inverseMassSum; + impulseTangent /= (float)manifold->contactsCount; + + float absImpulseTangent = fabs(impulseTangent); + + // Don't apply tiny friction impulses + if (absImpulseTangent <= PHYSAC_EPSILON) return; + + // Apply coulumb's law + Vector2 tangentImpulse = { 0 }; + if (absImpulseTangent < impulse*manifold->staticFriction) tangentImpulse = (Vector2){ tangent.x*impulseTangent, tangent.y*impulseTangent }; + else tangentImpulse = (Vector2){ tangent.x*-impulse*manifold->dynamicFriction, tangent.y*-impulse*manifold->dynamicFriction }; + + // Apply friction impulse + if (bodyA->enabled) + { + bodyA->velocity.x += bodyA->inverseMass*(-tangentImpulse.x); + bodyA->velocity.y += bodyA->inverseMass*(-tangentImpulse.y); + + if (!bodyA->freezeOrient) bodyA->angularVelocity += bodyA->inverseInertia*MathCrossVector2(radiusA, (Vector2){ -tangentImpulse.x, -tangentImpulse.y }); + } + + if (bodyB->enabled) + { + bodyB->velocity.x += bodyB->inverseMass*(tangentImpulse.x); + bodyB->velocity.y += bodyB->inverseMass*(tangentImpulse.y); + + if (!bodyB->freezeOrient) bodyB->angularVelocity += bodyB->inverseInertia*MathCrossVector2(radiusB, tangentImpulse); + } + } +} + +// Integrates physics velocity into position and forces +static void IntegratePhysicsVelocity(PhysicsBody body) +{ + if (!body->enabled) return; + + body->position.x += body->velocity.x*deltaTime; + body->position.y += body->velocity.y*deltaTime; + + if (!body->freezeOrient) body->orient += body->angularVelocity*deltaTime; + Mat2Set(&body->shape.vertexData.transform, body->orient); + + IntegratePhysicsForces(body); +} + +// Corrects physics bodies positions based on manifolds collision information +static void CorrectPhysicsPositions(PhysicsManifold manifold) +{ + PhysicsBody bodyA = manifold->bodyA; + PhysicsBody bodyB = manifold->bodyB; + + Vector2 correction = { 0 }; + correction.x = (max(manifold->penetration - PHYSAC_PENETRATION_ALLOWANCE, 0)/(bodyA->inverseMass + bodyB->inverseMass))*manifold->normal.x*PHYSAC_PENETRATION_CORRECTION; + correction.y = (max(manifold->penetration - PHYSAC_PENETRATION_ALLOWANCE, 0)/(bodyA->inverseMass + bodyB->inverseMass))*manifold->normal.y*PHYSAC_PENETRATION_CORRECTION; + + if (bodyA->enabled) + { + bodyA->position.x -= correction.x*bodyA->inverseMass; + bodyA->position.y -= correction.y*bodyA->inverseMass; + } + + if (bodyB->enabled) + { + bodyB->position.x += correction.x*bodyB->inverseMass; + bodyB->position.y += correction.y*bodyB->inverseMass; + } +} + +// Returns the extreme point along a direction within a polygon +static Vector2 GetSupport(PhysicsShape shape, Vector2 dir) +{ + float bestProjection = -PHYSAC_FLT_MAX; + Vector2 bestVertex = { 0 }; + PolygonData data = shape.vertexData; + + for (int i = 0; i < data.vertexCount; i++) + { + Vector2 vertex = data.vertices[i]; + float projection = MathDot(vertex, dir); + + if (projection > bestProjection) + { + bestVertex = vertex; + bestProjection = projection; + } + } + + return bestVertex; +} + +// Finds polygon shapes axis least penetration +static float FindAxisLeastPenetration(int *faceIndex, PhysicsShape shapeA, PhysicsShape shapeB) +{ + float bestDistance = -PHYSAC_FLT_MAX; + int bestIndex = 0; + + PolygonData dataA = shapeA.vertexData; + PolygonData dataB = shapeB.vertexData; + + for (int i = 0; i < dataA.vertexCount; i++) + { + // Retrieve a face normal from A shape + Vector2 normal = dataA.normals[i]; + Vector2 transNormal = Mat2MultiplyVector2(dataA.transform, normal); + + // Transform face normal into B shape's model space + Mat2 buT = Mat2Transpose(dataB.transform); + normal = Mat2MultiplyVector2(buT, transNormal); + + // Retrieve support point from B shape along -n + Vector2 support = GetSupport(shapeB, (Vector2){ -normal.x, -normal.y }); + + // Retrieve vertex on face from A shape, transform into B shape's model space + Vector2 vertex = dataA.vertices[i]; + vertex = Mat2MultiplyVector2(dataA.transform, vertex); + vertex = Vector2Add(vertex, shapeA.body->position); + vertex = Vector2Subtract(vertex, shapeB.body->position); + vertex = Mat2MultiplyVector2(buT, vertex); + + // Compute penetration distance in B shape's model space + float distance = MathDot(normal, Vector2Subtract(support, vertex)); + + // Store greatest distance + if (distance > bestDistance) + { + bestDistance = distance; + bestIndex = i; + } + } + + *faceIndex = bestIndex; + return bestDistance; +} + +// Finds two polygon shapes incident face +static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, PhysicsShape inc, int index) +{ + PolygonData refData = ref.vertexData; + PolygonData incData = inc.vertexData; + + Vector2 referenceNormal = refData.normals[index]; + + // Calculate normal in incident's frame of reference + referenceNormal = Mat2MultiplyVector2(refData.transform, referenceNormal); // To world space + referenceNormal = Mat2MultiplyVector2(Mat2Transpose(incData.transform), referenceNormal); // To incident's model space + + // Find most anti-normal face on polygon + int incidentFace = 0; + float minDot = PHYSAC_FLT_MAX; + + for (int i = 0; i < incData.vertexCount; i++) + { + float dot = MathDot(referenceNormal, incData.normals[i]); + + if (dot < minDot) + { + minDot = dot; + incidentFace = i; + } + } + + // Assign face vertices for incident face + *v0 = Mat2MultiplyVector2(incData.transform, incData.vertices[incidentFace]); + *v0 = Vector2Add(*v0, inc.body->position); + incidentFace = (((incidentFace + 1) < incData.vertexCount) ? (incidentFace + 1) : 0); + *v1 = Mat2MultiplyVector2(incData.transform, incData.vertices[incidentFace]); + *v1 = Vector2Add(*v1, inc.body->position); +} + +// Calculates clipping based on a normal and two faces +static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB) +{ + int sp = 0; + Vector2 out[2] = { *faceA, *faceB }; + + // Retrieve distances from each endpoint to the line + float distanceA = MathDot(normal, *faceA) - clip; + float distanceB = MathDot(normal, *faceB) - clip; + + // If negative (behind plane) + if (distanceA <= 0) out[sp++] = *faceA; + if (distanceB <= 0) out[sp++] = *faceB; + + // If the points are on different sides of the plane + if ((distanceA*distanceB) < 0) + { + // Push intersection point + float alpha = distanceA/(distanceA - distanceB); + out[sp] = *faceA; + Vector2 delta = Vector2Subtract(*faceB, *faceA); + delta.x *= alpha; + delta.y *= alpha; + out[sp] = Vector2Add(out[sp], delta); + sp++; + } + + // Assign the new converted values + *faceA = out[0]; + *faceB = out[1]; + + return sp; +} + +// Check if values are between bias range +static bool BiasGreaterThan(float valueA, float valueB) +{ + return (valueA >= (valueB*0.95f + valueA*0.01f)); +} + +// Returns the barycenter of a triangle given by 3 points +static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3) +{ + Vector2 result = { 0 }; + + result.x = (v1.x + v2.x + v3.x)/3; + result.y = (v1.y + v2.y + v3.y)/3; + + return result; +} + +// Initializes hi-resolution timer +static void InitTimer(void) +{ + srand(time(NULL)); // Initialize random seed + + #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) + struct timespec now; + if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) baseTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; + #endif + + startTime = GetCurrentTime(); +} + +// Get current time in milliseconds +static double GetCurrentTime(void) +{ + double time = 0; + + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) + unsigned long long int clockFrequency, currentTime; + + QueryPerformanceFrequency(&clockFrequency); + QueryPerformanceCounter(¤tTime); + + time = (double)((double)currentTime/clockFrequency)*1000; + #endif + + #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec; + + time = (double)((double)(temp - baseTime)*1e-6); + #endif + + return time; +} + +// Returns a random number between min and max (both included) +static int GetRandomNumber(int min, int max) +{ + if (min > max) + { + int tmp = max; + max = min; + min = tmp; + } + + return (rand()%(abs(max - min) + 1) + min); +} + +// Clamp a value in a range +static inline void MathClamp(double *value, double min, double max) +{ + if (*value < min) *value = min; + else if (*value > max) *value = max; +} + +// Returns the cross product of a vector and a value +static inline Vector2 MathCross(float value, Vector2 vector) +{ + return (Vector2){ -value*vector.y, value*vector.x }; +} + +// Returns the cross product of two vectors +static inline float MathCrossVector2(Vector2 v1, Vector2 v2) +{ + return (v1.x*v2.y - v1.y*v2.x); +} + +// Returns the len square root of a vector +static inline float MathLenSqr(Vector2 vector) +{ + return (vector.x*vector.x + vector.y*vector.y); +} + +// Returns the dot product of two vectors +static inline float MathDot(Vector2 v1, Vector2 v2) +{ + return (v1.x*v2.x + v1.y*v2.y); +} + +// Returns the square root of distance between two vectors +static inline float DistSqr(Vector2 v1, Vector2 v2) +{ + Vector2 dir = Vector2Subtract(v1, v2); + return MathDot(dir, dir); +} + +// Returns the normalized values of a vector +static void MathNormalize(Vector2 *vector) +{ + float length, ilength; + + Vector2 aux = *vector; + length = sqrtf(aux.x*aux.x + aux.y*aux.y); + + if (length == 0) length = 1.0f; + + ilength = 1.0f/length; + + vector->x *= ilength; + vector->y *= ilength; +} + +// Returns the sum of two given vectors +static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2) +{ + return (Vector2){ v1.x + v2.x, v1.y + v2.y }; +} + +// Returns the subtract of two given vectors +static inline Vector2 Vector2Subtract(Vector2 v1, Vector2 v2) +{ + return (Vector2){ v1.x - v2.x, v1.y - v2.y }; +} + +// Creates a matrix 2x2 from a given radians value +static inline Mat2 Mat2Radians(float radians) +{ + float c = cosf(radians); + float s = sinf(radians); + + return (Mat2){ c, -s, s, c }; +} + +// Set values from radians to a created matrix 2x2 +static void Mat2Set(Mat2 *matrix, float radians) +{ + float cos = cosf(radians); + float sin = sinf(radians); + + matrix->m00 = cos; + matrix->m01 = -sin; + matrix->m10 = sin; + matrix->m11 = cos; +} + +// Returns the transpose of a given matrix 2x2 +static inline Mat2 Mat2Transpose(Mat2 matrix) +{ + return (Mat2){ matrix.m00, matrix.m10, matrix.m01, matrix.m11 }; +} + +// Multiplies a vector by a matrix 2x2 +static inline Vector2 Mat2MultiplyVector2(Mat2 matrix, Vector2 vector) +{ + return (Vector2){ matrix.m00*vector.x + matrix.m01*vector.y, matrix.m10*vector.x + matrix.m11*vector.y }; +} + +#endif // PHYSAC_IMPLEMENTATION diff --git a/src/raylib.h b/src/raylib.h index f62433041..d28b07a35 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -6,37 +6,39 @@ * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -305,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -725,7 +724,7 @@ RLAPI float GetGesturePinchAngle(void); // Get gesture pin //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -RLAPI void SetCameraMode(Camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) @@ -803,7 +802,7 @@ RLAPI void ImageColorInvert(Image *image); RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -RLAPI void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode @@ -836,7 +835,7 @@ RLAPI const char *SubText(const char *text, int position, int length); // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -RLAPI void DrawCircle3D(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires @@ -851,7 +850,7 @@ RLAPI void DrawRay(Ray ray, Color color); RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo RLAPI void DrawLight(Light light); // Draw light in 3D world -//DrawTorus(), DrawTeapot() are useless... +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) @@ -918,7 +917,7 @@ RLAPI void DestroyLight(Light light); // Des //------------------------------------------------------------------------------------ RLAPI void InitVrDevice(int vdDevice); // Init VR device RLAPI void CloseVrDevice(void); // Close VR device -RLAPI bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) @@ -927,7 +926,7 @@ RLAPI void ToggleVrMode(void); // Enable/Disable VR experienc // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ RLAPI void InitAudioDevice(void); // Initialize audio device and context -RLAPI void CloseAudioDevice(void); // Close the audio device and context (and music stream) +RLAPI void CloseAudioDevice(void); // Close the audio device and context RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM @@ -951,9 +950,9 @@ RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file RLAPI void UnloadMusicStream(Music music); // Unload music stream -RLAPI void PlayMusicStream(Music music); // Start music playing (open stream) +RLAPI void PlayMusicStream(Music music); // Start music playing RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming -RLAPI void StopMusicStream(Music music); // Stop music playing (close stream) +RLAPI void StopMusicStream(Music music); // Stop music playing RLAPI void PauseMusicStream(Music music); // Pause music playing RLAPI void ResumeMusicStream(Music music); // Resume playing paused music RLAPI bool IsMusicPlaying(Music music); // Check if music is playing @@ -964,7 +963,7 @@ RLAPI float GetMusicTimePlayed(Music music); // Get cur RLAPI AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, - unsigned int channels); // Init audio stream (to stream audio pcm data) + unsigned int channels); // Init audio stream (to stream raw audio pcm data) RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill diff --git a/src/resources b/src/resources index e0fe66ba5..5c76749d0 100644 Binary files a/src/resources and b/src/resources differ diff --git a/src/rlgl.c b/src/rlgl.c index d3bba07b0..629d79674 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -2,11 +2,30 @@ * * rlgl - raylib OpenGL abstraction layer * -* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version: -* OpenGL 1.1 - Direct map rl* -> gl* -* OpenGL 2.1 - Vertex data is stored in VBOs, call rlglDraw() to render -* OpenGL 3.3 - Vertex data is stored in VAOs, call rlglDraw() to render -* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render +* rlgl allows usage of OpenGL 1.1 style functions (rlVertex) that are internally mapped to +* selected OpenGL version (1.1, 2.1, 3.3 Core, ES 2.0). +* +* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal +* VBO buffers (and VAOs if available). It requires calling 3 functions: +* rlglInit() - Initialize internal buffers and auxiliar resources +* rlglDraw() - Process internal buffers and send required draw calls +* rlglClose() - De-initialize internal buffers data and other auxiliar resources +* +* External libs: +* raymath - 3D math functionality (Vector3, Matrix, Quaternion) +* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only) +* +* Module Configuration Flags: +* GRAPHICS_API_OPENGL_11 - Use OpenGL 1.1 backend +* GRAPHICS_API_OPENGL_21 - Use OpenGL 2.1 backend +* GRAPHICS_API_OPENGL_33 - Use OpenGL 3.3 Core profile backend +* GRAPHICS_API_OPENGL_ES2 - Use OpenGL ES 2.0 backend +* +* RLGL_STANDALONE - Use rlgl as standalone library (no raylib dependency) +* RLGL_NO_STANDARD_SHADER - Avoid standard shader (shader_standard.h) inclusion +* RLGL_NO_DISTORTION_SHADER - Avoid stereo rendering distortion sahder (shader_distortion.h) inclusion +* RLGL_OCULUS_SUPPORT - Enable Oculus Rift CV1 functionality +* * * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * @@ -1700,15 +1719,15 @@ void rlglUpdateTexture(unsigned int id, int width, int height, int format, void } // Generate mipmap data for selected texture -void rlglGenerateMipmaps(Texture2D texture) +void rlglGenerateMipmaps(Texture2D *texture) { - glBindTexture(GL_TEXTURE_2D, texture.id); + glBindTexture(GL_TEXTURE_2D, texture->id); // Check if texture is power-of-two (POT) bool texIsPOT = false; - if (((texture.width > 0) && ((texture.width & (texture.width - 1)) == 0)) && - ((texture.height > 0) && ((texture.height & (texture.height - 1)) == 0))) texIsPOT = true; + if (((texture->width > 0) && ((texture->width & (texture->width - 1)) == 0)) && + ((texture->height > 0) && ((texture->height & (texture->height - 1)) == 0))) texIsPOT = true; if ((texIsPOT) || (npotSupported)) { @@ -1718,13 +1737,13 @@ void rlglGenerateMipmaps(Texture2D texture) // NOTE: data size is reallocated to fit mipmaps data // NOTE: CPU mipmap generation only supports RGBA 32bit data - int mipmapCount = GenerateMipmaps(data, texture.width, texture.height); + int mipmapCount = GenerateMipmaps(data, texture->width, texture->height); - int size = texture.width*texture.height*4; // RGBA 32bit only + int size = texture->width*texture->height*4; // RGBA 32bit only int offset = size; - int mipWidth = texture.width/2; - int mipHeight = texture.height/2; + int mipWidth = texture->width/2; + int mipHeight = texture->height/2; // Load the mipmaps for (int level = 1; level < mipmapCount; level++) @@ -1738,23 +1757,29 @@ void rlglGenerateMipmaps(Texture2D texture) mipHeight /= 2; } - TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture.id); + TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture->id); // NOTE: Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data free(data); + texture->mipmaps = mipmapCount + 1; #endif #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically - TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", texture.id); + TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", texture->id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps (must be available) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps + + #define MIN(a,b) (((a)<(b))?(a):(b)) + #define MAX(a,b) (((a)>(b))?(a):(b)) + + texture->mipmaps = 1 + floor(log2(MAX(texture->width, texture->height))); #endif } - else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", texture.id); + else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", texture->id); glBindTexture(GL_TEXTURE_2D, 0); } @@ -2767,13 +2792,13 @@ void CloseVrDevice(void) // Detect if VR device is available bool IsVrDeviceReady(void) { - return (vrDeviceReady || vrSimulator) && vrEnabled; + return (vrDeviceReady && vrEnabled); } // Detect if VR simulator is running bool IsVrSimulator(void) { - return vrSimulator; + return (vrSimulator && vrEnabled); } // Enable/Disable VR experience (device or simulator) diff --git a/src/rlgl.h b/src/rlgl.h index 9be73f363..bc12db0f9 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -2,11 +2,27 @@ * * rlgl - raylib OpenGL abstraction layer * -* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version: -* OpenGL 1.1 - Direct map rl* -> gl* -* OpenGL 2.1 - Vertex data is stored in VBOs, call rlglDraw() to render -* OpenGL 3.3 - Vertex data is stored in VAOs, call rlglDraw() to render -* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render +* rlgl allows usage of OpenGL 1.1 style functions (rlVertex) that are internally mapped to +* selected OpenGL version (1.1, 2.1, 3.3 Core, ES 2.0). +* +* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal +* VBO buffers (and VAOs if available). It requires calling 3 functions: +* rlglInit() - Initialize internal buffers and auxiliar resources +* rlglDraw() - Process internal buffers and send required draw calls +* rlglClose() - De-initialize internal buffers data and other auxiliar resources +* +* External libs: +* raymath - 3D math functionality (Vector3, Matrix, Quaternion) +* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only) +* +* Module Configuration Flags: +* GRAPHICS_API_OPENGL_11 - Use OpenGL 1.1 backend +* GRAPHICS_API_OPENGL_21 - Use OpenGL 2.1 backend +* GRAPHICS_API_OPENGL_33 - Use OpenGL 3.3 Core profile backend +* GRAPHICS_API_OPENGL_ES2 - Use OpenGL ES 2.0 backend +* +* RLGL_STANDALONE - Use rlgl as standalone library (no raylib dependency) +* * * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * @@ -117,15 +133,14 @@ typedef enum { RL_PROJECTION, RL_MODELVIEW, RL_TEXTURE } MatrixMode; typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode; +typedef unsigned char byte; + #if defined(RLGL_STANDALONE) #ifndef __cplusplus // Boolean type typedef enum { false, true } bool; #endif - // byte type - typedef unsigned char byte; - // Color type, RGBA (32bit) typedef struct Color { unsigned char r; @@ -356,7 +371,7 @@ void rlglLoadExtensions(void *loader); // Load OpenGL extensions unsigned int rlglLoadTexture(void *data, int width, int height, int textureFormat, int mipmapCount); // Load texture in GPU RenderTexture2D rlglLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments) void rlglUpdateTexture(unsigned int id, int width, int height, int format, void *data); // Update GPU texture with new data -void rlglGenerateMipmaps(Texture2D texture); // Generate mipmap data for selected texture +void rlglGenerateMipmaps(Texture2D *texture); // Generate mipmap data for selected texture void rlglLoadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update vertex data on GPU (upload new data to one buffer) @@ -408,7 +423,8 @@ float *MatrixToFloat(Matrix mat); void InitVrDevice(int vrDevice); // Init VR device void CloseVrDevice(void); // Close VR device -bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready +bool IsVrDeviceReady(void); // Detect if VR device is ready +bool IsVrSimulator(void); // Detect if VR simulator is running void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) diff --git a/src/rlua.h b/src/rlua.h index 97d229221..961ed1c10 100644 --- a/src/rlua.h +++ b/src/rlua.h @@ -1095,14 +1095,14 @@ int lua_IsFileDropped(lua_State* L) int lua_GetDroppedFiles(lua_State* L) { int count = 0; - char ** result = GetDroppedFiles(&count); + char ** result = GetDroppedFiles(&count); lua_createtable(L, count, 0); for (int i = 0; i < count; i++) { lua_pushstring(L, result[i]); lua_rawseti(L, -2, i + 1); } - return 1; + return 1; } int lua_ClearDroppedFiles(lua_State* L) @@ -1130,7 +1130,6 @@ int lua_StorageLoadValue(lua_State* L) //------------------------------------------------------------------------------------ // raylib [core] module functions - Input Handling //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) int lua_IsKeyPressed(lua_State* L) { int arg1 = LuaGetArgument_int(L, 1); @@ -1185,12 +1184,22 @@ int lua_IsGamepadAvailable(lua_State* L) return 1; } -int lua_GetGamepadAxisMovement(lua_State* L) +int lua_IsGamepadName(lua_State* L) { int arg1 = LuaGetArgument_int(L, 1); - int arg2 = LuaGetArgument_int(L, 2); - float result = GetGamepadAxisMovement(arg1, arg2); - lua_pushnumber(L, result); + const char * arg2 = LuaGetArgument_string(L, 2); + bool result = IsGamepadName(arg1, arg2); + lua_pushboolean(L, result); + return 1; +} + +int lua_GetGamepadName(lua_State* L) +{ + // TODO: Return gamepad name id + + int arg1 = LuaGetArgument_int(L, 1); + char * result = GetGamepadName(arg1); + //lua_pushboolean(L, result); return 1; } @@ -1229,7 +1238,30 @@ int lua_IsGamepadButtonUp(lua_State* L) lua_pushboolean(L, result); return 1; } -#endif + +int lua_GetGamepadButtonPressed(lua_State* L) +{ + int result = GetGamepadButtonPressed(); + lua_pushinteger(L, result); + return 1; +} + +int lua_GetGamepadAxisCount(lua_State* L) +{ + int arg1 = LuaGetArgument_int(L, 1); + int result = GetGamepadAxisCount(arg1); + lua_pushinteger(L, result); + return 1; +} + +int lua_GetGamepadAxisMovement(lua_State* L) +{ + int arg1 = LuaGetArgument_int(L, 1); + int arg2 = LuaGetArgument_int(L, 2); + float result = GetGamepadAxisMovement(arg1, arg2); + lua_pushnumber(L, result); + return 1; +} int lua_IsMouseButtonPressed(lua_State* L) { @@ -1419,8 +1451,9 @@ int lua_GetGesturePinchAngle(lua_State* L) //------------------------------------------------------------------------------------ int lua_SetCameraMode(lua_State* L) { - int arg1 = LuaGetArgument_int(L, 1); - SetCameraMode(arg1); + Camera arg1 = LuaGetArgument_Camera(L, 1); + int arg2 = LuaGetArgument_int(L, 2); + SetCameraMode(arg1, arg2); return 0; } @@ -1432,37 +1465,6 @@ int lua_UpdateCamera(lua_State* L) return 1; } -int lua_UpdateCameraPlayer(lua_State* L) -{ - Camera arg1 = LuaGetArgument_Camera(L, 1); - Vector3 arg2 = LuaGetArgument_Vector3(L, 2); - UpdateCameraPlayer(&arg1, &arg2); - LuaPush_Camera(L, arg1); - LuaPush_Vector3(L, arg2); - return 2; -} - -int lua_SetCameraPosition(lua_State* L) -{ - Vector3 arg1 = LuaGetArgument_Vector3(L, 1); - SetCameraPosition(arg1); - return 0; -} - -int lua_SetCameraTarget(lua_State* L) -{ - Vector3 arg1 = LuaGetArgument_Vector3(L, 1); - SetCameraTarget(arg1); - return 0; -} - -int lua_SetCameraFovy(lua_State* L) -{ - float arg1 = LuaGetArgument_float(L, 1); - SetCameraFovy(arg1); - return 0; -} - int lua_SetCameraPanControl(lua_State* L) { int arg1 = LuaGetArgument_int(L, 1); @@ -1496,13 +1498,6 @@ int lua_SetCameraMoveControls(lua_State* L) return 0; } -int lua_SetCameraMouseSensitivity(lua_State* L) -{ - float arg1 = LuaGetArgument_float(L, 1); - SetCameraMouseSensitivity(arg1); - return 0; -} - //------------------------------------------------------------------------------------ // raylib [shapes] module functions - Basic Shapes Drawing //------------------------------------------------------------------------------------ @@ -1790,6 +1785,8 @@ int lua_LoadImage(lua_State* L) int lua_LoadImageEx(lua_State* L) { + // TODO: Image LoadImageEx(Color *pixels, int width, int height); + GET_TABLE(Color, arg1, 1); int arg2 = LuaGetArgument_int(L, 2); int arg3 = LuaGetArgument_int(L, 3); @@ -1888,6 +1885,8 @@ int lua_UnloadRenderTexture(lua_State* L) int lua_GetImageData(lua_State* L) { + // TODO: Color *GetImageData(Image image); + Image arg1 = LuaGetArgument_Image(L, 1); Color * result = GetImageData(arg1); lua_createtable(L, arg1.width*arg1.height, 0); @@ -1908,6 +1907,16 @@ int lua_GetTextureData(lua_State* L) return 1; } +int lua_UpdateTexture(lua_State* L) +{ + // TODO: void UpdateTexture(Texture2D texture, void *pixels); + + Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); + void * arg2 = (char *)LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string? + UpdateTexture(arg1, arg2); // ISSUE: #2 string expected, got table -> GetImageData() returns a table! + return 0; +} + int lua_ImageToPOT(lua_State* L) { Image arg1 = LuaGetArgument_Image(L, 1); @@ -2096,15 +2105,24 @@ int lua_ImageColorBrightness(lua_State* L) int lua_GenTextureMipmaps(lua_State* L) { Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); - GenTextureMipmaps(arg1); + GenTextureMipmaps(&arg1); + LuaPush_Texture2D(L, arg1); + return 1; +} + +int lua_SetTextureFilter(lua_State* L) +{ + Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); + int arg2 = LuaGetArgument_int(L, 2); + SetTextureFilter(arg1, arg2); return 0; } -int lua_UpdateTexture(lua_State* L) +int lua_SetTextureWrap(lua_State* L) { Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); - void * arg2 = (char *)LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string? - UpdateTexture(arg1, arg2); // ISSUE: #2 string expected, got table -> GetImageData() returns a table! + int arg2 = LuaGetArgument_int(L, 2); + SetTextureWrap(arg1, arg2); return 0; } @@ -2178,6 +2196,18 @@ int lua_LoadSpriteFont(lua_State* L) return 1; } +int lua_LoadSpriteFontTTF(lua_State* L) +{ + const char * arg1 = LuaGetArgument_string(L, 1); + int arg2 = LuaGetArgument_int(L, 2); + int arg3 = LuaGetArgument_int(L, 3); + int arg4 = LuaGetArgument_int(L, 4); + //LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); + SpriteFont result = LoadSpriteFontTTF(arg1, arg2, arg3, &arg4); + LuaPush_SpriteFont(L, result); + return 1; +} + int lua_UnloadSpriteFont(lua_State* L) { SpriteFont arg1 = LuaGetArgument_SpriteFont(L, 1); @@ -2255,8 +2285,8 @@ int lua_DrawCircle3D(lua_State* L) { Vector3 arg1 = LuaGetArgument_Vector3(L, 1); float arg2 = LuaGetArgument_float(L, 2); - float arg3 = LuaGetArgument_float(L, 3); - Vector3 arg4 = LuaGetArgument_Vector3(L, 4); + Vector3 arg3 = LuaGetArgument_Vector3(L, 3); + float arg4 = LuaGetArgument_float(L, 4); Color arg5 = LuaGetArgument_Color(L, 5); DrawCircle3D(arg1, arg2, arg3, arg4, arg5); return 0; @@ -2619,18 +2649,6 @@ int lua_CheckCollisionRayBox(lua_State* L) return 1; } -int lua_ResolveCollisionCubicmap(lua_State* L) -{ - Image arg1 = LuaGetArgument_Image(L, 1); - Vector3 arg2 = LuaGetArgument_Vector3(L, 2); - Vector3 arg3 = LuaGetArgument_Vector3(L, 3); - float arg4 = LuaGetArgument_float(L, 4); - Vector3 result = ResolveCollisionCubicmap(arg1, arg2, &arg3, arg4); - LuaPush_Vector3(L, result); - LuaPush_Vector3(L, arg3); - return 2; -} - //------------------------------------------------------------------------------------ // raylib [raymath] module functions - Shaders //------------------------------------------------------------------------------------ @@ -2790,10 +2808,19 @@ int lua_IsVrDeviceReady(lua_State* L) return 1; } +int lua_IsVrSimulator(lua_State* L) +{ + bool result = IsVrSimulator(); + lua_pushboolean(L, result); + return 1; +} + int lua_UpdateVrTracking(lua_State* L) { - UpdateVrTracking(); - return 0; + Camera arg1 = LuaGetArgument_Camera(L, 1); + UpdateVrTracking(&arg1); + LuaPush_Camera(L, arg1); + return 1; } int lua_ToggleVrMode(lua_State* L) @@ -2873,6 +2900,8 @@ int lua_LoadSoundFromRES(lua_State* L) int lua_UpdateSound(lua_State* L) { + // TODO: void UpdateSound(Sound sound, void *data, int numSamples); + Sound arg1 = LuaGetArgument_Sound(L, 1); const char * arg2 = LuaGetArgument_string(L, 2); int * arg3 = LuaGetArgument_int(L, 3); @@ -2952,11 +2981,11 @@ int lua_WaveFormat(lua_State* L) int arg2 = LuaGetArgument_int(L, 2); int arg3 = LuaGetArgument_int(L, 3); int arg4 = LuaGetArgument_int(L, 4); - WaveFormat(arg1, arg2, arg3, arg4); + WaveFormat(&arg1, arg2, arg3, arg4); return 0; } -int lua_LoadMusicStream(lua_State* L) +int lua_WaveCopy(lua_State* L) { Wave arg1 = LuaGetArgument_Wave(L, 1); Wave result = WaveCopy(arg1); @@ -2969,7 +2998,7 @@ int lua_WaveCrop(lua_State* L) Wave arg1 = LuaGetArgument_Wave(L, 1); int arg2 = LuaGetArgument_int(L, 2); int arg3 = LuaGetArgument_int(L, 3); - WaveCrop(arg1, arg2, arg3); + WaveCrop(&arg1, arg2, arg3); return 0; } @@ -2978,9 +3007,10 @@ int lua_GetWaveData(lua_State* L) // TODO: float *GetWaveData(Wave wave); Wave arg1 = LuaGetArgument_Wave(L, 1); - float result = GetWaveData(arg1); - LuaPush_float(L, result); - return 1; + float * result = GetWaveData(arg1); + //LuaPush_float(L, result); + //lua_pushnumber(L, result); + return 0; } int lua_LoadMusicStream(lua_State* L) @@ -3012,7 +3042,6 @@ int lua_PlayMusicStream(lua_State* L) return 0; } - int lua_StopMusicStream(lua_State* L) { Music arg1 = LuaGetArgument_Music(L, 1); @@ -3093,6 +3122,8 @@ int lua_CloseAudioStream(lua_State* L) int lua_UpdateAudioStream(lua_State* L) { + // TODO: void UpdateAudioStream(AudioStream stream, void *data, int numSamples); + AudioStream arg1 = LuaGetArgument_AudioStream(L, 1); void * arg2 = (char *)LuaGetArgument_string(L, 2); int arg3 = LuaGetArgument_int(L, 3); @@ -3667,7 +3698,6 @@ static luaL_Reg raylib_functions[] = { REG(StorageSaveValue) REG(StorageLoadValue) -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) REG(IsKeyPressed) REG(IsKeyDown) REG(IsKeyReleased) @@ -3676,12 +3706,15 @@ static luaL_Reg raylib_functions[] = { REG(SetExitKey) REG(IsGamepadAvailable) - REG(GetGamepadAxisMovement) + REG(IsGamepadName) + REG(GetGamepadName) REG(IsGamepadButtonPressed) REG(IsGamepadButtonDown) REG(IsGamepadButtonReleased) REG(IsGamepadButtonUp) -#endif + REG(GetGamepadButtonPressed) + REG(GetGamepadAxisCount) + REG(GetGamepadAxisMovement) REG(IsMouseButtonPressed) REG(IsMouseButtonDown) @@ -3714,16 +3747,10 @@ static luaL_Reg raylib_functions[] = { REG(SetCameraMode) REG(UpdateCamera) - REG(UpdateCameraPlayer) - REG(SetCameraPosition) - REG(SetCameraTarget) - REG(SetCameraFovy) - REG(SetCameraPanControl) REG(SetCameraAltControl) REG(SetCameraSmoothZoomControl) REG(SetCameraMoveControls) - REG(SetCameraMouseSensitivity) REG(DrawPixel) REG(DrawPixelV) @@ -3766,6 +3793,7 @@ static luaL_Reg raylib_functions[] = { REG(UnloadRenderTexture) REG(GetImageData) REG(GetTextureData) + REG(UpdateTexture) REG(ImageToPOT) REG(ImageFormat) REG(ImageDither) @@ -3786,8 +3814,9 @@ static luaL_Reg raylib_functions[] = { REG(ImageColorContrast) REG(ImageColorBrightness) REG(GenTextureMipmaps) - REG(UpdateTexture) - + REG(SetTextureFilter) + REG(SetTextureWrap) + REG(DrawTexture) REG(DrawTextureV) REG(DrawTextureEx) @@ -3796,6 +3825,7 @@ static luaL_Reg raylib_functions[] = { REG(GetDefaultFont) REG(LoadSpriteFont) + REG(LoadSpriteFontTTF) REG(UnloadSpriteFont) REG(DrawText) REG(DrawTextEx) @@ -3845,7 +3875,6 @@ static luaL_Reg raylib_functions[] = { REG(CheckCollisionRaySphere) REG(CheckCollisionRaySphereEx) REG(CheckCollisionRayBox) - REG(ResolveCollisionCubicmap) REG(LoadShader) REG(UnloadShader) @@ -3868,6 +3897,7 @@ static luaL_Reg raylib_functions[] = { REG(InitVrDevice) REG(CloseVrDevice) REG(IsVrDeviceReady) + REG(IsVrSimulator) REG(UpdateVrTracking) REG(ToggleVrMode) @@ -4067,24 +4097,36 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("RIGHT_BUTTON", 1); LuaSetEnum("MIDDLE_BUTTON", 2); LuaEndEnum("MOUSE"); - + LuaStartEnum(); LuaSetEnum("PLAYER1", 0); LuaSetEnum("PLAYER2", 1); LuaSetEnum("PLAYER3", 2); LuaSetEnum("PLAYER4", 3); - LuaSetEnum("PS3_BUTTON_A", 2); - LuaSetEnum("PS3_BUTTON_B", 1); - LuaSetEnum("PS3_BUTTON_X", 3); - LuaSetEnum("PS3_BUTTON_Y", 4); - LuaSetEnum("PS3_BUTTON_R1", 7); - LuaSetEnum("PS3_BUTTON_R2", 5); + LuaSetEnum("PS3_BUTTON_TRIANGLE", 0); + LuaSetEnum("PS3_BUTTON_CIRCLE", 1); + LuaSetEnum("PS3_BUTTON_CROSS", 2); + LuaSetEnum("PS3_BUTTON_SQUARE", 3); LuaSetEnum("PS3_BUTTON_L1", 6); - LuaSetEnum("PS3_BUTTON_L2", 8); + LuaSetEnum("PS3_BUTTON_R1", 7); + LuaSetEnum("PS3_BUTTON_L2", 4); + LuaSetEnum("PS3_BUTTON_R2", 5); + LuaSetEnum("PS3_BUTTON_START", 8); LuaSetEnum("PS3_BUTTON_SELECT", 9); - LuaSetEnum("PS3_BUTTON_START", 10); + LuaSetEnum("PS3_BUTTON_UP", 24); + LuaSetEnum("PS3_BUTTON_RIGHT", 25); + LuaSetEnum("PS3_BUTTON_DOWN", 26); + LuaSetEnum("PS3_BUTTON_LEFT", 27); + LuaSetEnum("PS3_BUTTON_PS", 12); + LuaSetEnum("PS3_AXIS_LEFT_X", 0); + LuaSetEnum("PS3_AXIS_LEFT_Y", 1); + LuaSetEnum("PS3_AXIS_RIGHT_X", 2); + LuaSetEnum("PS3_AXIS_RIGHT_Y", 5); + LuaSetEnum("PS3_AXIS_L2", 3); // [1..-1] (pressure-level) + LuaSetEnum("PS3_AXIS_R2", 4); // [1..-1] (pressure-level) +// Xbox360 USB Controller Buttons LuaSetEnum("XBOX_BUTTON_A", 0); LuaSetEnum("XBOX_BUTTON_B", 1); LuaSetEnum("XBOX_BUTTON_X", 2); @@ -4093,25 +4135,26 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("XBOX_BUTTON_RB", 5); LuaSetEnum("XBOX_BUTTON_SELECT", 6); LuaSetEnum("XBOX_BUTTON_START", 7); - -#if defined(PLATFORM_RPI) - LuaSetEnum("XBOX_AXIS_DPAD_X", 7); - LuaSetEnum("XBOX_AXIS_DPAD_Y", 6); - LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); - LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4); - LuaSetEnum("XBOX_AXIS_LT", 2); - LuaSetEnum("XBOX_AXIS_RT", 5); -#else LuaSetEnum("XBOX_BUTTON_UP", 10); + LuaSetEnum("XBOX_BUTTON_RIGHT", 11); LuaSetEnum("XBOX_BUTTON_DOWN", 12); LuaSetEnum("XBOX_BUTTON_LEFT", 13); - LuaSetEnum("XBOX_BUTTON_RIGHT", 11); - LuaSetEnum("XBOX_AXIS_RIGHT_X", 4); - LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3); - LuaSetEnum("XBOX_AXIS_LT_RT", 2); + LuaSetEnum("XBOX_BUTTON_HOME", 8); +#if defined(PLATFORM_RPI) + LuaSetEnum("XBOX_AXIS_LEFT_X", 0); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); // [-1..1] (up->down) + LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4); // [-1..1] (up->down) + LuaSetEnum("XBOX_AXIS_LT", 2); // [-1..1] (pressure-level) + LuaSetEnum("XBOX_AXIS_RT", 5); // [-1..1] (pressure-level) +#else + LuaSetEnum("XBOX_AXIS_LEFT_X", 0); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); // [1..-1] (up->down) + LuaSetEnum("XBOX_AXIS_RIGHT_X", 2); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3); // [1..-1] (up->down) + LuaSetEnum("XBOX_AXIS_LT", 4); // [-1..1] (pressure-level) + LuaSetEnum("XBOX_AXIS_RT", 5); // [-1..1] (pressure-level) #endif - LuaSetEnum("XBOX_AXIS_LEFT_X", 0); - LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); LuaEndEnum("GAMEPAD"); lua_pushglobaltable(L); @@ -4175,6 +4218,15 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("DIRECTIONAL", LIGHT_DIRECTIONAL); LuaSetEnum("SPOT", LIGHT_SPOT); LuaEndEnum("LightType"); + + LuaStartEnum(); + LuaSetEnum("POINT", FILTER_POINT); + LuaSetEnum("BILINEAR", FILTER_BILINEAR); + LuaSetEnum("TRILINEAR", FILTER_TRILINEAR); + LuaSetEnum("ANISOTROPIC_4X", FILTER_ANISOTROPIC_4X); + LuaSetEnum("ANISOTROPIC_8X", FILTER_ANISOTROPIC_8X); + LuaSetEnum("ANISOTROPIC_16X", FILTER_ANISOTROPIC_16X); + LuaEndEnum("TextureFilter"); LuaStartEnum(); LuaSetEnum("NONE", GESTURE_NONE); diff --git a/src/shapes.c b/src/shapes.c index 79cf567a4..70aad59ac 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -4,6 +4,12 @@ * * Basic functions to draw 2d Shapes and check collisions * +* External libs: +* rlgl - raylib OpenGL abstraction layer +* +* Module Configuration Flags: +* ... +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -25,11 +31,11 @@ #include "raylib.h" +#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 + #include // Required for: abs() #include // Required for: sinf(), cosf(), sqrtf() -#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2 - //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- diff --git a/src/text.c b/src/text.c index 72d273d41..c394889ec 100644 --- a/src/text.c +++ b/src/text.c @@ -4,6 +4,12 @@ * * Basic functions to load SpriteFonts and draw Text * +* External libs: +* stb_truetype - Load TTF file and rasterize characters data +* +* Module Configuration Flags: +* ... +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -33,7 +39,7 @@ #include "utils.h" // Required for: GetExtension(), GetNextPOT() // Following libs are used on LoadTTF() -//#define STBTT_STATIC +#define STBTT_STATIC // Define stb_truetype functions static to this module #define STB_TRUETYPE_IMPLEMENTATION #include "external/stb_truetype.h" // Required for: stbtt_BakeFontBitmap() @@ -869,10 +875,18 @@ static SpriteFont LoadBMFont(const char *fileName) TraceLog(DEBUG, "[%s] Font texture loading path: %s", fileName, texPath); Image imFont = LoadImage(texPath); + + if (imFont.format == UNCOMPRESSED_GRAYSCALE) + { + Image imCopy = ImageCopy(imFont); + + for (int i = 0; i < imCopy.width*imCopy.height; i++) ((unsigned char *)imCopy.data)[i] = 0xff; // WHITE pixel - if (imFont.format == UNCOMPRESSED_GRAYSCALE) ImageAlphaMask(&imFont, imFont); - - font.texture = LoadTextureFromImage(imFont); + ImageAlphaMask(&imCopy, imFont); + font.texture = LoadTextureFromImage(imCopy); + UnloadImage(imCopy); + } + else font.texture = LoadTextureFromImage(imFont); font.size = fontSize; font.numChars = numChars; diff --git a/src/textures.c b/src/textures.c index 5354a74fe..126adad36 100644 --- a/src/textures.c +++ b/src/textures.c @@ -4,9 +4,13 @@ * * Basic functions to load and draw Textures (2d) * -* Uses external lib: -* stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC) -* NOTE: stb_image has been slightly modified, original library: https://github.com/nothings/stb +* External libs: +* stb_image - Multiple image formats loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC) +* NOTE: stb_image has been slightly modified to support Android platform. +* stb_image_resize - Multiple image resize algorythms +* +* Module Configuration Flags: +* ... * * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * @@ -1512,14 +1516,14 @@ void ImageColorBrightness(Image *image, int brightness) } // Generate GPU mipmaps for a texture -void GenTextureMipmaps(Texture2D texture) +void GenTextureMipmaps(Texture2D *texture) { #if PLATFORM_WEB - int potWidth = GetNextPOT(texture.width); - int potHeight = GetNextPOT(texture.height); + int potWidth = GetNextPOT(texture->width); + int potHeight = GetNextPOT(texture->height); // Check if texture is POT - if ((potWidth != texture.width) || (potHeight != texture.height)) + if ((potWidth != texture->width) || (potHeight != texture->height)) { TraceLog(WARNING, "Limited NPOT support, no mipmaps available for NPOT textures"); } diff --git a/src/utils.c b/src/utils.c index b96e2c70a..640c57205 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2,12 +2,16 @@ * * raylib.utils * -* Utils Functions Definitions +* Some utility functions * -* Uses external libs: -* tinfl - zlib DEFLATE algorithm decompression lib +* External libs: +* tinfl - zlib DEFLATE algorithm decompression * stb_image_write - PNG writting functions * +* Module Configuration Flags: +* DO_NOT_TRACE_DEBUG_MSGS - Avoid showing DEBUG TraceLog() messages +* +* * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event @@ -46,7 +50,9 @@ #endif #include "external/tinfl.c" // Required for: tinfl_decompress_mem_to_mem() - // NOTE: Deflate algorythm data decompression + // NOTE: DEFLATE algorythm data decompression + +#define DO_NOT_TRACE_DEBUG_MSGS // Avoid DEBUG messages tracing //---------------------------------------------------------------------------------- // Global Variables Definition diff --git a/src/utils.h b/src/utils.h index 899cf5836..045b0692c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -2,9 +2,9 @@ * * raylib.utils * -* Some utility functions: rRES files data decompression +* Some utility functions * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -34,8 +34,6 @@ //---------------------------------------------------------------------------------- // Some basic Defines //---------------------------------------------------------------------------------- -#define DO_NOT_TRACE_DEBUG_MSGS // Use this define to avoid DEBUG tracing - #if defined(PLATFORM_ANDROID) #define fopen(name, mode) android_fopen(name, mode) #endif diff --git a/templates/android_project/jni/basic_game.c b/templates/android_project/jni/basic_game.c index 4e8bef31e..c801cbaa8 100644 --- a/templates/android_project/jni/basic_game.c +++ b/templates/android_project/jni/basic_game.c @@ -37,14 +37,13 @@ void android_main(struct android_app *app) InitAudioDevice(); // Initialize audio device - Sound fx = LoadSound("coin.wav"); // Load WAV audio file (placed on assets folder) - Texture2D texture = LoadTexture("raylib_logo.png"); // Load texture (placed on assets folder) - int framesCounter = 0; // Used to count frames - + Sound fx = LoadSound("coin.wav"); // Load WAV audio file (placed on assets folder) Music ambient = LoadMusicStream("ambient.ogg"); PlayMusicStream(ambient); + + int framesCounter = 0; // Used to count frames SetTargetFPS(60); // Not required on Android, already locked to 60 fps //-------------------------------------------------------------------------------------- diff --git a/templates/android_project/jni/include/raylib.h b/templates/android_project/jni/include/raylib.h index 68cddc5aa..d28b07a35 100644 --- a/templates/android_project/jni/include/raylib.h +++ b/templates/android_project/jni/include/raylib.h @@ -6,37 +6,39 @@ * * Features: * Library written in plain C code (C99) -* Uses C# PascalCase/camelCase notation +* Uses PascalCase/camelCase notation * Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) * Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) * Multiple textures support, including compressed formats and mipmaps generation * Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps * Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support -* Powerful math module for Vector, Matrix and Quaternion operations [raymath] -* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD) +* Powerful math module for Vector, Matrix and Quaternion operations: [raymath] +* Audio loading and playing with streaming support and mixing channels [audio] * VR stereo rendering support with configurable HMD device parameters * Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1 * Custom color palette for fancy visuals on raywhite background * Minimal external dependencies (GLFW3, OpenGL, OpenAL) +* Complete binding for LUA [rlua] * -* Used external libs: -* GLFW3 (www.glfw.org) for window/context management and input -* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) -* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) -* stb_image_write (Sean Barret) for image writting (PNG) -* stb_vorbis (Sean Barret) for ogg audio loading -* stb_truetype (Sean Barret) for ttf fonts loading -* jar_xm (Joshua Reisenauer) for XM audio module loading -* jar_mod (Joshua Reisenauer) for MOD audio module loading -* OpenAL Soft for audio device/context management -* tinfl for data decompression (DEFLATE algorithm) +* External libs: +* GLFW3 (www.glfw.org) for window/context management and input [core] +* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] +* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] +* stb_image_write (Sean Barret) for image writting (PNG) [utils] +* stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_vorbis (Sean Barret) for ogg audio loading [audio] +* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] +* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] +* dr_flac (David Reid) for FLAC audio file loading [audio] +* OpenAL Soft for audio device/context management [audio] +* tinfl for data decompression (DEFLATE algorithm) [utils] * * Some design decisions: * 32bit Colors - All defined color are always RGBA (struct Color is 4 byte) -* One custom default font is loaded automatically when InitWindow() +* One custom default font could be loaded automatically when InitWindow() [core] * If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads -* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined) +* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined) * * -- LICENSE -- * @@ -77,10 +79,6 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) -#endif - #if defined(_WIN32) && defined(BUILDING_DLL) #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL #elif defined(_WIN32) && defined(RAYLIB_DLL) @@ -93,7 +91,7 @@ // Some basic Defines //---------------------------------------------------------------------------------- #ifndef PI - #define PI 3.14159265358979323846 + #define PI 3.14159265358979323846f #endif #define DEG2RAD (PI/180.0f) @@ -101,11 +99,12 @@ // raylib Config Flags #define FLAG_FULLSCREEN_MODE 1 -#define FLAG_SHOW_LOGO 2 -#define FLAG_SHOW_MOUSE_CURSOR 4 -#define FLAG_CENTERED_MODE 8 -#define FLAG_MSAA_4X_HINT 16 -#define FLAG_VSYNC_HINT 32 +#define FLAG_RESIZABLE_WINDOW 2 +#define FLAG_SHOW_LOGO 4 +#define FLAG_SHOW_MOUSE_CURSOR 8 +#define FLAG_CENTERED_MODE 16 +#define FLAG_MSAA_4X_HINT 32 +#define FLAG_VSYNC_HINT 64 // Keyboard Function Keys #define KEY_SPACE 32 @@ -173,15 +172,18 @@ #define KEY_Y 89 #define KEY_Z 90 +#if defined(PLATFORM_ANDROID) + // Android Physical Buttons + #define KEY_BACK 4 + #define KEY_MENU 82 + #define KEY_VOLUME_UP 24 + #define KEY_VOLUME_DOWN 25 +#endif + // Mouse Buttons #define MOUSE_LEFT_BUTTON 0 -#if defined(PLATFORM_WEB) - #define MOUSE_RIGHT_BUTTON 2 - #define MOUSE_MIDDLE_BUTTON 1 -#else - #define MOUSE_RIGHT_BUTTON 1 - #define MOUSE_MIDDLE_BUTTON 2 -#endif +#define MOUSE_RIGHT_BUTTON 1 +#define MOUSE_MIDDLE_BUTTON 2 // Touch points registered #define MAX_TOUCH_POINTS 2 @@ -189,24 +191,35 @@ // Gamepad Number #define GAMEPAD_PLAYER1 0 #define GAMEPAD_PLAYER2 1 -#define GAMEPAD_PLAYER3 2 // Not supported -#define GAMEPAD_PLAYER4 3 // Not supported +#define GAMEPAD_PLAYER3 2 +#define GAMEPAD_PLAYER4 3 -// Gamepad Buttons +// Gamepad Buttons/Axis -// PS3 USB Controller -#define GAMEPAD_PS3_BUTTON_A 2 -#define GAMEPAD_PS3_BUTTON_B 1 -#define GAMEPAD_PS3_BUTTON_X 3 -#define GAMEPAD_PS3_BUTTON_Y 4 -#define GAMEPAD_PS3_BUTTON_R1 7 -#define GAMEPAD_PS3_BUTTON_R2 5 +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 #define GAMEPAD_PS3_BUTTON_L1 6 -#define GAMEPAD_PS3_BUTTON_L2 8 +#define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 +#define GAMEPAD_PS3_BUTTON_R2 5 +#define GAMEPAD_PS3_BUTTON_START 8 #define GAMEPAD_PS3_BUTTON_SELECT 9 -#define GAMEPAD_PS3_BUTTON_START 10 +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 -// TODO: Add PS3 d-pad axis +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -217,33 +230,30 @@ #define GAMEPAD_XBOX_BUTTON_RB 5 #define GAMEPAD_XBOX_BUTTON_SELECT 6 #define GAMEPAD_XBOX_BUTTON_START 7 +#define GAMEPAD_XBOX_BUTTON_UP 10 +#define GAMEPAD_XBOX_BUTTON_RIGHT 11 +#define GAMEPAD_XBOX_BUTTON_DOWN 12 +#define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 8 +// Xbox360 USB Controller Axis +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #else - #define GAMEPAD_XBOX_BUTTON_UP 10 - #define GAMEPAD_XBOX_BUTTON_DOWN 12 - #define GAMEPAD_XBOX_BUTTON_LEFT 13 - #define GAMEPAD_XBOX_BUTTON_RIGHT 11 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 - -// Android Physic Buttons -#define ANDROID_BACK 4 -#define ANDROID_MENU 82 -#define ANDROID_VOLUME_UP 24 -#define ANDROID_VOLUME_DOWN 25 - // NOTE: MSC C++ compiler does not support compound literals (C99 feature) // Plain structures in C++ (without constructors) can be initialized from { } initializers. #ifdef __cplusplus @@ -297,9 +307,6 @@ #endif #endif -// byte type -typedef unsigned char byte; - // Vector2 type typedef struct Vector2 { float x; @@ -427,7 +434,9 @@ typedef struct Shader { // Uniform locations int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader) - int tintColorLoc; // Diffuse color uniform location point (fragment shader) + int colDiffuseLoc; // Diffuse color uniform location point (fragment shader) + int colAmbientLoc; // Ambient color uniform location point (fragment shader) + int colSpecularLoc; // Specular color uniform location point (fragment shader) // Texture map locations (generic for any kind of map) int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0) @@ -464,7 +473,7 @@ typedef struct LightData { int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT Vector3 position; // Light position - Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) + Vector3 target; // Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) float radius; // Light attenuation radius light intensity reduced with distance (world distance) Color diffuse; // Light diffuse color @@ -482,12 +491,6 @@ typedef struct Ray { Vector3 direction; // Ray direction } Ray; -// Sound source type -typedef struct Sound { - unsigned int source; // OpenAL audio source id - unsigned int buffer; // OpenAL audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { unsigned int sampleCount; // Number of samples @@ -497,6 +500,13 @@ typedef struct Wave { void *data; // Buffer data pointer } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + // Music type (file streaming from memory) // NOTE: Anything longer than ~10 seconds should be streamed typedef struct MusicData *Music; @@ -536,6 +546,21 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +// NOTE 1: Filtering considers mipmaps if available in the texture +// NOTE 2: Filter is accordingly set for minification and magnification +typedef enum { + FILTER_POINT = 0, // No filter, just pixel aproximation + FILTER_BILINEAR, // Linear filtering + FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x +} TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -556,7 +581,13 @@ typedef enum { } Gestures; // Camera system modes -typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; +typedef enum { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON +} CameraMode; // Head Mounted Display devices typedef enum { @@ -584,7 +615,7 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -RLAPI void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif @@ -596,11 +627,13 @@ RLAPI void ToggleFullscreen(void); // Fullscreen RLAPI int GetScreenWidth(void); // Get current screen width RLAPI int GetScreenHeight(void); // Get current screen height +#if !defined(PLATFORM_ANDROID) RLAPI void ShowCursor(void); // Shows cursor RLAPI void HideCursor(void); // Hides cursor RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible RLAPI void EnableCursor(void); // Enables cursor RLAPI void DisableCursor(void); // Disables cursor +#endif RLAPI void ClearBackground(Color color); // Sets Background Color RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing @@ -643,7 +676,6 @@ RLAPI int StorageLoadValue(int position); // Storage loa //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) //------------------------------------------------------------------------------------ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once @@ -652,12 +684,15 @@ RLAPI int GetKeyPressed(void); // Get latest key RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available -RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) +RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed -#endif +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed @@ -673,12 +708,6 @@ RLAPI int GetTouchX(void); // Returns touch p RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) -#if defined(PLATFORM_ANDROID) -bool IsButtonPressed(int button); // Detect if an android physic button has been pressed -bool IsButtonDown(int button); // Detect if an android physic button is being pressed -bool IsButtonReleased(int button); // Detect if an android physic button has been released -#endif - //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ @@ -695,22 +724,15 @@ RLAPI float GetGesturePinchAngle(void); // Get gesture pin //------------------------------------------------------------------------------------ // Camera System Functions (Module: camera) //------------------------------------------------------------------------------------ -RLAPI void SetCameraMode(int mode); // Set camera mode (multiple camera modes available) -RLAPI void UpdateCamera(Camera *camera); // Update camera (player position is ignored) -RLAPI void UpdateCameraPlayer(Camera *camera, Vector3 *position); // Update camera and player position (1st person and 3rd person cameras) - -RLAPI void SetCameraPosition(Vector3 position); // Set internal camera position -RLAPI void SetCameraTarget(Vector3 target); // Set internal camera target -RLAPI void SetCameraFovy(float fovy); // Set internal camera field-of-view-y +RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) +RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) - RLAPI void SetCameraMoveControls(int frontKey, int backKey, - int leftKey, int rightKey, - int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) -RLAPI void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras) + int rightKey, int leftKey, + int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras) //------------------------------------------------------------------------------------ // Basic Shapes Drawing Functions (Module: shapes) @@ -759,8 +781,10 @@ RLAPI void UnloadTexture(Texture2D texture); RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format +RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle @@ -778,8 +802,9 @@ RLAPI void ImageColorInvert(Image *image); RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) -RLAPI void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 @@ -793,13 +818,14 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest //------------------------------------------------------------------------------------ RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory +RLAPI SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars); // Load a SpriteFont from TTF font with parameters RLAPI void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters float fontSize, int spacing, Color tint); RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font -RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont +RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' @@ -809,7 +835,7 @@ RLAPI const char *SubText(const char *text, int position, int length); // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space -RLAPI void DrawCircle3D(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space +RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires @@ -824,7 +850,7 @@ RLAPI void DrawRay(Ray ray, Color color); RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0)) RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo RLAPI void DrawLight(Light light); // Draw light in 3D world -//DrawTorus(), DrawTeapot() are useless... +//DrawTorus(), DrawTeapot() could be useful? //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) @@ -836,9 +862,7 @@ RLAPI Model LoadHeightmap(Image heightmap, Vector3 size); // Load a RLAPI Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based) RLAPI void UnloadModel(Model model); // Unload 3d model from memory -RLAPI Mesh GenMeshCube(float width, float height, float depth); // Generate mesh: cube - -RLAPI Material LoadMaterial(const char *fileName); // Load material data (from file) +RLAPI Material LoadMaterial(const char *fileName); // Load material data (.MTL) RLAPI Material LoadDefaultMaterial(void); // Load default material (uses default models shader) RLAPI Material LoadStandardMaterial(void); // Load standard material (uses material attributes and lighting shader) RLAPI void UnloadMaterial(Material material); // Unload material textures from VRAM @@ -859,8 +883,7 @@ RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box -RLAPI Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap - // NOTE: Return the normal vector of the impacted surface + //------------------------------------------------------------------------------------ // Shaders System Functions (Module: rlgl) // NOTE: This functions are useless when using OpenGL 1.1 @@ -894,20 +917,25 @@ RLAPI void DestroyLight(Light light); // Des //------------------------------------------------------------------------------------ RLAPI void InitVrDevice(int vdDevice); // Init VR device RLAPI void CloseVrDevice(void); // Close VR device -RLAPI bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready -RLAPI void UpdateVrTracking(void); // Update VR tracking (position and orientation) +RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready +RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running +RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator) //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) //------------------------------------------------------------------------------------ RLAPI void InitAudioDevice(void); // Initialize audio device and context -RLAPI void CloseAudioDevice(void); // Close the audio device and context (and music stream) +RLAPI void CloseAudioDevice(void); // Close the audio device and context RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -RLAPI Sound LoadSound(char *fileName); // Load sound to memory +RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM +RLAPI Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +RLAPI Sound LoadSound(const char *fileName); // Load sound to memory RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data RLAPI Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) +RLAPI void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +RLAPI void UnloadWave(Wave wave); // Unload wave data RLAPI void UnloadSound(Sound sound); // Unload sound RLAPI void PlaySound(Sound sound); // Play a sound RLAPI void PauseSound(Sound sound); // Pause a sound @@ -916,12 +944,15 @@ RLAPI void StopSound(Sound sound); // Stop pl RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) - -RLAPI Music LoadMusicStream(char *fileName); // Load music stream from file +RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave +RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file RLAPI void UnloadMusicStream(Music music); // Unload music stream -RLAPI void PlayMusicStream(Music music); // Start music playing (open stream) +RLAPI void PlayMusicStream(Music music); // Start music playing RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming -RLAPI void StopMusicStream(Music music); // Stop music playing (close stream) +RLAPI void StopMusicStream(Music music); // Stop music playing RLAPI void PauseMusicStream(Music music); // Pause music playing RLAPI void ResumeMusicStream(Music music); // Resume playing paused music RLAPI bool IsMusicPlaying(Music music); // Check if music is playing @@ -932,7 +963,7 @@ RLAPI float GetMusicTimePlayed(Music music); // Get cur RLAPI AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, - unsigned int channels); // Init audio stream (to stream audio pcm data) + unsigned int channels); // Init audio stream (to stream raw audio pcm data) RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill diff --git a/templates/android_project/jni/libs/libraylib.a b/templates/android_project/jni/libs/libraylib.a index 24344d0ce..39975a6ba 100644 Binary files a/templates/android_project/jni/libs/libraylib.a and b/templates/android_project/jni/libs/libraylib.a differ