aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2016-11-24 17:26:07 +0100
committerGitHub <noreply@github.com>2016-11-24 17:26:07 +0100
commit17f09cb03484a408cdd50a3d2e4d6604bb1f4c70 (patch)
tree51e909c419de9625f1beaaca44696857a600e8d5 /examples
parent05f68c22d5c8d8f7c4254ae47700318e21709887 (diff)
parenta81dfabf863c512044b246e23aaf43489d2fa1ac (diff)
downloadraylib-17f09cb03484a408cdd50a3d2e4d6604bb1f4c70.tar.gz
raylib-17f09cb03484a408cdd50a3d2e4d6604bb1f4c70.zip
Merge pull request #198 from raysan5/develop
Develop branch integration
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile54
-rw-r--r--examples/audio_module_playing.c35
-rw-r--r--examples/audio_module_playing.lua31
-rw-r--r--examples/audio_module_playing.pngbin215508 -> 47970 bytes
-rw-r--r--examples/audio_raw_stream.pngbin0 -> 16736 bytes
-rw-r--r--examples/audio_standalone.c12
-rw-r--r--examples/core_3d_camera_first_person.lua11
-rw-r--r--examples/core_3d_camera_free.lua11
-rw-r--r--examples/core_3d_picking.lua8
-rw-r--r--examples/core_drop_files.c2
-rw-r--r--examples/core_input_gamepad.lua134
-rw-r--r--examples/core_input_gamepad.pngbin10840 -> 38066 bytes
-rw-r--r--examples/core_oculus_rift.c6
-rw-r--r--examples/core_world_screen.lua7
-rw-r--r--examples/models_billboard.lua9
-rw-r--r--examples/models_cubicmap.lua8
-rw-r--r--examples/models_heightmap.lua7
-rw-r--r--examples/physics_basic_rigidbody.c135
-rw-r--r--examples/physics_basic_rigidbody.pngbin15294 -> 0 bytes
-rw-r--r--examples/physics_demo.c122
-rw-r--r--examples/physics_demo.pngbin0 -> 23466 bytes
-rw-r--r--examples/physics_forces.c193
-rw-r--r--examples/physics_forces.pngbin17935 -> 0 bytes
-rw-r--r--examples/physics_friction.c136
-rw-r--r--examples/physics_friction.pngbin0 -> 18150 bytes
-rw-r--r--examples/physics_movement.c122
-rw-r--r--examples/physics_movement.pngbin0 -> 15947 bytes
-rw-r--r--examples/physics_restitution.c115
-rw-r--r--examples/physics_restitution.pngbin0 -> 17833 bytes
-rw-r--r--examples/physics_shatter.c107
-rw-r--r--examples/physics_shatter.pngbin0 -> 23197 bytes
-rw-r--r--examples/resources/fonts/KAISG.ttfbin0 -> 79912 bytes
-rw-r--r--examples/resources/fonts/pixantiqua.fnt188
-rw-r--r--examples/resources/fonts/pixantiqua_0.pngbin0 -> 4531 bytes
-rw-r--r--examples/rlua_execute_file.c9
-rw-r--r--examples/shaders_custom_uniform.lua14
-rw-r--r--examples/shaders_model_shader.c4
-rw-r--r--examples/shaders_model_shader.lua6
-rw-r--r--examples/shaders_postprocessing.lua10
-rw-r--r--examples/shaders_standard_lighting.lua10
-rw-r--r--examples/text_bmfont_unordered.c65
-rw-r--r--examples/text_bmfont_unordered.lua57
-rw-r--r--examples/text_bmfont_unordered.pngbin0 -> 18713 bytes
-rw-r--r--examples/text_ttf_loading.c130
-rw-r--r--examples/text_ttf_loading.lua118
-rw-r--r--examples/text_ttf_loading.pngbin0 -> 55588 bytes
46 files changed, 1400 insertions, 476 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 378f5edf..710e97c4 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 7da3579c..a9ee4619 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 3c5ad641..7c675424 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)
-
- 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)
+ ClearBackground(RAYWHITE)
- 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 7c2e469f..8bde9879 100644
--- a/examples/audio_module_playing.png
+++ b/examples/audio_module_playing.png
Binary files differ
diff --git a/examples/audio_raw_stream.png b/examples/audio_raw_stream.png
new file mode 100644
index 00000000..344f4a71
--- /dev/null
+++ b/examples/audio_raw_stream.png
Binary files differ
diff --git a/examples/audio_standalone.c b/examples/audio_standalone.c
index c716faed..7688b881 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 800c3c2a..22ccdc5c 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 244aad6b..57fa7a12 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 1adee67c..230f5756 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 5eea35f3..5c1501b8 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 78d9b84e..ade3f00f 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)
+
+ 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)
- DrawCircleV(ballPosition, 50, MAROON)
+ -- 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 f7e55658..5996eece 100644
--- a/examples/core_input_gamepad.png
+++ b/examples/core_input_gamepad.png
Binary files differ
diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c
index 7276e3de..eb628cd7 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 51f2cdbf..48b617dd 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 457198e6..9d81f6ce 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 bae3bac2..79faafc9 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 4240f8b7..efcbfb4b 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 87316a98..00000000
--- 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 52f265ac..00000000
--- a/examples/physics_basic_rigidbody.png
+++ /dev/null
Binary files differ
diff --git a/examples/physics_demo.c b/examples/physics_demo.c
new file mode 100644
index 00000000..bed7c94d
--- /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 00000000..12dc7e72
--- /dev/null
+++ b/examples/physics_demo.png
Binary files differ
diff --git a/examples/physics_forces.c b/examples/physics_forces.c
deleted file mode 100644
index e45cb44c..00000000
--- 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 832bdbd9..00000000
--- a/examples/physics_forces.png
+++ /dev/null
Binary files differ
diff --git a/examples/physics_friction.c b/examples/physics_friction.c
new file mode 100644
index 00000000..28d3c4b8
--- /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 00000000..e791ec2b
--- /dev/null
+++ b/examples/physics_friction.png
Binary files differ
diff --git a/examples/physics_movement.c b/examples/physics_movement.c
new file mode 100644
index 00000000..ca18f3df
--- /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 00000000..a88a7d79
--- /dev/null
+++ b/examples/physics_movement.png
Binary files differ
diff --git a/examples/physics_restitution.c b/examples/physics_restitution.c
new file mode 100644
index 00000000..3543db69
--- /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 00000000..8ec4b3f3
--- /dev/null
+++ b/examples/physics_restitution.png
Binary files differ
diff --git a/examples/physics_shatter.c b/examples/physics_shatter.c
new file mode 100644
index 00000000..2cb9d195
--- /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 00000000..68f9a1b7
--- /dev/null
+++ b/examples/physics_shatter.png
Binary files differ
diff --git a/examples/resources/fonts/KAISG.ttf b/examples/resources/fonts/KAISG.ttf
new file mode 100644
index 00000000..04478b25
--- /dev/null
+++ b/examples/resources/fonts/KAISG.ttf
Binary files differ
diff --git a/examples/resources/fonts/pixantiqua.fnt b/examples/resources/fonts/pixantiqua.fnt
new file mode 100644
index 00000000..971b9b0b
--- /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 00000000..2aa2870f
--- /dev/null
+++ b/examples/resources/fonts/pixantiqua_0.png
Binary files differ
diff --git a/examples/rlua_execute_file.c b/examples/rlua_execute_file.c
index 71720313..a91ce42f 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 3a8bbae5..dafd3b84 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 26de4922..51e9c1b3 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 d1436a7e..38f0fd30 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 f20f31ec..7dfac816 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 2f3700ff..1d4dcfcf 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 00000000..b29c5f8b
--- /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 00000000..f324ca19
--- /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 00000000..c6767567
--- /dev/null
+++ b/examples/text_bmfont_unordered.png
Binary files differ
diff --git a/examples/text_ttf_loading.c b/examples/text_ttf_loading.c
new file mode 100644
index 00000000..918209dd
--- /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 00000000..26443212
--- /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 00000000..29ea263a
--- /dev/null
+++ b/examples/text_ttf_loading.png
Binary files differ