Review examples and added new ones

This commit is contained in:
raysan5 2016-11-18 14:05:49 +01:00
parent 6b072e696d
commit 0603e59cae
9 changed files with 158 additions and 11 deletions

View File

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -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;
}

View File

@ -23,7 +23,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
int count = 0;
char **droppedFiles;
char **droppedFiles = { 0 };
SetTargetFPS(60);
//--------------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -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

Binary file not shown.

125
examples/text_ttf_loading.c Normal file
View File

@ -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 - raysan@raysanweb.com)
*
********************************************************************************************/
#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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB