summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2016-11-18 14:05:49 +0100
committerraysan5 <[email protected]>2016-11-18 14:05:49 +0100
commit0603e59cae0da924d7fe811b078972e04cdfe1e9 (patch)
tree55aff2d0cb67ee60018911ecf04d0b1be25dd722 /examples
parent6b072e696d1b2b029ec1c8464ed22bf7ab65e5ee (diff)
downloadraylib-0603e59cae0da924d7fe811b078972e04cdfe1e9.tar.gz
raylib-0603e59cae0da924d7fe811b078972e04cdfe1e9.zip
Review examples and added new ones
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile24
-rw-r--r--examples/audio_raw_stream.pngbin0 -> 16736 bytes
-rw-r--r--examples/audio_standalone.c12
-rw-r--r--examples/core_drop_files.c2
-rw-r--r--examples/core_input_gamepad.pngbin10840 -> 38066 bytes
-rw-r--r--examples/core_oculus_rift.c6
-rw-r--r--examples/resources/fonts/KAISG.ttfbin0 -> 79912 bytes
-rw-r--r--examples/text_ttf_loading.c125
-rw-r--r--examples/text_ttf_loading.pngbin0 -> 55588 bytes
9 files changed, 158 insertions, 11 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 378f5edf..da29e915 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,7 @@ EXAMPLES = \
text_format_text \
text_font_select \
text_writing_anim \
+ text_ttf_loading \
models_geometric_shapes \
models_box_collisions \
models_billboard \
@@ -400,6 +414,10 @@ 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 [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/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_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.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/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/text_ttf_loading.c b/examples/text_ttf_loading.c
new file mode 100644
index 00000000..1135619e
--- /dev/null
+++ b/examples/text_ttf_loading.c
@@ -0,0 +1,125 @@
+/*******************************************************************************************
+*
+* 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 - [email protected])
+*
+********************************************************************************************/
+
+#include "raylib.h"
+#include <stdio.h>
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
+
+ const char msg1[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);
+
+ float fontSize = font.size;
+ Vector2 fontPosition = { 40, screenHeight/2 + 50 };
+ Vector2 textSize;
+
+ 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 not supported in font because there are not mipmap levels
+ SetTextureFilter(font.texture, FILTER_TRILINEAR);
+ //currentFontFilter = 2;
+ }
+
+ textSize = MeasureTextEx(font, msg1, 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, msg1, 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);
+
+ 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.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