summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt32
-rw-r--r--src/Makefile28
-rw-r--r--src/audio.c31
-rw-r--r--src/audio.h55
-rw-r--r--src/core.c62
-rw-r--r--src/external/stb_image.h4
-rw-r--r--src/models.c62
-rw-r--r--src/raylib.h89
-rw-r--r--src/resourcesbin107204 -> 107212 bytes
-rw-r--r--src/rlgl.c35
-rw-r--r--src/rlgl.h34
-rw-r--r--src/rlua.h201
-rw-r--r--src/shapes.c10
-rw-r--r--src/text.c95
-rw-r--r--src/textures.c10
-rw-r--r--src/utils.c14
-rw-r--r--src/utils.h6
17 files changed, 438 insertions, 330 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
deleted file mode 100644
index c094ad96..00000000
--- a/src/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-cmake_minimum_required (VERSION 3.0)
-project (raylib)
-SET(PLATFORM_TO_USE "PLATFORM_DESKTOP" CACHE STRING "Platform to compile for")
-SET_PROPERTY(CACHE PLATFORM_TO_USE PROPERTY STRINGS PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB)
-
-set(CMAKE_C_FLAGS "-O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces")
-
-IF(${PLATFORM_TO_USE} MATCHES "PLATFORM_DESKTOP")
-
- add_definitions(-DPLATFORM_DESKTOP, -DGRAPHICS_API_OPENGL_33)
- include_directories("." "external/" "external/openal_soft/include" "external/glfw3/include")
-
-ENDIF()
-
-IF(${PLATFORM_TO_USE} MATCHES "PLATFORM_RPI")
-
- add_definitions(-DPLATFORM_RPI, -GRAPHICS_API_OPENGL_ES2)
- include_directories("." "external/" "/opt/vc/include" "/opt/vc/include/interface/vmcs_host/linux" "/opt/vc/include/interface/vcos/pthreads")
-
-ENDIF()
-
-IF(${PLATFORM_TO_USE} MATCHES "PLATFORM_WEB")
-
- add_definitions(-DPLATFORM_WEB, -GRAPHICS_API_OPENGL_ES2)
- include_directories("." "external/" "external/openal_soft/include" "external/glfw3/include")
-
-ENDIF()
-
-
-file(GLOB SOURCES "*.c" "external/*.c")
-add_library(raylib STATIC ${SOURCES})
-install(TARGETS raylib DESTINATION ../lib/) \ No newline at end of file
diff --git a/src/Makefile b/src/Makefile
index ee3f0c12..2e263189 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -38,6 +38,14 @@ PLATFORM ?= PLATFORM_DESKTOP
# define YES if you want shared/dynamic version of library instead of static (default)
SHARED ?= NO
+# define NO to use OpenAL Soft as static library (or shared by default)
+SHARED_OPENAL ?= YES
+
+# on PLATFORM_WEB force OpenAL Soft shared library
+ifeq ($(PLATFORM),PLATFORM_WEB)
+ SHARED_OPENAL ?= YES
+endif
+
# determine if the file has root access (only for installing raylib)
# "whoami" prints the name of the user that calls him (so, if it is the root
# user, "whoami" prints "root").
@@ -99,11 +107,20 @@ CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces
ifeq ($(SHARED),YES)
CFLAGS += -fPIC
SHAREDFLAG = BUILDING_DLL
- SHAREDLIBS = -Lexternal/glfw3/lib/win32 -Lexternal/openal_soft/lib/win32 -lglfw3 -lopenal32 -lgdi32
+ SHAREDLIBS = -Lexternal/glfw3/lib/win32 -Lexternal/openal_soft/lib/win32 -lglfw3 -lgdi32
else
SHAREDFLAG = BUILDING_STATIC
endif
+# if static OpenAL Soft required, define the corresponding flags
+ifeq ($(SHARED_OPENAL),NO)
+ SHAREDLIBS += -lopenal32 -lwinmm
+ SHAREDOPENALFLAG = AL_LIBTYPE_STATIC
+else
+ SHAREDLIBS += -lopenal32dll
+ SHAREDOPENALFLAG = SHARED_OPENAL
+endif
+
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
# define any directories containing required header files
@@ -165,12 +182,17 @@ else
endif
ifeq ($(PLATFORM_OS),WINDOWS)
$(CC) -shared -o $(OUTPUT_PATH)/raylib.dll $(OBJS) $(SHAREDLIBS) -Wl,--out-implib,$(OUTPUT_PATH)/libraylibdll.a
- @echo "raylib dynamic library (raylib.dll) and MSVC required import library (libraylibdll.a) generated!"
+ @echo "raylib dynamic library (raylib.dll) and import library (libraylibdll.a) generated!"
endif
else
# compile raylib static library for desktop platforms.
ar rcs $(OUTPUT_PATH)/libraylib.a $(OBJS)
@echo "libraylib.a generated (static library)!"
+ ifeq ($(SHARED_OPENAL),NO)
+ @echo "expected OpenAL Soft static library linking"
+ else
+ @echo "expected OpenAL Soft shared library linking"
+ endif
endif
endif
@@ -202,7 +224,7 @@ models.o : models.c raylib.h rlgl.h raymath.h
# compile audio module
audio.o : audio.c raylib.h
- $(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG)
+ $(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG) -D$(SHAREDOPENALFLAG)
# compile stb_vorbis library
external/stb_vorbis.o: external/stb_vorbis.c external/stb_vorbis.h
diff --git a/src/audio.c b/src/audio.c
index 3684e10a..49aca4b0 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -2,18 +2,22 @@
*
* raylib.audio
*
-* Basic functions to manage Audio:
+* This module provides basic functionality to work with audio:
* Manage audio device (init/close)
-* Load and Unload audio files
+* Load and Unload audio files (WAV, OGG, FLAC, XM, MOD)
* Play/Stop/Pause/Resume loaded audio
* Manage mixing channels
* Manage raw audio context
*
-* Uses external lib:
-* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
-* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
-* jar_xm - XM module file loading
-* jar_mod - MOD audio file loading
+* External libs:
+* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html)
+* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/)
+* jar_xm - XM module file loading
+* jar_mod - MOD audio file loading
+* dr_flac - FLAC audio file loading
+*
+* Module Configuration Flags:
+* AUDIO_STANDALONE - Use this module as standalone library (independently of raylib)
*
* Many thanks to Joshua Reisenauer (github: @kd7tck) for the following additions:
* XM audio module support (jar_xm)
@@ -21,6 +25,7 @@
* Mixing channels support
* Raw audio context support
*
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -44,8 +49,11 @@
#if defined(AUDIO_STANDALONE)
#include "audio.h"
+ #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
#else
#include "raylib.h"
+ #include "utils.h" // Required for: DecompressData()
+ // NOTE: Includes Android fopen() function map
#endif
#include "AL/al.h" // OpenAL basic header
@@ -63,13 +71,6 @@
#define AL_FORMAT_STEREO_FLOAT32 0x10011
#endif
-#if defined(AUDIO_STANDALONE)
- #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
-#else
- #include "utils.h" // Required for: DecompressData()
- // NOTE: Includes Android fopen() function map
-#endif
-
//#define STB_VORBIS_HEADER_ONLY
#include "external/stb_vorbis.h" // OGG loading functions
@@ -117,7 +118,7 @@ typedef struct MusicData {
bool loop; // Repeat music after finish (loop)
unsigned int totalSamples; // Total number of samples
unsigned int samplesLeft; // Number of samples left to end
-} MusicData, *Music;
+} MusicData;
#if defined(AUDIO_STANDALONE)
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
diff --git a/src/audio.h b/src/audio.h
index 923492ca..2b3c5933 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -2,18 +2,19 @@
*
* raylib.audio
*
-* Basic functions to manage Audio:
+* This module provides basic functionality to work with audio:
* Manage audio device (init/close)
-* Load and Unload audio files
+* Load and Unload audio files (WAV, OGG, FLAC, XM, MOD)
* Play/Stop/Pause/Resume loaded audio
* Manage mixing channels
* Manage raw audio context
*
-* Uses external lib:
-* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
-* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
-* jar_xm - XM module file loading
-* jar_mod - MOD audio file loading
+* External libs:
+* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html)
+* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/)
+* jar_xm - XM module file loading
+* jar_mod - MOD audio file loading
+* dr_flac - FLAC audio file loading
*
* Many thanks to Joshua Reisenauer (github: @kd7tck) for the following additions:
* XM audio module support (jar_xm)
@@ -21,6 +22,7 @@
* Mixing channels support
* Raw audio context support
*
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -60,12 +62,6 @@
#endif
#endif
-// Sound source type
-typedef struct Sound {
- unsigned int source; // Sound audio source id
- unsigned int buffer; // Sound audio buffer id
-} Sound;
-
// Wave type, defines audio wave data
typedef struct Wave {
unsigned int sampleCount; // Number of samples
@@ -75,9 +71,16 @@ typedef struct Wave {
void *data; // Buffer data pointer
} Wave;
+// Sound source type
+typedef struct Sound {
+ unsigned int source; // OpenAL audio source id
+ unsigned int buffer; // OpenAL audio buffer id
+ int format; // OpenAL audio format specifier
+} Sound;
+
// Music type (file streaming from memory)
// NOTE: Anything longer than ~10 seconds should be streamed
-typedef struct Music *Music;
+typedef struct MusicData *Music;
// Audio stream type
// NOTE: Useful to create custom audio streams not bound to a specific file
@@ -104,13 +107,16 @@ extern "C" { // Prevents name mangling of functions
// Module Functions Declaration
//----------------------------------------------------------------------------------
void InitAudioDevice(void); // Initialize audio device and context
-void CloseAudioDevice(void); // Close the audio device and context (and music stream)
+void CloseAudioDevice(void); // Close the audio device and context
bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully
-Sound LoadSound(char *fileName); // Load sound to memory
+Wave LoadWave(const char *fileName); // Load wave data from file into RAM
+Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit)
+Sound LoadSound(const char *fileName); // Load sound to memory
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource)
void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data
+void UnloadWave(Wave wave); // Unload wave data
void UnloadSound(Sound sound); // Unload sound
void PlaySound(Sound sound); // Play a sound
void PauseSound(Sound sound); // Pause a sound
@@ -119,12 +125,15 @@ void StopSound(Sound sound); // Stop playing
bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing
void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
-
-Music LoadMusicStream(char *fileName); // Load music stream from file
+void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
+Wave WaveCopy(Wave wave); // Copy a wave to a new wave
+void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range
+float *GetWaveData(Wave wave); // Get samples data from wave as a floats array
+Music LoadMusicStream(const char *fileName); // Load music stream from file
void UnloadMusicStream(Music music); // Unload music stream
-void PlayMusicStream(Music music); // Start music playing (open stream)
+void PlayMusicStream(Music music); // Start music playing
void UpdateMusicStream(Music music); // Updates buffers for music streaming
-void StopMusicStream(Music music); // Stop music playing (close stream)
+void StopMusicStream(Music music); // Stop music playing
void PauseMusicStream(Music music); // Pause music playing
void ResumeMusicStream(Music music); // Resume playing paused music
bool IsMusicPlaying(Music music); // Check if music is playing
@@ -133,9 +142,9 @@ void SetMusicPitch(Music music, float pitch); // Set pitch for
float GetMusicTimeLength(Music music); // Get music time length (in seconds)
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
-AudioStream InitAudioStream(unsigned int sampleRate,
- unsigned int sampleSize,
- unsigned int channels); // Init audio stream (to stream audio pcm data)
+AudioStream InitAudioStream(unsigned int sampleRate,
+ unsigned int sampleSize,
+ unsigned int channels); // Init audio stream (to stream raw audio pcm data)
void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
diff --git a/src/core.c b/src/core.c
index 3bade07b..241772ec 100644
--- a/src/core.c
+++ b/src/core.c
@@ -4,24 +4,25 @@
*
* Basic functions to manage windows, OpenGL context and input on multiple platforms
*
-* The following platforms are supported:
-* PLATFORM_DESKTOP - Windows, Linux, Mac (OSX)
-* PLATFORM_ANDROID - Only OpenGL ES 2.0 devices
-* PLATFORM_RPI - Rapsberry Pi (tested on Raspbian)
-* PLATFORM_WEB - Emscripten, HTML5
-* Oculus Rift CV1 (with desktop mirror) - View [rlgl] module to enable it
+* The following platforms are supported: Windows, Linux, Mac (OSX), Android, Raspberry Pi, HTML5, Oculus Rift CV1
*
-* On PLATFORM_DESKTOP, the external lib GLFW3 (www.glfw.com) is used to manage graphic
-* device, OpenGL context and input on multiple operating systems (Windows, Linux, OSX).
-*
-* On PLATFORM_ANDROID, graphic device is managed by EGL and input system by Android activity.
-*
-* On PLATFORM_RPI, graphic device is managed by EGL and input system is coded in raw mode.
+* External libs:
+* GLFW3 - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX)
+* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
+* camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person)
+* gestures - Gestures system for touch-ready devices (or simulated from mouse inputs)
*
* Module Configuration Flags:
+* PLATFORM_DESKTOP - Windows, Linux, Mac (OSX)
+* PLATFORM_ANDROID - Android (only OpenGL ES 2.0 devices), graphic device is managed by EGL and input system by Android activity.
+* PLATFORM_RPI - Rapsberry Pi (tested on Raspbian), graphic device is managed by EGL and input system is coded in raw mode.
+* PLATFORM_WEB - HTML5 (using emscripten compiler)
*
* RL_LOAD_DEFAULT_FONT - Use external module functions to load default raylib font (module: text)
*
+* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for render mirror - View [rlgl] module to enable it
+*
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -96,8 +97,8 @@
#include <sys/ioctl.h> // UNIX System call for device-specific input/output operations - ioctl()
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
#include <linux/input.h> // Linux: Keycodes constants definition (KEY_A, ...)
- #include <linux/joystick.h>
-
+ #include <linux/joystick.h> // Linux: Joystick support library
+
#include "bcm_host.h" // Raspberry Pi VideoCore IV access functions
#include "EGL/egl.h" // Khronos EGL library - Native platform display device control functions
@@ -175,6 +176,7 @@ static pthread_t mouseThreadId; // Mouse reading thread id
// Gamepad input variables
static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descriptor
static pthread_t gamepadThreadId; // Gamepad reading thread id
+static char gamepadName[64]; // Gamepad name holder
#endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
@@ -666,7 +668,7 @@ void Begin3dMode(Camera camera)
{
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
- if (IsVrDeviceReady()) BeginVrDrawing();
+ if (IsVrDeviceReady() || IsVrSimulator()) BeginVrDrawing();
rlMatrixMode(RL_PROJECTION); // Switch to projection matrix
@@ -696,7 +698,7 @@ void End3dMode(void)
{
rlglDraw(); // Process internal buffers (update + draw)
- if (IsVrDeviceReady()) EndVrDrawing();
+ if (IsVrDeviceReady() || IsVrSimulator()) EndVrDrawing();
rlMatrixMode(RL_PROJECTION); // Switch to projection matrix
rlPopMatrix(); // Restore previous matrix (PROJECTION) from matrix stack
@@ -1173,12 +1175,14 @@ bool IsGamepadAvailable(int gamepad)
bool IsGamepadName(int gamepad, const char *name)
{
bool result = false;
+
+#if !defined(PLATFORM_ANDROID)
const char *gamepadName = NULL;
-
+
if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad);
-
if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0);
-
+#endif
+
return result;
}
@@ -1188,6 +1192,10 @@ const char *GetGamepadName(int gamepad)
#if defined(PLATFORM_DESKTOP)
if (gamepadReady[gamepad]) return glfwGetJoystickName(gamepad);
else return NULL;
+#elif defined(PLATFORM_RPI)
+ if (gamepadReady[gamepad]) ioctl(gamepadStream[gamepad], JSIOCGNAME(64), &gamepadName);
+
+ return gamepadName;
#else
return NULL;
#endif
@@ -1196,6 +1204,11 @@ const char *GetGamepadName(int gamepad)
// Return gamepad axis count
int GetGamepadAxisCount(int gamepad)
{
+#if defined(PLATFORM_RPI)
+ int axisCount = 0;
+ if (gamepadReady[gamepad]) ioctl(gamepadStream[gamepad], JSIOCGAXES, &axisCount);
+ gamepadAxisCount = axisCount;
+#endif
return gamepadAxisCount;
}
@@ -1939,9 +1952,11 @@ static void PollInputEvents(void)
// Reset last key pressed registered
lastKeyPressed = -1;
- // Reset last gamepad button pressed registered
+#if !defined(PLATFORM_RPI)
+ // Reset last gamepad button/axis registered state
lastGamepadButtonPressed = -1;
gamepadAxisCount = 0;
+#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
// Mouse input polling
@@ -1963,7 +1978,11 @@ static void PollInputEvents(void)
previousMouseWheelY = currentMouseWheelY;
currentMouseWheelY = 0;
-
+#endif
+
+// NOTE: GLFW3 joystick functionality not available in web
+// TODO: Support joysticks using emscripten API
+#if defined(PLATFORM_DESKTOP)
// Check if gamepads are ready
// NOTE: We do it here in case of disconection
for (int i = 0; i < MAX_GAMEPADS; i++)
@@ -2850,6 +2869,7 @@ static void *GamepadThread(void *arg)
currentGamepadState[i][gamepadEvent.number] = (int)gamepadEvent.value;
if ((int)gamepadEvent.value == 1) lastGamepadButtonPressed = gamepadEvent.number;
+ else lastGamepadButtonPressed = -1;
}
}
else if (gamepadEvent.type == JS_EVENT_AXIS)
diff --git a/src/external/stb_image.h b/src/external/stb_image.h
index ce87646d..5572a880 100644
--- a/src/external/stb_image.h
+++ b/src/external/stb_image.h
@@ -390,7 +390,7 @@ publish, and distribute this file as you see fit.
#define STBI_NO_HDR // RaySan: not required by raylib
-#define STBI_NO_SIMD // RaySan: issues when compiling with GCC 4.7.2
+//#define STBI_NO_SIMD // RaySan: issues when compiling with GCC 4.7.2
#ifndef STBI_NO_STDIO
#include <stdio.h>
@@ -398,7 +398,7 @@ publish, and distribute this file as you see fit.
// NOTE: Added to work with raylib on Android
#if defined(PLATFORM_ANDROID)
- #include "utils.h" // Android fopen function map
+ #include "utils.h" // RaySan: Android fopen function map
#endif
#define STBI_VERSION 1
diff --git a/src/models.c b/src/models.c
index c0f04387..48f8b813 100644
--- a/src/models.c
+++ b/src/models.c
@@ -4,6 +4,12 @@
*
* Basic functions to draw 3d shapes and load/draw 3d models (.OBJ)
*
+* External libs:
+* rlgl - raylib OpenGL abstraction layer
+*
+* Module Configuration Flags:
+* ...
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -34,8 +40,7 @@
#include <string.h> // Required for: strcmp()
#include <math.h> // Required for: sin(), cos()
-#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
-#include "raymath.h" // Matrix data type and Matrix functions
+#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
//----------------------------------------------------------------------------------
// Defines and Macros
@@ -76,11 +81,11 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color)
}
// Draw a circle in 3D world space
-void DrawCircle3D(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color)
+void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color)
{
rlPushMatrix();
rlTranslatef(center.x, center.y, center.z);
- rlRotatef(rotationAngle, rotation.x, rotation.y, rotation.z);
+ rlRotatef(rotationAngle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
rlBegin(RL_LINES);
for (int i = 0; i < 360; i += 10)
@@ -579,9 +584,9 @@ void DrawLight(Light light)
{
DrawSphereWires(light->position, 0.3f*light->intensity, 8, 8, (light->enabled ? light->diffuse : GRAY));
- DrawCircle3D(light->position, light->radius, 0.0f, (Vector3){ 0, 0, 0 }, (light->enabled ? light->diffuse : GRAY));
- DrawCircle3D(light->position, light->radius, 90.0f, (Vector3){ 1, 0, 0 }, (light->enabled ? light->diffuse : GRAY));
- DrawCircle3D(light->position, light->radius, 90.0f, (Vector3){ 0, 1, 0 }, (light->enabled ? light->diffuse : GRAY));
+ DrawCircle3D(light->position, light->radius, (Vector3){ 0, 0, 0 }, 0.0f, (light->enabled ? light->diffuse : GRAY));
+ DrawCircle3D(light->position, light->radius, (Vector3){ 1, 0, 0 }, 90.0f, (light->enabled ? light->diffuse : GRAY));
+ DrawCircle3D(light->position, light->radius, (Vector3){ 0, 1, 0 },90.0f, (light->enabled ? light->diffuse : GRAY));
} break;
case LIGHT_DIRECTIONAL:
{
@@ -597,7 +602,7 @@ void DrawLight(Light light)
Vector3 dir = VectorSubtract(light->target, light->position);
VectorNormalize(&dir);
- DrawCircle3D(light->position, 0.5f, 0.0f, dir, (light->enabled ? light->diffuse : GRAY));
+ DrawCircle3D(light->position, 0.5f, dir, 0.0f, (light->enabled ? light->diffuse : GRAY));
//DrawCylinderWires(light->position, 0.0f, 0.3f*light->coneAngle/50, 0.6f, 5, (light->enabled ? light->diffuse : GRAY));
DrawCubeWires(light->target, 0.3f, 0.3f, 0.3f, (light->enabled ? light->diffuse : GRAY));
@@ -1411,7 +1416,7 @@ bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, floa
float dy = centerA.y - centerB.y; // Y distance between centers
float dz = centerA.z - centerB.z; // Y distance between centers
- float distance = sqrt(dx*dx + dy*dy + dz*dz); // Distance between centers
+ float distance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance between centers
if (distance <= (radiusA + radiusB)) collision = true;
@@ -1441,14 +1446,14 @@ bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radius
float dmin = 0;
- if (centerSphere.x < box.min.x) dmin += pow(centerSphere.x - box.min.x, 2);
- else if (centerSphere.x > box.max.x) dmin += pow(centerSphere.x - box.max.x, 2);
+ if (centerSphere.x < box.min.x) dmin += powf(centerSphere.x - box.min.x, 2);
+ else if (centerSphere.x > box.max.x) dmin += powf(centerSphere.x - box.max.x, 2);
- if (centerSphere.y < box.min.y) dmin += pow(centerSphere.y - box.min.y, 2);
- else if (centerSphere.y > box.max.y) dmin += pow(centerSphere.y - box.max.y, 2);
+ if (centerSphere.y < box.min.y) dmin += powf(centerSphere.y - box.min.y, 2);
+ else if (centerSphere.y > box.max.y) dmin += powf(centerSphere.y - box.max.y, 2);
- if (centerSphere.z < box.min.z) dmin += pow(centerSphere.z - box.min.z, 2);
- else if (centerSphere.z > box.max.z) dmin += pow(centerSphere.z - box.max.z, 2);
+ if (centerSphere.z < box.min.z) dmin += powf(centerSphere.z - box.min.z, 2);
+ else if (centerSphere.z > box.max.z) dmin += powf(centerSphere.z - box.max.z, 2);
if (dmin <= (radiusSphere*radiusSphere)) collision = true;
@@ -1487,8 +1492,8 @@ bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadi
float collisionDistance = 0;
// Check if ray origin is inside the sphere to calculate the correct collision point
- if (distance < sphereRadius) collisionDistance = vector + sqrt(d);
- else collisionDistance = vector - sqrt(d);
+ if (distance < sphereRadius) collisionDistance = vector + sqrtf(d);
+ else collisionDistance = vector - sqrtf(d);
VectorScale(&offset, collisionDistance);
Vector3 cPoint = VectorAdd(ray.position, offset);
@@ -1811,7 +1816,8 @@ static Material LoadMTL(const char *fileName)
char buffer[MAX_BUFFER_SIZE];
Vector3 color = { 1.0f, 1.0f, 1.0f };
- char *mapFileName = NULL;
+ char mapFileName[128];
+ int result = 0;
FILE *mtlFile;
@@ -1896,13 +1902,13 @@ static Material LoadMTL(const char *fileName)
{
if (buffer[5] == 'd') // map_Kd string Diffuse color texture map.
{
- sscanf(buffer, "map_Kd %s", mapFileName);
- if (mapFileName != NULL) material.texDiffuse = LoadTexture(mapFileName);
+ result = sscanf(buffer, "map_Kd %s", mapFileName);
+ if (result != EOF) material.texDiffuse = LoadTexture(mapFileName);
}
else if (buffer[5] == 's') // map_Ks string Specular color texture map.
{
- sscanf(buffer, "map_Ks %s", mapFileName);
- if (mapFileName != NULL) material.texSpecular = LoadTexture(mapFileName);
+ result = sscanf(buffer, "map_Ks %s", mapFileName);
+ if (result != EOF) material.texSpecular = LoadTexture(mapFileName);
}
else if (buffer[5] == 'a') // map_Ka string Ambient color texture map.
{
@@ -1911,13 +1917,13 @@ static Material LoadMTL(const char *fileName)
} break;
case 'B': // map_Bump string Bump texture map.
{
- sscanf(buffer, "map_Bump %s", mapFileName);
- if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName);
+ result = sscanf(buffer, "map_Bump %s", mapFileName);
+ if (result != EOF) material.texNormal = LoadTexture(mapFileName);
} break;
case 'b': // map_bump string Bump texture map.
{
- sscanf(buffer, "map_bump %s", mapFileName);
- if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName);
+ result = sscanf(buffer, "map_bump %s", mapFileName);
+ if (result != EOF) material.texNormal = LoadTexture(mapFileName);
} break;
case 'd': // map_d string Opacity texture map.
{
@@ -1941,8 +1947,8 @@ static Material LoadMTL(const char *fileName)
} break;
case 'b': // bump string Bump texture map
{
- sscanf(buffer, "bump %s", mapFileName);
- if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName);
+ result = sscanf(buffer, "bump %s", mapFileName);
+ if (result != EOF) material.texNormal = LoadTexture(mapFileName);
} break;
case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d
{
diff --git a/src/raylib.h b/src/raylib.h
index 58037770..6d67051e 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -6,37 +6,39 @@
*
* Features:
* Library written in plain C code (C99)
-* Uses C# PascalCase/camelCase notation
+* Uses PascalCase/camelCase notation
* Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0)
* Unique OpenGL abstraction layer (usable as standalone module): [rlgl]
* Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF)
* Multiple textures support, including compressed formats and mipmaps generation
* Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps
* Materials (diffuse, normal, specular) and Lighting (point, directional, spot) support
-* Powerful math module for Vector, Matrix and Quaternion operations [raymath]
-* Audio loading and playing with streaming support and mixing channels (WAV, OGG, XM, MOD)
+* Powerful math module for Vector, Matrix and Quaternion operations: [raymath]
+* Audio loading and playing with streaming support and mixing channels [audio]
* VR stereo rendering support with configurable HMD device parameters
* Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi, HTML5 and Oculus Rift CV1
* Custom color palette for fancy visuals on raywhite background
* Minimal external dependencies (GLFW3, OpenGL, OpenAL)
+* Complete binding for LUA [rlua]
*
-* Used external libs:
-* GLFW3 (www.glfw.org) for window/context management and input
-* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP)
-* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC)
-* stb_image_write (Sean Barret) for image writting (PNG)
-* stb_vorbis (Sean Barret) for ogg audio loading
-* stb_truetype (Sean Barret) for ttf fonts loading
-* jar_xm (Joshua Reisenauer) for XM audio module loading
-* jar_mod (Joshua Reisenauer) for MOD audio module loading
-* OpenAL Soft for audio device/context management
-* tinfl for data decompression (DEFLATE algorithm)
+* External libs:
+* GLFW3 (www.glfw.org) for window/context management and input [core]
+* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl]
+* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures]
+* stb_image_write (Sean Barret) for image writting (PNG) [utils]
+* stb_truetype (Sean Barret) for ttf fonts loading [text]
+* stb_vorbis (Sean Barret) for ogg audio loading [audio]
+* jar_xm (Joshua Reisenauer) for XM audio module loading [audio]
+* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio]
+* dr_flac (David Reid) for FLAC audio file loading [audio]
+* OpenAL Soft for audio device/context management [audio]
+* tinfl for data decompression (DEFLATE algorithm) [utils]
*
* Some design decisions:
* 32bit Colors - All defined color are always RGBA (struct Color is 4 byte)
-* One custom default font is loaded automatically when InitWindow()
+* One custom default font could be loaded automatically when InitWindow() [core]
* If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads
-* If using OpenGL 3.3 or ES2, two default shaders are loaded automatically (internally defined)
+* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined)
*
* -- LICENSE --
*
@@ -216,8 +218,8 @@
#define GAMEPAD_PS3_AXIS_LEFT_Y 1
#define GAMEPAD_PS3_AXIS_RIGHT_X 2
#define GAMEPAD_PS3_AXIS_RIGHT_Y 5
-#define GAMEPAD_PS3_AXIS_L2 3 // 1.0(not pressed) --> -1.0(completely pressed)
-#define GAMEPAD_PS3_AXIS_R2 4 // 1.0(not pressed) --> -1.0(completely pressed)
+#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level)
+#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level)
// Xbox360 USB Controller Buttons
#define GAMEPAD_XBOX_BUTTON_A 0
@@ -232,27 +234,25 @@
#define GAMEPAD_XBOX_BUTTON_RIGHT 11
#define GAMEPAD_XBOX_BUTTON_DOWN 12
#define GAMEPAD_XBOX_BUTTON_LEFT 13
-#define GAMEPAD_XBOX_BUTTON_HOME 9
+#define GAMEPAD_XBOX_BUTTON_HOME 8
// Xbox360 USB Controller Axis
-#define GAMEPAD_XBOX_AXIS_LEFT_X 0
-#define GAMEPAD_XBOX_AXIS_LEFT_Y 1
-#define GAMEPAD_XBOX_AXIS_RIGHT_X 2
-#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3
-#define GAMEPAD_XBOX_AXIS_LT 4 // -1.0(not pressed) --> 1.0(completely pressed)
-#define GAMEPAD_XBOX_AXIS_RT 5 // -1.0(not pressed) --> 1.0(completely pressed)
-
-/*
// NOTE: For Raspberry Pi, axis must be reconfigured
#if defined(PLATFORM_RPI)
- #define GAMEPAD_XBOX_AXIS_LEFT_X 7
- #define GAMEPAD_XBOX_AXIS_LEFT_Y 6
- #define GAMEPAD_XBOX_AXIS_RIGHT_X 3
- #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4
- #define GAMEPAD_XBOX_AXIS_LT 2
- #define GAMEPAD_XBOX_AXIS_RT 5
+ #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level)
+ #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level)
+#else
+ #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level)
+ #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level)
#endif
-*/
// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
@@ -307,9 +307,6 @@
#endif
#endif
-// byte type
-typedef unsigned char byte;
-
// Vector2 type
typedef struct Vector2 {
float x;
@@ -727,7 +724,7 @@ RLAPI float GetGesturePinchAngle(void); // Get gesture pin
//------------------------------------------------------------------------------------
// Camera System Functions (Module: camera)
//------------------------------------------------------------------------------------
-RLAPI void SetCameraMode(Camera, int mode); // Set camera mode (multiple camera modes available)
+RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available)
RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode
RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
@@ -828,7 +825,7 @@ RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color co
RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters
float fontSize, int spacing, Color tint);
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
-RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing); // Measure string size for SpriteFont
+RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont
RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner
RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
@@ -838,7 +835,7 @@ RLAPI const char *SubText(const char *text, int position, int length);
// Basic 3d Shapes Drawing Functions (Module: models)
//------------------------------------------------------------------------------------
RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space
-RLAPI void DrawCircle3D(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space
+RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space
RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube
RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version)
RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires
@@ -853,7 +850,7 @@ RLAPI void DrawRay(Ray ray, Color color);
RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0))
RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo
RLAPI void DrawLight(Light light); // Draw light in 3D world
-//DrawTorus(), DrawTeapot() are useless...
+//DrawTorus(), DrawTeapot() could be useful?
//------------------------------------------------------------------------------------
// Model 3d Loading and Drawing Functions (Module: models)
@@ -920,7 +917,7 @@ RLAPI void DestroyLight(Light light); // Des
//------------------------------------------------------------------------------------
RLAPI void InitVrDevice(int vdDevice); // Init VR device
RLAPI void CloseVrDevice(void); // Close VR device
-RLAPI bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready
+RLAPI bool IsVrDeviceReady(void); // Detect if VR device is ready
RLAPI bool IsVrSimulator(void); // Detect if VR simulator is running
RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
RLAPI void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
@@ -929,7 +926,7 @@ RLAPI void ToggleVrMode(void); // Enable/Disable VR experienc
// Audio Loading and Playing Functions (Module: audio)
//------------------------------------------------------------------------------------
RLAPI void InitAudioDevice(void); // Initialize audio device and context
-RLAPI void CloseAudioDevice(void); // Close the audio device and context (and music stream)
+RLAPI void CloseAudioDevice(void); // Close the audio device and context
RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully
RLAPI Wave LoadWave(const char *fileName); // Load wave data from file into RAM
@@ -953,9 +950,9 @@ RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a
RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array
RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file
RLAPI void UnloadMusicStream(Music music); // Unload music stream
-RLAPI void PlayMusicStream(Music music); // Start music playing (open stream)
+RLAPI void PlayMusicStream(Music music); // Start music playing
RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming
-RLAPI void StopMusicStream(Music music); // Stop music playing (close stream)
+RLAPI void StopMusicStream(Music music); // Stop music playing
RLAPI void PauseMusicStream(Music music); // Pause music playing
RLAPI void ResumeMusicStream(Music music); // Resume playing paused music
RLAPI bool IsMusicPlaying(Music music); // Check if music is playing
@@ -966,7 +963,7 @@ RLAPI float GetMusicTimePlayed(Music music); // Get cur
RLAPI AudioStream InitAudioStream(unsigned int sampleRate,
unsigned int sampleSize,
- unsigned int channels); // Init audio stream (to stream audio pcm data)
+ unsigned int channels); // Init audio stream (to stream raw audio pcm data)
RLAPI void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data
RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
diff --git a/src/resources b/src/resources
index e0fe66ba..5c76749d 100644
--- a/src/resources
+++ b/src/resources
Binary files differ
diff --git a/src/rlgl.c b/src/rlgl.c
index e2804e9c..b567f8fd 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -2,11 +2,30 @@
*
* rlgl - raylib OpenGL abstraction layer
*
-* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
-* OpenGL 1.1 - Direct map rl* -> gl*
-* OpenGL 2.1 - Vertex data is stored in VBOs, call rlglDraw() to render
-* OpenGL 3.3 - Vertex data is stored in VAOs, call rlglDraw() to render
-* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render
+* rlgl allows usage of OpenGL 1.1 style functions (rlVertex) that are internally mapped to
+* selected OpenGL version (1.1, 2.1, 3.3 Core, ES 2.0).
+*
+* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal
+* VBO buffers (and VAOs if available). It requires calling 3 functions:
+* rlglInit() - Initialize internal buffers and auxiliar resources
+* rlglDraw() - Process internal buffers and send required draw calls
+* rlglClose() - De-initialize internal buffers data and other auxiliar resources
+*
+* External libs:
+* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
+* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only)
+*
+* Module Configuration Flags:
+* GRAPHICS_API_OPENGL_11 - Use OpenGL 1.1 backend
+* GRAPHICS_API_OPENGL_21 - Use OpenGL 2.1 backend
+* GRAPHICS_API_OPENGL_33 - Use OpenGL 3.3 Core profile backend
+* GRAPHICS_API_OPENGL_ES2 - Use OpenGL ES 2.0 backend
+*
+* RLGL_STANDALONE - Use rlgl as standalone library (no raylib dependency)
+* RLGL_NO_STANDARD_SHADER - Avoid standard shader (shader_standard.h) inclusion
+* RLGL_NO_DISTORTION_SHADER - Avoid stereo rendering distortion sahder (shader_distortion.h) inclusion
+* RLGL_OCULUS_SUPPORT - Enable Oculus Rift CV1 functionality
+*
*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
@@ -2767,13 +2786,13 @@ void CloseVrDevice(void)
// Detect if VR device is available
bool IsVrDeviceReady(void)
{
- return (vrDeviceReady || vrSimulator) && vrEnabled;
+ return (vrDeviceReady && vrEnabled);
}
// Detect if VR simulator is running
bool IsVrSimulator(void)
{
- return vrSimulator;
+ return (vrSimulator && vrEnabled);
}
// Enable/Disable VR experience (device or simulator)
@@ -3882,7 +3901,7 @@ static void SetStereoConfig(VrDeviceInfo hmd)
// Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)*RAD2DEG
// ...but with lens distortion it is increased (see Oculus SDK Documentation)
//float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance)*RAD2DEG; // Really need distortionScale?
- float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance)*RAD2DEG;
+ float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance)*RAD2DEG;
// Compute camera projection matrices
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
diff --git a/src/rlgl.h b/src/rlgl.h
index 9be73f36..7d328a52 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -2,11 +2,27 @@
*
* rlgl - raylib OpenGL abstraction layer
*
-* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
-* OpenGL 1.1 - Direct map rl* -> gl*
-* OpenGL 2.1 - Vertex data is stored in VBOs, call rlglDraw() to render
-* OpenGL 3.3 - Vertex data is stored in VAOs, call rlglDraw() to render
-* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render
+* rlgl allows usage of OpenGL 1.1 style functions (rlVertex) that are internally mapped to
+* selected OpenGL version (1.1, 2.1, 3.3 Core, ES 2.0).
+*
+* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal
+* VBO buffers (and VAOs if available). It requires calling 3 functions:
+* rlglInit() - Initialize internal buffers and auxiliar resources
+* rlglDraw() - Process internal buffers and send required draw calls
+* rlglClose() - De-initialize internal buffers data and other auxiliar resources
+*
+* External libs:
+* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
+* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only)
+*
+* Module Configuration Flags:
+* GRAPHICS_API_OPENGL_11 - Use OpenGL 1.1 backend
+* GRAPHICS_API_OPENGL_21 - Use OpenGL 2.1 backend
+* GRAPHICS_API_OPENGL_33 - Use OpenGL 3.3 Core profile backend
+* GRAPHICS_API_OPENGL_ES2 - Use OpenGL ES 2.0 backend
+*
+* RLGL_STANDALONE - Use rlgl as standalone library (no raylib dependency)
+*
*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
@@ -117,15 +133,14 @@ typedef enum { RL_PROJECTION, RL_MODELVIEW, RL_TEXTURE } MatrixMode;
typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
+typedef unsigned char byte;
+
#if defined(RLGL_STANDALONE)
#ifndef __cplusplus
// Boolean type
typedef enum { false, true } bool;
#endif
- // byte type
- typedef unsigned char byte;
-
// Color type, RGBA (32bit)
typedef struct Color {
unsigned char r;
@@ -408,7 +423,8 @@ float *MatrixToFloat(Matrix mat);
void InitVrDevice(int vrDevice); // Init VR device
void CloseVrDevice(void); // Close VR device
-bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready
+bool IsVrDeviceReady(void); // Detect if VR device is ready
+bool IsVrSimulator(void); // Detect if VR simulator is running
void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
diff --git a/src/rlua.h b/src/rlua.h
index 97d22922..c801a328 100644
--- a/src/rlua.h
+++ b/src/rlua.h
@@ -1095,14 +1095,14 @@ int lua_IsFileDropped(lua_State* L)
int lua_GetDroppedFiles(lua_State* L)
{
int count = 0;
- char ** result = GetDroppedFiles(&count);
+ char ** result = GetDroppedFiles(&count);
lua_createtable(L, count, 0);
for (int i = 0; i < count; i++)
{
lua_pushstring(L, result[i]);
lua_rawseti(L, -2, i + 1);
}
- return 1;
+ return 1;
}
int lua_ClearDroppedFiles(lua_State* L)
@@ -1130,7 +1130,6 @@ int lua_StorageLoadValue(lua_State* L)
//------------------------------------------------------------------------------------
// raylib [core] module functions - Input Handling
//------------------------------------------------------------------------------------
-#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
int lua_IsKeyPressed(lua_State* L)
{
int arg1 = LuaGetArgument_int(L, 1);
@@ -1185,12 +1184,22 @@ int lua_IsGamepadAvailable(lua_State* L)
return 1;
}
-int lua_GetGamepadAxisMovement(lua_State* L)
+int lua_IsGamepadName(lua_State* L)
{
int arg1 = LuaGetArgument_int(L, 1);
- int arg2 = LuaGetArgument_int(L, 2);
- float result = GetGamepadAxisMovement(arg1, arg2);
- lua_pushnumber(L, result);
+ const char * arg2 = LuaGetArgument_string(L, 2);
+ bool result = IsGamepadName(arg1, arg2);
+ lua_pushboolean(L, result);
+ return 1;
+}
+
+int lua_GetGamepadName(lua_State* L)
+{
+ // TODO: Return gamepad name id
+
+ int arg1 = LuaGetArgument_int(L, 1);
+ char * result = GetGamepadName(arg1);
+ //lua_pushboolean(L, result);
return 1;
}
@@ -1229,7 +1238,30 @@ int lua_IsGamepadButtonUp(lua_State* L)
lua_pushboolean(L, result);
return 1;
}
-#endif
+
+int lua_GetGamepadButtonPressed(lua_State* L)
+{
+ int result = GetGamepadButtonPressed();
+ lua_pushinteger(L, result);
+ return 1;
+}
+
+int lua_GetGamepadAxisCount(lua_State* L)
+{
+ int arg1 = LuaGetArgument_int(L, 1);
+ int result = GetGamepadAxisCount(arg1);
+ lua_pushinteger(L, result);
+ return 1;
+}
+
+int lua_GetGamepadAxisMovement(lua_State* L)
+{
+ int arg1 = LuaGetArgument_int(L, 1);
+ int arg2 = LuaGetArgument_int(L, 2);
+ float result = GetGamepadAxisMovement(arg1, arg2);
+ lua_pushnumber(L, result);
+ return 1;
+}
int lua_IsMouseButtonPressed(lua_State* L)
{
@@ -1419,8 +1451,9 @@ int lua_GetGesturePinchAngle(lua_State* L)
//------------------------------------------------------------------------------------
int lua_SetCameraMode(lua_State* L)
{
- int arg1 = LuaGetArgument_int(L, 1);
- SetCameraMode(arg1);
+ Camera arg1 = LuaGetArgument_Camera(L, 1);
+ int arg2 = LuaGetArgument_int(L, 2);
+ SetCameraMode(arg1, arg2);
return 0;
}
@@ -1432,37 +1465,6 @@ int lua_UpdateCamera(lua_State* L)
return 1;
}
-int lua_UpdateCameraPlayer(lua_State* L)
-{
- Camera arg1 = LuaGetArgument_Camera(L, 1);
- Vector3 arg2 = LuaGetArgument_Vector3(L, 2);
- UpdateCameraPlayer(&arg1, &arg2);
- LuaPush_Camera(L, arg1);
- LuaPush_Vector3(L, arg2);
- return 2;
-}
-
-int lua_SetCameraPosition(lua_State* L)
-{
- Vector3 arg1 = LuaGetArgument_Vector3(L, 1);
- SetCameraPosition(arg1);
- return 0;
-}
-
-int lua_SetCameraTarget(lua_State* L)
-{
- Vector3 arg1 = LuaGetArgument_Vector3(L, 1);
- SetCameraTarget(arg1);
- return 0;
-}
-
-int lua_SetCameraFovy(lua_State* L)
-{
- float arg1 = LuaGetArgument_float(L, 1);
- SetCameraFovy(arg1);
- return 0;
-}
-
int lua_SetCameraPanControl(lua_State* L)
{
int arg1 = LuaGetArgument_int(L, 1);
@@ -1496,13 +1498,6 @@ int lua_SetCameraMoveControls(lua_State* L)
return 0;
}
-int lua_SetCameraMouseSensitivity(lua_State* L)
-{
- float arg1 = LuaGetArgument_float(L, 1);
- SetCameraMouseSensitivity(arg1);
- return 0;
-}
-
//------------------------------------------------------------------------------------
// raylib [shapes] module functions - Basic Shapes Drawing
//------------------------------------------------------------------------------------
@@ -1790,6 +1785,8 @@ int lua_LoadImage(lua_State* L)
int lua_LoadImageEx(lua_State* L)
{
+ // TODO: Image LoadImageEx(Color *pixels, int width, int height);
+
GET_TABLE(Color, arg1, 1);
int arg2 = LuaGetArgument_int(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
@@ -1888,6 +1885,8 @@ int lua_UnloadRenderTexture(lua_State* L)
int lua_GetImageData(lua_State* L)
{
+ // TODO: Color *GetImageData(Image image);
+
Image arg1 = LuaGetArgument_Image(L, 1);
Color * result = GetImageData(arg1);
lua_createtable(L, arg1.width*arg1.height, 0);
@@ -1908,6 +1907,16 @@ int lua_GetTextureData(lua_State* L)
return 1;
}
+int lua_UpdateTexture(lua_State* L)
+{
+ // TODO: void UpdateTexture(Texture2D texture, void *pixels);
+
+ Texture2D arg1 = LuaGetArgument_Texture2D(L, 1);
+ void * arg2 = (char *)LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string?
+ UpdateTexture(arg1, arg2); // ISSUE: #2 string expected, got table -> GetImageData() returns a table!
+ return 0;
+}
+
int lua_ImageToPOT(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
@@ -2100,11 +2109,19 @@ int lua_GenTextureMipmaps(lua_State* L)
return 0;
}
-int lua_UpdateTexture(lua_State* L)
+int lua_SetTextureFilter(lua_State* L)
{
Texture2D arg1 = LuaGetArgument_Texture2D(L, 1);
- void * arg2 = (char *)LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string?
- UpdateTexture(arg1, arg2); // ISSUE: #2 string expected, got table -> GetImageData() returns a table!
+ int arg2 = LuaGetArgument_int(L, 2);
+ SetTextureFilter(arg1, arg2);
+ return 0;
+}
+
+int lua_SetTextureWrap(lua_State* L)
+{
+ Texture2D arg1 = LuaGetArgument_Texture2D(L, 1);
+ int arg2 = LuaGetArgument_int(L, 2);
+ SetTextureWrap(arg1, arg2);
return 0;
}
@@ -2178,6 +2195,18 @@ int lua_LoadSpriteFont(lua_State* L)
return 1;
}
+int lua_LoadSpriteFontTTF(lua_State* L)
+{
+ const char * arg1 = LuaGetArgument_string(L, 1);
+ int arg2 = LuaGetArgument_int(L, 2);
+ int arg3 = LuaGetArgument_int(L, 3);
+ int arg4 = LuaGetArgument_int(L, 4);
+ //LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars);
+ SpriteFont result = LoadSpriteFontTTF(arg1, arg2, arg3, &arg4);
+ LuaPush_SpriteFont(L, result);
+ return 1;
+}
+
int lua_UnloadSpriteFont(lua_State* L)
{
SpriteFont arg1 = LuaGetArgument_SpriteFont(L, 1);
@@ -2255,8 +2284,8 @@ int lua_DrawCircle3D(lua_State* L)
{
Vector3 arg1 = LuaGetArgument_Vector3(L, 1);
float arg2 = LuaGetArgument_float(L, 2);
- float arg3 = LuaGetArgument_float(L, 3);
- Vector3 arg4 = LuaGetArgument_Vector3(L, 4);
+ Vector3 arg3 = LuaGetArgument_Vector3(L, 3);
+ float arg4 = LuaGetArgument_float(L, 4);
Color arg5 = LuaGetArgument_Color(L, 5);
DrawCircle3D(arg1, arg2, arg3, arg4, arg5);
return 0;
@@ -2619,18 +2648,6 @@ int lua_CheckCollisionRayBox(lua_State* L)
return 1;
}
-int lua_ResolveCollisionCubicmap(lua_State* L)
-{
- Image arg1 = LuaGetArgument_Image(L, 1);
- Vector3 arg2 = LuaGetArgument_Vector3(L, 2);
- Vector3 arg3 = LuaGetArgument_Vector3(L, 3);
- float arg4 = LuaGetArgument_float(L, 4);
- Vector3 result = ResolveCollisionCubicmap(arg1, arg2, &arg3, arg4);
- LuaPush_Vector3(L, result);
- LuaPush_Vector3(L, arg3);
- return 2;
-}
-
//------------------------------------------------------------------------------------
// raylib [raymath] module functions - Shaders
//------------------------------------------------------------------------------------
@@ -2790,10 +2807,19 @@ int lua_IsVrDeviceReady(lua_State* L)
return 1;
}
+int lua_IsVrSimulator(lua_State* L)
+{
+ bool result = IsVrSimulator();
+ lua_pushboolean(L, result);
+ return 1;
+}
+
int lua_UpdateVrTracking(lua_State* L)
{
- UpdateVrTracking();
- return 0;
+ Camera arg1 = LuaGetArgument_Camera(L, 1);
+ UpdateVrTracking(&arg1);
+ LuaPush_Camera(L, arg1);
+ return 1;
}
int lua_ToggleVrMode(lua_State* L)
@@ -2873,6 +2899,8 @@ int lua_LoadSoundFromRES(lua_State* L)
int lua_UpdateSound(lua_State* L)
{
+ // TODO: void UpdateSound(Sound sound, void *data, int numSamples);
+
Sound arg1 = LuaGetArgument_Sound(L, 1);
const char * arg2 = LuaGetArgument_string(L, 2);
int * arg3 = LuaGetArgument_int(L, 3);
@@ -2952,11 +2980,11 @@ int lua_WaveFormat(lua_State* L)
int arg2 = LuaGetArgument_int(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
int arg4 = LuaGetArgument_int(L, 4);
- WaveFormat(arg1, arg2, arg3, arg4);
+ WaveFormat(&arg1, arg2, arg3, arg4);
return 0;
}
-int lua_LoadMusicStream(lua_State* L)
+int lua_WaveCopy(lua_State* L)
{
Wave arg1 = LuaGetArgument_Wave(L, 1);
Wave result = WaveCopy(arg1);
@@ -2969,7 +2997,7 @@ int lua_WaveCrop(lua_State* L)
Wave arg1 = LuaGetArgument_Wave(L, 1);
int arg2 = LuaGetArgument_int(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
- WaveCrop(arg1, arg2, arg3);
+ WaveCrop(&arg1, arg2, arg3);
return 0;
}
@@ -2978,9 +3006,10 @@ int lua_GetWaveData(lua_State* L)
// TODO: float *GetWaveData(Wave wave);
Wave arg1 = LuaGetArgument_Wave(L, 1);
- float result = GetWaveData(arg1);
- LuaPush_float(L, result);
- return 1;
+ float * result = GetWaveData(arg1);
+ //LuaPush_float(L, result);
+ //lua_pushnumber(L, result);
+ return 0;
}
int lua_LoadMusicStream(lua_State* L)
@@ -3012,7 +3041,6 @@ int lua_PlayMusicStream(lua_State* L)
return 0;
}
-
int lua_StopMusicStream(lua_State* L)
{
Music arg1 = LuaGetArgument_Music(L, 1);
@@ -3093,6 +3121,8 @@ int lua_CloseAudioStream(lua_State* L)
int lua_UpdateAudioStream(lua_State* L)
{
+ // TODO: void UpdateAudioStream(AudioStream stream, void *data, int numSamples);
+
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
void * arg2 = (char *)LuaGetArgument_string(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
@@ -3667,7 +3697,6 @@ static luaL_Reg raylib_functions[] = {
REG(StorageSaveValue)
REG(StorageLoadValue)
-#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
REG(IsKeyPressed)
REG(IsKeyDown)
REG(IsKeyReleased)
@@ -3676,12 +3705,15 @@ static luaL_Reg raylib_functions[] = {
REG(SetExitKey)
REG(IsGamepadAvailable)
- REG(GetGamepadAxisMovement)
+ REG(IsGamepadName)
+ REG(GetGamepadName)
REG(IsGamepadButtonPressed)
REG(IsGamepadButtonDown)
REG(IsGamepadButtonReleased)
REG(IsGamepadButtonUp)
-#endif
+ REG(GetGamepadButtonPressed)
+ REG(GetGamepadAxisCount)
+ REG(GetGamepadAxisMovement)
REG(IsMouseButtonPressed)
REG(IsMouseButtonDown)
@@ -3714,16 +3746,10 @@ static luaL_Reg raylib_functions[] = {
REG(SetCameraMode)
REG(UpdateCamera)
- REG(UpdateCameraPlayer)
- REG(SetCameraPosition)
- REG(SetCameraTarget)
- REG(SetCameraFovy)
-
REG(SetCameraPanControl)
REG(SetCameraAltControl)
REG(SetCameraSmoothZoomControl)
REG(SetCameraMoveControls)
- REG(SetCameraMouseSensitivity)
REG(DrawPixel)
REG(DrawPixelV)
@@ -3766,6 +3792,7 @@ static luaL_Reg raylib_functions[] = {
REG(UnloadRenderTexture)
REG(GetImageData)
REG(GetTextureData)
+ REG(UpdateTexture)
REG(ImageToPOT)
REG(ImageFormat)
REG(ImageDither)
@@ -3786,8 +3813,9 @@ static luaL_Reg raylib_functions[] = {
REG(ImageColorContrast)
REG(ImageColorBrightness)
REG(GenTextureMipmaps)
- REG(UpdateTexture)
-
+ REG(SetTextureFilter)
+ REG(SetTextureWrap)
+
REG(DrawTexture)
REG(DrawTextureV)
REG(DrawTextureEx)
@@ -3796,6 +3824,7 @@ static luaL_Reg raylib_functions[] = {
REG(GetDefaultFont)
REG(LoadSpriteFont)
+ REG(LoadSpriteFontTTF)
REG(UnloadSpriteFont)
REG(DrawText)
REG(DrawTextEx)
@@ -3845,7 +3874,6 @@ static luaL_Reg raylib_functions[] = {
REG(CheckCollisionRaySphere)
REG(CheckCollisionRaySphereEx)
REG(CheckCollisionRayBox)
- REG(ResolveCollisionCubicmap)
REG(LoadShader)
REG(UnloadShader)
@@ -3868,6 +3896,7 @@ static luaL_Reg raylib_functions[] = {
REG(InitVrDevice)
REG(CloseVrDevice)
REG(IsVrDeviceReady)
+ REG(IsVrSimulator)
REG(UpdateVrTracking)
REG(ToggleVrMode)
diff --git a/src/shapes.c b/src/shapes.c
index 79cf567a..70aad59a 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -4,6 +4,12 @@
*
* Basic functions to draw 2d Shapes and check collisions
*
+* External libs:
+* rlgl - raylib OpenGL abstraction layer
+*
+* Module Configuration Flags:
+* ...
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -25,11 +31,11 @@
#include "raylib.h"
+#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
+
#include <stdlib.h> // Required for: abs()
#include <math.h> // Required for: sinf(), cosf(), sqrtf()
-#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
-
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
diff --git a/src/text.c b/src/text.c
index 23041603..c394889e 100644
--- a/src/text.c
+++ b/src/text.c
@@ -4,6 +4,12 @@
*
* Basic functions to load SpriteFonts and draw Text
*
+* External libs:
+* stb_truetype - Load TTF file and rasterize characters data
+*
+* Module Configuration Flags:
+* ...
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -33,7 +39,7 @@
#include "utils.h" // Required for: GetExtension(), GetNextPOT()
// Following libs are used on LoadTTF()
-//#define STBTT_STATIC
+#define STBTT_STATIC // Define stb_truetype functions static to this module
#define STB_TRUETYPE_IMPLEMENTATION
#include "external/stb_truetype.h" // Required for: stbtt_BakeFontBitmap()
@@ -344,13 +350,13 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, float fontSize, int spacing, Color tint)
{
int length = strlen(text);
- int textOffsetX = 0;
- int textOffsetY = 0; // Line break!
+ int textOffsetX = 0; // Offset between characters
+ int textOffsetY = 0; // Required for line break!
float scaleFactor;
- unsigned char letter;
-
- Rectangle rec;
-
+
+ unsigned char letter; // Current character
+ int index; // Index position in sprite font
+
scaleFactor = fontSize/spriteFont.size;
// NOTE: Some ugly hacks are made to support Latin-1 Extended characters directly
@@ -358,41 +364,37 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, float
for (int i = 0; i < length; i++)
{
- if ((unsigned char)text[i] == 0xc2) // UTF-8 encoding identification HACK!
- {
- // Support UTF-8 encoded values from [0xc2 0x80] -> [0xc2 0xbf](¿)
- letter = (unsigned char)text[i + 1];
- rec = spriteFont.charRecs[GetCharIndex(spriteFont, (int)letter)];
- i++;
- }
- else if ((unsigned char)text[i] == 0xc3) // UTF-8 encoding identification HACK!
+ if ((unsigned char)text[i] == '\n')
{
- // Support UTF-8 encoded values from [0xc3 0x80](À) -> [0xc3 0xbf](ÿ)
- letter = (unsigned char)text[i + 1];
- rec = spriteFont.charRecs[GetCharIndex(spriteFont, (int)letter + 64)];
- i++;
+ // NOTE: Fixed line spacing of 1.5 lines
+ textOffsetY += ((spriteFont.size + spriteFont.size/2)*scaleFactor);
+ textOffsetX = 0;
}
else
{
- if ((unsigned char)text[i] == '\n')
+ if ((unsigned char)text[i] == 0xc2) // UTF-8 encoding identification HACK!
{
- // NOTE: Fixed line spacing of 1.5 lines
- textOffsetY += ((spriteFont.size + spriteFont.size/2)*scaleFactor);
- textOffsetX = 0;
- rec.x = -1;
+ // Support UTF-8 encoded values from [0xc2 0x80] -> [0xc2 0xbf](¿)
+ letter = (unsigned char)text[i + 1];
+ index = GetCharIndex(spriteFont, (int)letter);
+ i++;
}
- else rec = spriteFont.charRecs[GetCharIndex(spriteFont, (int)text[i])];
- }
+ else if ((unsigned char)text[i] == 0xc3) // UTF-8 encoding identification HACK!
+ {
+ // Support UTF-8 encoded values from [0xc3 0x80](À) -> [0xc3 0xbf](ÿ)
+ letter = (unsigned char)text[i + 1];
+ index = GetCharIndex(spriteFont, (int)letter + 64);
+ i++;
+ }
+ else index = GetCharIndex(spriteFont, (int)text[i]);
- if (rec.x >= 0)
- {
- int index = GetCharIndex(spriteFont, (int)text[i]);
-
- DrawTexturePro(spriteFont.texture, rec, (Rectangle){ position.x + textOffsetX + spriteFont.charOffsets[index].x*scaleFactor,
- position.y + textOffsetY + spriteFont.charOffsets[index].y*scaleFactor,
- rec.width*scaleFactor, rec.height*scaleFactor} , (Vector2){ 0, 0 }, 0.0f, tint);
+ DrawTexturePro(spriteFont.texture, spriteFont.charRecs[index],
+ (Rectangle){ position.x + textOffsetX + spriteFont.charOffsets[index].x*scaleFactor,
+ position.y + textOffsetY + spriteFont.charOffsets[index].y*scaleFactor,
+ spriteFont.charRecs[index].width*scaleFactor,
+ spriteFont.charRecs[index].height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, tint);
- if (spriteFont.charAdvanceX[index] == 0) textOffsetX += (rec.width*scaleFactor + spacing);
+ if (spriteFont.charAdvanceX[index] == 0) textOffsetX += (spriteFont.charRecs[index].width*scaleFactor + spacing);
else textOffsetX += (spriteFont.charAdvanceX[index]*scaleFactor + spacing);
}
}
@@ -448,14 +450,14 @@ int MeasureText(const char *text, int fontSize)
if (fontSize < defaultFontSize) fontSize = defaultFontSize;
int spacing = fontSize/defaultFontSize;
- vec = MeasureTextEx(GetDefaultFont(), text, fontSize, spacing);
+ vec = MeasureTextEx(GetDefaultFont(), text, (float)fontSize, spacing);
}
return (int)vec.x;
}
// Measure string size for SpriteFont
-Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing)
+Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing)
{
int len = strlen(text);
int tempLen = 0; // Used to count longer text line num chars
@@ -465,7 +467,7 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int
int tempTextWidth = 0; // Used to count longer text line width
int textHeight = spriteFont.size;
- float scaleFactor;
+ float scaleFactor = fontSize/spriteFont.size;
for (int i = 0; i < len; i++)
{
@@ -491,9 +493,6 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
- if (fontSize <= spriteFont.size) scaleFactor = 1.0f;
- else scaleFactor = (float)fontSize/spriteFont.size;
-
Vector2 vec;
vec.x = (float)tempTextWidth*scaleFactor + (tempLen - 1)*spacing; // Adds chars spacing to measure
vec.y = (float)textHeight*scaleFactor;
@@ -535,7 +534,7 @@ void DrawFPS(int posX, int posY)
static int GetCharIndex(SpriteFont font, int letter)
{
-//#define UNORDERED_CHARSET
+#define UNORDERED_CHARSET
#if defined(UNORDERED_CHARSET)
int index = 0;
@@ -876,10 +875,18 @@ static SpriteFont LoadBMFont(const char *fileName)
TraceLog(DEBUG, "[%s] Font texture loading path: %s", fileName, texPath);
Image imFont = LoadImage(texPath);
+
+ if (imFont.format == UNCOMPRESSED_GRAYSCALE)
+ {
+ Image imCopy = ImageCopy(imFont);
+
+ for (int i = 0; i < imCopy.width*imCopy.height; i++) ((unsigned char *)imCopy.data)[i] = 0xff; // WHITE pixel
- if (imFont.format == UNCOMPRESSED_GRAYSCALE) ImageAlphaMask(&imFont, imFont);
-
- font.texture = LoadTextureFromImage(imFont);
+ ImageAlphaMask(&imCopy, imFont);
+ font.texture = LoadTextureFromImage(imCopy);
+ UnloadImage(imCopy);
+ }
+ else font.texture = LoadTextureFromImage(imFont);
font.size = fontSize;
font.numChars = numChars;
diff --git a/src/textures.c b/src/textures.c
index 5354a74f..af59d035 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -4,9 +4,13 @@
*
* Basic functions to load and draw Textures (2d)
*
-* Uses external lib:
-* stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC)
-* NOTE: stb_image has been slightly modified, original library: https://github.com/nothings/stb
+* External libs:
+* stb_image - Multiple image formats loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC)
+* NOTE: stb_image has been slightly modified to support Android platform.
+* stb_image_resize - Multiple image resize algorythms
+*
+* Module Configuration Flags:
+* ...
*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
diff --git a/src/utils.c b/src/utils.c
index b96e2c70..640c5720 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -2,12 +2,16 @@
*
* raylib.utils
*
-* Utils Functions Definitions
+* Some utility functions
*
-* Uses external libs:
-* tinfl - zlib DEFLATE algorithm decompression lib
+* External libs:
+* tinfl - zlib DEFLATE algorithm decompression
* stb_image_write - PNG writting functions
*
+* Module Configuration Flags:
+* DO_NOT_TRACE_DEBUG_MSGS - Avoid showing DEBUG TraceLog() messages
+*
+*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
@@ -46,7 +50,9 @@
#endif
#include "external/tinfl.c" // Required for: tinfl_decompress_mem_to_mem()
- // NOTE: Deflate algorythm data decompression
+ // NOTE: DEFLATE algorythm data decompression
+
+#define DO_NOT_TRACE_DEBUG_MSGS // Avoid DEBUG messages tracing
//----------------------------------------------------------------------------------
// Global Variables Definition
diff --git a/src/utils.h b/src/utils.h
index 899cf583..045b0692 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -2,9 +2,9 @@
*
* raylib.utils
*
-* Some utility functions: rRES files data decompression
+* Some utility functions
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@@ -34,8 +34,6 @@
//----------------------------------------------------------------------------------
// Some basic Defines
//----------------------------------------------------------------------------------
-#define DO_NOT_TRACE_DEBUG_MSGS // Use this define to avoid DEBUG tracing
-
#if defined(PLATFORM_ANDROID)
#define fopen(name, mode) android_fopen(name, mode)
#endif