aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorvictorfisac <victorfisac@gmail.com>2016-02-26 14:28:05 +0100
committervictorfisac <victorfisac@gmail.com>2016-02-26 14:28:05 +0100
commit68088bc5be39beff4f9997fe0966ce30054f67c1 (patch)
treeef7a773a5cd69193abce4e635dc1555cbd9ad9b7 /examples
parent233f7611da96ea6bc0b7c62f6a06dacef707f9d7 (diff)
parent0dfc7fffff68b0bfafd30a86fb322073daf7fc0e (diff)
downloadraylib-68088bc5be39beff4f9997fe0966ce30054f67c1.tar.gz
raylib-68088bc5be39beff4f9997fe0966ce30054f67c1.zip
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'examples')
-rw-r--r--examples/core_3d_camera_first_person.c2
-rw-r--r--examples/core_3d_camera_free.c8
-rw-r--r--examples/core_3d_camera_free.pngbin25106 -> 25167 bytes
-rw-r--r--examples/core_3d_mode.c6
-rw-r--r--examples/core_3d_picking.c5
-rw-r--r--examples/core_3d_picking.pngbin23100 -> 24383 bytes
-rw-r--r--examples/core_gestures_detection.c115
-rw-r--r--examples/core_gestures_detection.pngbin0 -> 19480 bytes
-rw-r--r--examples/core_input_mouse.c14
-rw-r--r--examples/core_storage_values.c2
-rw-r--r--examples/makefile66
-rw-r--r--examples/models_billboard.pngbin53998 -> 54859 bytes
-rw-r--r--examples/models_heightmap.c16
-rw-r--r--examples/models_heightmap.pngbin123602 -> 96976 bytes
-rw-r--r--examples/physics_basic_rigidbody.c44
-rw-r--r--examples/physics_rigidbody_force.c33
-rw-r--r--examples/resources/cat.pngbin0 -> 388532 bytes
-rw-r--r--examples/resources/fonts/bmfont.fnt99
-rw-r--r--examples/resources/fonts/bmfont.pngbin0 -> 14471 bytes
-rw-r--r--examples/resources/fonts/pixantiqua.ttfbin0 -> 35408 bytes
-rw-r--r--examples/resources/parrots.pngbin0 -> 295054 bytes
-rw-r--r--examples/resources/shaders/phong.vs2
-rw-r--r--examples/resources/shaders/shapes_base.vs2
-rw-r--r--examples/resources/shaders/shapes_grayscale.fs2
-rw-r--r--examples/shaders_basic_lighting.c31
-rw-r--r--examples/shapes_logo_raylib_anim.c30
-rw-r--r--examples/text_bmfont_ttf.c68
-rw-r--r--examples/text_bmfont_ttf.pngbin0 -> 19542 bytes
-rw-r--r--examples/text_writing_anim.c60
-rw-r--r--examples/text_writing_anim.pngbin0 -> 15773 bytes
-rw-r--r--examples/textures_formats_loading.pngbin79031 -> 125797 bytes
-rw-r--r--examples/textures_image_drawing.c78
-rw-r--r--examples/textures_image_drawing.pngbin0 -> 420135 bytes
-rw-r--r--examples/textures_image_processing.c154
-rw-r--r--examples/textures_image_processing.pngbin0 -> 259470 bytes
-rw-r--r--examples/textures_srcrec_dstrec.c4
36 files changed, 715 insertions, 126 deletions
diff --git a/examples/core_3d_camera_first_person.c b/examples/core_3d_camera_first_person.c
index 8a092275..2b8dc7fc 100644
--- a/examples/core_3d_camera_first_person.c
+++ b/examples/core_3d_camera_first_person.c
@@ -22,7 +22,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
- // Define the camera to look into our 3d world
+ // Define the camera to look into our 3d world (position, target, up vector)
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
// Generates some random columns
diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c
index df1b480c..4b45373d 100644
--- a/examples/core_3d_camera_free.c
+++ b/examples/core_3d_camera_free.c
@@ -22,10 +22,10 @@ int main()
// Define the camera to look into our 3d world
Camera camera;
- camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
- camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
- camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
-
+ camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
SetCameraMode(CAMERA_FREE); // Set a free camera mode
diff --git a/examples/core_3d_camera_free.png b/examples/core_3d_camera_free.png
index afb5a7c5..17920620 100644
--- a/examples/core_3d_camera_free.png
+++ b/examples/core_3d_camera_free.png
Binary files differ
diff --git a/examples/core_3d_mode.c b/examples/core_3d_mode.c
index 40415fea..7be5dd45 100644
--- a/examples/core_3d_mode.c
+++ b/examples/core_3d_mode.c
@@ -22,9 +22,9 @@ int main()
// Define the camera to look into our 3d world
Camera camera;
- camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
- camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
- camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c
index 9a6cc138..fdf77030 100644
--- a/examples/core_3d_picking.c
+++ b/examples/core_3d_picking.c
@@ -21,7 +21,10 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// Define the camera to look into our 3d world
- Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
+ Camera camera;
+ camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
diff --git a/examples/core_3d_picking.png b/examples/core_3d_picking.png
index 828c41a8..bb7660b0 100644
--- a/examples/core_3d_picking.png
+++ b/examples/core_3d_picking.png
Binary files differ
diff --git a/examples/core_gestures_detection.c b/examples/core_gestures_detection.c
new file mode 100644
index 00000000..b69497c5
--- /dev/null
+++ b/examples/core_gestures_detection.c
@@ -0,0 +1,115 @@
+/*******************************************************************************************
+*
+* raylib [core] example - Gestures Detection
+*
+* 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"
+#include <string.h>
+
+#define MAX_GESTURE_STRINGS 20
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
+
+ Vector2 touchPosition = { 0, 0 };
+ Rectangle touchArea = { 220, 10, screenWidth - 230, screenHeight - 20 };
+
+ int gesturesCount = 0;
+ char gestureStrings[MAX_GESTURE_STRINGS][32];
+
+ int currentGesture = GESTURE_NONE;
+ int lastGesture = GESTURE_NONE;
+
+ //SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
+
+ SetTargetFPS(30);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ lastGesture = currentGesture;
+ touchPosition = GetTouchPosition(0);
+
+ if (CheckCollisionPointRec(touchPosition, touchArea) && IsGestureDetected())
+ {
+ currentGesture = GetGestureType();
+
+ if (currentGesture != lastGesture)
+ {
+ // Store gesture string
+ switch (currentGesture)
+ {
+ case GESTURE_TAP: strcpy(gestureStrings[gesturesCount], "GESTURE TAP"); break;
+ case GESTURE_DOUBLETAP: strcpy(gestureStrings[gesturesCount], "GESTURE DOUBLETAP"); break;
+ case GESTURE_HOLD: strcpy(gestureStrings[gesturesCount], "GESTURE HOLD"); break;
+ case GESTURE_DRAG: strcpy(gestureStrings[gesturesCount], "GESTURE DRAG"); break;
+ case GESTURE_SWIPE_RIGHT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE RIGHT"); break;
+ case GESTURE_SWIPE_LEFT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE LEFT"); break;
+ case GESTURE_SWIPE_UP: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE UP"); break;
+ case GESTURE_SWIPE_DOWN: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE DOWN"); break;
+ default: break;
+ }
+
+ gesturesCount++;
+
+ // Reset gestures strings
+ if (gesturesCount >= MAX_GESTURE_STRINGS)
+ {
+ for (int i = 0; i < MAX_GESTURE_STRINGS; i++) strcpy(gestureStrings[i], "\0");
+
+ gesturesCount = 0;
+ }
+ }
+ }
+ else currentGesture = GESTURE_NONE;
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawRectangleRec(touchArea, GRAY);
+ DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);
+
+ DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));
+
+ for (int i = 0; i < gesturesCount; i++)
+ {
+ if (i%2 == 0) DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
+ else DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
+
+ if (i < gesturesCount - 1) DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
+ else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
+ }
+
+ DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
+ DrawText("DETECTED GESTURES", 50, 15, 10, GRAY);
+
+ if (currentGesture != GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+} \ No newline at end of file
diff --git a/examples/core_gestures_detection.png b/examples/core_gestures_detection.png
new file mode 100644
index 00000000..d2bbb5d7
--- /dev/null
+++ b/examples/core_gestures_detection.png
Binary files differ
diff --git a/examples/core_input_mouse.c b/examples/core_input_mouse.c
index 358b5fd6..24d2dfcd 100644
--- a/examples/core_input_mouse.c
+++ b/examples/core_input_mouse.c
@@ -21,6 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
Vector2 ballPosition = { -100.0f, -100.0f };
+ Color ballColor = DARKBLUE;
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
@@ -30,10 +31,11 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
- {
- ballPosition = GetMousePosition();
- }
+ ballPosition = GetMousePosition();
+
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
+ else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
+ else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
//----------------------------------------------------------------------------------
// Draw
@@ -42,9 +44,9 @@ int main()
ClearBackground(RAYWHITE);
- DrawCircleV(ballPosition, 40, GOLD);
+ DrawCircleV(ballPosition, 40, ballColor);
- DrawText("mouse click to draw the ball", 10, 10, 20, DARKGRAY);
+ DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/core_storage_values.c b/examples/core_storage_values.c
index 3190d0a0..43f0882f 100644
--- a/examples/core_storage_values.c
+++ b/examples/core_storage_values.c
@@ -5,7 +5,7 @@
* 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) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/makefile b/examples/makefile
index 04dc7756..2a9e88ba 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -85,8 +85,8 @@ else
# external libraries headers
# GLFW3
INCLUDES += -I../external/glfw3/include
-# GLEW
- INCLUDES += -I../external/glew/include
+# GLEW - Not required any more, replaced by GLAD
+ #INCLUDES += -I../external/glew/include
# OpenAL Soft
INCLUDES += -I../external/openal_soft/include
endif
@@ -102,8 +102,8 @@ else
ifneq ($(PLATFORM_OS),OSX)
# OpenAL Soft
LFLAGS += -L../external/openal_soft/lib/$(LIBPATH)
- # GLEW
- LFLAGS += -L../external/glew/lib/$(LIBPATH)
+ # GLEW - Not required any more, replaced by GLAD
+ #LFLAGS += -L../external/glew/lib/$(LIBPATH)
endif
endif
@@ -126,7 +126,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
else
# libraries for Windows desktop compiling
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
- LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32
+ LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32
endif
endif
endif
@@ -161,6 +161,8 @@ EXAMPLES = \
core_random_values \
core_color_select \
core_drop_files \
+ core_storage_values \
+ core_gestures_detection \
core_3d_mode \
core_3d_picking \
core_3d_camera_free \
@@ -177,10 +179,14 @@ EXAMPLES = \
textures_raw_data \
textures_formats_loading \
textures_particles_trail_blending \
+ textures_image_processing \
+ textures_image_drawing \
text_sprite_fonts \
+ text_bmfont_ttf \
text_rbmf_fonts \
text_format_text \
text_font_select \
+ text_writing_anim \
models_geometric_shapes \
models_box_collisions \
models_billboard \
@@ -195,8 +201,6 @@ EXAMPLES = \
audio_music_stream \
fix_dylib \
- #core_input_gamepad \
-
# typing 'make' will invoke the first target entry in the file,
# in this case, the 'default' target entry is raylib
@@ -217,16 +221,24 @@ core_input_keys: core_input_keys.c
core_input_mouse: core_input_mouse.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+# compile [core] example - mouse wheel
+core_mouse_wheel: core_mouse_wheel.c
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+
# compile [core] example - gamepad input
core_input_gamepad: core_input_gamepad.c
-ifeq ($(PLATFORM),PLATFORM_DESKTOP)
+ifeq ($(PLATFORM), $(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_RPI))
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
else
- @echo core_input_gamepad: Only supported on desktop platform
+ @echo core_input_gamepad: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB
endif
-# compile [core] example - mouse wheel
-core_mouse_wheel: core_mouse_wheel.c
+# compile [core] example - generate random values
+core_random_values: core_random_values.c
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+
+# compile [core] example - color selection (collision detection)
+core_color_select: core_color_select.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - drop files
@@ -234,15 +246,19 @@ core_drop_files: core_drop_files.c
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
else
- @echo core_drop_files: Only supported on desktop platform
+ @echo core_drop_files: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB or PLATFORM_RPI
endif
-
-# compile [core] example - generate random values
-core_random_values: core_random_values.c
+
+# compile [core] example - storage values
+core_storage_values: core_storage_values.c
+ifeq ($(PLATFORM), $(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_RPI))
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+else
+ @echo core_storage_values: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB
+endif
-# compile [core] example - color selection (collision detection)
-core_color_select: core_color_select.c
+# compile [core] example - gestures detection
+core_gestures_detection: core_gestures_detection.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [core] example - 3d mode
@@ -309,9 +325,21 @@ textures_formats_loading: textures_formats_loading.c
textures_particles_trail_blending: textures_particles_trail_blending.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+# compile [textures] example - texture image processing
+textures_image_processing: textures_image_processing.c
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+
+# compile [textures] example - texture image drawing
+textures_image_drawing: textures_image_drawing.c
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+
# compile [text] example - sprite fonts loading
text_sprite_fonts: text_sprite_fonts.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+
+# compile [text] example - bmfonts and ttf loading
+text_bmfont_ttf: text_bmfont_ttf.c
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - raylib bitmap fonts (rBMF)
text_rbmf_fonts: text_rbmf_fonts.c
@@ -325,6 +353,10 @@ text_format_text: text_format_text.c
text_font_select: text_font_select.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+# compile [text] example - text writing animation
+text_writing_anim: text_writing_anim.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)
diff --git a/examples/models_billboard.png b/examples/models_billboard.png
index f1ed9239..dad1e55b 100644
--- a/examples/models_billboard.png
+++ b/examples/models_billboard.png
Binary files differ
diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c
index ac578c61..f1da3301 100644
--- a/examples/models_heightmap.c
+++ b/examples/models_heightmap.c
@@ -21,13 +21,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
// Define our custom camera to look into our 3d world
- Camera camera = {{ 24.0f, 18.0f, 24.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
+ Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
- Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
- Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
- Model map = LoadHeightmap(image, 32); // Load heightmap model
- SetModelTexture(&map, texture); // Bind texture to model
- Vector3 mapPosition = { -16.0f, 0.0f, -16.0f }; // Set model position (depends on model scaling!)
+ Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
+ Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
+ Model map = LoadHeightmap(image, (Vector3){ 16, 8, 16 }); // Load heightmap model with defined size
+ SetModelTexture(&map, texture); // Bind texture to model
+ Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
@@ -54,7 +54,9 @@ int main()
Begin3dMode(camera);
// NOTE: Model is scaled to 1/4 of its original size (128x128 units)
- DrawModel(map, mapPosition, 1/4.0f, RED);
+ DrawModel(map, mapPosition, 1.0f, RED);
+
+ DrawGrid(20, 1.0f);
End3dMode();
diff --git a/examples/models_heightmap.png b/examples/models_heightmap.png
index 9ed04586..6dcf01f0 100644
--- a/examples/models_heightmap.png
+++ b/examples/models_heightmap.png
Binary files differ
diff --git a/examples/physics_basic_rigidbody.c b/examples/physics_basic_rigidbody.c
index b82fe638..6c354eb7 100644
--- a/examples/physics_basic_rigidbody.c
+++ b/examples/physics_basic_rigidbody.c
@@ -2,20 +2,10 @@
*
* raylib [physac] physics example - Basic rigidbody
*
-* Welcome to raylib!
-*
-* To test examples, just press F6 and execute raylib_compile_execute script
-* Note that compiled executable is placed in the same folder as .c file
-*
-* You can find all basic examples on C:\raylib\raylib\examples folder or
-* raylib official webpage: www.raylib.com
-*
-* Enjoy using raylib. :)
-*
-* This example has been created using raylib 1.3 (www.raylib.com)
+* 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) 2015 Ramon Santamaria (@raysan5)
+* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -33,13 +23,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [physics] example - basic rigidbody");
- InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
-
- // Physics initialization
- Physics worldPhysics = { true, false, (Vector2){ 0, -9.81f } };
-
- // Set internal physics settings
- SetPhysics(worldPhysics);
+ InitPhysics(3); // Initialize physics system with maximum physic objects
// Object initialization
Transform player = (Transform){(Vector2){(screenWidth - OBJECT_SIZE) / 2, (screenHeight - OBJECT_SIZE) / 2}, 0.0f, (Vector2){OBJECT_SIZE, OBJECT_SIZE}};
@@ -55,6 +39,8 @@ int main()
float moveSpeed = 6.0f;
float jumpForce = 5.0f;
+ bool physicsDebug = false;
+
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -91,14 +77,7 @@ int main()
}
// Check debug mode toggle button input
- if(IsKeyPressed(KEY_P))
- {
- // Update program physics value
- worldPhysics.debug = !worldPhysics.debug;
-
- // Update internal physics value
- SetPhysics(worldPhysics);
- }
+ if (IsKeyPressed(KEY_P)) physicsDebug = !physicsDebug;
//----------------------------------------------------------------------------------
// Draw
@@ -112,7 +91,7 @@ int main()
DrawText("Use P to switch DEBUG MODE", (screenWidth - MeasureText("Use P to switch DEBUG MODE", 20)) / 2, screenHeight * 0.3f, 20, LIGHTGRAY);
// Check if debug mode is enabled
- if (worldPhysics.debug)
+ if (physicsDebug)
{
// Draw every internal physics stored collider if it is active
for (int i = 0; i < 2; i++)
@@ -122,14 +101,11 @@ int main()
DrawRectangleLines(GetCollider(i).bounds.x, GetCollider(i).bounds.y, GetCollider(i).bounds.width, GetCollider(i).bounds.height, GREEN);
}
}
-
}
else
{
- // Draw player
+ // Draw player and floor
DrawRectangleRec((Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, GRAY);
-
- // Draw floor
DrawRectangleRec((Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, BLACK);
}
@@ -138,7 +114,9 @@ int main()
}
// De-Initialization
- //--------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
+ UnloadPhysics(); // Unload physic objects
+
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/physics_rigidbody_force.c b/examples/physics_rigidbody_force.c
index 3ac560c5..74a88a97 100644
--- a/examples/physics_rigidbody_force.c
+++ b/examples/physics_rigidbody_force.c
@@ -2,10 +2,10 @@
*
* raylib [physac] physics example - Rigidbody forces
*
-* This example has been created using raylib 1.3 (www.raylib.com)
+* 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) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -26,15 +26,9 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces");
- InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
+ InitPhysics(MAX_OBJECTS + 1); // Initialize physics system with maximum physic objects
- // Physics initialization
- Physics worldPhysics = {true, false, (Vector2){0, -9.81f}};
-
- // Set internal physics settings
- SetPhysics(worldPhysics);
-
- // Objects initialization
+ // Physic Objects initialization
Transform objects[MAX_OBJECTS];
for (int i = 0; i < MAX_OBJECTS; i++)
@@ -49,6 +43,8 @@ int main()
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
AddCollider(MAX_OBJECTS, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
+ bool physicsDebug = false;
+
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -72,14 +68,7 @@ int main()
}
// Check debug mode toggle button input
- if (IsKeyPressed(KEY_P))
- {
- // Update program physics value
- worldPhysics.debug = !worldPhysics.debug;
-
- // Update internal physics value
- SetPhysics(worldPhysics);
- }
+ if (IsKeyPressed(KEY_P)) physicsDebug = !physicsDebug;
//----------------------------------------------------------------------------------
// Draw
@@ -89,10 +78,10 @@ int main()
ClearBackground(RAYWHITE);
// Check if debug mode is enabled
- if (worldPhysics.debug)
+ if (physicsDebug)
{
// Draw every internal physics stored collider if it is active (floor included)
- for (int i = 0; i < MAX_OBJECTS + 1; i++)
+ for (int i = 0; i < MAX_OBJECTS; i++)
{
if (GetCollider(i).enabled)
{
@@ -136,7 +125,9 @@ int main()
}
// De-Initialization
- //--------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
+ UnloadPhysics(); // Unload physic objects
+
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/resources/cat.png b/examples/resources/cat.png
new file mode 100644
index 00000000..d023aa21
--- /dev/null
+++ b/examples/resources/cat.png
Binary files differ
diff --git a/examples/resources/fonts/bmfont.fnt b/examples/resources/fonts/bmfont.fnt
new file mode 100644
index 00000000..372c2c88
--- /dev/null
+++ b/examples/resources/fonts/bmfont.fnt
@@ -0,0 +1,99 @@
+info face="Arial Black" size=-32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 outline=0
+common lineHeight=45 base=35 scaleW=512 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
+page id=0 file="bmfont.png"
+chars count=95
+char id=32 x=423 y=141 width=3 height=45 xoffset=-1 yoffset=0 xadvance=11 page=0 chnl=15
+char id=33 x=323 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
+char id=34 x=123 y=141 width=16 height=45 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15
+char id=35 x=221 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=36 x=244 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=37 x=70 y=0 width=30 height=45 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=15
+char id=38 x=390 y=0 width=25 height=45 xoffset=2 yoffset=0 xadvance=28 page=0 chnl=15
+char id=39 x=378 y=141 width=8 height=45 xoffset=1 yoffset=0 xadvance=9 page=0 chnl=15
+char id=40 x=222 y=141 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
+char id=41 x=499 y=94 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
+char id=42 x=497 y=47 width=13 height=45 xoffset=2 yoffset=0 xadvance=18 page=0 chnl=15
+char id=43 x=394 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=44 x=367 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
+char id=45 x=261 y=141 width=11 height=45 xoffset=0 yoffset=0 xadvance=11 page=0 chnl=15
+char id=46 x=356 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
+char id=47 x=248 y=141 width=11 height=45 xoffset=-1 yoffset=0 xadvance=9 page=0 chnl=15
+char id=48 x=382 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=49 x=496 y=0 width=14 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
+char id=50 x=134 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=51 x=359 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=52 x=313 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=53 x=336 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=54 x=178 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=55 x=478 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=56 x=290 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=57 x=90 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=58 x=345 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
+char id=59 x=334 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
+char id=60 x=0 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=61 x=21 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=62 x=310 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=63 x=352 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=20 page=0 chnl=15
+char id=64 x=279 y=0 width=26 height=45 xoffset=-1 yoffset=0 xadvance=24 page=0 chnl=15
+char id=65 x=193 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
+char id=66 x=150 y=47 width=22 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
+char id=67 x=444 y=0 width=24 height=45 xoffset=1 yoffset=0 xadvance=25 page=0 chnl=15
+char id=68 x=174 y=47 width=22 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
+char id=69 x=156 y=94 width=20 height=45 xoffset=2 yoffset=0 xadvance=23 page=0 chnl=15
+char id=70 x=63 y=141 width=18 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
+char id=71 x=417 y=0 width=25 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
+char id=72 x=125 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
+char id=73 x=388 y=141 width=8 height=45 xoffset=2 yoffset=0 xadvance=12 page=0 chnl=15
+char id=74 x=200 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=75 x=251 y=0 width=26 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
+char id=76 x=373 y=94 width=19 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
+char id=77 x=134 y=0 width=28 height=45 xoffset=1 yoffset=0 xadvance=30 page=0 chnl=15
+char id=78 x=100 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
+char id=79 x=363 y=0 width=25 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
+char id=80 x=112 y=94 width=20 height=45 xoffset=2 yoffset=0 xadvance=23 page=0 chnl=15
+char id=81 x=335 y=0 width=26 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
+char id=82 x=470 y=0 width=24 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
+char id=83 x=75 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
+char id=84 x=50 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
+char id=85 x=25 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
+char id=86 x=307 y=0 width=26 height=45 xoffset=0 yoffset=0 xadvance=25 page=0 chnl=15
+char id=87 x=0 y=0 width=34 height=45 xoffset=-1 yoffset=0 xadvance=32 page=0 chnl=15
+char id=88 x=222 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
+char id=89 x=164 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
+char id=90 x=0 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
+char id=91 x=274 y=141 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
+char id=92 x=300 y=141 width=10 height=45 xoffset=-1 yoffset=0 xadvance=9 page=0 chnl=15
+char id=93 x=287 y=141 width=11 height=45 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
+char id=94 x=457 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=95 x=103 y=141 width=18 height=45 xoffset=-1 yoffset=0 xadvance=16 page=0 chnl=15
+char id=96 x=312 y=141 width=9 height=45 xoffset=0 yoffset=0 xadvance=11 page=0 chnl=15
+char id=97 x=474 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=98 x=68 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=99 x=267 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=100 x=46 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=101 x=198 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=102 x=141 y=141 width=15 height=45 xoffset=-1 yoffset=0 xadvance=12 page=0 chnl=15
+char id=103 x=222 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=104 x=415 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=105 x=398 y=141 width=7 height=45 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=15
+char id=106 x=235 y=141 width=11 height=45 xoffset=-2 yoffset=0 xadvance=11 page=0 chnl=15
+char id=107 x=405 y=47 width=21 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=108 x=407 y=141 width=7 height=45 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=15
+char id=109 x=102 y=0 width=30 height=45 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=15
+char id=110 x=331 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=111 x=428 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=112 x=266 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=113 x=288 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=114 x=158 y=141 width=15 height=45 xoffset=1 yoffset=0 xadvance=14 page=0 chnl=15
+char id=115 x=244 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
+char id=116 x=175 y=141 width=14 height=45 xoffset=0 yoffset=0 xadvance=14 page=0 chnl=15
+char id=117 x=436 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
+char id=118 x=451 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
+char id=119 x=36 y=0 width=32 height=45 xoffset=-1 yoffset=0 xadvance=30 page=0 chnl=15
+char id=120 x=0 y=94 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
+char id=121 x=23 y=94 width=21 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
+char id=122 x=83 y=141 width=18 height=45 xoffset=0 yoffset=0 xadvance=18 page=0 chnl=15
+char id=123 x=191 y=141 width=14 height=45 xoffset=-1 yoffset=0 xadvance=12 page=0 chnl=15
+char id=124 x=416 y=141 width=5 height=45 xoffset=2 yoffset=0 xadvance=9 page=0 chnl=15
+char id=125 x=207 y=141 width=13 height=45 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
+char id=126 x=42 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
diff --git a/examples/resources/fonts/bmfont.png b/examples/resources/fonts/bmfont.png
new file mode 100644
index 00000000..9d621594
--- /dev/null
+++ b/examples/resources/fonts/bmfont.png
Binary files differ
diff --git a/examples/resources/fonts/pixantiqua.ttf b/examples/resources/fonts/pixantiqua.ttf
new file mode 100644
index 00000000..e012875d
--- /dev/null
+++ b/examples/resources/fonts/pixantiqua.ttf
Binary files differ
diff --git a/examples/resources/parrots.png b/examples/resources/parrots.png
new file mode 100644
index 00000000..d6ec60ba
--- /dev/null
+++ b/examples/resources/parrots.png
Binary files differ
diff --git a/examples/resources/shaders/phong.vs b/examples/resources/shaders/phong.vs
index ee6d34bf..52cc2227 100644
--- a/examples/resources/shaders/phong.vs
+++ b/examples/resources/shaders/phong.vs
@@ -7,7 +7,9 @@ in vec3 vertexNormal;
// Projection and model data
uniform mat4 mvpMatrix;
+
uniform mat4 modelMatrix;
+//uniform mat4 viewMatrix; // Not used
// Attributes to fragment shader
out vec2 fragTexCoord;
diff --git a/examples/resources/shaders/shapes_base.vs b/examples/resources/shaders/shapes_base.vs
index 1fd686be..ad272dc1 100644
--- a/examples/resources/shaders/shapes_base.vs
+++ b/examples/resources/shaders/shapes_base.vs
@@ -1,4 +1,4 @@
-#version 110
+#version 330
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
diff --git a/examples/resources/shaders/shapes_grayscale.fs b/examples/resources/shaders/shapes_grayscale.fs
index 23ba9153..0698e1bf 100644
--- a/examples/resources/shaders/shapes_grayscale.fs
+++ b/examples/resources/shaders/shapes_grayscale.fs
@@ -1,4 +1,4 @@
-#version 110
+#version 330
uniform sampler2D texture0;
varying vec2 fragTexCoord;
diff --git a/examples/shaders_basic_lighting.c b/examples/shaders_basic_lighting.c
index ba779b94..84bd1af4 100644
--- a/examples/shaders_basic_lighting.c
+++ b/examples/shaders_basic_lighting.c
@@ -14,6 +14,17 @@
#define SHININESS_SPEED 1.0f
#define LIGHT_SPEED 0.25f
+// Light type
+typedef struct Light {
+ Vector3 position;
+ Vector3 direction;
+ float intensity;
+ float specIntensity;
+ Color diffuse;
+ Color ambient;
+ Color specular;
+} Light;
+
int main()
{
// Initialization
@@ -48,6 +59,10 @@ int main()
int cameraLoc = GetShaderLocation(shader, "cameraPos");
int lightLoc = GetShaderLocation(shader, "lightPos");
+ // Model and View matrix locations (required for lighting)
+ int modelLoc = GetShaderLocation(shader, "modelMatrix");
+ //int viewLoc = GetShaderLocation(shader, "viewMatrix"); // Not used
+
// Light and material definitions
Light light;
Material matBlinn;
@@ -62,9 +77,9 @@ int main()
light.specIntensity = 1.0f;
// Material initialization
- matBlinn.diffuse = WHITE;
- matBlinn.ambient = (Color){ 50, 50, 50, 255 };
- matBlinn.specular = WHITE;
+ matBlinn.colDiffuse = WHITE;
+ matBlinn.colAmbient = (Color){ 50, 50, 50, 255 };
+ matBlinn.colSpecular = WHITE;
matBlinn.glossiness = 50.0f;
// Setup camera
@@ -82,6 +97,10 @@ int main()
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera position
+ // NOTE: Model transform can be set in model.transform or directly with params at draw... WATCH OUT!
+ SetShaderValueMatrix(shader, modelLoc, model.transform); // Send model matrix to shader
+ //SetShaderValueMatrix(shader, viewLoc, GetCameraMatrix(camera)); // Not used
+
// Glossiness input control
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
else if(IsKeyDown(KEY_DOWN))
@@ -110,8 +129,8 @@ int main()
SetShaderValue(shader, lSpecIntensityLoc, &light.specIntensity, 1);
// Send material values to shader
- SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.ambient), 3);
- SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.specular), 3);
+ SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.colAmbient), 3);
+ SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.colSpecular), 3);
SetShaderValue(shader, mGlossLoc, &matBlinn.glossiness, 1);
// Send camera and light transform values to shader
@@ -127,7 +146,7 @@ int main()
Begin3dMode(camera);
- DrawModel(model, position, 4.0f, matBlinn.diffuse);
+ DrawModel(model, position, 4.0f, matBlinn.colDiffuse);
DrawSphere(light.position, 0.5f, GOLD);
DrawGrid(20, 1.0f);
diff --git a/examples/shapes_logo_raylib_anim.c b/examples/shapes_logo_raylib_anim.c
index b1bdc3a8..c6d3796e 100644
--- a/examples/shapes_logo_raylib_anim.c
+++ b/examples/shapes_logo_raylib_anim.c
@@ -2,7 +2,7 @@
*
* raylib [shapes] example - raylib logo animation
*
-* This example has been created using raylib 1.1 (www.raylib.com)
+* 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) 2014 Ramon Santamaria (@raysan5)
@@ -32,8 +32,6 @@ int main()
int bottomSideRecWidth = 16;
int rightSideRecHeight = 16;
- char raylib[8] = " \0"; // raylib text array, max 8 letters
-
int state = 0; // Tracking animation states (State Machine)
float alpha = 1.0f; // Useful for fading
@@ -79,24 +77,13 @@ int main()
framesCounter = 0;
}
- switch (lettersCount)
- {
- case 1: raylib[0] = 'r'; break;
- case 2: raylib[1] = 'a'; break;
- case 3: raylib[2] = 'y'; break;
- case 4: raylib[3] = 'l'; break;
- case 5: raylib[4] = 'i'; break;
- case 6: raylib[5] = 'b'; break;
- default: break;
- }
-
if (lettersCount >= 10) // When all letters have appeared, just fade out everything
{
- alpha -= 0.02;
+ alpha -= 0.02f;
- if (alpha <= 0)
+ if (alpha <= 0.0f)
{
- alpha = 0;
+ alpha = 0.0f;
state = 4;
}
}
@@ -114,12 +101,7 @@ int main()
bottomSideRecWidth = 16;
rightSideRecHeight = 16;
- for (int i = 0; i < 7; i++) raylib[i] = ' ';
-
- raylib[7] = '\0'; // Last character is end-of-line
-
- alpha = 1.0;
-
+ alpha = 1.0f;
state = 0; // Return to State 0
}
}
@@ -158,7 +140,7 @@ int main()
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
- DrawText(raylib, screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
+ DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{
diff --git a/examples/text_bmfont_ttf.c b/examples/text_bmfont_ttf.c
new file mode 100644
index 00000000..caece548
--- /dev/null
+++ b/examples/text_bmfont_ttf.c
@@ -0,0 +1,68 @@
+/*******************************************************************************************
+*
+* raylib [text] example - BMFont and TTF SpriteFonts loading
+*
+* 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 and ttf sprite fonts loading");
+
+ const char msgBm[64] = "THIS IS AN AngelCode SPRITE FONT";
+ const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF";
+
+ // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
+ SpriteFont fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt"); // BMFont (AngelCode)
+ SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf"); // TTF font
+
+ Vector2 fontPosition;
+
+ fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2;
+ fontPosition.y = screenHeight/2 - fontBm.size/2 - 80;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update variables here...
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON);
+ DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadSpriteFont(fontBm); // AngelCode SpriteFont unloading
+ UnloadSpriteFont(fontTtf); // TTF SpriteFont unloading
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/text_bmfont_ttf.png b/examples/text_bmfont_ttf.png
new file mode 100644
index 00000000..8305d36b
--- /dev/null
+++ b/examples/text_bmfont_ttf.png
Binary files differ
diff --git a/examples/text_writing_anim.c b/examples/text_writing_anim.c
new file mode 100644
index 00000000..5f19b468
--- /dev/null
+++ b/examples/text_writing_anim.c
@@ -0,0 +1,60 @@
+/*******************************************************************************************
+*
+* raylib [text] example - Text Writing Animation
+*
+* 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 - text writing anim");
+
+ const char message[128] = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
+
+ int framesCounter = 0;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ framesCounter++;
+
+ if (IsKeyPressed(KEY_ENTER)) framesCounter = 0;
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
+
+ DrawText("PRESS [ENTER] to RESTART!", 240, 280, 20, LIGHTGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/text_writing_anim.png b/examples/text_writing_anim.png
new file mode 100644
index 00000000..d6752dd8
--- /dev/null
+++ b/examples/text_writing_anim.png
Binary files differ
diff --git a/examples/textures_formats_loading.png b/examples/textures_formats_loading.png
index 4cdb2f13..6778080f 100644
--- a/examples/textures_formats_loading.png
+++ b/examples/textures_formats_loading.png
Binary files differ
diff --git a/examples/textures_image_drawing.c b/examples/textures_image_drawing.c
new file mode 100644
index 00000000..1c6a1fb9
--- /dev/null
+++ b/examples/textures_image_drawing.c
@@ -0,0 +1,78 @@
+/*******************************************************************************************
+*
+* raylib [textures] example - Image loading and drawing on it
+*
+* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
+*
+* 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 [textures] example - image drawing");
+
+ // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
+
+ Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM)
+ ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 }); // Crop an image piece
+ ImageFlipHorizontal(&cat); // Flip cropped image horizontally
+ ImageResize(&cat, 150, 200); // Resize flipped-cropped image
+
+ Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
+
+ // Draw one image over the other with a scaling of 1.5f
+ ImageDraw(&parrots, cat, (Rectangle){ 0, 0, cat.width, cat.height }, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f });
+ ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }); // Crop resulting image
+
+ UnloadImage(cat); // Unload image from RAM
+
+ Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
+ UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
+
+ SetTargetFPS(60);
+ //---------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE);
+ DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY);
+
+ DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY);
+ DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Texture unloading
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/textures_image_drawing.png b/examples/textures_image_drawing.png
new file mode 100644
index 00000000..acfee069
--- /dev/null
+++ b/examples/textures_image_drawing.png
Binary files differ
diff --git a/examples/textures_image_processing.c b/examples/textures_image_processing.c
new file mode 100644
index 00000000..58b746e0
--- /dev/null
+++ b/examples/textures_image_processing.c
@@ -0,0 +1,154 @@
+/*******************************************************************************************
+*
+* raylib [textures] example - Image processing
+*
+* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
+*
+* 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"
+
+#include <stdlib.h> // Required for: free()
+
+#define NUM_PROCESSES 8
+
+typedef enum {
+ NONE = 0,
+ COLOR_GRAYSCALE,
+ COLOR_TINT,
+ COLOR_INVERT,
+ COLOR_CONTRAST,
+ COLOR_BRIGHTNESS,
+ FLIP_VERTICAL,
+ FLIP_HORIZONTAL
+} ImageProcess;
+
+static const char *processText[] = {
+ "NO PROCESSING",
+ "COLOR GRAYSCALE",
+ "COLOR TINT",
+ "COLOR INVERT",
+ "COLOR CONTRAST",
+ "COLOR BRIGHTNESS",
+ "FLIP VERTICAL",
+ "FLIP HORIZONTAL"
+};
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing");
+
+ // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
+
+ Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
+ ImageFormat(&image, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update)
+ Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
+
+ int currentProcess = NONE;
+ bool textureReload = false;
+
+ Rectangle selectRecs[NUM_PROCESSES];
+
+ for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = (Rectangle){ 40, 50 + 32*i, 150, 30 };
+
+ SetTargetFPS(60);
+ //---------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (IsKeyPressed(KEY_DOWN))
+ {
+ currentProcess++;
+ if (currentProcess > 7) currentProcess = 0;
+ textureReload = true;
+ }
+ else if (IsKeyPressed(KEY_UP))
+ {
+ currentProcess--;
+ if (currentProcess < 0) currentProcess = 7;
+ textureReload = true;
+ }
+
+ if (textureReload)
+ {
+ UnloadImage(image); // Unload current image data
+ image = LoadImage("resources/parrots.png"); // Re-load image data
+
+ // NOTE: Image processing is a costly CPU process to be done every frame,
+ // If image processing is required in a frame-basis, it should be done
+ // with a texture and by shaders
+ switch (currentProcess)
+ {
+ case COLOR_GRAYSCALE: ImageColorGrayscale(&image); break;
+ case COLOR_TINT: ImageColorTint(&image, GREEN); break;
+ case COLOR_INVERT: ImageColorInvert(&image); break;
+ case COLOR_CONTRAST: ImageColorContrast(&image, -40); break;
+ case COLOR_BRIGHTNESS: ImageColorBrightness(&image, -80); break;
+ case FLIP_VERTICAL: ImageFlipVertical(&image); break;
+ case FLIP_HORIZONTAL: ImageFlipHorizontal(&image); break;
+ default: break;
+ }
+
+ Color *pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit)
+ UpdateTexture(texture, pixels); // Update texture with new image data
+ free(pixels); // Unload pixels data from RAM
+
+ textureReload = false;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY);
+
+ // Draw rectangles
+ for (int i = 0; i < NUM_PROCESSES; i++)
+ {
+ if (i == currentProcess)
+ {
+ DrawRectangleRec(selectRecs[i], SKYBLUE);
+ DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, BLUE);
+ DrawText(processText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2, selectRecs[i].y + 11, 10, DARKBLUE);
+ }
+ else
+ {
+ DrawRectangleRec(selectRecs[i], LIGHTGRAY);
+ DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, GRAY);
+ DrawText(processText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2, selectRecs[i].y + 11, 10, DARKGRAY);
+ }
+ }
+
+ DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);
+ DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Unload texture from VRAM
+ UnloadImage(image); // Unload image from RAM
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/textures_image_processing.png b/examples/textures_image_processing.png
new file mode 100644
index 00000000..c15e19f9
--- /dev/null
+++ b/examples/textures_image_processing.png
Binary files differ
diff --git a/examples/textures_srcrec_dstrec.c b/examples/textures_srcrec_dstrec.c
index 58917421..6d824ce6 100644
--- a/examples/textures_srcrec_dstrec.c
+++ b/examples/textures_srcrec_dstrec.c
@@ -55,6 +55,10 @@ int main()
ClearBackground(RAYWHITE);
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
+ // sourceRec defines the part of the texture we use for drawing
+ // destRec defines the rectangle where our texture part will fit (scaling it to fit)
+ // origin defines the point of the texture used as reference for rotation and scaling
+ // rotation defines the texture rotation (using origin as rotation point)
DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, WHITE);
DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY);