summaryrefslogtreecommitdiffhomepage
path: root/templates
diff options
context:
space:
mode:
authorRay San <[email protected]>2017-09-28 17:05:43 +0200
committerRay San <[email protected]>2017-09-28 17:05:43 +0200
commitf5dcb51efead4a7964c8536b9d33980f4734b3d1 (patch)
tree548a1148e1d1df87ec612c421d1f6f595a003069 /templates
parente284adcfc1f88d7075a7b357f94dbe21a55271a6 (diff)
downloadraylib-f5dcb51efead4a7964c8536b9d33980f4734b3d1.tar.gz
raylib-f5dcb51efead4a7964c8536b9d33980f4734b3d1.zip
Work on custom Android build
- Renamed some folders - Added some files for testing - Removed useless files
Diffstat (limited to 'templates')
-rw-r--r--templates/android_project/Makefile15
-rw-r--r--templates/android_project/assets/EMPTY0
-rw-r--r--templates/android_project/assets/alagard.rbmfbin2159 -> 0 bytes
-rw-r--r--templates/android_project/assets/ambient.oggbin2672956 -> 0 bytes
-rw-r--r--templates/android_project/assets/coin.wavbin9508 -> 0 bytes
-rw-r--r--templates/android_project/assets/raylib_logo.pngbin3760 -> 0 bytes
-rw-r--r--templates/android_project/jni/Android.mk100
-rw-r--r--templates/android_project/jni/basic_game.c172
-rw-r--r--templates/android_project/jni/include/AL/al.h656
-rw-r--r--templates/android_project/jni/include/AL/alc.h237
-rw-r--r--templates/android_project/jni/include/AL/alext.h455
-rw-r--r--templates/android_project/jni/include/AL/efx-creative.h3
-rw-r--r--templates/android_project/jni/include/AL/efx-presets.h402
-rw-r--r--templates/android_project/jni/include/AL/efx.h761
-rw-r--r--templates/android_project/jni/libs/libraylib.abin507474 -> 0 bytes
-rw-r--r--templates/android_project/src/core.c3476
-rw-r--r--templates/android_project/src/game_crash.c58
-rw-r--r--templates/android_project/src/game_ok.c684
-rw-r--r--templates/android_project/src/libs/libopenal.so (renamed from templates/android_project/jni/libs/libopenal.so)bin2389824 -> 2389824 bytes
-rw-r--r--templates/android_project/src/raylib.h (renamed from templates/android_project/jni/include/raylib.h)0
-rw-r--r--templates/android_project/src/raymath.h1367
-rw-r--r--templates/android_project/src/rlgl.c4184
-rw-r--r--templates/android_project/src/rlgl.h474
-rw-r--r--templates/android_project/src/utils.c214
-rw-r--r--templates/android_project/src/utils.h79
25 files changed, 10545 insertions, 2792 deletions
diff --git a/templates/android_project/Makefile b/templates/android_project/Makefile
index 79a2725f..e504d9b7 100644
--- a/templates/android_project/Makefile
+++ b/templates/android_project/Makefile
@@ -44,7 +44,7 @@ ANDROID_BUILD_TOOLS = C:/android-sdk/build-tools/26.0.1
JAVA_HOME = C:/PROGRA~1/Java/jdk1.8.0_144
# Compilers
-CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-gcc
+CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
# Define compiler flags
@@ -54,11 +54,11 @@ CFLAGS = -Wall -std=c99 -DPLATFORM_ANDROID -march=armv7-a -mfloat-abi=softfp -mf
INCLUDES = -I. -Ijni/include -I$(ANDROID_NDK)/sources/android/native_app_glue
# Define library paths containing required libs
-LFLAGS = -L. -Ljni/libs -Ljni -Llib
+LFLAGS = -L. -Ljni -Llib -Ljni/libs
# Define any libraries to link into executable
# if you want to link libraries (libname.so or libname.a), use the -lname
-LIBS = -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES
+LIBS = -llog -landroid -lEGL -lGLESv2 -lOpenSLES
# Building APK
# NOTE: typing 'make' will invoke the default target entry called 'all',
@@ -91,8 +91,11 @@ native_app_glue:
# Compile project code as shared libraries
# OUTPUT: $(PROJECT_DIR)/lib/lib$(LIBRARY_NAME).so
project_code:
- $(CC) -c jni/basic_game.c -o temp/obj/basic_game.o $(INCLUDES) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -fPIC
- $(CC) -o lib/armeabi-v7a/lib$(LIBRARY_NAME).so temp/obj/basic_game.o -shared $(INCLUDES) $(LFLAGS) $(LIBS) -lnative_app_glue -u ANativeActivity_onCreate
+ $(CC) -c src/core.c -o temp/obj/core.o $(INCLUDES) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -fPIC
+ $(CC) -c src/rlgl.c -o temp/obj/rlgl.o $(INCLUDES) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -fPIC -DGRAPHICS_API_OPENGL_ES2
+ $(CC) -c src/utils.c -o temp/obj/utils.o $(INCLUDES) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -fPIC
+ $(CC) -c src/game_crash.c -o temp/obj/game_crash.o $(INCLUDES) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -fPIC
+ $(CC) -o lib/armeabi-v7a/lib$(LIBRARY_NAME).so temp/obj/game_crash.o temp/obj/core.o temp/obj/rlgl.o temp/obj/utils.o -shared $(INCLUDES) $(LFLAGS) -lnative_app_glue $(LIBS) -u ANativeActivity_onCreate
# Generate key for APK signing
# OUTPUT: $(PROJECT_DIR)/temp/$(PROJECT_NAME).keystore
@@ -137,7 +140,7 @@ deploy:
$(ANDROID_HOME)/platform-tools/adb install -r $(PROJECT_NAME).apk
$(ANDROID_HOME)/platform-tools/adb logcat -c
$(ANDROID_HOME)/platform-tools/adb logcat *:W
-
+
#$(ANDROID_HOME)/platform-tools/adb logcat *:W
#$(ANDROID_HOME)/platform-tools/adb -d logcat raylib:V *:S
diff --git a/templates/android_project/assets/EMPTY b/templates/android_project/assets/EMPTY
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/templates/android_project/assets/EMPTY
diff --git a/templates/android_project/assets/alagard.rbmf b/templates/android_project/assets/alagard.rbmf
deleted file mode 100644
index 8c9b68d3..00000000
--- a/templates/android_project/assets/alagard.rbmf
+++ /dev/null
Binary files differ
diff --git a/templates/android_project/assets/ambient.ogg b/templates/android_project/assets/ambient.ogg
deleted file mode 100644
index af7f836e..00000000
--- a/templates/android_project/assets/ambient.ogg
+++ /dev/null
Binary files differ
diff --git a/templates/android_project/assets/coin.wav b/templates/android_project/assets/coin.wav
deleted file mode 100644
index 6684ffc6..00000000
--- a/templates/android_project/assets/coin.wav
+++ /dev/null
Binary files differ
diff --git a/templates/android_project/assets/raylib_logo.png b/templates/android_project/assets/raylib_logo.png
deleted file mode 100644
index 66545627..00000000
--- a/templates/android_project/assets/raylib_logo.png
+++ /dev/null
Binary files differ
diff --git a/templates/android_project/jni/Android.mk b/templates/android_project/jni/Android.mk
deleted file mode 100644
index 4bd6f57a..00000000
--- a/templates/android_project/jni/Android.mk
+++ /dev/null
@@ -1,100 +0,0 @@
-#**************************************************************************************************
-#
-# raylib for Android
-#
-# Game template makefile
-#
-# 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.
-#
-# Permission is granted to anyone to use this software for any purpose, including commercial
-# applications, and to alter it and redistribute it freely, subject to the following restrictions:
-#
-# 1. The origin of this software must not be misrepresented; you must not claim that you
-# wrote the original software. If you use this software in a product, an acknowledgment
-# in the product documentation would be appreciated but is not required.
-#
-# 2. Altered source versions must be plainly marked as such, and must not be misrepresented
-# as being the original software.
-#
-# 3. This notice may not be removed or altered from any source distribution.
-#
-#**************************************************************************************************
-
-# Path of the current directory (i.e. the directory containing the Android.mk file itself)
-LOCAL_PATH := $(call my-dir)
-
-# OpenAL module (prebuilt static library)
-#--------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-# Module name
-LOCAL_MODULE := openal
-
-# Precompiled lib
-LOCAL_SRC_FILES := libs/libopenal.so
-
-# Export headers
-LOCAL_EXPORT_C_INCLUDES := include
-
-# Build static library
-include $(PREBUILT_SHARED_LIBRARY)
-#--------------------------------------------------------------------
-
-
-# raylib module (prebuilt static library)
-#--------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-# Module name
-LOCAL_MODULE := raylib
-
-# Precompiled lib
-LOCAL_SRC_FILES := libs/libraylib.a
-
-# Export headers
-LOCAL_EXPORT_C_INCLUDES := include
-
-# Static library dependency
-LOCAL_STATIC_LIBRARIES := android_native_app_glue
-
-# Build static library
-include $(PREBUILT_STATIC_LIBRARY)
-#--------------------------------------------------------------------
-
-
-# raylib game module (shared library)
-#--------------------------------------------------------------------
-# Makefile that will clear many LOCAL_XXX variables for you
-include $(CLEAR_VARS)
-
-# Module name
-LOCAL_MODULE := raylib_game
-
-# Module source files
-LOCAL_SRC_FILES := basic_game.c
-
-# Required includes paths (.h)
-# NOTE: raylib header and openal headers are included using LOCAL_EXPORT_C_INCLUDES
-LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/include
-
-# Required flags for compilation: defines PLATFORM_ANDROID
-LOCAL_CFLAGS := -Wall -std=c99 -DPLATFORM_ANDROID
-
-# Linker required libraries (not many...)
-LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lOpenSLES
-
-# Required static library
-LOCAL_STATIC_LIBRARIES := android_native_app_glue raylib openal
-
-# Required shared library
-# NOTE: It brokes the build, using static library instead
-#LOCAL_SHARED_LIBRARIES := openal
-
-# Build the shared library libraylib_game.so
-include $(BUILD_SHARED_LIBRARY)
-
-$(call import-module,android/native_app_glue)
-#--------------------------------------------------------------------
diff --git a/templates/android_project/jni/basic_game.c b/templates/android_project/jni/basic_game.c
deleted file mode 100644
index 94fbc6cd..00000000
--- a/templates/android_project/jni/basic_game.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - Android Basic Game template
-*
-* <Game title>
-* <Game description>
-*
-* This game has been created using raylib v1.2 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include "android_native_app_glue.h"
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef enum GameScreen { LOGO, TITLE, GAMEPLAY, ENDING } GameScreen;
-
-//----------------------------------------------------------------------------------
-// Android Main entry point
-//----------------------------------------------------------------------------------
-void android_main(struct android_app *app)
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = 800;
- const int screenHeight = 450;
-
- GameScreen currentScreen = LOGO;
-
- InitWindow(screenWidth, screenHeight, app);
-
- // TODO: Initialize all required variables and load all required data here!
-
- InitAudioDevice(); // Initialize audio device
-
- Texture2D texture = LoadTexture("raylib_logo.png"); // Load texture (placed on assets folder)
-
- Sound fx = LoadSound("coin.wav"); // Load WAV audio file (placed on assets folder)
- Music ambient = LoadMusicStream("ambient.ogg");
- PlayMusicStream(ambient);
-
- int framesCounter = 0; // Used to count frames
-
- SetTargetFPS(60); // Not required on Android, already locked to 60 fps
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateMusicStream(ambient);
-
- switch(currentScreen)
- {
- case LOGO:
- {
- // TODO: Update LOGO screen variables here!
-
- framesCounter++; // Count frames
-
- // Wait for 4 seconds (240 frames) before jumping to TITLE screen
- if (framesCounter > 240)
- {
- currentScreen = TITLE;
- }
- } break;
- case TITLE:
- {
- // TODO: Update TITLE screen variables here!
-
- // Press enter to change to GAMEPLAY screen
- if (IsGestureDetected(GESTURE_TAP))
- {
- PlaySound(fx);
- currentScreen = GAMEPLAY;
- }
- } break;
- case GAMEPLAY:
- {
- // TODO: Update GAMEPLAY screen variables here!
-
- // Press enter to change to ENDING screen
- if (IsGestureDetected(GESTURE_TAP))
- {
- PlaySound(fx);
- currentScreen = ENDING;
- }
- } break;
- case ENDING:
- {
- // TODO: Update ENDING screen variables here!
-
- // Press enter to return to TITLE screen
- if (IsGestureDetected(GESTURE_TAP))
- {
- PlaySound(fx);
- currentScreen = TITLE;
- }
- } break;
- default: break;
- }
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- switch(currentScreen)
- {
- case LOGO:
- {
- // TODO: Draw LOGO screen here!
- DrawText("LOGO SCREEN", 20, 20, 40, LIGHTGRAY);
- DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
- DrawText("WAIT for 4 SECONDS...", 290, 400, 20, GRAY);
-
- } break;
- case TITLE:
- {
- // TODO: Draw TITLE screen here!
- DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
- DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN);
- DrawText("TAP SCREEN to JUMP to GAMEPLAY SCREEN", 160, 220, 20, DARKGREEN);
-
- } break;
- case GAMEPLAY:
- {
- // TODO: Draw GAMEPLAY screen here!
- DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE);
- DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
- DrawText("TAP SCREEN to JUMP to ENDING SCREEN", 170, 220, 20, MAROON);
-
- } break;
- case ENDING:
- {
- // TODO: Draw ENDING screen here!
- DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
- DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
- DrawText("TAP SCREEN to RETURN to TITLE SCREEN", 160, 220, 20, DARKBLUE);
-
- } break;
- default: break;
- }
-
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
-
- // TODO: Unload all loaded data (textures, fonts, audio) here!
-
- UnloadSound(fx); // Unload sound data
- UnloadMusicStream(ambient); // Unload music stream data
-
- CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
-
- UnloadTexture(texture); // Unload texture data
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-} \ No newline at end of file
diff --git a/templates/android_project/jni/include/AL/al.h b/templates/android_project/jni/include/AL/al.h
deleted file mode 100644
index 413b3833..00000000
--- a/templates/android_project/jni/include/AL/al.h
+++ /dev/null
@@ -1,656 +0,0 @@
-#ifndef AL_AL_H
-#define AL_AL_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#ifndef AL_API
- #if defined(AL_LIBTYPE_STATIC)
- #define AL_API
- #elif defined(_WIN32)
- #define AL_API __declspec(dllimport)
- #else
- #define AL_API extern
- #endif
-#endif
-
-#if defined(_WIN32)
- #define AL_APIENTRY __cdecl
-#else
- #define AL_APIENTRY
-#endif
-
-
-/** Deprecated macro. */
-#define OPENAL
-#define ALAPI AL_API
-#define ALAPIENTRY AL_APIENTRY
-#define AL_INVALID (-1)
-#define AL_ILLEGAL_ENUM AL_INVALID_ENUM
-#define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
-
-/** Supported AL version. */
-#define AL_VERSION_1_0
-#define AL_VERSION_1_1
-
-/** 8-bit boolean */
-typedef char ALboolean;
-
-/** character */
-typedef char ALchar;
-
-/** signed 8-bit 2's complement integer */
-typedef signed char ALbyte;
-
-/** unsigned 8-bit integer */
-typedef unsigned char ALubyte;
-
-/** signed 16-bit 2's complement integer */
-typedef short ALshort;
-
-/** unsigned 16-bit integer */
-typedef unsigned short ALushort;
-
-/** signed 32-bit 2's complement integer */
-typedef int ALint;
-
-/** unsigned 32-bit integer */
-typedef unsigned int ALuint;
-
-/** non-negative 32-bit binary integer size */
-typedef int ALsizei;
-
-/** enumerated 32-bit value */
-typedef int ALenum;
-
-/** 32-bit IEEE754 floating-point */
-typedef float ALfloat;
-
-/** 64-bit IEEE754 floating-point */
-typedef double ALdouble;
-
-/** void type (for opaque pointers only) */
-typedef void ALvoid;
-
-
-/* Enumerant values begin at column 50. No tabs. */
-
-/** "no distance model" or "no buffer" */
-#define AL_NONE 0
-
-/** Boolean False. */
-#define AL_FALSE 0
-
-/** Boolean True. */
-#define AL_TRUE 1
-
-
-/**
- * Relative source.
- * Type: ALboolean
- * Range: [AL_TRUE, AL_FALSE]
- * Default: AL_FALSE
- *
- * Specifies if the Source has relative coordinates.
- */
-#define AL_SOURCE_RELATIVE 0x202
-
-
-/**
- * Inner cone angle, in degrees.
- * Type: ALint, ALfloat
- * Range: [0 - 360]
- * Default: 360
- *
- * The angle covered by the inner cone, where the source will not attenuate.
- */
-#define AL_CONE_INNER_ANGLE 0x1001
-
-/**
- * Outer cone angle, in degrees.
- * Range: [0 - 360]
- * Default: 360
- *
- * The angle covered by the outer cone, where the source will be fully
- * attenuated.
- */
-#define AL_CONE_OUTER_ANGLE 0x1002
-
-/**
- * Source pitch.
- * Type: ALfloat
- * Range: [0.5 - 2.0]
- * Default: 1.0
- *
- * A multiplier for the frequency (sample rate) of the source's buffer.
- */
-#define AL_PITCH 0x1003
-
-/**
- * Source or listener position.
- * Type: ALfloat[3], ALint[3]
- * Default: {0, 0, 0}
- *
- * The source or listener location in three dimensional space.
- *
- * OpenAL, like OpenGL, uses a right handed coordinate system, where in a
- * frontal default view X (thumb) points right, Y points up (index finger), and
- * Z points towards the viewer/camera (middle finger).
- *
- * To switch from a left handed coordinate system, flip the sign on the Z
- * coordinate.
- */
-#define AL_POSITION 0x1004
-
-/**
- * Source direction.
- * Type: ALfloat[3], ALint[3]
- * Default: {0, 0, 0}
- *
- * Specifies the current direction in local space.
- * A zero-length vector specifies an omni-directional source (cone is ignored).
- */
-#define AL_DIRECTION 0x1005
-
-/**
- * Source or listener velocity.
- * Type: ALfloat[3], ALint[3]
- * Default: {0, 0, 0}
- *
- * Specifies the current velocity in local space.
- */
-#define AL_VELOCITY 0x1006
-
-/**
- * Source looping.
- * Type: ALboolean
- * Range: [AL_TRUE, AL_FALSE]
- * Default: AL_FALSE
- *
- * Specifies whether source is looping.
- */
-#define AL_LOOPING 0x1007
-
-/**
- * Source buffer.
- * Type: ALuint
- * Range: any valid Buffer.
- *
- * Specifies the buffer to provide sound samples.
- */
-#define AL_BUFFER 0x1009
-
-/**
- * Source or listener gain.
- * Type: ALfloat
- * Range: [0.0 - ]
- *
- * A value of 1.0 means unattenuated. Each division by 2 equals an attenuation
- * of about -6dB. Each multiplicaton by 2 equals an amplification of about
- * +6dB.
- *
- * A value of 0.0 is meaningless with respect to a logarithmic scale; it is
- * silent.
- */
-#define AL_GAIN 0x100A
-
-/**
- * Minimum source gain.
- * Type: ALfloat
- * Range: [0.0 - 1.0]
- *
- * The minimum gain allowed for a source, after distance and cone attenation is
- * applied (if applicable).
- */
-#define AL_MIN_GAIN 0x100D
-
-/**
- * Maximum source gain.
- * Type: ALfloat
- * Range: [0.0 - 1.0]
- *
- * The maximum gain allowed for a source, after distance and cone attenation is
- * applied (if applicable).
- */
-#define AL_MAX_GAIN 0x100E
-
-/**
- * Listener orientation.
- * Type: ALfloat[6]
- * Default: {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}
- *
- * Effectively two three dimensional vectors. The first vector is the front (or
- * "at") and the second is the top (or "up").
- *
- * Both vectors are in local space.
- */
-#define AL_ORIENTATION 0x100F
-
-/**
- * Source state (query only).
- * Type: ALint
- * Range: [AL_INITIAL, AL_PLAYING, AL_PAUSED, AL_STOPPED]
- */
-#define AL_SOURCE_STATE 0x1010
-
-/** Source state value. */
-#define AL_INITIAL 0x1011
-#define AL_PLAYING 0x1012
-#define AL_PAUSED 0x1013
-#define AL_STOPPED 0x1014
-
-/**
- * Source Buffer Queue size (query only).
- * Type: ALint
- *
- * The number of buffers queued using alSourceQueueBuffers, minus the buffers
- * removed with alSourceUnqueueBuffers.
- */
-#define AL_BUFFERS_QUEUED 0x1015
-
-/**
- * Source Buffer Queue processed count (query only).
- * Type: ALint
- *
- * The number of queued buffers that have been fully processed, and can be
- * removed with alSourceUnqueueBuffers.
- *
- * Looping sources will never fully process buffers because they will be set to
- * play again for when the source loops.
- */
-#define AL_BUFFERS_PROCESSED 0x1016
-
-/**
- * Source reference distance.
- * Type: ALfloat
- * Range: [0.0 - ]
- * Default: 1.0
- *
- * The distance in units that no attenuation occurs.
- *
- * At 0.0, no distance attenuation ever occurs on non-linear attenuation models.
- */
-#define AL_REFERENCE_DISTANCE 0x1020
-
-/**
- * Source rolloff factor.
- * Type: ALfloat
- * Range: [0.0 - ]
- * Default: 1.0
- *
- * Multiplier to exaggerate or diminish distance attenuation.
- *
- * At 0.0, no distance attenuation ever occurs.
- */
-#define AL_ROLLOFF_FACTOR 0x1021
-
-/**
- * Outer cone gain.
- * Type: ALfloat
- * Range: [0.0 - 1.0]
- * Default: 0.0
- *
- * The gain attenuation applied when the listener is outside of the source's
- * outer cone.
- */
-#define AL_CONE_OUTER_GAIN 0x1022
-
-/**
- * Source maximum distance.
- * Type: ALfloat
- * Range: [0.0 - ]
- * Default: +inf
- *
- * The distance above which the source is not attenuated any further with a
- * clamped distance model, or where attenuation reaches 0.0 gain for linear
- * distance models with a default rolloff factor.
- */
-#define AL_MAX_DISTANCE 0x1023
-
-/** Source buffer position, in seconds */
-#define AL_SEC_OFFSET 0x1024
-/** Source buffer position, in sample frames */
-#define AL_SAMPLE_OFFSET 0x1025
-/** Source buffer position, in bytes */
-#define AL_BYTE_OFFSET 0x1026
-
-/**
- * Source type (query only).
- * Type: ALint
- * Range: [AL_STATIC, AL_STREAMING, AL_UNDETERMINED]
- *
- * A Source is Static if a Buffer has been attached using AL_BUFFER.
- *
- * A Source is Streaming if one or more Buffers have been attached using
- * alSourceQueueBuffers.
- *
- * A Source is Undetermined when it has the NULL buffer attached using
- * AL_BUFFER.
- */
-#define AL_SOURCE_TYPE 0x1027
-
-/** Source type value. */
-#define AL_STATIC 0x1028
-#define AL_STREAMING 0x1029
-#define AL_UNDETERMINED 0x1030
-
-/** Buffer format specifier. */
-#define AL_FORMAT_MONO8 0x1100
-#define AL_FORMAT_MONO16 0x1101
-#define AL_FORMAT_STEREO8 0x1102
-#define AL_FORMAT_STEREO16 0x1103
-
-/** Buffer frequency (query only). */
-#define AL_FREQUENCY 0x2001
-/** Buffer bits per sample (query only). */
-#define AL_BITS 0x2002
-/** Buffer channel count (query only). */
-#define AL_CHANNELS 0x2003
-/** Buffer data size (query only). */
-#define AL_SIZE 0x2004
-
-/**
- * Buffer state.
- *
- * Not for public use.
- */
-#define AL_UNUSED 0x2010
-#define AL_PENDING 0x2011
-#define AL_PROCESSED 0x2012
-
-
-/** No error. */
-#define AL_NO_ERROR 0
-
-/** Invalid name paramater passed to AL call. */
-#define AL_INVALID_NAME 0xA001
-
-/** Invalid enum parameter passed to AL call. */
-#define AL_INVALID_ENUM 0xA002
-
-/** Invalid value parameter passed to AL call. */
-#define AL_INVALID_VALUE 0xA003
-
-/** Illegal AL call. */
-#define AL_INVALID_OPERATION 0xA004
-
-/** Not enough memory. */
-#define AL_OUT_OF_MEMORY 0xA005
-
-
-/** Context string: Vendor ID. */
-#define AL_VENDOR 0xB001
-/** Context string: Version. */
-#define AL_VERSION 0xB002
-/** Context string: Renderer ID. */
-#define AL_RENDERER 0xB003
-/** Context string: Space-separated extension list. */
-#define AL_EXTENSIONS 0xB004
-
-
-/**
- * Doppler scale.
- * Type: ALfloat
- * Range: [0.0 - ]
- * Default: 1.0
- *
- * Scale for source and listener velocities.
- */
-#define AL_DOPPLER_FACTOR 0xC000
-AL_API void AL_APIENTRY alDopplerFactor(ALfloat value);
-
-/**
- * Doppler velocity (deprecated).
- *
- * A multiplier applied to the Speed of Sound.
- */
-#define AL_DOPPLER_VELOCITY 0xC001
-AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value);
-
-/**
- * Speed of Sound, in units per second.
- * Type: ALfloat
- * Range: [0.0001 - ]
- * Default: 343.3
- *
- * The speed at which sound waves are assumed to travel, when calculating the
- * doppler effect.
- */
-#define AL_SPEED_OF_SOUND 0xC003
-AL_API void AL_APIENTRY alSpeedOfSound(ALfloat value);
-
-/**
- * Distance attenuation model.
- * Type: ALint
- * Range: [AL_NONE, AL_INVERSE_DISTANCE, AL_INVERSE_DISTANCE_CLAMPED,
- * AL_LINEAR_DISTANCE, AL_LINEAR_DISTANCE_CLAMPED,
- * AL_EXPONENT_DISTANCE, AL_EXPONENT_DISTANCE_CLAMPED]
- * Default: AL_INVERSE_DISTANCE_CLAMPED
- *
- * The model by which sources attenuate with distance.
- *
- * None - No distance attenuation.
- * Inverse - Doubling the distance halves the source gain.
- * Linear - Linear gain scaling between the reference and max distances.
- * Exponent - Exponential gain dropoff.
- *
- * Clamped variations work like the non-clamped counterparts, except the
- * distance calculated is clamped between the reference and max distances.
- */
-#define AL_DISTANCE_MODEL 0xD000
-AL_API void AL_APIENTRY alDistanceModel(ALenum distanceModel);
-
-/** Distance model value. */
-#define AL_INVERSE_DISTANCE 0xD001
-#define AL_INVERSE_DISTANCE_CLAMPED 0xD002
-#define AL_LINEAR_DISTANCE 0xD003
-#define AL_LINEAR_DISTANCE_CLAMPED 0xD004
-#define AL_EXPONENT_DISTANCE 0xD005
-#define AL_EXPONENT_DISTANCE_CLAMPED 0xD006
-
-/** Renderer State management. */
-AL_API void AL_APIENTRY alEnable(ALenum capability);
-AL_API void AL_APIENTRY alDisable(ALenum capability);
-AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability);
-
-/** State retrieval. */
-AL_API const ALchar* AL_APIENTRY alGetString(ALenum param);
-AL_API void AL_APIENTRY alGetBooleanv(ALenum param, ALboolean *values);
-AL_API void AL_APIENTRY alGetIntegerv(ALenum param, ALint *values);
-AL_API void AL_APIENTRY alGetFloatv(ALenum param, ALfloat *values);
-AL_API void AL_APIENTRY alGetDoublev(ALenum param, ALdouble *values);
-AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum param);
-AL_API ALint AL_APIENTRY alGetInteger(ALenum param);
-AL_API ALfloat AL_APIENTRY alGetFloat(ALenum param);
-AL_API ALdouble AL_APIENTRY alGetDouble(ALenum param);
-
-/**
- * Error retrieval.
- *
- * Obtain the first error generated in the AL context since the last check.
- */
-AL_API ALenum AL_APIENTRY alGetError(void);
-
-/**
- * Extension support.
- *
- * Query for the presence of an extension, and obtain any appropriate function
- * pointers and enum values.
- */
-AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extname);
-AL_API void* AL_APIENTRY alGetProcAddress(const ALchar *fname);
-AL_API ALenum AL_APIENTRY alGetEnumValue(const ALchar *ename);
-
-
-/** Set Listener parameters */
-AL_API void AL_APIENTRY alListenerf(ALenum param, ALfloat value);
-AL_API void AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
-AL_API void AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values);
-AL_API void AL_APIENTRY alListeneri(ALenum param, ALint value);
-AL_API void AL_APIENTRY alListener3i(ALenum param, ALint value1, ALint value2, ALint value3);
-AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values);
-
-/** Get Listener parameters */
-AL_API void AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value);
-AL_API void AL_APIENTRY alGetListener3f(ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
-AL_API void AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values);
-AL_API void AL_APIENTRY alGetListeneri(ALenum param, ALint *value);
-AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *value2, ALint *value3);
-AL_API void AL_APIENTRY alGetListeneriv(ALenum param, ALint *values);
-
-
-/** Create Source objects. */
-AL_API void AL_APIENTRY alGenSources(ALsizei n, ALuint *sources);
-/** Delete Source objects. */
-AL_API void AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources);
-/** Verify a handle is a valid Source. */
-AL_API ALboolean AL_APIENTRY alIsSource(ALuint source);
-
-/** Set Source parameters. */
-AL_API void AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value);
-AL_API void AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
-AL_API void AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat *values);
-AL_API void AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value);
-AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, ALint value2, ALint value3);
-AL_API void AL_APIENTRY alSourceiv(ALuint source, ALenum param, const ALint *values);
-
-/** Get Source parameters. */
-AL_API void AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *value);
-AL_API void AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
-AL_API void AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *values);
-AL_API void AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value);
-AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1, ALint *value2, ALint *value3);
-AL_API void AL_APIENTRY alGetSourceiv(ALuint source, ALenum param, ALint *values);
-
-
-/** Play, replay, or resume (if paused) a list of Sources */
-AL_API void AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources);
-/** Stop a list of Sources */
-AL_API void AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources);
-/** Rewind a list of Sources */
-AL_API void AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources);
-/** Pause a list of Sources */
-AL_API void AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources);
-
-/** Play, replay, or resume a Source */
-AL_API void AL_APIENTRY alSourcePlay(ALuint source);
-/** Stop a Source */
-AL_API void AL_APIENTRY alSourceStop(ALuint source);
-/** Rewind a Source (set playback postiton to beginning) */
-AL_API void AL_APIENTRY alSourceRewind(ALuint source);
-/** Pause a Source */
-AL_API void AL_APIENTRY alSourcePause(ALuint source);
-
-/** Queue buffers onto a source */
-AL_API void AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei nb, const ALuint *buffers);
-/** Unqueue processed buffers from a source */
-AL_API void AL_APIENTRY alSourceUnqueueBuffers(ALuint source, ALsizei nb, ALuint *buffers);
-
-
-/** Create Buffer objects */
-AL_API void AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers);
-/** Delete Buffer objects */
-AL_API void AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers);
-/** Verify a handle is a valid Buffer */
-AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer);
-
-/** Specifies the data to be copied into a buffer */
-AL_API void AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq);
-
-/** Set Buffer parameters, */
-AL_API void AL_APIENTRY alBufferf(ALuint buffer, ALenum param, ALfloat value);
-AL_API void AL_APIENTRY alBuffer3f(ALuint buffer, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
-AL_API void AL_APIENTRY alBufferfv(ALuint buffer, ALenum param, const ALfloat *values);
-AL_API void AL_APIENTRY alBufferi(ALuint buffer, ALenum param, ALint value);
-AL_API void AL_APIENTRY alBuffer3i(ALuint buffer, ALenum param, ALint value1, ALint value2, ALint value3);
-AL_API void AL_APIENTRY alBufferiv(ALuint buffer, ALenum param, const ALint *values);
-
-/** Get Buffer parameters. */
-AL_API void AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *value);
-AL_API void AL_APIENTRY alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
-AL_API void AL_APIENTRY alGetBufferfv(ALuint buffer, ALenum param, ALfloat *values);
-AL_API void AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value);
-AL_API void AL_APIENTRY alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1, ALint *value2, ALint *value3);
-AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum param, ALint *values);
-
-/** Pointer-to-function type, useful for dynamically getting AL entry points. */
-typedef void (AL_APIENTRY *LPALENABLE)(ALenum capability);
-typedef void (AL_APIENTRY *LPALDISABLE)(ALenum capability);
-typedef ALboolean (AL_APIENTRY *LPALISENABLED)(ALenum capability);
-typedef const ALchar* (AL_APIENTRY *LPALGETSTRING)(ALenum param);
-typedef void (AL_APIENTRY *LPALGETBOOLEANV)(ALenum param, ALboolean *values);
-typedef void (AL_APIENTRY *LPALGETINTEGERV)(ALenum param, ALint *values);
-typedef void (AL_APIENTRY *LPALGETFLOATV)(ALenum param, ALfloat *values);
-typedef void (AL_APIENTRY *LPALGETDOUBLEV)(ALenum param, ALdouble *values);
-typedef ALboolean (AL_APIENTRY *LPALGETBOOLEAN)(ALenum param);
-typedef ALint (AL_APIENTRY *LPALGETINTEGER)(ALenum param);
-typedef ALfloat (AL_APIENTRY *LPALGETFLOAT)(ALenum param);
-typedef ALdouble (AL_APIENTRY *LPALGETDOUBLE)(ALenum param);
-typedef ALenum (AL_APIENTRY *LPALGETERROR)(void);
-typedef ALboolean (AL_APIENTRY *LPALISEXTENSIONPRESENT)(const ALchar *extname);
-typedef void* (AL_APIENTRY *LPALGETPROCADDRESS)(const ALchar *fname);
-typedef ALenum (AL_APIENTRY *LPALGETENUMVALUE)(const ALchar *ename);
-typedef void (AL_APIENTRY *LPALLISTENERF)(ALenum param, ALfloat value);
-typedef void (AL_APIENTRY *LPALLISTENER3F)(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
-typedef void (AL_APIENTRY *LPALLISTENERFV)(ALenum param, const ALfloat *values);
-typedef void (AL_APIENTRY *LPALLISTENERI)(ALenum param, ALint value);
-typedef void (AL_APIENTRY *LPALLISTENER3I)(ALenum param, ALint value1, ALint value2, ALint value3);
-typedef void (AL_APIENTRY *LPALLISTENERIV)(ALenum param, const ALint *values);
-typedef void (AL_APIENTRY *LPALGETLISTENERF)(ALenum param, ALfloat *value);
-typedef void (AL_APIENTRY *LPALGETLISTENER3F)(ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
-typedef void (AL_APIENTRY *LPALGETLISTENERFV)(ALenum param, ALfloat *values);
-typedef void (AL_APIENTRY *LPALGETLISTENERI)(ALenum param, ALint *value);
-typedef void (AL_APIENTRY *LPALGETLISTENER3I)(ALenum param, ALint *value1, ALint *value2, ALint *value3);
-typedef void (AL_APIENTRY *LPALGETLISTENERIV)(ALenum param, ALint *values);
-typedef void (AL_APIENTRY *LPALGENSOURCES)(ALsizei n, ALuint *sources);
-typedef void (AL_APIENTRY *LPALDELETESOURCES)(ALsizei n, const ALuint *sources);
-typedef ALboolean (AL_APIENTRY *LPALISSOURCE)(ALuint source);
-typedef void (AL_APIENTRY *LPALSOURCEF)(ALuint source, ALenum param, ALfloat value);
-typedef void (AL_APIENTRY *LPALSOURCE3F)(ALuint source, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
-typedef void (AL_APIENTRY *LPALSOURCEFV)(ALuint source, ALenum param, const ALfloat *values);
-typedef void (AL_APIENTRY *LPALSOURCEI)(ALuint source, ALenum param, ALint value);
-typedef void (AL_APIENTRY *LPALSOURCE3I)(ALuint source, ALenum param, ALint value1, ALint value2, ALint value3);
-typedef void (AL_APIENTRY *LPALSOURCEIV)(ALuint source, ALenum param, const ALint *values);
-typedef void (AL_APIENTRY *LPALGETSOURCEF)(ALuint source, ALenum param, ALfloat *value);
-typedef void (AL_APIENTRY *LPALGETSOURCE3F)(ALuint source, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
-typedef void (AL_APIENTRY *LPALGETSOURCEFV)(ALuint source, ALenum param, ALfloat *values);
-typedef void (AL_APIENTRY *LPALGETSOURCEI)(ALuint source, ALenum param, ALint *value);
-typedef void (AL_APIENTRY *LPALGETSOURCE3I)(ALuint source, ALenum param, ALint *value1, ALint *value2, ALint *value3);
-typedef void (AL_APIENTRY *LPALGETSOURCEIV)(ALuint source, ALenum param, ALint *values);
-typedef void (AL_APIENTRY *LPALSOURCEPLAYV)(ALsizei n, const ALuint *sources);
-typedef void (AL_APIENTRY *LPALSOURCESTOPV)(ALsizei n, const ALuint *sources);
-typedef void (AL_APIENTRY *LPALSOURCEREWINDV)(ALsizei n, const ALuint *sources);
-typedef void (AL_APIENTRY *LPALSOURCEPAUSEV)(ALsizei n, const ALuint *sources);
-typedef void (AL_APIENTRY *LPALSOURCEPLAY)(ALuint source);
-typedef void (AL_APIENTRY *LPALSOURCESTOP)(ALuint source);
-typedef void (AL_APIENTRY *LPALSOURCEREWIND)(ALuint source);
-typedef void (AL_APIENTRY *LPALSOURCEPAUSE)(ALuint source);
-typedef void (AL_APIENTRY *LPALSOURCEQUEUEBUFFERS)(ALuint source, ALsizei nb, const ALuint *buffers);
-typedef void (AL_APIENTRY *LPALSOURCEUNQUEUEBUFFERS)(ALuint source, ALsizei nb, ALuint *buffers);
-typedef void (AL_APIENTRY *LPALGENBUFFERS)(ALsizei n, ALuint *buffers);
-typedef void (AL_APIENTRY *LPALDELETEBUFFERS)(ALsizei n, const ALuint *buffers);
-typedef ALboolean (AL_APIENTRY *LPALISBUFFER)(ALuint buffer);
-typedef void (AL_APIENTRY *LPALBUFFERDATA)(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq);
-typedef void (AL_APIENTRY *LPALBUFFERF)(ALuint buffer, ALenum param, ALfloat value);
-typedef void (AL_APIENTRY *LPALBUFFER3F)(ALuint buffer, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
-typedef void (AL_APIENTRY *LPALBUFFERFV)(ALuint buffer, ALenum param, const ALfloat *values);
-typedef void (AL_APIENTRY *LPALBUFFERI)(ALuint buffer, ALenum param, ALint value);
-typedef void (AL_APIENTRY *LPALBUFFER3I)(ALuint buffer, ALenum param, ALint value1, ALint value2, ALint value3);
-typedef void (AL_APIENTRY *LPALBUFFERIV)(ALuint buffer, ALenum param, const ALint *values);
-typedef void (AL_APIENTRY *LPALGETBUFFERF)(ALuint buffer, ALenum param, ALfloat *value);
-typedef void (AL_APIENTRY *LPALGETBUFFER3F)(ALuint buffer, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
-typedef void (AL_APIENTRY *LPALGETBUFFERFV)(ALuint buffer, ALenum param, ALfloat *values);
-typedef void (AL_APIENTRY *LPALGETBUFFERI)(ALuint buffer, ALenum param, ALint *value);
-typedef void (AL_APIENTRY *LPALGETBUFFER3I)(ALuint buffer, ALenum param, ALint *value1, ALint *value2, ALint *value3);
-typedef void (AL_APIENTRY *LPALGETBUFFERIV)(ALuint buffer, ALenum param, ALint *values);
-typedef void (AL_APIENTRY *LPALDOPPLERFACTOR)(ALfloat value);
-typedef void (AL_APIENTRY *LPALDOPPLERVELOCITY)(ALfloat value);
-typedef void (AL_APIENTRY *LPALSPEEDOFSOUND)(ALfloat value);
-typedef void (AL_APIENTRY *LPALDISTANCEMODEL)(ALenum distanceModel);
-
-#if defined(__cplusplus)
-} /* extern "C" */
-#endif
-
-#endif /* AL_AL_H */
diff --git a/templates/android_project/jni/include/AL/alc.h b/templates/android_project/jni/include/AL/alc.h
deleted file mode 100644
index 294e8b33..00000000
--- a/templates/android_project/jni/include/AL/alc.h
+++ /dev/null
@@ -1,237 +0,0 @@
-#ifndef AL_ALC_H
-#define AL_ALC_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#ifndef ALC_API
- #if defined(AL_LIBTYPE_STATIC)
- #define ALC_API
- #elif defined(_WIN32)
- #define ALC_API __declspec(dllimport)
- #else
- #define ALC_API extern
- #endif
-#endif
-
-#if defined(_WIN32)
- #define ALC_APIENTRY __cdecl
-#else
- #define ALC_APIENTRY
-#endif
-
-
-/** Deprecated macro. */
-#define ALCAPI ALC_API
-#define ALCAPIENTRY ALC_APIENTRY
-#define ALC_INVALID 0
-
-/** Supported ALC version? */
-#define ALC_VERSION_0_1 1
-
-/** Opaque device handle */
-typedef struct ALCdevice_struct ALCdevice;
-/** Opaque context handle */
-typedef struct ALCcontext_struct ALCcontext;
-
-/** 8-bit boolean */
-typedef char ALCboolean;
-
-/** character */
-typedef char ALCchar;
-
-/** signed 8-bit 2's complement integer */
-typedef signed char ALCbyte;
-
-/** unsigned 8-bit integer */
-typedef unsigned char ALCubyte;
-
-/** signed 16-bit 2's complement integer */
-typedef short ALCshort;
-
-/** unsigned 16-bit integer */
-typedef unsigned short ALCushort;
-
-/** signed 32-bit 2's complement integer */
-typedef int ALCint;
-
-/** unsigned 32-bit integer */
-typedef unsigned int ALCuint;
-
-/** non-negative 32-bit binary integer size */
-typedef int ALCsizei;
-
-/** enumerated 32-bit value */
-typedef int ALCenum;
-
-/** 32-bit IEEE754 floating-point */
-typedef float ALCfloat;
-
-/** 64-bit IEEE754 floating-point */
-typedef double ALCdouble;
-
-/** void type (for opaque pointers only) */
-typedef void ALCvoid;
-
-
-/* Enumerant values begin at column 50. No tabs. */
-
-/** Boolean False. */
-#define ALC_FALSE 0
-
-/** Boolean True. */
-#define ALC_TRUE 1
-
-/** Context attribute: <int> Hz. */
-#define ALC_FREQUENCY 0x1007
-
-/** Context attribute: <int> Hz. */
-#define ALC_REFRESH 0x1008
-
-/** Context attribute: AL_TRUE or AL_FALSE. */
-#define ALC_SYNC 0x1009
-
-/** Context attribute: <int> requested Mono (3D) Sources. */
-#define ALC_MONO_SOURCES 0x1010
-
-/** Context attribute: <int> requested Stereo Sources. */
-#define ALC_STEREO_SOURCES 0x1011
-
-/** No error. */
-#define ALC_NO_ERROR 0
-
-/** Invalid device handle. */
-#define ALC_INVALID_DEVICE 0xA001
-
-/** Invalid context handle. */
-#define ALC_INVALID_CONTEXT 0xA002
-
-/** Invalid enum parameter passed to an ALC call. */
-#define ALC_INVALID_ENUM 0xA003
-
-/** Invalid value parameter passed to an ALC call. */
-#define ALC_INVALID_VALUE 0xA004
-
-/** Out of memory. */
-#define ALC_OUT_OF_MEMORY 0xA005
-
-
-/** Runtime ALC version. */
-#define ALC_MAJOR_VERSION 0x1000
-#define ALC_MINOR_VERSION 0x1001
-
-/** Context attribute list properties. */
-#define ALC_ATTRIBUTES_SIZE 0x1002
-#define ALC_ALL_ATTRIBUTES 0x1003
-
-/** String for the default device specifier. */
-#define ALC_DEFAULT_DEVICE_SPECIFIER 0x1004
-/**
- * String for the given device's specifier.
- *
- * If device handle is NULL, it is instead a null-char separated list of
- * strings of known device specifiers (list ends with an empty string).
- */
-#define ALC_DEVICE_SPECIFIER 0x1005
-/** String for space-separated list of ALC extensions. */
-#define ALC_EXTENSIONS 0x1006
-
-
-/** Capture extension */
-#define ALC_EXT_CAPTURE 1
-/**
- * String for the given capture device's specifier.
- *
- * If device handle is NULL, it is instead a null-char separated list of
- * strings of known capture device specifiers (list ends with an empty string).
- */
-#define ALC_CAPTURE_DEVICE_SPECIFIER 0x310
-/** String for the default capture device specifier. */
-#define ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER 0x311
-/** Number of sample frames available for capture. */
-#define ALC_CAPTURE_SAMPLES 0x312
-
-
-/** Enumerate All extension */
-#define ALC_ENUMERATE_ALL_EXT 1
-/** String for the default extended device specifier. */
-#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
-/**
- * String for the given extended device's specifier.
- *
- * If device handle is NULL, it is instead a null-char separated list of
- * strings of known extended device specifiers (list ends with an empty string).
- */
-#define ALC_ALL_DEVICES_SPECIFIER 0x1013
-
-
-/** Context management. */
-ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint* attrlist);
-ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context);
-ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context);
-ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context);
-ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context);
-ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void);
-ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context);
-
-/** Device management. */
-ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename);
-ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device);
-
-
-/**
- * Error support.
- *
- * Obtain the most recent Device error.
- */
-ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device);
-
-/**
- * Extension support.
- *
- * Query for the presence of an extension, and obtain any appropriate
- * function pointers and enum values.
- */
-ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname);
-ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname);
-ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname);
-
-/** Query function. */
-ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param);
-ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values);
-
-/** Capture function. */
-ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize);
-ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device);
-ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device);
-ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device);
-ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
-
-/** Pointer-to-function type, useful for dynamically getting ALC entry points. */
-typedef ALCcontext* (ALC_APIENTRY *LPALCCREATECONTEXT)(ALCdevice *device, const ALCint *attrlist);
-typedef ALCboolean (ALC_APIENTRY *LPALCMAKECONTEXTCURRENT)(ALCcontext *context);
-typedef void (ALC_APIENTRY *LPALCPROCESSCONTEXT)(ALCcontext *context);
-typedef void (ALC_APIENTRY *LPALCSUSPENDCONTEXT)(ALCcontext *context);
-typedef void (ALC_APIENTRY *LPALCDESTROYCONTEXT)(ALCcontext *context);
-typedef ALCcontext* (ALC_APIENTRY *LPALCGETCURRENTCONTEXT)(void);
-typedef ALCdevice* (ALC_APIENTRY *LPALCGETCONTEXTSDEVICE)(ALCcontext *context);
-typedef ALCdevice* (ALC_APIENTRY *LPALCOPENDEVICE)(const ALCchar *devicename);
-typedef ALCboolean (ALC_APIENTRY *LPALCCLOSEDEVICE)(ALCdevice *device);
-typedef ALCenum (ALC_APIENTRY *LPALCGETERROR)(ALCdevice *device);
-typedef ALCboolean (ALC_APIENTRY *LPALCISEXTENSIONPRESENT)(ALCdevice *device, const ALCchar *extname);
-typedef void* (ALC_APIENTRY *LPALCGETPROCADDRESS)(ALCdevice *device, const ALCchar *funcname);
-typedef ALCenum (ALC_APIENTRY *LPALCGETENUMVALUE)(ALCdevice *device, const ALCchar *enumname);
-typedef const ALCchar* (ALC_APIENTRY *LPALCGETSTRING)(ALCdevice *device, ALCenum param);
-typedef void (ALC_APIENTRY *LPALCGETINTEGERV)(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values);
-typedef ALCdevice* (ALC_APIENTRY *LPALCCAPTUREOPENDEVICE)(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize);
-typedef ALCboolean (ALC_APIENTRY *LPALCCAPTURECLOSEDEVICE)(ALCdevice *device);
-typedef void (ALC_APIENTRY *LPALCCAPTURESTART)(ALCdevice *device);
-typedef void (ALC_APIENTRY *LPALCCAPTURESTOP)(ALCdevice *device);
-typedef void (ALC_APIENTRY *LPALCCAPTURESAMPLES)(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* AL_ALC_H */
diff --git a/templates/android_project/jni/include/AL/alext.h b/templates/android_project/jni/include/AL/alext.h
deleted file mode 100644
index 50ad10ec..00000000
--- a/templates/android_project/jni/include/AL/alext.h
+++ /dev/null
@@ -1,455 +0,0 @@
-/**
- * OpenAL cross platform audio library
- * Copyright (C) 2008 by authors.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * Or go to http://www.gnu.org/copyleft/lgpl.html
- */
-
-#ifndef AL_ALEXT_H
-#define AL_ALEXT_H
-
-#include <stddef.h>
-/* Define int64_t and uint64_t types */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#include <inttypes.h>
-#elif defined(_WIN32) && defined(__GNUC__)
-#include <stdint.h>
-#elif defined(_WIN32)
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-#else
-/* Fallback if nothing above works */
-#include <inttypes.h>
-#endif
-
-#include "alc.h"
-#include "al.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef AL_LOKI_IMA_ADPCM_format
-#define AL_LOKI_IMA_ADPCM_format 1
-#define AL_FORMAT_IMA_ADPCM_MONO16_EXT 0x10000
-#define AL_FORMAT_IMA_ADPCM_STEREO16_EXT 0x10001
-#endif
-
-#ifndef AL_LOKI_WAVE_format
-#define AL_LOKI_WAVE_format 1
-#define AL_FORMAT_WAVE_EXT 0x10002
-#endif
-
-#ifndef AL_EXT_vorbis
-#define AL_EXT_vorbis 1
-#define AL_FORMAT_VORBIS_EXT 0x10003
-#endif
-
-#ifndef AL_LOKI_quadriphonic
-#define AL_LOKI_quadriphonic 1
-#define AL_FORMAT_QUAD8_LOKI 0x10004
-#define AL_FORMAT_QUAD16_LOKI 0x10005
-#endif
-
-#ifndef AL_EXT_float32
-#define AL_EXT_float32 1
-#define AL_FORMAT_MONO_FLOAT32 0x10010
-#define AL_FORMAT_STEREO_FLOAT32 0x10011
-#endif
-
-#ifndef AL_EXT_double
-#define AL_EXT_double 1
-#define AL_FORMAT_MONO_DOUBLE_EXT 0x10012
-#define AL_FORMAT_STEREO_DOUBLE_EXT 0x10013
-#endif
-
-#ifndef AL_EXT_MULAW
-#define AL_EXT_MULAW 1
-#define AL_FORMAT_MONO_MULAW_EXT 0x10014
-#define AL_FORMAT_STEREO_MULAW_EXT 0x10015
-#endif
-
-#ifndef AL_EXT_ALAW
-#define AL_EXT_ALAW 1
-#define AL_FORMAT_MONO_ALAW_EXT 0x10016
-#define AL_FORMAT_STEREO_ALAW_EXT 0x10017
-#endif
-
-#ifndef ALC_LOKI_audio_channel
-#define ALC_LOKI_audio_channel 1
-#define ALC_CHAN_MAIN_LOKI 0x500001
-#define ALC_CHAN_PCM_LOKI 0x500002
-#define ALC_CHAN_CD_LOKI 0x500003
-#endif
-
-#ifndef AL_EXT_MCFORMATS
-#define AL_EXT_MCFORMATS 1
-#define AL_FORMAT_QUAD8 0x1204
-#define AL_FORMAT_QUAD16 0x1205
-#define AL_FORMAT_QUAD32 0x1206
-#define AL_FORMAT_REAR8 0x1207
-#define AL_FORMAT_REAR16 0x1208
-#define AL_FORMAT_REAR32 0x1209
-#define AL_FORMAT_51CHN8 0x120A
-#define AL_FORMAT_51CHN16 0x120B
-#define AL_FORMAT_51CHN32 0x120C
-#define AL_FORMAT_61CHN8 0x120D
-#define AL_FORMAT_61CHN16 0x120E
-#define AL_FORMAT_61CHN32 0x120F
-#define AL_FORMAT_71CHN8 0x1210
-#define AL_FORMAT_71CHN16 0x1211
-#define AL_FORMAT_71CHN32 0x1212
-#endif
-
-#ifndef AL_EXT_MULAW_MCFORMATS
-#define AL_EXT_MULAW_MCFORMATS 1
-#define AL_FORMAT_MONO_MULAW 0x10014
-#define AL_FORMAT_STEREO_MULAW 0x10015
-#define AL_FORMAT_QUAD_MULAW 0x10021
-#define AL_FORMAT_REAR_MULAW 0x10022
-#define AL_FORMAT_51CHN_MULAW 0x10023
-#define AL_FORMAT_61CHN_MULAW 0x10024
-#define AL_FORMAT_71CHN_MULAW 0x10025
-#endif
-
-#ifndef AL_EXT_IMA4
-#define AL_EXT_IMA4 1
-#define AL_FORMAT_MONO_IMA4 0x1300
-#define AL_FORMAT_STEREO_IMA4 0x1301
-#endif
-
-#ifndef AL_EXT_STATIC_BUFFER
-#define AL_EXT_STATIC_BUFFER 1
-typedef ALvoid (AL_APIENTRY*PFNALBUFFERDATASTATICPROC)(const ALint,ALenum,ALvoid*,ALsizei,ALsizei);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API ALvoid AL_APIENTRY alBufferDataStatic(const ALint buffer, ALenum format, ALvoid *data, ALsizei len, ALsizei freq);
-#endif
-#endif
-
-#ifndef ALC_EXT_EFX
-#define ALC_EXT_EFX 1
-#include "efx.h"
-#endif
-
-#ifndef ALC_EXT_disconnect
-#define ALC_EXT_disconnect 1
-#define ALC_CONNECTED 0x313
-#endif
-
-#ifndef ALC_EXT_thread_local_context
-#define ALC_EXT_thread_local_context 1
-typedef ALCboolean (ALC_APIENTRY*PFNALCSETTHREADCONTEXTPROC)(ALCcontext *context);
-typedef ALCcontext* (ALC_APIENTRY*PFNALCGETTHREADCONTEXTPROC)(void);
-#ifdef AL_ALEXT_PROTOTYPES
-ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context);
-ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void);
-#endif
-#endif
-
-#ifndef AL_EXT_source_distance_model
-#define AL_EXT_source_distance_model 1
-#define AL_SOURCE_DISTANCE_MODEL 0x200
-#endif
-
-#ifndef AL_SOFT_buffer_sub_data
-#define AL_SOFT_buffer_sub_data 1
-#define AL_BYTE_RW_OFFSETS_SOFT 0x1031
-#define AL_SAMPLE_RW_OFFSETS_SOFT 0x1032
-typedef ALvoid (AL_APIENTRY*PFNALBUFFERSUBDATASOFTPROC)(ALuint,ALenum,const ALvoid*,ALsizei,ALsizei);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length);
-#endif
-#endif
-
-#ifndef AL_SOFT_loop_points
-#define AL_SOFT_loop_points 1
-#define AL_LOOP_POINTS_SOFT 0x2015
-#endif
-
-#ifndef AL_EXT_FOLDBACK
-#define AL_EXT_FOLDBACK 1
-#define AL_EXT_FOLDBACK_NAME "AL_EXT_FOLDBACK"
-#define AL_FOLDBACK_EVENT_BLOCK 0x4112
-#define AL_FOLDBACK_EVENT_START 0x4111
-#define AL_FOLDBACK_EVENT_STOP 0x4113
-#define AL_FOLDBACK_MODE_MONO 0x4101
-#define AL_FOLDBACK_MODE_STEREO 0x4102
-typedef void (AL_APIENTRY*LPALFOLDBACKCALLBACK)(ALenum,ALsizei);
-typedef void (AL_APIENTRY*LPALREQUESTFOLDBACKSTART)(ALenum,ALsizei,ALsizei,ALfloat*,LPALFOLDBACKCALLBACK);
-typedef void (AL_APIENTRY*LPALREQUESTFOLDBACKSTOP)(void);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API void AL_APIENTRY alRequestFoldbackStart(ALenum mode,ALsizei count,ALsizei length,ALfloat *mem,LPALFOLDBACKCALLBACK callback);
-AL_API void AL_APIENTRY alRequestFoldbackStop(void);
-#endif
-#endif
-
-#ifndef ALC_EXT_DEDICATED
-#define ALC_EXT_DEDICATED 1
-#define AL_DEDICATED_GAIN 0x0001
-#define AL_EFFECT_DEDICATED_DIALOGUE 0x9001
-#define AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT 0x9000
-#endif
-
-#ifndef AL_SOFT_buffer_samples
-#define AL_SOFT_buffer_samples 1
-/* Channel configurations */
-#define AL_MONO_SOFT 0x1500
-#define AL_STEREO_SOFT 0x1501
-#define AL_REAR_SOFT 0x1502
-#define AL_QUAD_SOFT 0x1503
-#define AL_5POINT1_SOFT 0x1504
-#define AL_6POINT1_SOFT 0x1505
-#define AL_7POINT1_SOFT 0x1506
-
-/* Sample types */
-#define AL_BYTE_SOFT 0x1400
-#define AL_UNSIGNED_BYTE_SOFT 0x1401
-#define AL_SHORT_SOFT 0x1402
-#define AL_UNSIGNED_SHORT_SOFT 0x1403
-#define AL_INT_SOFT 0x1404
-#define AL_UNSIGNED_INT_SOFT 0x1405
-#define AL_FLOAT_SOFT 0x1406
-#define AL_DOUBLE_SOFT 0x1407
-#define AL_BYTE3_SOFT 0x1408
-#define AL_UNSIGNED_BYTE3_SOFT 0x1409
-
-/* Storage formats */
-#define AL_MONO8_SOFT 0x1100
-#define AL_MONO16_SOFT 0x1101
-#define AL_MONO32F_SOFT 0x10010
-#define AL_STEREO8_SOFT 0x1102
-#define AL_STEREO16_SOFT 0x1103
-#define AL_STEREO32F_SOFT 0x10011
-#define AL_QUAD8_SOFT 0x1204
-#define AL_QUAD16_SOFT 0x1205
-#define AL_QUAD32F_SOFT 0x1206
-#define AL_REAR8_SOFT 0x1207
-#define AL_REAR16_SOFT 0x1208
-#define AL_REAR32F_SOFT 0x1209
-#define AL_5POINT1_8_SOFT 0x120A
-#define AL_5POINT1_16_SOFT 0x120B
-#define AL_5POINT1_32F_SOFT 0x120C
-#define AL_6POINT1_8_SOFT 0x120D
-#define AL_6POINT1_16_SOFT 0x120E
-#define AL_6POINT1_32F_SOFT 0x120F
-#define AL_7POINT1_8_SOFT 0x1210
-#define AL_7POINT1_16_SOFT 0x1211
-#define AL_7POINT1_32F_SOFT 0x1212
-
-/* Buffer attributes */
-#define AL_INTERNAL_FORMAT_SOFT 0x2008
-#define AL_BYTE_LENGTH_SOFT 0x2009
-#define AL_SAMPLE_LENGTH_SOFT 0x200A
-#define AL_SEC_LENGTH_SOFT 0x200B
-
-typedef void (AL_APIENTRY*LPALBUFFERSAMPLESSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
-typedef void (AL_APIENTRY*LPALBUFFERSUBSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
-typedef void (AL_APIENTRY*LPALGETBUFFERSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
-typedef ALboolean (AL_APIENTRY*LPALISBUFFERFORMATSUPPORTEDSOFT)(ALenum);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer, ALuint samplerate, ALenum internalformat, ALsizei samples, ALenum channels, ALenum type, const ALvoid *data);
-AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, const ALvoid *data);
-AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, ALvoid *data);
-AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format);
-#endif
-#endif
-
-#ifndef AL_SOFT_direct_channels
-#define AL_SOFT_direct_channels 1
-#define AL_DIRECT_CHANNELS_SOFT 0x1033
-#endif
-
-#ifndef ALC_SOFT_loopback
-#define ALC_SOFT_loopback 1
-#define ALC_FORMAT_CHANNELS_SOFT 0x1990
-#define ALC_FORMAT_TYPE_SOFT 0x1991
-
-/* Sample types */
-#define ALC_BYTE_SOFT 0x1400
-#define ALC_UNSIGNED_BYTE_SOFT 0x1401
-#define ALC_SHORT_SOFT 0x1402
-#define ALC_UNSIGNED_SHORT_SOFT 0x1403
-#define ALC_INT_SOFT 0x1404
-#define ALC_UNSIGNED_INT_SOFT 0x1405
-#define ALC_FLOAT_SOFT 0x1406
-
-/* Channel configurations */
-#define ALC_MONO_SOFT 0x1500
-#define ALC_STEREO_SOFT 0x1501
-#define ALC_QUAD_SOFT 0x1503
-#define ALC_5POINT1_SOFT 0x1504
-#define ALC_6POINT1_SOFT 0x1505
-#define ALC_7POINT1_SOFT 0x1506
-
-typedef ALCdevice* (ALC_APIENTRY*LPALCLOOPBACKOPENDEVICESOFT)(const ALCchar*);
-typedef ALCboolean (ALC_APIENTRY*LPALCISRENDERFORMATSUPPORTEDSOFT)(ALCdevice*,ALCsizei,ALCenum,ALCenum);
-typedef void (ALC_APIENTRY*LPALCRENDERSAMPLESSOFT)(ALCdevice*,ALCvoid*,ALCsizei);
-#ifdef AL_ALEXT_PROTOTYPES
-ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceName);
-ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type);
-ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
-#endif
-#endif
-
-#ifndef AL_EXT_STEREO_ANGLES
-#define AL_EXT_STEREO_ANGLES 1
-#define AL_STEREO_ANGLES 0x1030
-#endif
-
-#ifndef AL_EXT_SOURCE_RADIUS
-#define AL_EXT_SOURCE_RADIUS 1
-#define AL_SOURCE_RADIUS 0x1031
-#endif
-
-#ifndef AL_SOFT_source_latency
-#define AL_SOFT_source_latency 1
-#define AL_SAMPLE_OFFSET_LATENCY_SOFT 0x1200
-#define AL_SEC_OFFSET_LATENCY_SOFT 0x1201
-typedef int64_t ALint64SOFT;
-typedef uint64_t ALuint64SOFT;
-typedef void (AL_APIENTRY*LPALSOURCEDSOFT)(ALuint,ALenum,ALdouble);
-typedef void (AL_APIENTRY*LPALSOURCE3DSOFT)(ALuint,ALenum,ALdouble,ALdouble,ALdouble);
-typedef void (AL_APIENTRY*LPALSOURCEDVSOFT)(ALuint,ALenum,const ALdouble*);
-typedef void (AL_APIENTRY*LPALGETSOURCEDSOFT)(ALuint,ALenum,ALdouble*);
-typedef void (AL_APIENTRY*LPALGETSOURCE3DSOFT)(ALuint,ALenum,ALdouble*,ALdouble*,ALdouble*);
-typedef void (AL_APIENTRY*LPALGETSOURCEDVSOFT)(ALuint,ALenum,ALdouble*);
-typedef void (AL_APIENTRY*LPALSOURCEI64SOFT)(ALuint,ALenum,ALint64SOFT);
-typedef void (AL_APIENTRY*LPALSOURCE3I64SOFT)(ALuint,ALenum,ALint64SOFT,ALint64SOFT,ALint64SOFT);
-typedef void (AL_APIENTRY*LPALSOURCEI64VSOFT)(ALuint,ALenum,const ALint64SOFT*);
-typedef void (AL_APIENTRY*LPALGETSOURCEI64SOFT)(ALuint,ALenum,ALint64SOFT*);
-typedef void (AL_APIENTRY*LPALGETSOURCE3I64SOFT)(ALuint,ALenum,ALint64SOFT*,ALint64SOFT*,ALint64SOFT*);
-typedef void (AL_APIENTRY*LPALGETSOURCEI64VSOFT)(ALuint,ALenum,ALint64SOFT*);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API void AL_APIENTRY alSourcedSOFT(ALuint source, ALenum param, ALdouble value);
-AL_API void AL_APIENTRY alSource3dSOFT(ALuint source, ALenum param, ALdouble value1, ALdouble value2, ALdouble value3);
-AL_API void AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdouble *values);
-AL_API void AL_APIENTRY alGetSourcedSOFT(ALuint source, ALenum param, ALdouble *value);
-AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble *value1, ALdouble *value2, ALdouble *value3);
-AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble *values);
-AL_API void AL_APIENTRY alSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT value);
-AL_API void AL_APIENTRY alSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT value1, ALint64SOFT value2, ALint64SOFT value3);
-AL_API void AL_APIENTRY alSourcei64vSOFT(ALuint source, ALenum param, const ALint64SOFT *values);
-AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT *value);
-AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT *value1, ALint64SOFT *value2, ALint64SOFT *value3);
-AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64SOFT *values);
-#endif
-#endif
-
-#ifndef ALC_EXT_DEFAULT_FILTER_ORDER
-#define ALC_EXT_DEFAULT_FILTER_ORDER 1
-#define ALC_DEFAULT_FILTER_ORDER 0x1100
-#endif
-
-#ifndef AL_SOFT_deferred_updates
-#define AL_SOFT_deferred_updates 1
-#define AL_DEFERRED_UPDATES_SOFT 0xC002
-typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
-typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
-AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
-#endif
-#endif
-
-#ifndef AL_SOFT_block_alignment
-#define AL_SOFT_block_alignment 1
-#define AL_UNPACK_BLOCK_ALIGNMENT_SOFT 0x200C
-#define AL_PACK_BLOCK_ALIGNMENT_SOFT 0x200D
-#endif
-
-#ifndef AL_SOFT_MSADPCM
-#define AL_SOFT_MSADPCM 1
-#define AL_FORMAT_MONO_MSADPCM_SOFT 0x1302
-#define AL_FORMAT_STEREO_MSADPCM_SOFT 0x1303
-#endif
-
-#ifndef AL_SOFT_source_length
-#define AL_SOFT_source_length 1
-/*#define AL_BYTE_LENGTH_SOFT 0x2009*/
-/*#define AL_SAMPLE_LENGTH_SOFT 0x200A*/
-/*#define AL_SEC_LENGTH_SOFT 0x200B*/
-#endif
-
-#ifndef ALC_SOFT_pause_device
-#define ALC_SOFT_pause_device 1
-typedef void (ALC_APIENTRY*LPALCDEVICEPAUSESOFT)(ALCdevice *device);
-typedef void (ALC_APIENTRY*LPALCDEVICERESUMESOFT)(ALCdevice *device);
-#ifdef AL_ALEXT_PROTOTYPES
-ALC_API void ALC_APIENTRY alcDevicePauseSOFT(ALCdevice *device);
-ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device);
-#endif
-#endif
-
-#ifndef AL_EXT_BFORMAT
-#define AL_EXT_BFORMAT 1
-#define AL_FORMAT_BFORMAT2D_8 0x20021
-#define AL_FORMAT_BFORMAT2D_16 0x20022
-#define AL_FORMAT_BFORMAT2D_FLOAT32 0x20023
-#define AL_FORMAT_BFORMAT3D_8 0x20031
-#define AL_FORMAT_BFORMAT3D_16 0x20032
-#define AL_FORMAT_BFORMAT3D_FLOAT32 0x20033
-#endif
-
-#ifndef AL_EXT_MULAW_BFORMAT
-#define AL_EXT_MULAW_BFORMAT 1
-#define AL_FORMAT_BFORMAT2D_MULAW 0x10031
-#define AL_FORMAT_BFORMAT3D_MULAW 0x10032
-#endif
-
-#ifndef ALC_SOFT_HRTF
-#define ALC_SOFT_HRTF 1
-#define ALC_HRTF_SOFT 0x1992
-#define ALC_DONT_CARE_SOFT 0x0002
-#define ALC_HRTF_STATUS_SOFT 0x1993
-#define ALC_HRTF_DISABLED_SOFT 0x0000
-#define ALC_HRTF_ENABLED_SOFT 0x0001
-#define ALC_HRTF_DENIED_SOFT 0x0002
-#define ALC_HRTF_REQUIRED_SOFT 0x0003
-#define ALC_HRTF_HEADPHONES_DETECTED_SOFT 0x0004
-#define ALC_HRTF_UNSUPPORTED_FORMAT_SOFT 0x0005
-#define ALC_NUM_HRTF_SPECIFIERS_SOFT 0x1994
-#define ALC_HRTF_SPECIFIER_SOFT 0x1995
-#define ALC_HRTF_ID_SOFT 0x1996
-typedef const ALCchar* (ALC_APIENTRY*LPALCGETSTRINGISOFT)(ALCdevice *device, ALCenum paramName, ALCsizei index);
-typedef ALCboolean (ALC_APIENTRY*LPALCRESETDEVICESOFT)(ALCdevice *device, const ALCint *attribs);
-#ifdef AL_ALEXT_PROTOTYPES
-ALC_API const ALCchar* ALC_APIENTRY alcGetStringiSOFT(ALCdevice *device, ALCenum paramName, ALCsizei index);
-ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCint *attribs);
-#endif
-#endif
-
-#ifndef AL_SOFT_gain_clamp_ex
-#define AL_SOFT_gain_clamp_ex 1
-#define AL_GAIN_LIMIT_SOFT 0x200E
-#endif
-
-#ifndef AL_SOFT_source_resampler
-#define AL_SOFT_source_resampler
-#define AL_NUM_RESAMPLERS_SOFT 0x1210
-#define AL_DEFAULT_RESAMPLER_SOFT 0x1211
-#define AL_SOURCE_RESAMPLER_SOFT 0x1212
-#define AL_RESAMPLER_NAME_SOFT 0x1213
-typedef const ALchar* (AL_APIENTRY*LPALGETSTRINGISOFT)(ALenum pname, ALsizei index);
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index);
-#endif
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/templates/android_project/jni/include/AL/efx-creative.h b/templates/android_project/jni/include/AL/efx-creative.h
deleted file mode 100644
index 0a04c982..00000000
--- a/templates/android_project/jni/include/AL/efx-creative.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/* The tokens that would be defined here are already defined in efx.h. This
- * empty file is here to provide compatibility with Windows-based projects
- * that would include it. */
diff --git a/templates/android_project/jni/include/AL/efx-presets.h b/templates/android_project/jni/include/AL/efx-presets.h
deleted file mode 100644
index 8539fd51..00000000
--- a/templates/android_project/jni/include/AL/efx-presets.h
+++ /dev/null
@@ -1,402 +0,0 @@
-/* Reverb presets for EFX */
-
-#ifndef EFX_PRESETS_H
-#define EFX_PRESETS_H
-
-#ifndef EFXEAXREVERBPROPERTIES_DEFINED
-#define EFXEAXREVERBPROPERTIES_DEFINED
-typedef struct {
- float flDensity;
- float flDiffusion;
- float flGain;
- float flGainHF;
- float flGainLF;
- float flDecayTime;
- float flDecayHFRatio;
- float flDecayLFRatio;
- float flReflectionsGain;
- float flReflectionsDelay;
- float flReflectionsPan[3];
- float flLateReverbGain;
- float flLateReverbDelay;
- float flLateReverbPan[3];
- float flEchoTime;
- float flEchoDepth;
- float flModulationTime;
- float flModulationDepth;
- float flAirAbsorptionGainHF;
- float flHFReference;
- float flLFReference;
- float flRoomRolloffFactor;
- int iDecayHFLimit;
-} EFXEAXREVERBPROPERTIES, *LPEFXEAXREVERBPROPERTIES;
-#endif
-
-/* Default Presets */
-
-#define EFX_REVERB_PRESET_GENERIC \
- { 1.0000f, 1.0000f, 0.3162f, 0.8913f, 1.0000f, 1.4900f, 0.8300f, 1.0000f, 0.0500f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PADDEDCELL \
- { 0.1715f, 1.0000f, 0.3162f, 0.0010f, 1.0000f, 0.1700f, 0.1000f, 1.0000f, 0.2500f, 0.0010f, { 0.0000f, 0.0000f, 0.0000f }, 1.2691f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ROOM \
- { 0.4287f, 1.0000f, 0.3162f, 0.5929f, 1.0000f, 0.4000f, 0.8300f, 1.0000f, 0.1503f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 1.0629f, 0.0030f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_BATHROOM \
- { 0.1715f, 1.0000f, 0.3162f, 0.2512f, 1.0000f, 1.4900f, 0.5400f, 1.0000f, 0.6531f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 3.2734f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_LIVINGROOM \
- { 0.9766f, 1.0000f, 0.3162f, 0.0010f, 1.0000f, 0.5000f, 0.1000f, 1.0000f, 0.2051f, 0.0030f, { 0.0000f, 0.0000f, 0.0000f }, 0.2805f, 0.0040f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_STONEROOM \
- { 1.0000f, 1.0000f, 0.3162f, 0.7079f, 1.0000f, 2.3100f, 0.6400f, 1.0000f, 0.4411f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1003f, 0.0170f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_AUDITORIUM \
- { 1.0000f, 1.0000f, 0.3162f, 0.5781f, 1.0000f, 4.3200f, 0.5900f, 1.0000f, 0.4032f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.7170f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CONCERTHALL \
- { 1.0000f, 1.0000f, 0.3162f, 0.5623f, 1.0000f, 3.9200f, 0.7000f, 1.0000f, 0.2427f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.9977f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CAVE \
- { 1.0000f, 1.0000f, 0.3162f, 1.0000f, 1.0000f, 2.9100f, 1.3000f, 1.0000f, 0.5000f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.7063f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_ARENA \
- { 1.0000f, 1.0000f, 0.3162f, 0.4477f, 1.0000f, 7.2400f, 0.3300f, 1.0000f, 0.2612f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.0186f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_HANGAR \
- { 1.0000f, 1.0000f, 0.3162f, 0.3162f, 1.0000f, 10.0500f, 0.2300f, 1.0000f, 0.5000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.2560f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CARPETEDHALLWAY \
- { 0.4287f, 1.0000f, 0.3162f, 0.0100f, 1.0000f, 0.3000f, 0.1000f, 1.0000f, 0.1215f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 0.1531f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_HALLWAY \
- { 0.3645f, 1.0000f, 0.3162f, 0.7079f, 1.0000f, 1.4900f, 0.5900f, 1.0000f, 0.2458f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.6615f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_STONECORRIDOR \
- { 1.0000f, 1.0000f, 0.3162f, 0.7612f, 1.0000f, 2.7000f, 0.7900f, 1.0000f, 0.2472f, 0.0130f, { 0.0000f, 0.0000f, 0.0000f }, 1.5758f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ALLEY \
- { 1.0000f, 0.3000f, 0.3162f, 0.7328f, 1.0000f, 1.4900f, 0.8600f, 1.0000f, 0.2500f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.9954f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 0.9500f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FOREST \
- { 1.0000f, 0.3000f, 0.3162f, 0.0224f, 1.0000f, 1.4900f, 0.5400f, 1.0000f, 0.0525f, 0.1620f, { 0.0000f, 0.0000f, 0.0000f }, 0.7682f, 0.0880f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CITY \
- { 1.0000f, 0.5000f, 0.3162f, 0.3981f, 1.0000f, 1.4900f, 0.6700f, 1.0000f, 0.0730f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.1427f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_MOUNTAINS \
- { 1.0000f, 0.2700f, 0.3162f, 0.0562f, 1.0000f, 1.4900f, 0.2100f, 1.0000f, 0.0407f, 0.3000f, { 0.0000f, 0.0000f, 0.0000f }, 0.1919f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_QUARRY \
- { 1.0000f, 1.0000f, 0.3162f, 0.3162f, 1.0000f, 1.4900f, 0.8300f, 1.0000f, 0.0000f, 0.0610f, { 0.0000f, 0.0000f, 0.0000f }, 1.7783f, 0.0250f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 0.7000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PLAIN \
- { 1.0000f, 0.2100f, 0.3162f, 0.1000f, 1.0000f, 1.4900f, 0.5000f, 1.0000f, 0.0585f, 0.1790f, { 0.0000f, 0.0000f, 0.0000f }, 0.1089f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PARKINGLOT \
- { 1.0000f, 1.0000f, 0.3162f, 1.0000f, 1.0000f, 1.6500f, 1.5000f, 1.0000f, 0.2082f, 0.0080f, { 0.0000f, 0.0000f, 0.0000f }, 0.2652f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_SEWERPIPE \
- { 0.3071f, 0.8000f, 0.3162f, 0.3162f, 1.0000f, 2.8100f, 0.1400f, 1.0000f, 1.6387f, 0.0140f, { 0.0000f, 0.0000f, 0.0000f }, 3.2471f, 0.0210f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_UNDERWATER \
- { 0.3645f, 1.0000f, 0.3162f, 0.0100f, 1.0000f, 1.4900f, 0.1000f, 1.0000f, 0.5963f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 7.0795f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 1.1800f, 0.3480f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_DRUGGED \
- { 0.4287f, 0.5000f, 0.3162f, 1.0000f, 1.0000f, 8.3900f, 1.3900f, 1.0000f, 0.8760f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 3.1081f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 1.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_DIZZY \
- { 0.3645f, 0.6000f, 0.3162f, 0.6310f, 1.0000f, 17.2300f, 0.5600f, 1.0000f, 0.1392f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.4937f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.8100f, 0.3100f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_PSYCHOTIC \
- { 0.0625f, 0.5000f, 0.3162f, 0.8404f, 1.0000f, 7.5600f, 0.9100f, 1.0000f, 0.4864f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 2.4378f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 4.0000f, 1.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-/* Castle Presets */
-
-#define EFX_REVERB_PRESET_CASTLE_SMALLROOM \
- { 1.0000f, 0.8900f, 0.3162f, 0.3981f, 0.1000f, 1.2200f, 0.8300f, 0.3100f, 0.8913f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_SHORTPASSAGE \
- { 1.0000f, 0.8900f, 0.3162f, 0.3162f, 0.1000f, 2.3200f, 0.8300f, 0.3100f, 0.8913f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_MEDIUMROOM \
- { 1.0000f, 0.9300f, 0.3162f, 0.2818f, 0.1000f, 2.0400f, 0.8300f, 0.4600f, 0.6310f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 1.5849f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1550f, 0.0300f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_LARGEROOM \
- { 1.0000f, 0.8200f, 0.3162f, 0.2818f, 0.1259f, 2.5300f, 0.8300f, 0.5000f, 0.4467f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.1850f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_LONGPASSAGE \
- { 1.0000f, 0.8900f, 0.3162f, 0.3981f, 0.1000f, 3.4200f, 0.8300f, 0.3100f, 0.8913f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_HALL \
- { 1.0000f, 0.8100f, 0.3162f, 0.2818f, 0.1778f, 3.1400f, 0.7900f, 0.6200f, 0.1778f, 0.0560f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_CUPBOARD \
- { 1.0000f, 0.8900f, 0.3162f, 0.2818f, 0.1000f, 0.6700f, 0.8700f, 0.3100f, 1.4125f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 3.5481f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CASTLE_COURTYARD \
- { 1.0000f, 0.4200f, 0.3162f, 0.4467f, 0.1995f, 2.1300f, 0.6100f, 0.2300f, 0.2239f, 0.1600f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0360f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.3700f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_CASTLE_ALCOVE \
- { 1.0000f, 0.8900f, 0.3162f, 0.5012f, 0.1000f, 1.6400f, 0.8700f, 0.3100f, 1.0000f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
-
-/* Factory Presets */
-
-#define EFX_REVERB_PRESET_FACTORY_SMALLROOM \
- { 0.3645f, 0.8200f, 0.3162f, 0.7943f, 0.5012f, 1.7200f, 0.6500f, 1.3100f, 0.7079f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.7783f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.1190f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_SHORTPASSAGE \
- { 0.3645f, 0.6400f, 0.2512f, 0.7943f, 0.5012f, 2.5300f, 0.6500f, 1.3100f, 1.0000f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.1350f, 0.2300f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_MEDIUMROOM \
- { 0.4287f, 0.8200f, 0.2512f, 0.7943f, 0.5012f, 2.7600f, 0.6500f, 1.3100f, 0.2818f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1740f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_LARGEROOM \
- { 0.4287f, 0.7500f, 0.2512f, 0.7079f, 0.6310f, 4.2400f, 0.5100f, 1.3100f, 0.1778f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.2310f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_LONGPASSAGE \
- { 0.3645f, 0.6400f, 0.2512f, 0.7943f, 0.5012f, 4.0600f, 0.6500f, 1.3100f, 1.0000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0370f, { 0.0000f, 0.0000f, 0.0000f }, 0.1350f, 0.2300f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_HALL \
- { 0.4287f, 0.7500f, 0.3162f, 0.7079f, 0.6310f, 7.4300f, 0.5100f, 1.3100f, 0.0631f, 0.0730f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0270f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_CUPBOARD \
- { 0.3071f, 0.6300f, 0.2512f, 0.7943f, 0.5012f, 0.4900f, 0.6500f, 1.3100f, 1.2589f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.1070f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_COURTYARD \
- { 0.3071f, 0.5700f, 0.3162f, 0.3162f, 0.6310f, 2.3200f, 0.2900f, 0.5600f, 0.2239f, 0.1400f, { 0.0000f, 0.0000f, 0.0000f }, 0.3981f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2900f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_FACTORY_ALCOVE \
- { 0.3645f, 0.5900f, 0.2512f, 0.7943f, 0.5012f, 3.1400f, 0.6500f, 1.3100f, 1.4125f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.1140f, 0.1000f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
-
-/* Ice Palace Presets */
-
-#define EFX_REVERB_PRESET_ICEPALACE_SMALLROOM \
- { 1.0000f, 0.8400f, 0.3162f, 0.5623f, 0.2818f, 1.5100f, 1.5300f, 0.2700f, 0.8913f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1640f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_SHORTPASSAGE \
- { 1.0000f, 0.7500f, 0.3162f, 0.5623f, 0.2818f, 1.7900f, 1.4600f, 0.2800f, 0.5012f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0190f, { 0.0000f, 0.0000f, 0.0000f }, 0.1770f, 0.0900f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_MEDIUMROOM \
- { 1.0000f, 0.8700f, 0.3162f, 0.5623f, 0.4467f, 2.2200f, 1.5300f, 0.3200f, 0.3981f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0270f, { 0.0000f, 0.0000f, 0.0000f }, 0.1860f, 0.1200f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_LARGEROOM \
- { 1.0000f, 0.8100f, 0.3162f, 0.5623f, 0.4467f, 3.1400f, 1.5300f, 0.3200f, 0.2512f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0270f, { 0.0000f, 0.0000f, 0.0000f }, 0.2140f, 0.1100f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_LONGPASSAGE \
- { 1.0000f, 0.7700f, 0.3162f, 0.5623f, 0.3981f, 3.0100f, 1.4600f, 0.2800f, 0.7943f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0250f, { 0.0000f, 0.0000f, 0.0000f }, 0.1860f, 0.0400f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_HALL \
- { 1.0000f, 0.7600f, 0.3162f, 0.4467f, 0.5623f, 5.4900f, 1.5300f, 0.3800f, 0.1122f, 0.0540f, { 0.0000f, 0.0000f, 0.0000f }, 0.6310f, 0.0520f, { 0.0000f, 0.0000f, 0.0000f }, 0.2260f, 0.1100f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_CUPBOARD \
- { 1.0000f, 0.8300f, 0.3162f, 0.5012f, 0.2239f, 0.7600f, 1.5300f, 0.2600f, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.1430f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_COURTYARD \
- { 1.0000f, 0.5900f, 0.3162f, 0.2818f, 0.3162f, 2.0400f, 1.2000f, 0.3800f, 0.3162f, 0.1730f, { 0.0000f, 0.0000f, 0.0000f }, 0.3162f, 0.0430f, { 0.0000f, 0.0000f, 0.0000f }, 0.2350f, 0.4800f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_ICEPALACE_ALCOVE \
- { 1.0000f, 0.8400f, 0.3162f, 0.5623f, 0.2818f, 2.7600f, 1.4600f, 0.2800f, 1.1220f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1610f, 0.0900f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
-
-/* Space Station Presets */
-
-#define EFX_REVERB_PRESET_SPACESTATION_SMALLROOM \
- { 0.2109f, 0.7000f, 0.3162f, 0.7079f, 0.8913f, 1.7200f, 0.8200f, 0.5500f, 0.7943f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0130f, { 0.0000f, 0.0000f, 0.0000f }, 0.1880f, 0.2600f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_SHORTPASSAGE \
- { 0.2109f, 0.8700f, 0.3162f, 0.6310f, 0.8913f, 3.5700f, 0.5000f, 0.5500f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.1720f, 0.2000f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_MEDIUMROOM \
- { 0.2109f, 0.7500f, 0.3162f, 0.6310f, 0.8913f, 3.0100f, 0.5000f, 0.5500f, 0.3981f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0350f, { 0.0000f, 0.0000f, 0.0000f }, 0.2090f, 0.3100f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_LARGEROOM \
- { 0.3645f, 0.8100f, 0.3162f, 0.6310f, 0.8913f, 3.8900f, 0.3800f, 0.6100f, 0.3162f, 0.0560f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0350f, { 0.0000f, 0.0000f, 0.0000f }, 0.2330f, 0.2800f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_LONGPASSAGE \
- { 0.4287f, 0.8200f, 0.3162f, 0.6310f, 0.8913f, 4.6200f, 0.6200f, 0.5500f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0310f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2300f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_HALL \
- { 0.4287f, 0.8700f, 0.3162f, 0.6310f, 0.8913f, 7.1100f, 0.3800f, 0.6100f, 0.1778f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.6310f, 0.0470f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2500f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_CUPBOARD \
- { 0.1715f, 0.5600f, 0.3162f, 0.7079f, 0.8913f, 0.7900f, 0.8100f, 0.5500f, 1.4125f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.7783f, 0.0180f, { 0.0000f, 0.0000f, 0.0000f }, 0.1810f, 0.3100f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPACESTATION_ALCOVE \
- { 0.2109f, 0.7800f, 0.3162f, 0.7079f, 0.8913f, 1.1600f, 0.8100f, 0.5500f, 1.4125f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0180f, { 0.0000f, 0.0000f, 0.0000f }, 0.1920f, 0.2100f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
-
-/* Wooden Galleon Presets */
-
-#define EFX_REVERB_PRESET_WOODEN_SMALLROOM \
- { 1.0000f, 1.0000f, 0.3162f, 0.1122f, 0.3162f, 0.7900f, 0.3200f, 0.8700f, 1.0000f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_SHORTPASSAGE \
- { 1.0000f, 1.0000f, 0.3162f, 0.1259f, 0.3162f, 1.7500f, 0.5000f, 0.8700f, 0.8913f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.6310f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_MEDIUMROOM \
- { 1.0000f, 1.0000f, 0.3162f, 0.1000f, 0.2818f, 1.4700f, 0.4200f, 0.8200f, 0.8913f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_LARGEROOM \
- { 1.0000f, 1.0000f, 0.3162f, 0.0891f, 0.2818f, 2.6500f, 0.3300f, 0.8200f, 0.8913f, 0.0660f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_LONGPASSAGE \
- { 1.0000f, 1.0000f, 0.3162f, 0.1000f, 0.3162f, 1.9900f, 0.4000f, 0.7900f, 1.0000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.4467f, 0.0360f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_HALL \
- { 1.0000f, 1.0000f, 0.3162f, 0.0794f, 0.2818f, 3.4500f, 0.3000f, 0.8200f, 0.8913f, 0.0880f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0630f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_CUPBOARD \
- { 1.0000f, 1.0000f, 0.3162f, 0.1413f, 0.3162f, 0.5600f, 0.4600f, 0.9100f, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0280f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_COURTYARD \
- { 1.0000f, 0.6500f, 0.3162f, 0.0794f, 0.3162f, 1.7900f, 0.3500f, 0.7900f, 0.5623f, 0.1230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1000f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_WOODEN_ALCOVE \
- { 1.0000f, 1.0000f, 0.3162f, 0.1259f, 0.3162f, 1.2200f, 0.6200f, 0.9100f, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
-
-/* Sports Presets */
-
-#define EFX_REVERB_PRESET_SPORT_EMPTYSTADIUM \
- { 1.0000f, 1.0000f, 0.3162f, 0.4467f, 0.7943f, 6.2600f, 0.5100f, 1.1000f, 0.0631f, 0.1830f, { 0.0000f, 0.0000f, 0.0000f }, 0.3981f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPORT_SQUASHCOURT \
- { 1.0000f, 0.7500f, 0.3162f, 0.3162f, 0.7943f, 2.2200f, 0.9100f, 1.1600f, 0.4467f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1260f, 0.1900f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPORT_SMALLSWIMMINGPOOL \
- { 1.0000f, 0.7000f, 0.3162f, 0.7943f, 0.8913f, 2.7600f, 1.2500f, 1.1400f, 0.6310f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1790f, 0.1500f, 0.8950f, 0.1900f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_SPORT_LARGESWIMMINGPOOL \
- { 1.0000f, 0.8200f, 0.3162f, 0.7943f, 1.0000f, 5.4900f, 1.3100f, 1.1400f, 0.4467f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 0.5012f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2220f, 0.5500f, 1.1590f, 0.2100f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_SPORT_GYMNASIUM \
- { 1.0000f, 0.8100f, 0.3162f, 0.4467f, 0.8913f, 3.1400f, 1.0600f, 1.3500f, 0.3981f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.5623f, 0.0450f, { 0.0000f, 0.0000f, 0.0000f }, 0.1460f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPORT_FULLSTADIUM \
- { 1.0000f, 1.0000f, 0.3162f, 0.0708f, 0.7943f, 5.2500f, 0.1700f, 0.8000f, 0.1000f, 0.1880f, { 0.0000f, 0.0000f, 0.0000f }, 0.2818f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SPORT_STADIUMTANNOY \
- { 1.0000f, 0.7800f, 0.3162f, 0.5623f, 0.5012f, 2.5300f, 0.8800f, 0.6800f, 0.2818f, 0.2300f, { 0.0000f, 0.0000f, 0.0000f }, 0.5012f, 0.0630f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-/* Prefab Presets */
-
-#define EFX_REVERB_PRESET_PREFAB_WORKSHOP \
- { 0.4287f, 1.0000f, 0.3162f, 0.1413f, 0.3981f, 0.7600f, 1.0000f, 1.0000f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_PREFAB_SCHOOLROOM \
- { 0.4022f, 0.6900f, 0.3162f, 0.6310f, 0.5012f, 0.9800f, 0.4500f, 0.1800f, 1.4125f, 0.0170f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.0950f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PREFAB_PRACTISEROOM \
- { 0.4022f, 0.8700f, 0.3162f, 0.3981f, 0.5012f, 1.1200f, 0.5600f, 0.1800f, 1.2589f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.0950f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PREFAB_OUTHOUSE \
- { 1.0000f, 0.8200f, 0.3162f, 0.1122f, 0.1585f, 1.3800f, 0.3800f, 0.3500f, 0.8913f, 0.0240f, { 0.0000f, 0.0000f, -0.0000f }, 0.6310f, 0.0440f, { 0.0000f, 0.0000f, 0.0000f }, 0.1210f, 0.1700f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_PREFAB_CARAVAN \
- { 1.0000f, 1.0000f, 0.3162f, 0.0891f, 0.1259f, 0.4300f, 1.5000f, 1.0000f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-/* Dome and Pipe Presets */
-
-#define EFX_REVERB_PRESET_DOME_TOMB \
- { 1.0000f, 0.7900f, 0.3162f, 0.3548f, 0.2239f, 4.1800f, 0.2100f, 0.1000f, 0.3868f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 1.6788f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.1770f, 0.1900f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_PIPE_SMALL \
- { 1.0000f, 1.0000f, 0.3162f, 0.3548f, 0.2239f, 5.0400f, 0.1000f, 0.1000f, 0.5012f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 2.5119f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_DOME_SAINTPAULS \
- { 1.0000f, 0.8700f, 0.3162f, 0.3548f, 0.2239f, 10.4800f, 0.1900f, 0.1000f, 0.1778f, 0.0900f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0420f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.1200f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PIPE_LONGTHIN \
- { 0.2560f, 0.9100f, 0.3162f, 0.4467f, 0.2818f, 9.2100f, 0.1800f, 0.1000f, 0.7079f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_PIPE_LARGE \
- { 1.0000f, 1.0000f, 0.3162f, 0.3548f, 0.2239f, 8.4500f, 0.1000f, 0.1000f, 0.3981f, 0.0460f, { 0.0000f, 0.0000f, 0.0000f }, 1.5849f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_PIPE_RESONANT \
- { 0.1373f, 0.9100f, 0.3162f, 0.4467f, 0.2818f, 6.8100f, 0.1800f, 0.1000f, 0.7079f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x0 }
-
-/* Outdoors Presets */
-
-#define EFX_REVERB_PRESET_OUTDOORS_BACKYARD \
- { 1.0000f, 0.4500f, 0.3162f, 0.2512f, 0.5012f, 1.1200f, 0.3400f, 0.4600f, 0.4467f, 0.0690f, { 0.0000f, 0.0000f, -0.0000f }, 0.7079f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.2180f, 0.3400f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_OUTDOORS_ROLLINGPLAINS \
- { 1.0000f, 0.0000f, 0.3162f, 0.0112f, 0.6310f, 2.1300f, 0.2100f, 0.4600f, 0.1778f, 0.3000f, { 0.0000f, 0.0000f, -0.0000f }, 0.4467f, 0.0190f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_OUTDOORS_DEEPCANYON \
- { 1.0000f, 0.7400f, 0.3162f, 0.1778f, 0.6310f, 3.8900f, 0.2100f, 0.4600f, 0.3162f, 0.2230f, { 0.0000f, 0.0000f, -0.0000f }, 0.3548f, 0.0190f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_OUTDOORS_CREEK \
- { 1.0000f, 0.3500f, 0.3162f, 0.1778f, 0.5012f, 2.1300f, 0.2100f, 0.4600f, 0.3981f, 0.1150f, { 0.0000f, 0.0000f, -0.0000f }, 0.1995f, 0.0310f, { 0.0000f, 0.0000f, 0.0000f }, 0.2180f, 0.3400f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_OUTDOORS_VALLEY \
- { 1.0000f, 0.2800f, 0.3162f, 0.0282f, 0.1585f, 2.8800f, 0.2600f, 0.3500f, 0.1413f, 0.2630f, { 0.0000f, 0.0000f, -0.0000f }, 0.3981f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.3400f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
-
-/* Mood Presets */
-
-#define EFX_REVERB_PRESET_MOOD_HEAVEN \
- { 1.0000f, 0.9400f, 0.3162f, 0.7943f, 0.4467f, 5.0400f, 1.1200f, 0.5600f, 0.2427f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0800f, 2.7420f, 0.0500f, 0.9977f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_MOOD_HELL \
- { 1.0000f, 0.5700f, 0.3162f, 0.3548f, 0.4467f, 3.5700f, 0.4900f, 2.0000f, 0.0000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1100f, 0.0400f, 2.1090f, 0.5200f, 0.9943f, 5000.0000f, 139.5000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_MOOD_MEMORY \
- { 1.0000f, 0.8500f, 0.3162f, 0.6310f, 0.3548f, 4.0600f, 0.8200f, 0.5600f, 0.0398f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.4740f, 0.4500f, 0.9886f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-/* Driving Presets */
-
-#define EFX_REVERB_PRESET_DRIVING_COMMENTATOR \
- { 1.0000f, 0.0000f, 0.3162f, 0.5623f, 0.5012f, 2.4200f, 0.8800f, 0.6800f, 0.1995f, 0.0930f, { 0.0000f, 0.0000f, 0.0000f }, 0.2512f, 0.0170f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9886f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_DRIVING_PITGARAGE \
- { 0.4287f, 0.5900f, 0.3162f, 0.7079f, 0.5623f, 1.7200f, 0.9300f, 0.8700f, 0.5623f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.1100f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_DRIVING_INCAR_RACER \
- { 0.0832f, 0.8000f, 0.3162f, 1.0000f, 0.7943f, 0.1700f, 2.0000f, 0.4100f, 1.7783f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10268.2002f, 251.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_DRIVING_INCAR_SPORTS \
- { 0.0832f, 0.8000f, 0.3162f, 0.6310f, 1.0000f, 0.1700f, 0.7500f, 0.4100f, 1.0000f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.5623f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10268.2002f, 251.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_DRIVING_INCAR_LUXURY \
- { 0.2560f, 1.0000f, 0.3162f, 0.1000f, 0.5012f, 0.1300f, 0.4100f, 0.4600f, 0.7943f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.5849f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10268.2002f, 251.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_DRIVING_FULLGRANDSTAND \
- { 1.0000f, 1.0000f, 0.3162f, 0.2818f, 0.6310f, 3.0100f, 1.3700f, 1.2800f, 0.3548f, 0.0900f, { 0.0000f, 0.0000f, 0.0000f }, 0.1778f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10420.2002f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_DRIVING_EMPTYGRANDSTAND \
- { 1.0000f, 1.0000f, 0.3162f, 1.0000f, 0.7943f, 4.6200f, 1.7500f, 1.4000f, 0.2082f, 0.0900f, { 0.0000f, 0.0000f, 0.0000f }, 0.2512f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10420.2002f, 250.0000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_DRIVING_TUNNEL \
- { 1.0000f, 0.8100f, 0.3162f, 0.3981f, 0.8913f, 3.4200f, 0.9400f, 1.3100f, 0.7079f, 0.0510f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0470f, { 0.0000f, 0.0000f, 0.0000f }, 0.2140f, 0.0500f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 155.3000f, 0.0000f, 0x1 }
-
-/* City Presets */
-
-#define EFX_REVERB_PRESET_CITY_STREETS \
- { 1.0000f, 0.7800f, 0.3162f, 0.7079f, 0.8913f, 1.7900f, 1.1200f, 0.9100f, 0.2818f, 0.0460f, { 0.0000f, 0.0000f, 0.0000f }, 0.1995f, 0.0280f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CITY_SUBWAY \
- { 1.0000f, 0.7400f, 0.3162f, 0.7079f, 0.8913f, 3.0100f, 1.2300f, 0.9100f, 0.7079f, 0.0460f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0280f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 0.2100f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CITY_MUSEUM \
- { 1.0000f, 0.8200f, 0.3162f, 0.1778f, 0.1778f, 3.2800f, 1.4000f, 0.5700f, 0.2512f, 0.0390f, { 0.0000f, 0.0000f, -0.0000f }, 0.8913f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 0.1300f, 0.1700f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_CITY_LIBRARY \
- { 1.0000f, 0.8200f, 0.3162f, 0.2818f, 0.0891f, 2.7600f, 0.8900f, 0.4100f, 0.3548f, 0.0290f, { 0.0000f, 0.0000f, -0.0000f }, 0.8913f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.1300f, 0.1700f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
-
-#define EFX_REVERB_PRESET_CITY_UNDERPASS \
- { 1.0000f, 0.8200f, 0.3162f, 0.4467f, 0.8913f, 3.5700f, 1.1200f, 0.9100f, 0.3981f, 0.0590f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0370f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.1400f, 0.2500f, 0.0000f, 0.9920f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CITY_ABANDONED \
- { 1.0000f, 0.6900f, 0.3162f, 0.7943f, 0.8913f, 3.2800f, 1.1700f, 0.9100f, 0.4467f, 0.0440f, { 0.0000f, 0.0000f, 0.0000f }, 0.2818f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2000f, 0.2500f, 0.0000f, 0.9966f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-/* Misc. Presets */
-
-#define EFX_REVERB_PRESET_DUSTYROOM \
- { 0.3645f, 0.5600f, 0.3162f, 0.7943f, 0.7079f, 1.7900f, 0.3800f, 0.2100f, 0.5012f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0060f, { 0.0000f, 0.0000f, 0.0000f }, 0.2020f, 0.0500f, 0.2500f, 0.0000f, 0.9886f, 13046.0000f, 163.3000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_CHAPEL \
- { 1.0000f, 0.8400f, 0.3162f, 0.5623f, 1.0000f, 4.6200f, 0.6400f, 1.2300f, 0.4467f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.1100f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
-
-#define EFX_REVERB_PRESET_SMALLWATERROOM \
- { 1.0000f, 0.7000f, 0.3162f, 0.4477f, 1.0000f, 1.5100f, 1.2500f, 1.1400f, 0.8913f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1790f, 0.1500f, 0.8950f, 0.1900f, 0.9920f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
-
-#endif /* EFX_PRESETS_H */
diff --git a/templates/android_project/jni/include/AL/efx.h b/templates/android_project/jni/include/AL/efx.h
deleted file mode 100644
index 57766983..00000000
--- a/templates/android_project/jni/include/AL/efx.h
+++ /dev/null
@@ -1,761 +0,0 @@
-#ifndef AL_EFX_H
-#define AL_EFX_H
-
-
-#include "alc.h"
-#include "al.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define ALC_EXT_EFX_NAME "ALC_EXT_EFX"
-
-#define ALC_EFX_MAJOR_VERSION 0x20001
-#define ALC_EFX_MINOR_VERSION 0x20002
-#define ALC_MAX_AUXILIARY_SENDS 0x20003
-
-
-/* Listener properties. */
-#define AL_METERS_PER_UNIT 0x20004
-
-/* Source properties. */
-#define AL_DIRECT_FILTER 0x20005
-#define AL_AUXILIARY_SEND_FILTER 0x20006
-#define AL_AIR_ABSORPTION_FACTOR 0x20007
-#define AL_ROOM_ROLLOFF_FACTOR 0x20008
-#define AL_CONE_OUTER_GAINHF 0x20009
-#define AL_DIRECT_FILTER_GAINHF_AUTO 0x2000A
-#define AL_AUXILIARY_SEND_FILTER_GAIN_AUTO 0x2000B
-#define AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO 0x2000C
-
-
-/* Effect properties. */
-
-/* Reverb effect parameters */
-#define AL_REVERB_DENSITY 0x0001
-#define AL_REVERB_DIFFUSION 0x0002
-#define AL_REVERB_GAIN 0x0003
-#define AL_REVERB_GAINHF 0x0004
-#define AL_REVERB_DECAY_TIME 0x0005
-#define AL_REVERB_DECAY_HFRATIO 0x0006
-#define AL_REVERB_REFLECTIONS_GAIN 0x0007
-#define AL_REVERB_REFLECTIONS_DELAY 0x0008
-#define AL_REVERB_LATE_REVERB_GAIN 0x0009
-#define AL_REVERB_LATE_REVERB_DELAY 0x000A
-#define AL_REVERB_AIR_ABSORPTION_GAINHF 0x000B
-#define AL_REVERB_ROOM_ROLLOFF_FACTOR 0x000C
-#define AL_REVERB_DECAY_HFLIMIT 0x000D
-
-/* EAX Reverb effect parameters */
-#define AL_EAXREVERB_DENSITY 0x0001
-#define AL_EAXREVERB_DIFFUSION 0x0002
-#define AL_EAXREVERB_GAIN 0x0003
-#define AL_EAXREVERB_GAINHF 0x0004
-#define AL_EAXREVERB_GAINLF 0x0005
-#define AL_EAXREVERB_DECAY_TIME 0x0006
-#define AL_EAXREVERB_DECAY_HFRATIO 0x0007
-#define AL_EAXREVERB_DECAY_LFRATIO 0x0008
-#define AL_EAXREVERB_REFLECTIONS_GAIN 0x0009
-#define AL_EAXREVERB_REFLECTIONS_DELAY 0x000A
-#define AL_EAXREVERB_REFLECTIONS_PAN 0x000B
-#define AL_EAXREVERB_LATE_REVERB_GAIN 0x000C
-#define AL_EAXREVERB_LATE_REVERB_DELAY 0x000D
-#define AL_EAXREVERB_LATE_REVERB_PAN 0x000E
-#define AL_EAXREVERB_ECHO_TIME 0x000F
-#define AL_EAXREVERB_ECHO_DEPTH 0x0010
-#define AL_EAXREVERB_MODULATION_TIME 0x0011
-#define AL_EAXREVERB_MODULATION_DEPTH 0x0012
-#define AL_EAXREVERB_AIR_ABSORPTION_GAINHF 0x0013
-#define AL_EAXREVERB_HFREFERENCE 0x0014
-#define AL_EAXREVERB_LFREFERENCE 0x0015
-#define AL_EAXREVERB_ROOM_ROLLOFF_FACTOR 0x0016
-#define AL_EAXREVERB_DECAY_HFLIMIT 0x0017
-
-/* Chorus effect parameters */
-#define AL_CHORUS_WAVEFORM 0x0001
-#define AL_CHORUS_PHASE 0x0002
-#define AL_CHORUS_RATE 0x0003
-#define AL_CHORUS_DEPTH 0x0004
-#define AL_CHORUS_FEEDBACK 0x0005
-#define AL_CHORUS_DELAY 0x0006
-
-/* Distortion effect parameters */
-#define AL_DISTORTION_EDGE 0x0001
-#define AL_DISTORTION_GAIN 0x0002
-#define AL_DISTORTION_LOWPASS_CUTOFF 0x0003
-#define AL_DISTORTION_EQCENTER 0x0004
-#define AL_DISTORTION_EQBANDWIDTH 0x0005
-
-/* Echo effect parameters */
-#define AL_ECHO_DELAY 0x0001
-#define AL_ECHO_LRDELAY 0x0002
-#define AL_ECHO_DAMPING 0x0003
-#define AL_ECHO_FEEDBACK 0x0004
-#define AL_ECHO_SPREAD 0x0005
-
-/* Flanger effect parameters */
-#define AL_FLANGER_WAVEFORM 0x0001
-#define AL_FLANGER_PHASE 0x0002
-#define AL_FLANGER_RATE 0x0003
-#define AL_FLANGER_DEPTH 0x0004
-#define AL_FLANGER_FEEDBACK 0x0005
-#define AL_FLANGER_DELAY 0x0006
-
-/* Frequency shifter effect parameters */
-#define AL_FREQUENCY_SHIFTER_FREQUENCY 0x0001
-#define AL_FREQUENCY_SHIFTER_LEFT_DIRECTION 0x0002
-#define AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION 0x0003
-
-/* Vocal morpher effect parameters */
-#define AL_VOCAL_MORPHER_PHONEMEA 0x0001
-#define AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING 0x0002
-#define AL_VOCAL_MORPHER_PHONEMEB 0x0003
-#define AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING 0x0004
-#define AL_VOCAL_MORPHER_WAVEFORM 0x0005
-#define AL_VOCAL_MORPHER_RATE 0x0006
-
-/* Pitchshifter effect parameters */
-#define AL_PITCH_SHIFTER_COARSE_TUNE 0x0001
-#define AL_PITCH_SHIFTER_FINE_TUNE 0x0002
-
-/* Ringmodulator effect parameters */
-#define AL_RING_MODULATOR_FREQUENCY 0x0001
-#define AL_RING_MODULATOR_HIGHPASS_CUTOFF 0x0002
-#define AL_RING_MODULATOR_WAVEFORM 0x0003
-
-/* Autowah effect parameters */
-#define AL_AUTOWAH_ATTACK_TIME 0x0001
-#define AL_AUTOWAH_RELEASE_TIME 0x0002
-#define AL_AUTOWAH_RESONANCE 0x0003
-#define AL_AUTOWAH_PEAK_GAIN 0x0004
-
-/* Compressor effect parameters */
-#define AL_COMPRESSOR_ONOFF 0x0001
-
-/* Equalizer effect parameters */
-#define AL_EQUALIZER_LOW_GAIN 0x0001
-#define AL_EQUALIZER_LOW_CUTOFF 0x0002
-#define AL_EQUALIZER_MID1_GAIN 0x0003
-#define AL_EQUALIZER_MID1_CENTER 0x0004
-#define AL_EQUALIZER_MID1_WIDTH 0x0005
-#define AL_EQUALIZER_MID2_GAIN 0x0006
-#define AL_EQUALIZER_MID2_CENTER 0x0007
-#define AL_EQUALIZER_MID2_WIDTH 0x0008
-#define AL_EQUALIZER_HIGH_GAIN 0x0009
-#define AL_EQUALIZER_HIGH_CUTOFF 0x000A
-
-/* Effect type */
-#define AL_EFFECT_FIRST_PARAMETER 0x0000
-#define AL_EFFECT_LAST_PARAMETER 0x8000
-#define AL_EFFECT_TYPE 0x8001
-
-/* Effect types, used with the AL_EFFECT_TYPE property */
-#define AL_EFFECT_NULL 0x0000
-#define AL_EFFECT_REVERB 0x0001
-#define AL_EFFECT_CHORUS 0x0002
-#define AL_EFFECT_DISTORTION 0x0003
-#define AL_EFFECT_ECHO 0x0004
-#define AL_EFFECT_FLANGER 0x0005
-#define AL_EFFECT_FREQUENCY_SHIFTER 0x0006
-#define AL_EFFECT_VOCAL_MORPHER 0x0007
-#define AL_EFFECT_PITCH_SHIFTER 0x0008
-#define AL_EFFECT_RING_MODULATOR 0x0009
-#define AL_EFFECT_AUTOWAH 0x000A
-#define AL_EFFECT_COMPRESSOR 0x000B
-#define AL_EFFECT_EQUALIZER 0x000C
-#define AL_EFFECT_EAXREVERB 0x8000
-
-/* Auxiliary Effect Slot properties. */
-#define AL_EFFECTSLOT_EFFECT 0x0001
-#define AL_EFFECTSLOT_GAIN 0x0002
-#define AL_EFFECTSLOT_AUXILIARY_SEND_AUTO 0x0003
-
-/* NULL Auxiliary Slot ID to disable a source send. */
-#define AL_EFFECTSLOT_NULL 0x0000
-
-
-/* Filter properties. */
-
-/* Lowpass filter parameters */
-#define AL_LOWPASS_GAIN 0x0001
-#define AL_LOWPASS_GAINHF 0x0002
-
-/* Highpass filter parameters */
-#define AL_HIGHPASS_GAIN 0x0001
-#define AL_HIGHPASS_GAINLF 0x0002
-
-/* Bandpass filter parameters */
-#define AL_BANDPASS_GAIN 0x0001
-#define AL_BANDPASS_GAINLF 0x0002
-#define AL_BANDPASS_GAINHF 0x0003
-
-/* Filter type */
-#define AL_FILTER_FIRST_PARAMETER 0x0000
-#define AL_FILTER_LAST_PARAMETER 0x8000
-#define AL_FILTER_TYPE 0x8001
-
-/* Filter types, used with the AL_FILTER_TYPE property */
-#define AL_FILTER_NULL 0x0000
-#define AL_FILTER_LOWPASS 0x0001
-#define AL_FILTER_HIGHPASS 0x0002
-#define AL_FILTER_BANDPASS 0x0003
-
-
-/* Effect object function types. */
-typedef void (AL_APIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);
-typedef void (AL_APIENTRY *LPALDELETEEFFECTS)(ALsizei, const ALuint*);
-typedef ALboolean (AL_APIENTRY *LPALISEFFECT)(ALuint);
-typedef void (AL_APIENTRY *LPALEFFECTI)(ALuint, ALenum, ALint);
-typedef void (AL_APIENTRY *LPALEFFECTIV)(ALuint, ALenum, const ALint*);
-typedef void (AL_APIENTRY *LPALEFFECTF)(ALuint, ALenum, ALfloat);
-typedef void (AL_APIENTRY *LPALEFFECTFV)(ALuint, ALenum, const ALfloat*);
-typedef void (AL_APIENTRY *LPALGETEFFECTI)(ALuint, ALenum, ALint*);
-typedef void (AL_APIENTRY *LPALGETEFFECTIV)(ALuint, ALenum, ALint*);
-typedef void (AL_APIENTRY *LPALGETEFFECTF)(ALuint, ALenum, ALfloat*);
-typedef void (AL_APIENTRY *LPALGETEFFECTFV)(ALuint, ALenum, ALfloat*);
-
-/* Filter object function types. */
-typedef void (AL_APIENTRY *LPALGENFILTERS)(ALsizei, ALuint*);
-typedef void (AL_APIENTRY *LPALDELETEFILTERS)(ALsizei, const ALuint*);
-typedef ALboolean (AL_APIENTRY *LPALISFILTER)(ALuint);
-typedef void (AL_APIENTRY *LPALFILTERI)(ALuint, ALenum, ALint);
-typedef void (AL_APIENTRY *LPALFILTERIV)(ALuint, ALenum, const ALint*);
-typedef void (AL_APIENTRY *LPALFILTERF)(ALuint, ALenum, ALfloat);
-typedef void (AL_APIENTRY *LPALFILTERFV)(ALuint, ALenum, const ALfloat*);
-typedef void (AL_APIENTRY *LPALGETFILTERI)(ALuint, ALenum, ALint*);
-typedef void (AL_APIENTRY *LPALGETFILTERIV)(ALuint, ALenum, ALint*);
-typedef void (AL_APIENTRY *LPALGETFILTERF)(ALuint, ALenum, ALfloat*);
-typedef void (AL_APIENTRY *LPALGETFILTERFV)(ALuint, ALenum, ALfloat*);
-
-/* Auxiliary Effect Slot object function types. */
-typedef void (AL_APIENTRY *LPALGENAUXILIARYEFFECTSLOTS)(ALsizei, ALuint*);
-typedef void (AL_APIENTRY *LPALDELETEAUXILIARYEFFECTSLOTS)(ALsizei, const ALuint*);
-typedef ALboolean (AL_APIENTRY *LPALISAUXILIARYEFFECTSLOT)(ALuint);
-typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTI)(ALuint, ALenum, ALint);
-typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTIV)(ALuint, ALenum, const ALint*);
-typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTF)(ALuint, ALenum, ALfloat);
-typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTFV)(ALuint, ALenum, const ALfloat*);
-typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTI)(ALuint, ALenum, ALint*);
-typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTIV)(ALuint, ALenum, ALint*);
-typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTF)(ALuint, ALenum, ALfloat*);
-typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTFV)(ALuint, ALenum, ALfloat*);
-
-#ifdef AL_ALEXT_PROTOTYPES
-AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects);
-AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects);
-AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect);
-AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue);
-AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, const ALint *piValues);
-AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue);
-AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat *pflValues);
-AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue);
-AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues);
-AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue);
-AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
-
-AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters);
-AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters);
-AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter);
-AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue);
-AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *piValues);
-AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue);
-AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *pflValues);
-AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue);
-AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues);
-AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue);
-AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
-
-AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots);
-AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *effectslots);
-AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot);
-AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue);
-AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, const ALint *piValues);
-AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue);
-AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, const ALfloat *pflValues);
-AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue);
-AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues);
-AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue);
-AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues);
-#endif
-
-/* Filter ranges and defaults. */
-
-/* Lowpass filter */
-#define AL_LOWPASS_MIN_GAIN (0.0f)
-#define AL_LOWPASS_MAX_GAIN (1.0f)
-#define AL_LOWPASS_DEFAULT_GAIN (1.0f)
-
-#define AL_LOWPASS_MIN_GAINHF (0.0f)
-#define AL_LOWPASS_MAX_GAINHF (1.0f)
-#define AL_LOWPASS_DEFAULT_GAINHF (1.0f)
-
-/* Highpass filter */
-#define AL_HIGHPASS_MIN_GAIN (0.0f)
-#define AL_HIGHPASS_MAX_GAIN (1.0f)
-#define AL_HIGHPASS_DEFAULT_GAIN (1.0f)
-
-#define AL_HIGHPASS_MIN_GAINLF (0.0f)
-#define AL_HIGHPASS_MAX_GAINLF (1.0f)
-#define AL_HIGHPASS_DEFAULT_GAINLF (1.0f)
-
-/* Bandpass filter */
-#define AL_BANDPASS_MIN_GAIN (0.0f)
-#define AL_BANDPASS_MAX_GAIN (1.0f)
-#define AL_BANDPASS_DEFAULT_GAIN (1.0f)
-
-#define AL_BANDPASS_MIN_GAINHF (0.0f)
-#define AL_BANDPASS_MAX_GAINHF (1.0f)
-#define AL_BANDPASS_DEFAULT_GAINHF (1.0f)
-
-#define AL_BANDPASS_MIN_GAINLF (0.0f)
-#define AL_BANDPASS_MAX_GAINLF (1.0f)
-#define AL_BANDPASS_DEFAULT_GAINLF (1.0f)
-
-
-/* Effect parameter ranges and defaults. */
-
-/* Standard reverb effect */
-#define AL_REVERB_MIN_DENSITY (0.0f)
-#define AL_REVERB_MAX_DENSITY (1.0f)
-#define AL_REVERB_DEFAULT_DENSITY (1.0f)
-
-#define AL_REVERB_MIN_DIFFUSION (0.0f)
-#define AL_REVERB_MAX_DIFFUSION (1.0f)
-#define AL_REVERB_DEFAULT_DIFFUSION (1.0f)
-
-#define AL_REVERB_MIN_GAIN (0.0f)
-#define AL_REVERB_MAX_GAIN (1.0f)
-#define AL_REVERB_DEFAULT_GAIN (0.32f)
-
-#define AL_REVERB_MIN_GAINHF (0.0f)
-#define AL_REVERB_MAX_GAINHF (1.0f)
-#define AL_REVERB_DEFAULT_GAINHF (0.89f)
-
-#define AL_REVERB_MIN_DECAY_TIME (0.1f)
-#define AL_REVERB_MAX_DECAY_TIME (20.0f)
-#define AL_REVERB_DEFAULT_DECAY_TIME (1.49f)
-
-#define AL_REVERB_MIN_DECAY_HFRATIO (0.1f)
-#define AL_REVERB_MAX_DECAY_HFRATIO (2.0f)
-#define AL_REVERB_DEFAULT_DECAY_HFRATIO (0.83f)
-
-#define AL_REVERB_MIN_REFLECTIONS_GAIN (0.0f)
-#define AL_REVERB_MAX_REFLECTIONS_GAIN (3.16f)
-#define AL_REVERB_DEFAULT_REFLECTIONS_GAIN (0.05f)
-
-#define AL_REVERB_MIN_REFLECTIONS_DELAY (0.0f)
-#define AL_REVERB_MAX_REFLECTIONS_DELAY (0.3f)
-#define AL_REVERB_DEFAULT_REFLECTIONS_DELAY (0.007f)
-
-#define AL_REVERB_MIN_LATE_REVERB_GAIN (0.0f)
-#define AL_REVERB_MAX_LATE_REVERB_GAIN (10.0f)
-#define AL_REVERB_DEFAULT_LATE_REVERB_GAIN (1.26f)
-
-#define AL_REVERB_MIN_LATE_REVERB_DELAY (0.0f)
-#define AL_REVERB_MAX_LATE_REVERB_DELAY (0.1f)
-#define AL_REVERB_DEFAULT_LATE_REVERB_DELAY (0.011f)
-
-#define AL_REVERB_MIN_AIR_ABSORPTION_GAINHF (0.892f)
-#define AL_REVERB_MAX_AIR_ABSORPTION_GAINHF (1.0f)
-#define AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF (0.994f)
-
-#define AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR (0.0f)
-#define AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR (10.0f)
-#define AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
-
-#define AL_REVERB_MIN_DECAY_HFLIMIT AL_FALSE
-#define AL_REVERB_MAX_DECAY_HFLIMIT AL_TRUE
-#define AL_REVERB_DEFAULT_DECAY_HFLIMIT AL_TRUE
-
-/* EAX reverb effect */
-#define AL_EAXREVERB_MIN_DENSITY (0.0f)
-#define AL_EAXREVERB_MAX_DENSITY (1.0f)
-#define AL_EAXREVERB_DEFAULT_DENSITY (1.0f)
-
-#define AL_EAXREVERB_MIN_DIFFUSION (0.0f)
-#define AL_EAXREVERB_MAX_DIFFUSION (1.0f)
-#define AL_EAXREVERB_DEFAULT_DIFFUSION (1.0f)
-
-#define AL_EAXREVERB_MIN_GAIN (0.0f)
-#define AL_EAXREVERB_MAX_GAIN (1.0f)
-#define AL_EAXREVERB_DEFAULT_GAIN (0.32f)
-
-#define AL_EAXREVERB_MIN_GAINHF (0.0f)
-#define AL_EAXREVERB_MAX_GAINHF (1.0f)
-#define AL_EAXREVERB_DEFAULT_GAINHF (0.89f)
-
-#define AL_EAXREVERB_MIN_GAINLF (0.0f)
-#define AL_EAXREVERB_MAX_GAINLF (1.0f)
-#define AL_EAXREVERB_DEFAULT_GAINLF (1.0f)
-
-#define AL_EAXREVERB_MIN_DECAY_TIME (0.1f)
-#define AL_EAXREVERB_MAX_DECAY_TIME (20.0f)
-#define AL_EAXREVERB_DEFAULT_DECAY_TIME (1.49f)
-
-#define AL_EAXREVERB_MIN_DECAY_HFRATIO (0.1f)
-#define AL_EAXREVERB_MAX_DECAY_HFRATIO (2.0f)
-#define AL_EAXREVERB_DEFAULT_DECAY_HFRATIO (0.83f)
-
-#define AL_EAXREVERB_MIN_DECAY_LFRATIO (0.1f)
-#define AL_EAXREVERB_MAX_DECAY_LFRATIO (2.0f)
-#define AL_EAXREVERB_DEFAULT_DECAY_LFRATIO (1.0f)
-
-#define AL_EAXREVERB_MIN_REFLECTIONS_GAIN (0.0f)
-#define AL_EAXREVERB_MAX_REFLECTIONS_GAIN (3.16f)
-#define AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN (0.05f)
-
-#define AL_EAXREVERB_MIN_REFLECTIONS_DELAY (0.0f)
-#define AL_EAXREVERB_MAX_REFLECTIONS_DELAY (0.3f)
-#define AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY (0.007f)
-
-#define AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ (0.0f)
-
-#define AL_EAXREVERB_MIN_LATE_REVERB_GAIN (0.0f)
-#define AL_EAXREVERB_MAX_LATE_REVERB_GAIN (10.0f)
-#define AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN (1.26f)
-
-#define AL_EAXREVERB_MIN_LATE_REVERB_DELAY (0.0f)
-#define AL_EAXREVERB_MAX_LATE_REVERB_DELAY (0.1f)
-#define AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY (0.011f)
-
-#define AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ (0.0f)
-
-#define AL_EAXREVERB_MIN_ECHO_TIME (0.075f)
-#define AL_EAXREVERB_MAX_ECHO_TIME (0.25f)
-#define AL_EAXREVERB_DEFAULT_ECHO_TIME (0.25f)
-
-#define AL_EAXREVERB_MIN_ECHO_DEPTH (0.0f)
-#define AL_EAXREVERB_MAX_ECHO_DEPTH (1.0f)
-#define AL_EAXREVERB_DEFAULT_ECHO_DEPTH (0.0f)
-
-#define AL_EAXREVERB_MIN_MODULATION_TIME (0.04f)
-#define AL_EAXREVERB_MAX_MODULATION_TIME (4.0f)
-#define AL_EAXREVERB_DEFAULT_MODULATION_TIME (0.25f)
-
-#define AL_EAXREVERB_MIN_MODULATION_DEPTH (0.0f)
-#define AL_EAXREVERB_MAX_MODULATION_DEPTH (1.0f)
-#define AL_EAXREVERB_DEFAULT_MODULATION_DEPTH (0.0f)
-
-#define AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF (0.892f)
-#define AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF (1.0f)
-#define AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF (0.994f)
-
-#define AL_EAXREVERB_MIN_HFREFERENCE (1000.0f)
-#define AL_EAXREVERB_MAX_HFREFERENCE (20000.0f)
-#define AL_EAXREVERB_DEFAULT_HFREFERENCE (5000.0f)
-
-#define AL_EAXREVERB_MIN_LFREFERENCE (20.0f)
-#define AL_EAXREVERB_MAX_LFREFERENCE (1000.0f)
-#define AL_EAXREVERB_DEFAULT_LFREFERENCE (250.0f)
-
-#define AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR (0.0f)
-#define AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR (10.0f)
-#define AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
-
-#define AL_EAXREVERB_MIN_DECAY_HFLIMIT AL_FALSE
-#define AL_EAXREVERB_MAX_DECAY_HFLIMIT AL_TRUE
-#define AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT AL_TRUE
-
-/* Chorus effect */
-#define AL_CHORUS_WAVEFORM_SINUSOID (0)
-#define AL_CHORUS_WAVEFORM_TRIANGLE (1)
-
-#define AL_CHORUS_MIN_WAVEFORM (0)
-#define AL_CHORUS_MAX_WAVEFORM (1)
-#define AL_CHORUS_DEFAULT_WAVEFORM (1)
-
-#define AL_CHORUS_MIN_PHASE (-180)
-#define AL_CHORUS_MAX_PHASE (180)
-#define AL_CHORUS_DEFAULT_PHASE (90)
-
-#define AL_CHORUS_MIN_RATE (0.0f)
-#define AL_CHORUS_MAX_RATE (10.0f)
-#define AL_CHORUS_DEFAULT_RATE (1.1f)
-
-#define AL_CHORUS_MIN_DEPTH (0.0f)
-#define AL_CHORUS_MAX_DEPTH (1.0f)
-#define AL_CHORUS_DEFAULT_DEPTH (0.1f)
-
-#define AL_CHORUS_MIN_FEEDBACK (-1.0f)
-#define AL_CHORUS_MAX_FEEDBACK (1.0f)
-#define AL_CHORUS_DEFAULT_FEEDBACK (0.25f)
-
-#define AL_CHORUS_MIN_DELAY (0.0f)
-#define AL_CHORUS_MAX_DELAY (0.016f)
-#define AL_CHORUS_DEFAULT_DELAY (0.016f)
-
-/* Distortion effect */
-#define AL_DISTORTION_MIN_EDGE (0.0f)
-#define AL_DISTORTION_MAX_EDGE (1.0f)
-#define AL_DISTORTION_DEFAULT_EDGE (0.2f)
-
-#define AL_DISTORTION_MIN_GAIN (0.01f)
-#define AL_DISTORTION_MAX_GAIN (1.0f)
-#define AL_DISTORTION_DEFAULT_GAIN (0.05f)
-
-#define AL_DISTORTION_MIN_LOWPASS_CUTOFF (80.0f)
-#define AL_DISTORTION_MAX_LOWPASS_CUTOFF (24000.0f)
-#define AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF (8000.0f)
-
-#define AL_DISTORTION_MIN_EQCENTER (80.0f)
-#define AL_DISTORTION_MAX_EQCENTER (24000.0f)
-#define AL_DISTORTION_DEFAULT_EQCENTER (3600.0f)
-
-#define AL_DISTORTION_MIN_EQBANDWIDTH (80.0f)
-#define AL_DISTORTION_MAX_EQBANDWIDTH (24000.0f)
-#define AL_DISTORTION_DEFAULT_EQBANDWIDTH (3600.0f)
-
-/* Echo effect */
-#define AL_ECHO_MIN_DELAY (0.0f)
-#define AL_ECHO_MAX_DELAY (0.207f)
-#define AL_ECHO_DEFAULT_DELAY (0.1f)
-
-#define AL_ECHO_MIN_LRDELAY (0.0f)
-#define AL_ECHO_MAX_LRDELAY (0.404f)
-#define AL_ECHO_DEFAULT_LRDELAY (0.1f)
-
-#define AL_ECHO_MIN_DAMPING (0.0f)
-#define AL_ECHO_MAX_DAMPING (0.99f)
-#define AL_ECHO_DEFAULT_DAMPING (0.5f)
-
-#define AL_ECHO_MIN_FEEDBACK (0.0f)
-#define AL_ECHO_MAX_FEEDBACK (1.0f)
-#define AL_ECHO_DEFAULT_FEEDBACK (0.5f)
-
-#define AL_ECHO_MIN_SPREAD (-1.0f)
-#define AL_ECHO_MAX_SPREAD (1.0f)
-#define AL_ECHO_DEFAULT_SPREAD (-1.0f)
-
-/* Flanger effect */
-#define AL_FLANGER_WAVEFORM_SINUSOID (0)
-#define AL_FLANGER_WAVEFORM_TRIANGLE (1)
-
-#define AL_FLANGER_MIN_WAVEFORM (0)
-#define AL_FLANGER_MAX_WAVEFORM (1)
-#define AL_FLANGER_DEFAULT_WAVEFORM (1)
-
-#define AL_FLANGER_MIN_PHASE (-180)
-#define AL_FLANGER_MAX_PHASE (180)
-#define AL_FLANGER_DEFAULT_PHASE (0)
-
-#define AL_FLANGER_MIN_RATE (0.0f)
-#define AL_FLANGER_MAX_RATE (10.0f)
-#define AL_FLANGER_DEFAULT_RATE (0.27f)
-
-#define AL_FLANGER_MIN_DEPTH (0.0f)
-#define AL_FLANGER_MAX_DEPTH (1.0f)
-#define AL_FLANGER_DEFAULT_DEPTH (1.0f)
-
-#define AL_FLANGER_MIN_FEEDBACK (-1.0f)
-#define AL_FLANGER_MAX_FEEDBACK (1.0f)
-#define AL_FLANGER_DEFAULT_FEEDBACK (-0.5f)
-
-#define AL_FLANGER_MIN_DELAY (0.0f)
-#define AL_FLANGER_MAX_DELAY (0.004f)
-#define AL_FLANGER_DEFAULT_DELAY (0.002f)
-
-/* Frequency shifter effect */
-#define AL_FREQUENCY_SHIFTER_MIN_FREQUENCY (0.0f)
-#define AL_FREQUENCY_SHIFTER_MAX_FREQUENCY (24000.0f)
-#define AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY (0.0f)
-
-#define AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION (0)
-#define AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION (2)
-#define AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION (0)
-
-#define AL_FREQUENCY_SHIFTER_DIRECTION_DOWN (0)
-#define AL_FREQUENCY_SHIFTER_DIRECTION_UP (1)
-#define AL_FREQUENCY_SHIFTER_DIRECTION_OFF (2)
-
-#define AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION (0)
-#define AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION (2)
-#define AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION (0)
-
-/* Vocal morpher effect */
-#define AL_VOCAL_MORPHER_MIN_PHONEMEA (0)
-#define AL_VOCAL_MORPHER_MAX_PHONEMEA (29)
-#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA (0)
-
-#define AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING (-24)
-#define AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING (24)
-#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING (0)
-
-#define AL_VOCAL_MORPHER_MIN_PHONEMEB (0)
-#define AL_VOCAL_MORPHER_MAX_PHONEMEB (29)
-#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB (10)
-
-#define AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING (-24)
-#define AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING (24)
-#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING (0)
-
-#define AL_VOCAL_MORPHER_PHONEME_A (0)
-#define AL_VOCAL_MORPHER_PHONEME_E (1)
-#define AL_VOCAL_MORPHER_PHONEME_I (2)
-#define AL_VOCAL_MORPHER_PHONEME_O (3)
-#define AL_VOCAL_MORPHER_PHONEME_U (4)
-#define AL_VOCAL_MORPHER_PHONEME_AA (5)
-#define AL_VOCAL_MORPHER_PHONEME_AE (6)
-#define AL_VOCAL_MORPHER_PHONEME_AH (7)
-#define AL_VOCAL_MORPHER_PHONEME_AO (8)
-#define AL_VOCAL_MORPHER_PHONEME_EH (9)
-#define AL_VOCAL_MORPHER_PHONEME_ER (10)
-#define AL_VOCAL_MORPHER_PHONEME_IH (11)
-#define AL_VOCAL_MORPHER_PHONEME_IY (12)
-#define AL_VOCAL_MORPHER_PHONEME_UH (13)
-#define AL_VOCAL_MORPHER_PHONEME_UW (14)
-#define AL_VOCAL_MORPHER_PHONEME_B (15)
-#define AL_VOCAL_MORPHER_PHONEME_D (16)
-#define AL_VOCAL_MORPHER_PHONEME_F (17)
-#define AL_VOCAL_MORPHER_PHONEME_G (18)
-#define AL_VOCAL_MORPHER_PHONEME_J (19)
-#define AL_VOCAL_MORPHER_PHONEME_K (20)
-#define AL_VOCAL_MORPHER_PHONEME_L (21)
-#define AL_VOCAL_MORPHER_PHONEME_M (22)
-#define AL_VOCAL_MORPHER_PHONEME_N (23)
-#define AL_VOCAL_MORPHER_PHONEME_P (24)
-#define AL_VOCAL_MORPHER_PHONEME_R (25)
-#define AL_VOCAL_MORPHER_PHONEME_S (26)
-#define AL_VOCAL_MORPHER_PHONEME_T (27)
-#define AL_VOCAL_MORPHER_PHONEME_V (28)
-#define AL_VOCAL_MORPHER_PHONEME_Z (29)
-
-#define AL_VOCAL_MORPHER_WAVEFORM_SINUSOID (0)
-#define AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE (1)
-#define AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH (2)
-
-#define AL_VOCAL_MORPHER_MIN_WAVEFORM (0)
-#define AL_VOCAL_MORPHER_MAX_WAVEFORM (2)
-#define AL_VOCAL_MORPHER_DEFAULT_WAVEFORM (0)
-
-#define AL_VOCAL_MORPHER_MIN_RATE (0.0f)
-#define AL_VOCAL_MORPHER_MAX_RATE (10.0f)
-#define AL_VOCAL_MORPHER_DEFAULT_RATE (1.41f)
-
-/* Pitch shifter effect */
-#define AL_PITCH_SHIFTER_MIN_COARSE_TUNE (-12)
-#define AL_PITCH_SHIFTER_MAX_COARSE_TUNE (12)
-#define AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE (12)
-
-#define AL_PITCH_SHIFTER_MIN_FINE_TUNE (-50)
-#define AL_PITCH_SHIFTER_MAX_FINE_TUNE (50)
-#define AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE (0)
-
-/* Ring modulator effect */
-#define AL_RING_MODULATOR_MIN_FREQUENCY (0.0f)
-#define AL_RING_MODULATOR_MAX_FREQUENCY (8000.0f)
-#define AL_RING_MODULATOR_DEFAULT_FREQUENCY (440.0f)
-
-#define AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF (0.0f)
-#define AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF (24000.0f)
-#define AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF (800.0f)
-
-#define AL_RING_MODULATOR_SINUSOID (0)
-#define AL_RING_MODULATOR_SAWTOOTH (1)
-#define AL_RING_MODULATOR_SQUARE (2)
-
-#define AL_RING_MODULATOR_MIN_WAVEFORM (0)
-#define AL_RING_MODULATOR_MAX_WAVEFORM (2)
-#define AL_RING_MODULATOR_DEFAULT_WAVEFORM (0)
-
-/* Autowah effect */
-#define AL_AUTOWAH_MIN_ATTACK_TIME (0.0001f)
-#define AL_AUTOWAH_MAX_ATTACK_TIME (1.0f)
-#define AL_AUTOWAH_DEFAULT_ATTACK_TIME (0.06f)
-
-#define AL_AUTOWAH_MIN_RELEASE_TIME (0.0001f)
-#define AL_AUTOWAH_MAX_RELEASE_TIME (1.0f)
-#define AL_AUTOWAH_DEFAULT_RELEASE_TIME (0.06f)
-
-#define AL_AUTOWAH_MIN_RESONANCE (2.0f)
-#define AL_AUTOWAH_MAX_RESONANCE (1000.0f)
-#define AL_AUTOWAH_DEFAULT_RESONANCE (1000.0f)
-
-#define AL_AUTOWAH_MIN_PEAK_GAIN (0.00003f)
-#define AL_AUTOWAH_MAX_PEAK_GAIN (31621.0f)
-#define AL_AUTOWAH_DEFAULT_PEAK_GAIN (11.22f)
-
-/* Compressor effect */
-#define AL_COMPRESSOR_MIN_ONOFF (0)
-#define AL_COMPRESSOR_MAX_ONOFF (1)
-#define AL_COMPRESSOR_DEFAULT_ONOFF (1)
-
-/* Equalizer effect */
-#define AL_EQUALIZER_MIN_LOW_GAIN (0.126f)
-#define AL_EQUALIZER_MAX_LOW_GAIN (7.943f)
-#define AL_EQUALIZER_DEFAULT_LOW_GAIN (1.0f)
-
-#define AL_EQUALIZER_MIN_LOW_CUTOFF (50.0f)
-#define AL_EQUALIZER_MAX_LOW_CUTOFF (800.0f)
-#define AL_EQUALIZER_DEFAULT_LOW_CUTOFF (200.0f)
-
-#define AL_EQUALIZER_MIN_MID1_GAIN (0.126f)
-#define AL_EQUALIZER_MAX_MID1_GAIN (7.943f)
-#define AL_EQUALIZER_DEFAULT_MID1_GAIN (1.0f)
-
-#define AL_EQUALIZER_MIN_MID1_CENTER (200.0f)
-#define AL_EQUALIZER_MAX_MID1_CENTER (3000.0f)
-#define AL_EQUALIZER_DEFAULT_MID1_CENTER (500.0f)
-
-#define AL_EQUALIZER_MIN_MID1_WIDTH (0.01f)
-#define AL_EQUALIZER_MAX_MID1_WIDTH (1.0f)
-#define AL_EQUALIZER_DEFAULT_MID1_WIDTH (1.0f)
-
-#define AL_EQUALIZER_MIN_MID2_GAIN (0.126f)
-#define AL_EQUALIZER_MAX_MID2_GAIN (7.943f)
-#define AL_EQUALIZER_DEFAULT_MID2_GAIN (1.0f)
-
-#define AL_EQUALIZER_MIN_MID2_CENTER (1000.0f)
-#define AL_EQUALIZER_MAX_MID2_CENTER (8000.0f)
-#define AL_EQUALIZER_DEFAULT_MID2_CENTER (3000.0f)
-
-#define AL_EQUALIZER_MIN_MID2_WIDTH (0.01f)
-#define AL_EQUALIZER_MAX_MID2_WIDTH (1.0f)
-#define AL_EQUALIZER_DEFAULT_MID2_WIDTH (1.0f)
-
-#define AL_EQUALIZER_MIN_HIGH_GAIN (0.126f)
-#define AL_EQUALIZER_MAX_HIGH_GAIN (7.943f)
-#define AL_EQUALIZER_DEFAULT_HIGH_GAIN (1.0f)
-
-#define AL_EQUALIZER_MIN_HIGH_CUTOFF (4000.0f)
-#define AL_EQUALIZER_MAX_HIGH_CUTOFF (16000.0f)
-#define AL_EQUALIZER_DEFAULT_HIGH_CUTOFF (6000.0f)
-
-
-/* Source parameter value ranges and defaults. */
-#define AL_MIN_AIR_ABSORPTION_FACTOR (0.0f)
-#define AL_MAX_AIR_ABSORPTION_FACTOR (10.0f)
-#define AL_DEFAULT_AIR_ABSORPTION_FACTOR (0.0f)
-
-#define AL_MIN_ROOM_ROLLOFF_FACTOR (0.0f)
-#define AL_MAX_ROOM_ROLLOFF_FACTOR (10.0f)
-#define AL_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
-
-#define AL_MIN_CONE_OUTER_GAINHF (0.0f)
-#define AL_MAX_CONE_OUTER_GAINHF (1.0f)
-#define AL_DEFAULT_CONE_OUTER_GAINHF (1.0f)
-
-#define AL_MIN_DIRECT_FILTER_GAINHF_AUTO AL_FALSE
-#define AL_MAX_DIRECT_FILTER_GAINHF_AUTO AL_TRUE
-#define AL_DEFAULT_DIRECT_FILTER_GAINHF_AUTO AL_TRUE
-
-#define AL_MIN_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_FALSE
-#define AL_MAX_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
-#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
-
-#define AL_MIN_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_FALSE
-#define AL_MAX_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
-#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
-
-
-/* Listener parameter value ranges and defaults. */
-#define AL_MIN_METERS_PER_UNIT FLT_MIN
-#define AL_MAX_METERS_PER_UNIT FLT_MAX
-#define AL_DEFAULT_METERS_PER_UNIT (1.0f)
-
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* AL_EFX_H */
diff --git a/templates/android_project/jni/libs/libraylib.a b/templates/android_project/jni/libs/libraylib.a
deleted file mode 100644
index 3d25003b..00000000
--- a/templates/android_project/jni/libs/libraylib.a
+++ /dev/null
Binary files differ
diff --git a/templates/android_project/src/core.c b/templates/android_project/src/core.c
new file mode 100644
index 00000000..4190fb98
--- /dev/null
+++ b/templates/android_project/src/core.c
@@ -0,0 +1,3476 @@
+/**********************************************************************************************
+*
+* raylib.core - Basic functions to manage windows, OpenGL context and input on multiple platforms
+*
+* PLATFORMS SUPPORTED:
+* - Windows (win32/Win64)
+* - Linux (tested on Ubuntu)
+* - OSX (Mac)
+* - Android (ARM or ARM64)
+* - Raspberry Pi (Raspbian)
+* - HTML5 (Chrome, Firefox)
+*
+* CONFIGURATION:
+*
+* #define PLATFORM_DESKTOP
+* Windowing and input system configured for desktop platforms: Windows, Linux, OSX (managed by GLFW3 library)
+* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for mirror rendering - View [rlgl] module to enable it
+*
+* #define PLATFORM_ANDROID
+* Windowing and input system configured for Android device, app activity managed internally in this module.
+* NOTE: OpenGL ES 2.0 is required and graphic device is managed by EGL
+*
+* #define PLATFORM_RPI
+* Windowing and input system configured for Raspberry Pi (tested on Raspbian), graphic device is managed by EGL
+* and inputs are processed is raw mode, reading from /dev/input/
+*
+* #define PLATFORM_WEB
+* Windowing and input system configured for HTML5 (run on browser), code converted from C to asm.js
+* using emscripten compiler. OpenGL ES 2.0 required for direct translation to WebGL equivalent code.
+*
+* #define SUPPORT_DEFAULT_FONT (default)
+* Default font is loaded on window initialization to be available for the user to render simple text.
+* NOTE: If enabled, uses external module functions to load default raylib font (module: text)
+*
+* #define SUPPORT_CAMERA_SYSTEM
+* Camera module is included (camera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
+*
+* #define SUPPORT_GESTURES_SYSTEM
+* Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag
+*
+* #define SUPPORT_MOUSE_GESTURES
+* Mouse gestures are directly mapped like touches and processed by gestures system.
+*
+* #define SUPPORT_BUSY_WAIT_LOOP
+* Use busy wait loop for timming sync, if not defined, a high-resolution timer is setup and used
+*
+* #define SUPPORT_GIF_RECORDING
+* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
+*
+* DEPENDENCIES:
+* 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)
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2014-2017 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+// Default configuration flags (supported features)
+//-------------------------------------------------
+//#define SUPPORT_DEFAULT_FONT
+//#define SUPPORT_MOUSE_GESTURES
+//#define SUPPORT_CAMERA_SYSTEM
+//#define SUPPORT_GESTURES_SYSTEM
+#define SUPPORT_BUSY_WAIT_LOOP
+//#define SUPPORT_GIF_RECORDING
+//-------------------------------------------------
+
+#include "raylib.h"
+
+#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
+#include "utils.h" // Required for: fopen() Android mapping
+
+#define RAYMATH_IMPLEMENTATION // Use raymath as a header-only library (includes implementation)
+#define RAYMATH_EXTERN_INLINE // Compile raymath functions as static inline (remember, it's a compiler hint)
+#include "raymath.h" // Required for: Vector3 and Matrix functions
+
+#if defined(SUPPORT_GESTURES_SYSTEM)
+ #define GESTURES_IMPLEMENTATION
+ #include "gestures.h" // Gestures detection functionality
+#endif
+
+#if defined(SUPPORT_CAMERA_SYSTEM) && !defined(PLATFORM_ANDROID)
+ #define CAMERA_IMPLEMENTATION
+ #include "camera.h" // Camera system functionality
+#endif
+
+#if defined(SUPPORT_GIF_RECORDING)
+ #define GIF_IMPLEMENTATION
+ #include "external/gif.h" // Support GIF recording
+#endif
+
+#if defined(__linux__) || defined(PLATFORM_WEB)
+ #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext.
+#endif
+
+#include <stdio.h> // Standard input / output lib
+#include <stdlib.h> // Required for: malloc(), free(), rand(), atexit()
+#include <stdint.h> // Required for: typedef unsigned long long int uint64_t, used by hi-res timer
+#include <time.h> // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!)
+#include <math.h> // Required for: tan() [Used in Begin3dMode() to set perspective]
+#include <string.h> // Required for: strrchr(), strcmp()
+//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
+
+#ifdef _WIN32
+ #include <direct.h> // Required for: _getch(), _chdir()
+ #define GETCWD _getcwd // NOTE: MSDN recommends not to use getcwd(), chdir()
+ #define CHDIR _chdir
+#else
+ #include "unistd.h" // Required for: getch(), chdir() (POSIX)
+ #define GETCWD getcwd
+ #define CHDIR chdir
+#endif
+
+#if defined(__linux__) || defined(PLATFORM_WEB)
+ #include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
+#elif defined(__APPLE__)
+ #include <unistd.h> // Required for: usleep()
+#endif
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
+ #include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
+
+ #if defined(__linux__)
+ #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
+ #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
+ #include <GLFW/glfw3native.h> // which are required for hiding mouse
+ #endif
+ //#include <GL/gl.h> // OpenGL functions (GLFW3 already includes gl.h)
+ //#define GLFW_DLL // Using GLFW DLL on Windows -> No, we use static version!
+
+ #if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
+ // NOTE: Those functions require linking with winmm library
+ __stdcall unsigned int timeBeginPeriod(unsigned int uPeriod);
+ __stdcall unsigned int timeEndPeriod(unsigned int uPeriod);
+ #endif
+#endif
+
+#if defined(PLATFORM_ANDROID)
+ //#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
+ #include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
+ #include <android_native_app_glue.h> // Defines basic app state struct and manages activity
+
+ #include <EGL/egl.h> // Khronos EGL library - Native platform display device control functions
+ #include <GLES2/gl2.h> // Khronos OpenGL ES 2.0 library
+#endif
+
+#if defined(PLATFORM_RPI)
+ #include <fcntl.h> // POSIX file control definitions - open(), creat(), fcntl()
+ #include <unistd.h> // POSIX standard function definitions - read(), close(), STDIN_FILENO
+ #include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
+ #include <pthread.h> // POSIX threads management (mouse input)
+
+ #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> // 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
+ #include "EGL/eglext.h" // Khronos EGL library - Extensions
+ #include "GLES2/gl2.h" // Khronos OpenGL ES 2.0 library
+#endif
+
+#if defined(PLATFORM_WEB)
+ #include <emscripten/emscripten.h>
+ #include <emscripten/html5.h>
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_RPI)
+ // Old device inputs system
+ #define DEFAULT_KEYBOARD_DEV STDIN_FILENO // Standard input
+ #define DEFAULT_MOUSE_DEV "/dev/input/mouse0" // Mouse input
+ #define DEFAULT_TOUCH_DEV "/dev/input/event4" // Touch input virtual device (created by ts_uinput)
+ #define DEFAULT_GAMEPAD_DEV "/dev/input/js" // Gamepad input (base dev for all gamepads: js0, js1, ...)
+
+ // New device input events (evdev) (must be detected)
+ //#define DEFAULT_KEYBOARD_DEV "/dev/input/eventN"
+ //#define DEFAULT_MOUSE_DEV "/dev/input/eventN"
+ //#define DEFAULT_GAMEPAD_DEV "/dev/input/eventN"
+
+ #define MOUSE_SENSITIVITY 0.8f
+#endif
+
+#define MAX_GAMEPADS 4 // Max number of gamepads supported
+#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
+#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
+
+#define STORAGE_FILENAME "storage.data"
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+// ...
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+static GLFWwindow *window; // Native window (graphic device)
+static bool windowMinimized = false;
+#endif
+
+#if defined(PLATFORM_ANDROID)
+static struct android_app *app; // Android activity
+static struct android_poll_source *source; // Android events polling source
+static int ident, events; // Android ALooper_pollAll() variables
+static const char *internalDataPath; // Android internal data path to write data (/data/data/<package>/files)
+
+static bool windowReady = false; // Used to detect display initialization
+static bool appEnabled = true; // Used to detec if app is active
+static bool contextRebindRequired = false; // Used to know context rebind required
+#endif
+
+#if defined(PLATFORM_RPI)
+static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device)
+
+// Keyboard input variables
+// NOTE: For keyboard we will use the standard input (but reconfigured...)
+static struct termios defaultKeyboardSettings; // Used to store default keyboard settings
+static int defaultKeyboardMode; // Used to store default keyboard mode
+
+// Mouse input variables
+static int mouseStream = -1; // Mouse device file descriptor
+static bool mouseReady = false; // Flag to know if mouse is ready
+static pthread_t mouseThreadId; // Mouse reading thread id
+
+// Touch input variables
+static int touchStream = -1; // Touch device file descriptor
+static bool touchReady = false; // Flag to know if touch interface is ready
+static pthread_t touchThreadId; // Touch 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)
+static EGLDisplay display; // Native display device (physical screen connection)
+static EGLSurface surface; // Surface to draw on, framebuffers (connected to context)
+static EGLContext context; // Graphic context, mode in which drawing can be done
+static EGLConfig config; // Graphic config
+static uint64_t baseTime; // Base time measure for hi-res timer
+static bool windowShouldClose = false; // Flag to set window for closing
+#endif
+
+// Display size-related data
+static unsigned int displayWidth, displayHeight; // Display width and height (monitor, device-screen, LCD, ...)
+static int screenWidth, screenHeight; // Screen width and height (used render area)
+static int renderWidth, renderHeight; // Framebuffer width and height (render area, including black bars if required)
+static int renderOffsetX = 0; // Offset X from render area (must be divided by 2)
+static int renderOffsetY = 0; // Offset Y from render area (must be divided by 2)
+static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP)
+static Matrix downscaleView; // Matrix to downscale view (in case screen size bigger than display size)
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
+static const char *windowTitle; // Window text title...
+static bool cursorOnScreen = false; // Tracks if cursor is inside client area
+static bool cursorHidden = false; // Track if cursor is hidden
+static int screenshotCounter = 0; // Screenshots counter
+
+// Register mouse states
+static char previousMouseState[3] = { 0 }; // Registers previous mouse button state
+static char currentMouseState[3] = { 0 }; // Registers current mouse button state
+static int previousMouseWheelY = 0; // Registers previous mouse wheel variation
+static int currentMouseWheelY = 0; // Registers current mouse wheel variation
+
+// Register gamepads states
+static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready
+static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
+static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
+static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
+
+// Keyboard configuration
+static int exitKey = KEY_ESCAPE; // Default exit key (ESC)
+#endif
+
+// Register keyboard states
+static char previousKeyState[512] = { 0 }; // Registers previous frame key state
+static char currentKeyState[512] = { 0 }; // Registers current frame key state
+
+static int lastKeyPressed = -1; // Register last key pressed
+static int lastGamepadButtonPressed = -1; // Register last gamepad button pressed
+static int gamepadAxisCount = 0; // Register number of available gamepad axis
+
+static Vector2 mousePosition; // Mouse position on screen
+
+#if defined(PLATFORM_WEB)
+static bool toggleCursorLock = false; // Ask for cursor pointer lock on next click
+#endif
+
+//#if defined(SUPPORT_GESTURES_SYSTEM)
+static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen
+//#endif
+
+#if defined(PLATFORM_DESKTOP)
+static char **dropFilesPath; // Store dropped files paths as strings
+static int dropFilesCount = 0; // Count stored strings
+#endif
+
+static double currentTime, previousTime; // Used to track timmings
+static double updateTime, drawTime; // Time measures for update and draw
+static double frameTime = 0.0; // Time measure for one frame
+static double targetTime = 0.0; // Desired time for one frame, if 0 not applied
+
+static char configFlags = 0; // Configuration flags (bit based)
+static bool showLogo = false; // Track if showing logo at init is enabled
+
+#if defined(SUPPORT_GIF_RECORDING)
+static int gifFramesCounter = 0;
+static bool gifRecording = false;
+#endif
+
+//----------------------------------------------------------------------------------
+// Other Modules Functions Declaration (required by core)
+//----------------------------------------------------------------------------------
+#if defined(SUPPORT_DEFAULT_FONT)
+extern void LoadDefaultFont(void); // [Module: text] Loads default font on InitWindow()
+extern void UnloadDefaultFont(void); // [Module: text] Unloads default font from GPU memory
+#endif
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Declaration
+//----------------------------------------------------------------------------------
+static void InitGraphicsDevice(int width, int height); // Initialize graphics device
+static void SetupFramebufferSize(int displayWidth, int displayHeight);
+static void InitTimer(void); // Initialize timer
+static double GetTime(void); // Returns time since InitTimer() was run
+static void Wait(float ms); // Wait for some milliseconds (stop program execution)
+static bool GetKeyStatus(int key); // Returns if a key has been pressed
+static bool GetMouseButtonStatus(int button); // Returns if a mouse button has been pressed
+static void PollInputEvents(void); // Register user events
+static void SwapBuffers(void); // Copy back buffer to front buffers
+static void LogoAnimation(void); // Plays raylib logo appearing animation
+static void SetupViewport(void); // Set viewport parameters
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
+static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
+static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
+static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
+static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
+static void ScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Srolling Callback, runs on mouse wheel
+static void CursorEnterCallback(GLFWwindow *window, int enter); // GLFW3 Cursor Enter Callback, cursor enters client area
+static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
+static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
+#endif
+
+#if defined(PLATFORM_DESKTOP)
+static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
+#endif
+
+#if defined(PLATFORM_ANDROID)
+static void AndroidCommandCallback(struct android_app *app, int32_t cmd); // Process Android activity lifecycle commands
+static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event); // Process Android inputs
+#endif
+
+#if defined(PLATFORM_WEB)
+static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData);
+static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData);
+static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
+static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData);
+static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData);
+#endif
+
+#if defined(PLATFORM_RPI)
+static void InitKeyboard(void); // Init raw keyboard system (standard input reading)
+static void ProcessKeyboard(void); // Process keyboard events
+static void RestoreKeyboard(void); // Restore keyboard system
+static void InitMouse(void); // Mouse initialization (including mouse thread)
+static void *MouseThread(void *arg); // Mouse reading thread
+static void InitTouch(void); // Touch device initialization (including touch thread)
+static void *TouchThread(void *arg); // Touch device reading thread
+static void InitGamepad(void); // Init raw gamepad input
+static void *GamepadThread(void *arg); // Mouse reading thread
+#endif
+
+#if defined(_WIN32)
+ // NOTE: We include Sleep() function signature here to avoid windows.h inclusion
+ void __stdcall Sleep(unsigned long msTimeout); // Required for Wait()
+#endif
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Window and OpenGL Context Functions
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
+// Initialize window and OpenGL context
+void InitWindow(int width, int height, const char *title)
+{
+ TraceLog(LOG_INFO, "Initializing raylib (v1.8.0)");
+
+ // Store window title (could be useful...)
+ windowTitle = title;
+
+ // Init graphics device (display device and OpenGL context)
+ InitGraphicsDevice(width, height);
+
+#if defined(SUPPORT_DEFAULT_FONT)
+ // Load default font
+ // NOTE: External function (defined in module: text)
+ LoadDefaultFont();
+#endif
+
+ // Init hi-res timer
+ InitTimer();
+
+#if defined(PLATFORM_RPI)
+ // Init raw input system
+ InitMouse(); // Mouse init
+ InitTouch(); // Touch init
+ InitKeyboard(); // Keyboard init
+ InitGamepad(); // Gamepad init
+#endif
+
+#if defined(PLATFORM_WEB)
+ emscripten_set_fullscreenchange_callback(0, 0, 1, EmscriptenFullscreenChangeCallback);
+
+ // Support keyboard events
+ emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback);
+
+ // Support mouse events
+ emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback);
+
+ // Support touch events
+ emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
+ emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
+ emscripten_set_touchmove_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
+ emscripten_set_touchcancel_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
+ //emscripten_set_touchstart_callback(0, NULL, 1, Emscripten_HandleTouch);
+ //emscripten_set_touchend_callback("#canvas", data, 0, Emscripten_HandleTouch);
+
+ // Support gamepad events (not provided by GLFW3 on emscripten)
+ emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
+ emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
+#endif
+
+ mousePosition.x = (float)screenWidth/2.0f;
+ mousePosition.y = (float)screenHeight/2.0f;
+
+ // raylib logo appearing animation (if enabled)
+ if (showLogo)
+ {
+ SetTargetFPS(60);
+ LogoAnimation();
+ }
+}
+#endif
+
+#if defined(PLATFORM_ANDROID)
+// Initialize Android activity
+void InitWindow(int width, int height, void *state)
+{
+ TraceLog(LOG_INFO, "Initializing raylib (v1.8.0)");
+
+ screenWidth = width;
+ screenHeight = height;
+
+ app = (struct android_app *)state;
+ internalDataPath = app->activity->internalDataPath;
+
+ // Set desired windows flags before initializing anything
+ ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
+ //ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FORCE_NOT_FULLSCREEN, AWINDOW_FLAG_FULLSCREEN);
+
+ int orientation = AConfiguration_getOrientation(app->config);
+
+ if (orientation == ACONFIGURATION_ORIENTATION_PORT) TraceLog(LOG_INFO, "PORTRAIT window orientation");
+ else if (orientation == ACONFIGURATION_ORIENTATION_LAND) TraceLog(LOG_INFO, "LANDSCAPE window orientation");
+
+ // TODO: Automatic orientation doesn't seem to work
+ if (width <= height)
+ {
+ AConfiguration_setOrientation(app->config, ACONFIGURATION_ORIENTATION_PORT);
+ TraceLog(LOG_WARNING, "Window set to portraid mode");
+ }
+ else
+ {
+ AConfiguration_setOrientation(app->config, ACONFIGURATION_ORIENTATION_LAND);
+ TraceLog(LOG_WARNING, "Window set to landscape mode");
+ }
+
+ //AConfiguration_getDensity(app->config);
+ //AConfiguration_getKeyboard(app->config);
+ //AConfiguration_getScreenSize(app->config);
+ //AConfiguration_getScreenLong(app->config);
+
+ //state->userData = &engine;
+ app->onAppCmd = AndroidCommandCallback;
+ app->onInputEvent = AndroidInputCallback;
+
+ InitAssetManager(app->activity->assetManager);
+
+ TraceLog(LOG_INFO, "Android app initialized successfully");
+
+ // Wait for window to be initialized (display and context)
+ while (!windowReady)
+ {
+ // Process events loop
+ while ((ident = ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0)
+ {
+ // Process this event
+ if (source != NULL) source->process(app, source);
+
+ // NOTE: Never close window, native activity is controlled by the system!
+ //if (app->destroyRequested != 0) windowShouldClose = true;
+ }
+ }
+}
+#endif
+
+// Close window and unload OpenGL context
+void CloseWindow(void)
+{
+#if defined(SUPPORT_GIF_RECORDING)
+ if (gifRecording)
+ {
+ GifEnd();
+ gifRecording = false;
+ }
+#endif
+
+#if defined(SUPPORT_DEFAULT_FONT)
+ UnloadDefaultFont();
+#endif
+
+ rlglClose(); // De-init rlgl
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ glfwDestroyWindow(window);
+ glfwTerminate();
+#endif
+
+#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
+ timeEndPeriod(1); // Restore time period
+#endif
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ // Close surface, context and display
+ if (display != EGL_NO_DISPLAY)
+ {
+ eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+
+ if (surface != EGL_NO_SURFACE)
+ {
+ eglDestroySurface(display, surface);
+ surface = EGL_NO_SURFACE;
+ }
+
+ if (context != EGL_NO_CONTEXT)
+ {
+ eglDestroyContext(display, context);
+ context = EGL_NO_CONTEXT;
+ }
+
+ eglTerminate(display);
+ display = EGL_NO_DISPLAY;
+ }
+#endif
+
+#if defined(PLATFORM_RPI)
+ // Wait for mouse and gamepad threads to finish before closing
+ // NOTE: Those threads should already have finished at this point
+ // because they are controlled by windowShouldClose variable
+
+ windowShouldClose = true; // Added to force threads to exit when the close window is called
+
+ pthread_join(mouseThreadId, NULL);
+ pthread_join(touchThreadId, NULL);
+ pthread_join(gamepadThreadId, NULL);
+#endif
+
+ TraceLog(LOG_INFO, "Window closed successfully");
+}
+
+// Check if KEY_ESCAPE pressed or Close icon pressed
+bool WindowShouldClose(void)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ // While window minimized, stop loop execution
+ while (windowMinimized) glfwWaitEvents();
+
+ return (glfwWindowShouldClose(window));
+#endif
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ return windowShouldClose;
+#endif
+}
+
+// Check if window has been minimized (or lost focus)
+bool IsWindowMinimized(void)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ return windowMinimized;
+#else
+ return false;
+#endif
+}
+
+// Toggle fullscreen mode (only PLATFORM_DESKTOP)
+void ToggleFullscreen(void)
+{
+#if defined(PLATFORM_DESKTOP)
+ fullscreen = !fullscreen; // Toggle fullscreen flag
+
+ // NOTE: glfwSetWindowMonitor() doesn't work properly (bugs)
+ if (fullscreen) glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
+ else glfwSetWindowMonitor(window, NULL, 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
+#endif
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ TraceLog(LOG_WARNING, "Could not toggle to windowed mode");
+#endif
+}
+
+// Set icon for window (only PLATFORM_DESKTOP)
+void SetWindowIcon(Image image)
+{
+#if defined(PLATFORM_DESKTOP)
+ ImageFormat(&image, UNCOMPRESSED_R8G8B8A8);
+
+ GLFWimage icon[1];
+
+ icon[0].width = image.width;
+ icon[0].height = image.height;
+ icon[0].pixels = (unsigned char *)image.data;
+
+ // NOTE: We only support one image icon
+ glfwSetWindowIcon(window, 1, icon);
+
+ // TODO: Support multi-image icons --> image.mipmaps
+#endif
+}
+
+// Set title for window (only PLATFORM_DESKTOP)
+void SetWindowTitle(const char *title)
+{
+#if defined(PLATFORM_DESKTOP)
+ glfwSetWindowTitle(window, title);
+#endif
+}
+
+// Set window position on screen (windowed mode)
+void SetWindowPosition(int x, int y)
+{
+#if defined(PLATFORM_DESKTOP)
+ glfwSetWindowPos(window, x, y);
+#endif
+}
+
+// Set monitor for the current window (fullscreen mode)
+void SetWindowMonitor(int monitor)
+{
+#if defined(PLATFORM_DESKTOP)
+ int monitorCount;
+ GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
+
+ if ((monitor >= 0) && (monitor < monitorCount))
+ {
+ glfwSetWindowMonitor(window, monitors[monitor], 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
+ TraceLog(LOG_INFO, "Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));
+ }
+ else TraceLog(LOG_WARNING, "Selected monitor not found");
+#endif
+}
+
+// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
+void SetWindowMinSize(int width, int height)
+{
+#if defined(PLATFORM_DESKTOP)
+ const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
+ glfwSetWindowSizeLimits(window, width, height, mode->width, mode->height);
+#endif
+}
+
+// Get current screen width
+int GetScreenWidth(void)
+{
+ return screenWidth;
+}
+
+// Get current screen height
+int GetScreenHeight(void)
+{
+ return screenHeight;
+}
+
+#if !defined(PLATFORM_ANDROID)
+// Show mouse cursor
+void ShowCursor()
+{
+#if defined(PLATFORM_DESKTOP)
+ #if defined(__linux__)
+ XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window));
+ #else
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ #endif
+#endif
+ cursorHidden = false;
+}
+
+// Hides mouse cursor
+void HideCursor()
+{
+#if defined(PLATFORM_DESKTOP)
+ #if defined(__linux__)
+ XColor col;
+ const char nil[] = {0};
+
+ Pixmap pix = XCreateBitmapFromData(glfwGetX11Display(), glfwGetX11Window(window), nil, 1, 1);
+ Cursor cur = XCreatePixmapCursor(glfwGetX11Display(), pix, pix, &col, &col, 0, 0);
+
+ XDefineCursor(glfwGetX11Display(), glfwGetX11Window(window), cur);
+ XFreeCursor(glfwGetX11Display(), cur);
+ #else
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+ #endif
+#endif
+ cursorHidden = true;
+}
+
+// Check if cursor is not visible
+bool IsCursorHidden()
+{
+ return cursorHidden;
+}
+
+// Enables cursor (unlock cursor)
+void EnableCursor()
+{
+#if defined(PLATFORM_DESKTOP)
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+#endif
+#if defined(PLATFORM_WEB)
+ toggleCursorLock = true;
+#endif
+ cursorHidden = false;
+}
+
+// Disables cursor (lock cursor)
+void DisableCursor()
+{
+#if defined(PLATFORM_DESKTOP)
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
+#endif
+#if defined(PLATFORM_WEB)
+ toggleCursorLock = true;
+#endif
+ cursorHidden = true;
+}
+#endif // !defined(PLATFORM_ANDROID)
+
+// Set background color (framebuffer clear color)
+void ClearBackground(Color color)
+{
+ // Clear full framebuffer (not only render area) to color
+ rlClearColor(color.r, color.g, color.b, color.a);
+}
+
+// Setup canvas (framebuffer) to start drawing
+void BeginDrawing(void)
+{
+ currentTime = GetTime(); // Number of elapsed seconds since InitTimer() was called
+ updateTime = currentTime - previousTime;
+ previousTime = currentTime;
+
+ rlClearScreenBuffers(); // Clear current framebuffers
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+ rlMultMatrixf(MatrixToFloat(downscaleView)); // If downscale required, apply it here
+
+ //rlTranslatef(0.375, 0.375, 0); // HACK to have 2D pixel-perfect drawing on OpenGL 1.1
+ // NOTE: Not required with OpenGL 3.3+
+}
+
+// End canvas drawing and swap buffers (double buffering)
+void EndDrawing(void)
+{
+ rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+#if defined(SUPPORT_GIF_RECORDING)
+
+ #define GIF_RECORD_FRAMERATE 10
+
+ if (gifRecording)
+ {
+ gifFramesCounter++;
+
+ // NOTE: We record one gif frame every 10 game frames
+ if ((gifFramesCounter%GIF_RECORD_FRAMERATE) == 0)
+ {
+ // Get image data for the current frame (from backbuffer)
+ // NOTE: This process is very slow... :(
+ unsigned char *screenData = rlReadScreenPixels(screenWidth, screenHeight);
+ GifWriteFrame(screenData, screenWidth, screenHeight, 10, 8, false);
+
+ free(screenData); // Free image data
+ }
+
+ if (((gifFramesCounter/15)%2) == 1)
+ {
+ DrawCircle(30, screenHeight - 20, 10, RED);
+ DrawText("RECORDING", 50, screenHeight - 25, 10, MAROON);
+ }
+
+ rlglDraw(); // Draw RECORDING message
+ }
+#endif
+
+ SwapBuffers(); // Copy back buffer to front buffer
+ PollInputEvents(); // Poll user events
+
+ // Frame time control system
+ currentTime = GetTime();
+ drawTime = currentTime - previousTime;
+ previousTime = currentTime;
+
+ frameTime = updateTime + drawTime;
+
+ // Wait for some milliseconds...
+ if (frameTime < targetTime)
+ {
+ Wait((targetTime - frameTime)*1000.0f);
+
+ currentTime = GetTime();
+ double extraTime = currentTime - previousTime;
+ previousTime = currentTime;
+
+ frameTime += extraTime;
+ }
+}
+
+// Initialize 2D mode with custom camera (2D)
+void Begin2dMode(Camera2D camera)
+{
+ rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ // Camera rotation and scaling is always relative to target
+ Matrix matOrigin = MatrixTranslate(-camera.target.x, -camera.target.y, 0.0f);
+ Matrix matRotation = MatrixRotate((Vector3){ 0.0f, 0.0f, 1.0f }, camera.rotation*DEG2RAD);
+ Matrix matScale = MatrixScale(camera.zoom, camera.zoom, 1.0f);
+ Matrix matTranslation = MatrixTranslate(camera.offset.x + camera.target.x, camera.offset.y + camera.target.y, 0.0f);
+
+ Matrix matTransform = MatrixMultiply(MatrixMultiply(matOrigin, MatrixMultiply(matScale, matRotation)), matTranslation);
+
+ rlMultMatrixf(MatrixToFloat(matTransform));
+}
+
+// Ends 2D mode with custom camera
+void End2dMode(void)
+{
+ rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+}
+
+// Initializes 3D mode with custom camera (3D)
+void Begin3dMode(Camera camera)
+{
+ rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+ rlMatrixMode(RL_PROJECTION); // Switch to projection matrix
+ rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection
+ rlLoadIdentity(); // Reset current matrix (PROJECTION)
+
+ // Setup perspective projection
+ float aspect = (float)screenWidth/(float)screenHeight;
+ double top = 0.01*tan(camera.fovy*0.5*DEG2RAD);
+ double right = top*aspect;
+
+ // NOTE: zNear and zFar values are important when computing depth buffer values
+ rlFrustum(-right, right, -top, top, 0.01, 1000.0);
+
+ rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ // Setup Camera view
+ Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
+ rlMultMatrixf(MatrixToFloat(matView)); // Multiply MODELVIEW matrix by view matrix (camera)
+
+ rlEnableDepthTest(); // Enable DEPTH_TEST for 3D
+}
+
+// Ends 3D mode and returns to default 2D orthographic mode
+void End3dMode(void)
+{
+ rlglDraw(); // Process internal buffers (update + draw)
+
+ rlMatrixMode(RL_PROJECTION); // Switch to projection matrix
+ rlPopMatrix(); // Restore previous matrix (PROJECTION) from matrix stack
+
+ rlMatrixMode(RL_MODELVIEW); // Get back to modelview matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ rlDisableDepthTest(); // Disable DEPTH_TEST for 2D
+}
+
+// Initializes render texture for drawing
+void BeginTextureMode(RenderTexture2D target)
+{
+ rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+ rlEnableRenderTexture(target.id); // Enable render target
+
+ rlClearScreenBuffers(); // Clear render texture buffers
+
+ // Set viewport to framebuffer size
+ rlViewport(0, 0, target.texture.width, target.texture.height);
+
+ rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
+ rlLoadIdentity(); // Reset current matrix (PROJECTION)
+
+ // Set orthographic projection to current framebuffer size
+ // NOTE: Configured top-left corner as (0, 0)
+ rlOrtho(0, target.texture.width, target.texture.height, 0, 0.0f, 1.0f);
+
+ rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ //rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?)
+}
+
+// Ends drawing to render texture
+void EndTextureMode(void)
+{
+ rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+ rlDisableRenderTexture(); // Disable render target
+
+ // Set viewport to default framebuffer size (screen size)
+ SetupViewport();
+
+ rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
+ rlLoadIdentity(); // Reset current matrix (PROJECTION)
+
+ // Set orthographic projection to current framebuffer size
+ // NOTE: Configured top-left corner as (0, 0)
+ rlOrtho(0, GetScreenWidth(), GetScreenHeight(), 0, 0.0f, 1.0f);
+
+ rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+}
+
+// Returns a ray trace from mouse position
+Ray GetMouseRay(Vector2 mousePosition, Camera camera)
+{
+ Ray ray;
+
+ // Calculate normalized device coordinates
+ // NOTE: y value is negative
+ float x = (2.0f*mousePosition.x)/(float)GetScreenWidth() - 1.0f;
+ float y = 1.0f - (2.0f*mousePosition.y)/(float)GetScreenHeight();
+ float z = 1.0f;
+
+ // Store values in a vector
+ Vector3 deviceCoords = { x, y, z };
+
+ TraceLog(LOG_DEBUG, "Device coordinates: (%f, %f, %f)", deviceCoords.x, deviceCoords.y, deviceCoords.z);
+
+ // Calculate projection matrix from perspective
+ Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0);
+
+ // Calculate view matrix from camera look at
+ Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
+
+ // Unproject far/near points
+ Vector3 nearPoint = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView);
+ Vector3 farPoint = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView);
+
+ // Calculate normalized direction vector
+ Vector3 direction = Vector3Subtract(farPoint, nearPoint);
+ Vector3Normalize(&direction);
+
+ // Apply calculated vectors to ray
+ ray.position = camera.position;
+ ray.direction = direction;
+
+ return ray;
+}
+
+// Returns the screen space position from a 3d world space position
+Vector2 GetWorldToScreen(Vector3 position, Camera camera)
+{
+ // Calculate projection matrix (from perspective instead of frustum
+ Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0);
+
+ // Calculate view matrix from camera look at (and transpose it)
+ Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
+
+ // Convert world position vector to quaternion
+ Quaternion worldPos = { position.x, position.y, position.z, 1.0f };
+
+ // Transform world position to view
+ QuaternionTransform(&worldPos, matView);
+
+ // Transform result to projection (clip space position)
+ QuaternionTransform(&worldPos, matProj);
+
+ // Calculate normalized device coordinates (inverted y)
+ Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w };
+
+ // Calculate 2d screen position vector
+ Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() };
+
+ return screenPosition;
+}
+
+// Get transform matrix for camera
+Matrix GetCameraMatrix(Camera camera)
+{
+ return MatrixLookAt(camera.position, camera.target, camera.up);
+}
+
+// Set target FPS (maximum)
+void SetTargetFPS(int fps)
+{
+ if (fps < 1) targetTime = 0.0;
+ else targetTime = 1.0/(double)fps;
+
+ TraceLog(LOG_INFO, "Target time per frame: %02.03f milliseconds", (float)targetTime*1000);
+}
+
+// Returns current FPS
+int GetFPS(void)
+{
+ return (int)(1.0f/GetFrameTime());
+}
+
+// Returns time in seconds for last frame drawn
+float GetFrameTime(void)
+{
+ // NOTE: We round value to milliseconds
+ return (float)frameTime;
+}
+
+// Converts Color to float array and normalizes
+float *ColorToFloat(Color color)
+{
+ static float buffer[4];
+
+ buffer[0] = (float)color.r/255;
+ buffer[1] = (float)color.g/255;
+ buffer[2] = (float)color.b/255;
+ buffer[3] = (float)color.a/255;
+
+ return buffer;
+}
+
+// Returns a Color struct from hexadecimal value
+Color GetColor(int hexValue)
+{
+ Color color;
+
+ color.r = (unsigned char)(hexValue >> 24) & 0xFF;
+ color.g = (unsigned char)(hexValue >> 16) & 0xFF;
+ color.b = (unsigned char)(hexValue >> 8) & 0xFF;
+ color.a = (unsigned char)hexValue & 0xFF;
+
+ return color;
+}
+
+// Returns hexadecimal value for a Color
+int GetHexValue(Color color)
+{
+ return (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a);
+}
+
+// Returns a random value between min and max (both included)
+int GetRandomValue(int min, int max)
+{
+ if (min > max)
+ {
+ int tmp = max;
+ max = min;
+ min = tmp;
+ }
+
+ return (rand()%(abs(max-min)+1) + min);
+}
+
+// Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
+Color Fade(Color color, float alpha)
+{
+ if (alpha < 0.0f) alpha = 0.0f;
+ else if (alpha > 1.0f) alpha = 1.0f;
+
+ float colorAlpha = (float)color.a*alpha;
+
+ return (Color){color.r, color.g, color.b, (unsigned char)colorAlpha};
+}
+
+// Activate raylib logo at startup (can be done with flags)
+void ShowLogo(void)
+{
+ showLogo = true;
+}
+
+// Setup window configuration flags (view FLAGS)
+void SetConfigFlags(char flags)
+{
+ configFlags = flags;
+
+ if (configFlags & FLAG_SHOW_LOGO) showLogo = true;
+ if (configFlags & FLAG_FULLSCREEN_MODE) fullscreen = true;
+}
+
+// NOTE TraceLog() function is located in [utils.h]
+
+// Takes a screenshot of current screen (saved a .png)
+void TakeScreenshot(const char *fileName)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
+ unsigned char *imgData = rlReadScreenPixels(renderWidth, renderHeight);
+ SavePNG(fileName, imgData, renderWidth, renderHeight, 4); // Save image as PNG
+ free(imgData);
+
+ TraceLog(LOG_INFO, "Screenshot taken: %s", fileName);
+#endif
+}
+
+// Check file extension
+bool IsFileExtension(const char *fileName, const char *ext)
+{
+ bool result = false;
+ const char *fileExt;
+
+ if ((fileExt = strrchr(fileName, '.')) != NULL)
+ {
+ if (strcmp(fileExt, ext) == 0) result = true;
+ }
+
+ return result;
+}
+
+// Get the extension for a filename
+const char *GetExtension(const char *fileName)
+{
+ const char *dot = strrchr(fileName, '.');
+
+ if (!dot || dot == fileName) return "";
+
+ return (dot + 1);
+}
+
+// Get directory for a given fileName (with path)
+const char *GetDirectoryPath(const char *fileName)
+{
+ char *lastSlash = NULL;
+ static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256
+ memset(filePath, 0, 256);
+
+ lastSlash = strrchr(fileName, '\\');
+ strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1));
+ filePath[strlen(fileName) - strlen(lastSlash)] = '\0';
+
+ return filePath;
+}
+
+// Get current working directory
+const char *GetWorkingDirectory(void)
+{
+ static char currentDir[256]; // MAX_DIRECTORY_PATH_SIZE = 256
+ memset(currentDir, 0, 256);
+
+ GETCWD(currentDir, 256 - 1);
+
+ return currentDir;
+}
+
+// Change working directory, returns true if success
+bool ChangeDirectory(const char *dir)
+{
+ return (CHDIR(dir) == 0);
+}
+
+#if defined(PLATFORM_DESKTOP)
+// Check if a file has been dropped into window
+bool IsFileDropped(void)
+{
+ if (dropFilesCount > 0) return true;
+ else return false;
+}
+
+// Get dropped files names
+char **GetDroppedFiles(int *count)
+{
+ *count = dropFilesCount;
+ return dropFilesPath;
+}
+
+// Clear dropped files paths buffer
+void ClearDroppedFiles(void)
+{
+ if (dropFilesCount > 0)
+ {
+ for (int i = 0; i < dropFilesCount; i++) free(dropFilesPath[i]);
+
+ free(dropFilesPath);
+
+ dropFilesCount = 0;
+ }
+}
+#endif
+
+// Save integer value to storage file (to defined position)
+// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
+void StorageSaveValue(int position, int value)
+{
+ FILE *storageFile = NULL;
+
+ char path[128];
+#if defined(PLATFORM_ANDROID)
+ strcpy(path, internalDataPath);
+ strcat(path, "/");
+ strcat(path, STORAGE_FILENAME);
+#else
+ strcpy(path, STORAGE_FILENAME);
+#endif
+
+ // Try open existing file to append data
+ storageFile = fopen(path, "rb+");
+
+ // If file doesn't exist, create a new storage data file
+ if (!storageFile) storageFile = fopen(path, "wb");
+
+ if (!storageFile) TraceLog(LOG_WARNING, "Storage data file could not be created");
+ else
+ {
+ // Get file size
+ fseek(storageFile, 0, SEEK_END);
+ int fileSize = ftell(storageFile); // Size in bytes
+ fseek(storageFile, 0, SEEK_SET);
+
+ if (fileSize < (position*4)) TraceLog(LOG_WARNING, "Storage position could not be found");
+ else
+ {
+ fseek(storageFile, (position*4), SEEK_SET);
+ fwrite(&value, 1, 4, storageFile);
+ }
+
+ fclose(storageFile);
+ }
+}
+
+// Load integer value from storage file (from defined position)
+// NOTE: If requested position could not be found, value 0 is returned
+int StorageLoadValue(int position)
+{
+ int value = 0;
+
+ char path[128];
+#if defined(PLATFORM_ANDROID)
+ strcpy(path, internalDataPath);
+ strcat(path, "/");
+ strcat(path, STORAGE_FILENAME);
+#else
+ strcpy(path, STORAGE_FILENAME);
+#endif
+
+ // Try open existing file to append data
+ FILE *storageFile = fopen(path, "rb");
+
+ if (!storageFile) TraceLog(LOG_WARNING, "Storage data file could not be found");
+ else
+ {
+ // Get file size
+ fseek(storageFile, 0, SEEK_END);
+ int fileSize = ftell(storageFile); // Size in bytes
+ rewind(storageFile);
+
+ if (fileSize < (position*4)) TraceLog(LOG_WARNING, "Storage position could not be found");
+ else
+ {
+ fseek(storageFile, (position*4), SEEK_SET);
+ fread(&value, 4, 1, storageFile); // Read 1 element of 4 bytes size
+ }
+
+ fclose(storageFile);
+ }
+
+ return value;
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
+//----------------------------------------------------------------------------------
+// Detect if a key has been pressed once
+bool IsKeyPressed(int key)
+{
+ bool pressed = false;
+
+ if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true;
+ else pressed = false;
+
+ return pressed;
+}
+
+// Detect if a key is being pressed (key held down)
+bool IsKeyDown(int key)
+{
+ if (GetKeyStatus(key) == 1) return true;
+ else return false;
+}
+
+// Detect if a key has been released once
+bool IsKeyReleased(int key)
+{
+ bool released = false;
+
+ if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true;
+ else released = false;
+
+ return released;
+}
+
+// Detect if a key is NOT being pressed (key not held down)
+bool IsKeyUp(int key)
+{
+ if (GetKeyStatus(key) == 0) return true;
+ else return false;
+}
+
+// Get the last key pressed
+int GetKeyPressed(void)
+{
+ return lastKeyPressed;
+}
+
+// Set a custom key to exit program
+// NOTE: default exitKey is ESCAPE
+void SetExitKey(int key)
+{
+#if !defined(PLATFORM_ANDROID)
+ exitKey = key;
+#endif
+}
+
+// NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB)
+
+// Detect if a gamepad is available
+bool IsGamepadAvailable(int gamepad)
+{
+ bool result = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad]) result = true;
+#endif
+
+ return result;
+}
+
+// Check gamepad name (if available)
+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;
+}
+
+// Return gamepad internal name id
+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
+}
+
+// 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;
+}
+
+// Return axis movement vector for a gamepad
+float GetGamepadAxisMovement(int gamepad, int axis)
+{
+ float value = 0;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (axis < MAX_GAMEPAD_AXIS)) value = gamepadAxisState[gamepad][axis];
+#endif
+
+ return value;
+}
+
+// Detect if a gamepad button has been pressed once
+bool IsGamepadButtonPressed(int gamepad, int button)
+{
+ bool pressed = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
+ (currentGamepadState[gamepad][button] == 1)) pressed = true;
+#endif
+
+ return pressed;
+}
+
+// Detect if a gamepad button is being pressed
+bool IsGamepadButtonDown(int gamepad, int button)
+{
+ bool result = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ (currentGamepadState[gamepad][button] == 1)) result = true;
+#endif
+
+ return result;
+}
+
+// Detect if a gamepad button has NOT been pressed once
+bool IsGamepadButtonReleased(int gamepad, int button)
+{
+ bool released = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
+ (currentGamepadState[gamepad][button] == 0)) released = true;
+#endif
+
+ return released;
+}
+
+// Detect if a mouse button is NOT being pressed
+bool IsGamepadButtonUp(int gamepad, int button)
+{
+ bool result = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ (currentGamepadState[gamepad][button] == 0)) result = true;
+#endif
+
+ return result;
+}
+
+// Get the last gamepad button pressed
+int GetGamepadButtonPressed(void)
+{
+ return lastGamepadButtonPressed;
+}
+
+// Detect if a mouse button has been pressed once
+bool IsMouseButtonPressed(int button)
+{
+ bool pressed = false;
+
+#if defined(PLATFORM_ANDROID)
+ if (IsGestureDetected(GESTURE_TAP)) pressed = true;
+#else
+ if ((currentMouseState[button] != previousMouseState[button]) && (currentMouseState[button] == 1)) pressed = true;
+#endif
+
+ return pressed;
+}
+
+// Detect if a mouse button is being pressed
+bool IsMouseButtonDown(int button)
+{
+ bool down = false;
+
+#if defined(PLATFORM_ANDROID)
+ if (IsGestureDetected(GESTURE_HOLD)) down = true;
+#else
+ if (GetMouseButtonStatus(button) == 1) down = true;
+#endif
+
+ return down;
+}
+
+// Detect if a mouse button has been released once
+bool IsMouseButtonReleased(int button)
+{
+ bool released = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if ((currentMouseState[button] != previousMouseState[button]) && (currentMouseState[button] == 0)) released = true;
+#endif
+
+ return released;
+}
+
+// Detect if a mouse button is NOT being pressed
+bool IsMouseButtonUp(int button)
+{
+ bool up = false;
+
+#if !defined(PLATFORM_ANDROID)
+ if (GetMouseButtonStatus(button) == 0) up = true;
+#endif
+
+ return up;
+}
+
+// Returns mouse position X
+int GetMouseX(void)
+{
+#if defined(PLATFORM_ANDROID)
+ return (int)touchPosition[0].x;
+#else
+ return (int)mousePosition.x;
+#endif
+}
+
+// Returns mouse position Y
+int GetMouseY(void)
+{
+#if defined(PLATFORM_ANDROID)
+ return (int)touchPosition[0].x;
+#else
+ return (int)mousePosition.y;
+#endif
+}
+
+// Returns mouse position XY
+Vector2 GetMousePosition(void)
+{
+#if defined(PLATFORM_ANDROID)
+ return GetTouchPosition(0);
+#else
+ return mousePosition;
+#endif
+}
+
+// Set mouse position XY
+void SetMousePosition(Vector2 position)
+{
+ mousePosition = position;
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ // NOTE: emscripten not implemented
+ glfwSetCursorPos(window, position.x, position.y);
+#endif
+}
+
+// Returns mouse wheel movement Y
+int GetMouseWheelMove(void)
+{
+#if defined(PLATFORM_ANDROID)
+ return 0;
+#elif defined(PLATFORM_WEB)
+ return previousMouseWheelY/100;
+#else
+ return previousMouseWheelY;
+#endif
+}
+
+// Returns touch position X for touch point 0 (relative to screen size)
+int GetTouchX(void)
+{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
+ return (int)touchPosition[0].x;
+#else // PLATFORM_DESKTOP, PLATFORM_RPI
+ return GetMouseX();
+#endif
+}
+
+// Returns touch position Y for touch point 0 (relative to screen size)
+int GetTouchY(void)
+{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
+ return (int)touchPosition[0].y;
+#else // PLATFORM_DESKTOP, PLATFORM_RPI
+ return GetMouseY();
+#endif
+}
+
+// Returns touch position XY for a touch point index (relative to screen size)
+// TODO: Touch position should be scaled depending on display size and render size
+Vector2 GetTouchPosition(int index)
+{
+ Vector2 position = { -1.0f, -1.0f };
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
+ if (index < MAX_TOUCH_POINTS) position = touchPosition[index];
+ else TraceLog(LOG_WARNING, "Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS);
+
+ if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
+ {
+ // TODO: Review touch position scaling for screenSize vs displaySize
+ position.x = position.x*((float)screenWidth/(float)(displayWidth - renderOffsetX)) - renderOffsetX/2;
+ position.y = position.y*((float)screenHeight/(float)(displayHeight - renderOffsetY)) - renderOffsetY/2;
+ }
+ else
+ {
+ position.x = position.x*((float)renderWidth/(float)displayWidth) - renderOffsetX/2;
+ position.y = position.y*((float)renderHeight/(float)displayHeight) - renderOffsetY/2;
+ }
+#else // PLATFORM_DESKTOP, PLATFORM_RPI
+ if (index == 0) position = GetMousePosition();
+#endif
+
+ return position;
+}
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Definition
+//----------------------------------------------------------------------------------
+
+// Initialize display device and framebuffer
+// NOTE: width and height represent the screen (framebuffer) desired size, not actual display size
+// If width or height are 0, default display size will be used for framebuffer size
+static void InitGraphicsDevice(int width, int height)
+{
+ screenWidth = width; // User desired width
+ screenHeight = height; // User desired height
+
+ // NOTE: Framebuffer (render area - renderWidth, renderHeight) could include black bars...
+ // ...in top-down or left-right to match display aspect ratio (no weird scalings)
+
+ // Downscale matrix is required in case desired screen area is bigger than display area
+ downscaleView = MatrixIdentity();
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ glfwSetErrorCallback(ErrorCallback);
+
+ if (!glfwInit()) TraceLog(LOG_ERROR, "Failed to initialize GLFW");
+
+ // NOTE: Getting video modes is not implemented in emscripten GLFW3 version
+#if defined(PLATFORM_DESKTOP)
+ // Find monitor resolution
+ const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
+
+ displayWidth = mode->width;
+ displayHeight = mode->height;
+
+ // Screen size security check
+ if (screenWidth <= 0) screenWidth = displayWidth;
+ if (screenHeight <= 0) screenHeight = displayHeight;
+#endif // defined(PLATFORM_DESKTOP)
+
+#if defined(PLATFORM_WEB)
+ displayWidth = screenWidth;
+ displayHeight = screenHeight;
+#endif // defined(PLATFORM_WEB)
+
+ glfwDefaultWindowHints(); // Set default windows hints
+
+ // Check some Window creation flags
+ if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window
+ else glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Avoid window being resizable
+
+ if (configFlags & FLAG_WINDOW_DECORATED) glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Border and buttons on Window
+
+ if (configFlags & FLAG_WINDOW_TRANSPARENT)
+ {
+ // TODO: Enable transparent window (not ready yet on GLFW 3.2)
+ }
+
+ if (configFlags & FLAG_MSAA_4X_HINT)
+ {
+ glfwWindowHint(GLFW_SAMPLES, 4); // Enables multisampling x4 (MSAA), default is 0
+ TraceLog(LOG_INFO, "Trying to enable MSAA x4");
+ }
+
+ //glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
+ //glfwWindowHint(GLFW_DEPTH_BITS, 16); // Depthbuffer bits (24 by default)
+ //glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window
+ //glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); // Default OpenGL API to use. Alternative: GLFW_OPENGL_ES_API
+ //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
+
+ // NOTE: When asking for an OpenGL context version, most drivers provide highest supported version
+ // with forward compatibility to older OpenGL versions.
+ // For example, if using OpenGL 1.1, driver can provide a 4.3 context forward compatible.
+
+ // Check selection OpenGL version
+ if (rlGetVersion() == OPENGL_21)
+ {
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // Choose OpenGL major version (just hint)
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // Choose OpenGL minor version (just hint)
+ }
+ else if (rlGetVersion() == OPENGL_33)
+ {
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Choose OpenGL major version (just hint)
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint)
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above!
+ // Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE
+#if defined(__APPLE__)
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires
+#else
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above!
+#endif
+ //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
+ }
+
+ if (fullscreen)
+ {
+ // Obtain recommended displayWidth/displayHeight from a valid videomode for the monitor
+ int count;
+ const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count);
+
+ // Get closest videomode to desired screenWidth/screenHeight
+ for (int i = 0; i < count; i++)
+ {
+ if (modes[i].width >= screenWidth)
+ {
+ if (modes[i].height >= screenHeight)
+ {
+ displayWidth = modes[i].width;
+ displayHeight = modes[i].height;
+ break;
+ }
+ }
+ }
+
+ TraceLog(LOG_WARNING, "Closest fullscreen videomode: %i x %i", displayWidth, displayHeight);
+
+ // NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example,
+ // for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3),
+ // framebuffer is rendered correctly but once displayed on a 16:9 monitor, it gets stretched
+ // by the sides to fit all monitor space...
+
+ // At this point we need to manage render size vs screen size
+ // NOTE: This function uses and modifies global module variables:
+ // screenWidth/screenHeight - renderWidth/renderHeight - downscaleView
+ SetupFramebufferSize(displayWidth, displayHeight);
+
+ window = glfwCreateWindow(displayWidth, displayHeight, windowTitle, glfwGetPrimaryMonitor(), NULL);
+
+ // NOTE: Full-screen change, not working properly...
+ //glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
+ }
+ else
+ {
+ // No-fullscreen window creation
+ window = glfwCreateWindow(screenWidth, screenHeight, windowTitle, NULL, NULL);
+
+#if defined(PLATFORM_DESKTOP)
+ // Center window on screen
+ int windowPosX = displayWidth/2 - screenWidth/2;
+ int windowPosY = displayHeight/2 - screenHeight/2;
+
+ if (windowPosX < 0) windowPosX = 0;
+ if (windowPosY < 0) windowPosY = 0;
+
+ glfwSetWindowPos(window, windowPosX, windowPosY);
+#endif
+ renderWidth = screenWidth;
+ renderHeight = screenHeight;
+ }
+
+ if (!window)
+ {
+ glfwTerminate();
+ TraceLog(LOG_ERROR, "GLFW Failed to initialize Window");
+ }
+ else
+ {
+ TraceLog(LOG_INFO, "Display device initialized successfully");
+#if defined(PLATFORM_DESKTOP)
+ TraceLog(LOG_INFO, "Display size: %i x %i", displayWidth, displayHeight);
+#endif
+ TraceLog(LOG_INFO, "Render size: %i x %i", renderWidth, renderHeight);
+ TraceLog(LOG_INFO, "Screen size: %i x %i", screenWidth, screenHeight);
+ TraceLog(LOG_INFO, "Viewport offsets: %i, %i", renderOffsetX, renderOffsetY);
+ }
+
+ glfwSetWindowSizeCallback(window, WindowSizeCallback); // NOTE: Resizing not allowed by default!
+ glfwSetCursorEnterCallback(window, CursorEnterCallback);
+ glfwSetKeyCallback(window, KeyCallback);
+ glfwSetMouseButtonCallback(window, MouseButtonCallback);
+ glfwSetCursorPosCallback(window, MouseCursorPosCallback); // Track mouse position changes
+ glfwSetCharCallback(window, CharCallback);
+ glfwSetScrollCallback(window, ScrollCallback);
+ glfwSetWindowIconifyCallback(window, WindowIconifyCallback);
+#if defined(PLATFORM_DESKTOP)
+ glfwSetDropCallback(window, WindowDropCallback);
+#endif
+
+ glfwMakeContextCurrent(window);
+
+ // Try to disable GPU V-Sync by default, set framerate using SetTargetFPS()
+ // NOTE: V-Sync can be enabled by graphic driver configuration
+ glfwSwapInterval(0);
+
+#if defined(PLATFORM_DESKTOP)
+ // Load OpenGL 3.3 extensions
+ // NOTE: GLFW loader function is passed as parameter
+ rlLoadExtensions(glfwGetProcAddress);
+#endif
+
+ // Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
+ // NOTE: V-Sync can be enabled by graphic driver configuration
+ if (configFlags & FLAG_VSYNC_HINT)
+ {
+ glfwSwapInterval(1);
+ TraceLog(LOG_INFO, "Trying to enable VSYNC");
+ }
+#endif // defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ fullscreen = true;
+
+ // Screen size security check
+ if (screenWidth <= 0) screenWidth = displayWidth;
+ if (screenHeight <= 0) screenHeight = displayHeight;
+
+#if defined(PLATFORM_RPI)
+ bcm_host_init();
+
+ DISPMANX_ELEMENT_HANDLE_T dispmanElement;
+ DISPMANX_DISPLAY_HANDLE_T dispmanDisplay;
+ DISPMANX_UPDATE_HANDLE_T dispmanUpdate;
+
+ VC_RECT_T dstRect;
+ VC_RECT_T srcRect;
+#endif
+
+ EGLint samples = 0;
+ EGLint sampleBuffer = 0;
+ if (configFlags & FLAG_MSAA_4X_HINT)
+ {
+ samples = 4;
+ sampleBuffer = 1;
+ TraceLog(LOG_INFO, "Trying to enable MSAA x4");
+ }
+
+ const EGLint framebufferAttribs[] =
+ {
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> Required on RPI?
+ //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android!
+ EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
+ EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6)
+ EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
+ //EGL_ALPHA_SIZE, 8, // ALPHA bit depth (required for transparent framebuffer)
+ //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
+ EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
+ //EGL_STENCIL_SIZE, 8, // Stencil buffer size
+ EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
+ EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
+ EGL_NONE
+ };
+
+ EGLint contextAttribs[] =
+ {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ EGLint numConfigs;
+
+ // Get an EGL display connection
+ display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+
+ // Initialize the EGL display connection
+ eglInitialize(display, NULL, NULL);
+
+ // Get an appropriate EGL framebuffer configuration
+ eglChooseConfig(display, framebufferAttribs, &config, 1, &numConfigs);
+
+ // Set rendering API
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ // Create an EGL rendering context
+ context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
+
+ // Create an EGL window surface
+ //---------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+ EGLint displayFormat;
+
+ displayWidth = ANativeWindow_getWidth(app->window);
+ displayHeight = ANativeWindow_getHeight(app->window);
+
+ // EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is guaranteed to be accepted by ANativeWindow_setBuffersGeometry()
+ // As soon as we picked a EGLConfig, we can safely reconfigure the ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID
+ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &displayFormat);
+
+ // At this point we need to manage render size vs screen size
+ // NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
+ SetupFramebufferSize(displayWidth, displayHeight);
+
+ ANativeWindow_setBuffersGeometry(app->window, renderWidth, renderHeight, displayFormat);
+ //ANativeWindow_setBuffersGeometry(app->window, 0, 0, displayFormat); // Force use of native display size
+
+ surface = eglCreateWindowSurface(display, config, app->window, NULL);
+#endif // defined(PLATFORM_ANDROID)
+
+#if defined(PLATFORM_RPI)
+ graphics_get_display_size(0, &displayWidth, &displayHeight);
+
+ // At this point we need to manage render size vs screen size
+ // NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
+ SetupFramebufferSize(displayWidth, displayHeight);
+
+ dstRect.x = 0;
+ dstRect.y = 0;
+ dstRect.width = displayWidth;
+ dstRect.height = displayHeight;
+
+ srcRect.x = 0;
+ srcRect.y = 0;
+ srcRect.width = renderWidth << 16;
+ srcRect.height = renderHeight << 16;
+
+ // NOTE: RPI dispmanx windowing system takes care of srcRec scaling to dstRec by hardware (no cost)
+ // Take care that renderWidth/renderHeight fit on displayWidth/displayHeight aspect ratio
+
+ VC_DISPMANX_ALPHA_T alpha;
+ alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
+ alpha.opacity = 255; // Set transparency level for framebuffer, requires EGLAttrib: EGL_TRANSPARENT_TYPE
+ alpha.mask = 0;
+
+ dispmanDisplay = vc_dispmanx_display_open(0); // LCD
+ dispmanUpdate = vc_dispmanx_update_start(0);
+
+ dispmanElement = vc_dispmanx_element_add(dispmanUpdate, dispmanDisplay, 0/*layer*/, &dstRect, 0/*src*/,
+ &srcRect, DISPMANX_PROTECTION_NONE, &alpha, 0/*clamp*/, DISPMANX_NO_ROTATE);
+
+ nativeWindow.element = dispmanElement;
+ nativeWindow.width = renderWidth;
+ nativeWindow.height = renderHeight;
+ vc_dispmanx_update_submit_sync(dispmanUpdate);
+
+ surface = eglCreateWindowSurface(display, config, &nativeWindow, NULL);
+ //---------------------------------------------------------------------------------
+#endif // defined(PLATFORM_RPI)
+ // There must be at least one frame displayed before the buffers are swapped
+ //eglSwapInterval(display, 1);
+
+ if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
+ {
+ TraceLog(LOG_ERROR, "Unable to attach EGL rendering context to EGL surface");
+ }
+ else
+ {
+ // Grab the width and height of the surface
+ //eglQuerySurface(display, surface, EGL_WIDTH, &renderWidth);
+ //eglQuerySurface(display, surface, EGL_HEIGHT, &renderHeight);
+
+ TraceLog(LOG_INFO, "Display device initialized successfully");
+ TraceLog(LOG_INFO, "Display size: %i x %i", displayWidth, displayHeight);
+ TraceLog(LOG_INFO, "Render size: %i x %i", renderWidth, renderHeight);
+ TraceLog(LOG_INFO, "Screen size: %i x %i", screenWidth, screenHeight);
+ TraceLog(LOG_INFO, "Viewport offsets: %i, %i", renderOffsetX, renderOffsetY);
+ }
+#endif // defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+
+ // Initialize OpenGL context (states and resources)
+ // NOTE: screenWidth and screenHeight not used, just stored as globals
+ rlglInit(screenWidth, screenHeight);
+
+ // Setup default viewport
+ SetupViewport();
+
+ // Initialize internal projection and modelview matrices
+ // NOTE: Default to orthographic projection mode with top-left corner at (0,0)
+ rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
+ rlLoadIdentity(); // Reset current matrix (PROJECTION)
+ rlOrtho(0, renderWidth - renderOffsetX, renderHeight - renderOffsetY, 0, 0.0f, 1.0f);
+ rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ ClearBackground(RAYWHITE); // Default background color for raylib games :P
+
+#if defined(PLATFORM_ANDROID)
+ windowReady = true; // IMPORTANT!
+#endif
+}
+
+// Set viewport parameters
+static void SetupViewport(void)
+{
+#if defined(__APPLE__)
+ // Get framebuffer size of current window
+ // NOTE: Required to handle HighDPI display correctly on OSX because framebuffer
+ // is automatically reasized to adapt to new DPI.
+ // When OS does that, it can be detected using GLFW3 callback: glfwSetFramebufferSizeCallback()
+ int fbWidth, fbHeight;
+ glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
+ rlViewport(renderOffsetX/2, renderOffsetY/2, fbWidth - renderOffsetX, fbHeight - renderOffsetY);
+#else
+ // Initialize screen viewport (area of the screen that you will actually draw to)
+ // NOTE: Viewport must be recalculated if screen is resized
+ rlViewport(renderOffsetX/2, renderOffsetY/2, renderWidth - renderOffsetX, renderHeight - renderOffsetY);
+#endif
+}
+
+// Compute framebuffer size relative to screen size and display size
+// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
+static void SetupFramebufferSize(int displayWidth, int displayHeight)
+{
+ // Calculate renderWidth and renderHeight, we have the display size (input params) and the desired screen size (global var)
+ if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
+ {
+ TraceLog(LOG_WARNING, "DOWNSCALING: Required screen size (%ix%i) is bigger than display size (%ix%i)", screenWidth, screenHeight, displayWidth, displayHeight);
+
+ // Downscaling to fit display with border-bars
+ float widthRatio = (float)displayWidth/(float)screenWidth;
+ float heightRatio = (float)displayHeight/(float)screenHeight;
+
+ if (widthRatio <= heightRatio)
+ {
+ renderWidth = displayWidth;
+ renderHeight = (int)round((float)screenHeight*widthRatio);
+ renderOffsetX = 0;
+ renderOffsetY = (displayHeight - renderHeight);
+ }
+ else
+ {
+ renderWidth = (int)round((float)screenWidth*heightRatio);
+ renderHeight = displayHeight;
+ renderOffsetX = (displayWidth - renderWidth);
+ renderOffsetY = 0;
+ }
+
+ // NOTE: downscale matrix required!
+ float scaleRatio = (float)renderWidth/(float)screenWidth;
+
+ downscaleView = MatrixScale(scaleRatio, scaleRatio, scaleRatio);
+
+ // NOTE: We render to full display resolution!
+ // We just need to calculate above parameters for downscale matrix and offsets
+ renderWidth = displayWidth;
+ renderHeight = displayHeight;
+
+ TraceLog(LOG_WARNING, "Downscale matrix generated, content will be rendered at: %i x %i", renderWidth, renderHeight);
+ }
+ else if ((screenWidth < displayWidth) || (screenHeight < displayHeight))
+ {
+ // Required screen size is smaller than display size
+ TraceLog(LOG_INFO, "UPSCALING: Required screen size: %i x %i -> Display size: %i x %i", screenWidth, screenHeight, displayWidth, displayHeight);
+
+ // Upscaling to fit display with border-bars
+ float displayRatio = (float)displayWidth/(float)displayHeight;
+ float screenRatio = (float)screenWidth/(float)screenHeight;
+
+ if (displayRatio <= screenRatio)
+ {
+ renderWidth = screenWidth;
+ renderHeight = (int)round((float)screenWidth/displayRatio);
+ renderOffsetX = 0;
+ renderOffsetY = (renderHeight - screenHeight);
+ }
+ else
+ {
+ renderWidth = (int)round((float)screenHeight*displayRatio);
+ renderHeight = screenHeight;
+ renderOffsetX = (renderWidth - screenWidth);
+ renderOffsetY = 0;
+ }
+ }
+ else // screen == display
+ {
+ renderWidth = screenWidth;
+ renderHeight = screenHeight;
+ renderOffsetX = 0;
+ renderOffsetY = 0;
+ }
+}
+
+// Initialize hi-resolution timer
+static void InitTimer(void)
+{
+ srand(time(NULL)); // Initialize random seed
+
+#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
+ timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms)
+#endif
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ struct timespec now;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) // Success
+ {
+ baseTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec;
+ }
+ else TraceLog(LOG_WARNING, "No hi-resolution timer available");
+#endif
+
+ previousTime = GetTime(); // Get time as double
+}
+
+// Get current time measure (in seconds) since InitTimer()
+static double GetTime(void)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ return glfwGetTime();
+#endif
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
+
+ return (double)(time - baseTime)*1e-9;
+#endif
+}
+
+// Wait for some milliseconds (stop program execution)
+// NOTE: Sleep() granularity could be around 10 ms, it means, Sleep() could
+// take longer than expected... for that reason we use the busy wait loop
+// http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected
+static void Wait(float ms)
+{
+#if defined(SUPPORT_BUSY_WAIT_LOOP)
+ double prevTime = GetTime();
+ double nextTime = 0.0;
+
+ // Busy wait loop
+ while ((nextTime - prevTime) < ms/1000.0f) nextTime = GetTime();
+#else
+ #if defined(_WIN32)
+ Sleep((unsigned int)ms);
+ #elif defined(__linux__) || defined(PLATFORM_WEB)
+ struct timespec req = { 0 };
+ time_t sec = (int)(ms/1000.0f);
+ ms -= (sec*1000);
+ req.tv_sec = sec;
+ req.tv_nsec = ms*1000000L;
+
+ // NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated.
+ while (nanosleep(&req, &req) == -1) continue;
+ #elif defined(__APPLE__)
+ usleep(ms*1000.0f);
+ #endif
+#endif
+}
+
+// Get one key state
+static bool GetKeyStatus(int key)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ return glfwGetKey(window, key);
+#elif defined(PLATFORM_ANDROID)
+ // NOTE: Android supports up to 260 keys
+ if (key < 0 || key > 260) return false;
+ else return currentKeyState[key];
+#elif defined(PLATFORM_RPI)
+ // NOTE: Keys states are filled in PollInputEvents()
+ if (key < 0 || key > 511) return false;
+ else return currentKeyState[key];
+#endif
+}
+
+// Get one mouse button state
+static bool GetMouseButtonStatus(int button)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ return glfwGetMouseButton(window, button);
+#elif defined(PLATFORM_ANDROID)
+ // TODO: Check for virtual mouse?
+ return false;
+#elif defined(PLATFORM_RPI)
+ // NOTE: Mouse buttons states are filled in PollInputEvents()
+ return currentMouseState[button];
+#endif
+}
+
+// Poll (store) all input events
+static void PollInputEvents(void)
+{
+#if defined(SUPPORT_GESTURES_SYSTEM)
+ // NOTE: Gestures update must be called every frame to reset gestures correctly
+ // because ProcessGestureEvent() is just called on an event, not every frame
+ UpdateGestures();
+#endif
+
+ // Reset last key pressed registered
+ lastKeyPressed = -1;
+
+#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
+ double mouseX;
+ double mouseY;
+
+ glfwGetCursorPos(window, &mouseX, &mouseY);
+
+ mousePosition.x = (float)mouseX;
+ mousePosition.y = (float)mouseY;
+
+ // Keyboard input polling (automatically managed by GLFW3 through callback)
+
+ // Register previous keys states
+ for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i];
+
+ // Register previous mouse states
+ for (int i = 0; i < 3; i++) previousMouseState[i] = currentMouseState[i];
+
+ previousMouseWheelY = currentMouseWheelY;
+ currentMouseWheelY = 0;
+#endif
+
+#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++)
+ {
+ if (glfwJoystickPresent(i)) gamepadReady[i] = true;
+ else gamepadReady[i] = false;
+ }
+
+ // Register gamepads buttons events
+ for (int i = 0; i < MAX_GAMEPADS; i++)
+ {
+ if (gamepadReady[i]) // Check if gamepad is available
+ {
+ // Register previous gamepad states
+ for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k];
+
+ // Get current gamepad state
+ // NOTE: There is no callback available, so we get it manually
+ const unsigned char *buttons;
+ int buttonsCount;
+
+ buttons = glfwGetJoystickButtons(i, &buttonsCount);
+
+ for (int k = 0; (buttons != NULL) && (k < buttonsCount) && (buttonsCount < MAX_GAMEPAD_BUTTONS); k++)
+ {
+ if (buttons[k] == GLFW_PRESS)
+ {
+ currentGamepadState[i][k] = 1;
+ lastGamepadButtonPressed = k;
+ }
+ else currentGamepadState[i][k] = 0;
+ }
+
+ // Get current axis state
+ const float *axes;
+ int axisCount = 0;
+
+ axes = glfwGetJoystickAxes(i, &axisCount);
+
+ for (int k = 0; (axes != NULL) && (k < axisCount) && (k < MAX_GAMEPAD_AXIS); k++)
+ {
+ gamepadAxisState[i][k] = axes[k];
+ }
+
+ gamepadAxisCount = axisCount;
+ }
+ }
+
+ glfwPollEvents(); // Register keyboard/mouse events (callbacks)... and window events!
+#endif
+
+// Gamepad support using emscripten API
+// NOTE: GLFW3 joystick functionality not available in web
+#if defined(PLATFORM_WEB)
+ // Get number of gamepads connected
+ int numGamepads = emscripten_get_num_gamepads();
+
+ for (int i = 0; (i < numGamepads) && (i < MAX_GAMEPADS); i++)
+ {
+ // Register previous gamepad button states
+ for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k];
+
+ EmscriptenGamepadEvent gamepadState;
+
+ int result = emscripten_get_gamepad_status(i, &gamepadState);
+
+ if (result == EMSCRIPTEN_RESULT_SUCCESS)
+ {
+ // Register buttons data for every connected gamepad
+ for (int j = 0; (j < gamepadState.numButtons) && (j < MAX_GAMEPAD_BUTTONS); j++)
+ {
+ if (gamepadState.digitalButton[j] == 1)
+ {
+ currentGamepadState[i][j] = 1;
+ lastGamepadButtonPressed = j;
+ }
+ else currentGamepadState[i][j] = 0;
+
+ //printf("Gamepad %d, button %d: Digital: %d, Analog: %g\n", gamepadState.index, j, gamepadState.digitalButton[j], gamepadState.analogButton[j]);
+ }
+
+ // Register axis data for every connected gamepad
+ for (int j = 0; (j < gamepadState.numAxes) && (j < MAX_GAMEPAD_AXIS); j++)
+ {
+ gamepadAxisState[i][j] = gamepadState.axis[j];
+ }
+
+ gamepadAxisCount = gamepadState.numAxes;
+ }
+ }
+#endif
+
+#if defined(PLATFORM_ANDROID)
+ // Register previous keys states
+ // NOTE: Android supports up to 260 keys
+ for (int i = 0; i < 260; i++) previousKeyState[i] = currentKeyState[i];
+
+ // Poll Events (registered events)
+ // NOTE: Activity is paused if not enabled (appEnabled)
+ while ((ident = ALooper_pollAll(appEnabled ? 0 : -1, NULL, &events,(void**)&source)) >= 0)
+ {
+ // Process this event
+ if (source != NULL) source->process(app, source);
+
+ // NOTE: Never close window, native activity is controlled by the system!
+ if (app->destroyRequested != 0)
+ {
+ //TraceLog(LOG_INFO, "Closing Window...");
+ //windowShouldClose = true;
+ //ANativeActivity_finish(app->activity);
+ }
+ }
+#endif
+
+#if defined(PLATFORM_RPI)
+ // NOTE: Mouse input events polling is done asynchonously in another pthread - MouseThread()
+
+ // NOTE: Keyboard reading could be done using input_event(s) reading or just read from stdin,
+ // we use method 2 (stdin) but maybe in a future we should change to method 1...
+ ProcessKeyboard();
+
+ // NOTE: Gamepad (Joystick) input events polling is done asynchonously in another pthread - GamepadThread()
+#endif
+}
+
+// Copy back buffer to front buffers
+static void SwapBuffers(void)
+{
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+ glfwSwapBuffers(window);
+#endif
+
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ eglSwapBuffers(display, surface);
+#endif
+}
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+// GLFW3 Error Callback, runs on GLFW3 error
+static void ErrorCallback(int error, const char *description)
+{
+ TraceLog(LOG_WARNING, "[GLFW3 Error] Code: %i Decription: %s", error, description);
+}
+
+// GLFW3 Srolling Callback, runs on mouse wheel
+static void ScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
+{
+ currentMouseWheelY = (int)yoffset;
+}
+
+// GLFW3 Keyboard Callback, runs on key pressed
+static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
+{
+ if (key == exitKey && action == GLFW_PRESS)
+ {
+ glfwSetWindowShouldClose(window, GL_TRUE);
+
+ // NOTE: Before closing window, while loop must be left!
+ }
+#if defined(PLATFORM_DESKTOP)
+ else if (key == GLFW_KEY_F12 && action == GLFW_PRESS)
+ {
+ #if defined(SUPPORT_GIF_RECORDING)
+ if (mods == GLFW_MOD_CONTROL)
+ {
+ if (gifRecording)
+ {
+ GifEnd();
+ gifRecording = false;
+
+ TraceLog(LOG_INFO, "End animated GIF recording");
+ }
+ else
+ {
+ gifRecording = true;
+ gifFramesCounter = 0;
+
+ // NOTE: delay represents the time between frames in the gif, if we capture a gif frame every
+ // 10 game frames and each frame trakes 16.6ms (60fps), delay between gif frames should be ~16.6*10.
+ GifBegin(FormatText("screenrec%03i.gif", screenshotCounter), screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false);
+ screenshotCounter++;
+
+ TraceLog(LOG_INFO, "Begin animated GIF recording: %s", FormatText("screenrec%03i.gif", screenshotCounter));
+ }
+ }
+ else
+ #endif // SUPPORT_GIF_RECORDING
+ {
+ TakeScreenshot(FormatText("screenshot%03i.png", screenshotCounter));
+ screenshotCounter++;
+ }
+ }
+#endif // PLATFORM_DESKTOP
+ else
+ {
+ currentKeyState[key] = action;
+ if (action == GLFW_PRESS) lastKeyPressed = key;
+ }
+}
+
+// GLFW3 Mouse Button Callback, runs on mouse button pressed
+static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
+{
+ currentMouseState[button] = action;
+
+#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
+ // Process mouse events as touches to be able to use mouse-gestures
+ GestureEvent gestureEvent;
+
+ // Register touch actions
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) gestureEvent.touchAction = TOUCH_DOWN;
+ else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) gestureEvent.touchAction = TOUCH_UP;
+
+ // NOTE: TOUCH_MOVE event is registered in MouseCursorPosCallback()
+
+ // Assign a pointer ID
+ gestureEvent.pointerId[0] = 0;
+
+ // Register touch points count
+ gestureEvent.pointCount = 1;
+
+ // Register touch points position, only one point registered
+ gestureEvent.position[0] = GetMousePosition();
+
+ // Normalize gestureEvent.position[0] for screenWidth and screenHeight
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+#endif
+}
+
+// GLFW3 Cursor Position Callback, runs on mouse move
+static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
+{
+#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
+ // Process mouse events as touches to be able to use mouse-gestures
+ GestureEvent gestureEvent;
+
+ gestureEvent.touchAction = TOUCH_MOVE;
+
+ // Assign a pointer ID
+ gestureEvent.pointerId[0] = 0;
+
+ // Register touch points count
+ gestureEvent.pointCount = 1;
+
+ // Register touch points position, only one point registered
+ gestureEvent.position[0] = (Vector2){ (float)x, (float)y };
+
+ touchPosition[0] = gestureEvent.position[0];
+
+ // Normalize gestureEvent.position[0] for screenWidth and screenHeight
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+#endif
+}
+
+// GLFW3 Char Key Callback, runs on key pressed (get char value)
+static void CharCallback(GLFWwindow *window, unsigned int key)
+{
+ lastKeyPressed = key;
+
+ //TraceLog(LOG_INFO, "Char Callback Key pressed: %i\n", key);
+}
+
+// GLFW3 CursorEnter Callback, when cursor enters the window
+static void CursorEnterCallback(GLFWwindow *window, int enter)
+{
+ if (enter == true) cursorOnScreen = true;
+ else cursorOnScreen = false;
+}
+
+// GLFW3 WindowSize Callback, runs when window is resized
+// NOTE: Window resizing not allowed by default
+static void WindowSizeCallback(GLFWwindow *window, int width, int height)
+{
+ // If window is resized, viewport and projection matrix needs to be re-calculated
+ rlViewport(0, 0, width, height); // Set viewport width and height
+ rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
+ rlLoadIdentity(); // Reset current matrix (PROJECTION)
+ rlOrtho(0, width, height, 0, 0.0f, 1.0f); // Orthographic projection mode with top-left corner at (0,0)
+ rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+ rlClearScreenBuffers(); // Clear screen buffers (color and depth)
+
+ // Window size must be updated to be used on 3D mode to get new aspect ratio (Begin3dMode())
+ screenWidth = width;
+ screenHeight = height;
+ renderWidth = width;
+ renderHeight = height;
+
+ // NOTE: Postprocessing texture is not scaled to new size
+}
+
+// GLFW3 WindowIconify Callback, runs when window is minimized/restored
+static void WindowIconifyCallback(GLFWwindow* window, int iconified)
+{
+ if (iconified) windowMinimized = true; // The window was iconified
+ else windowMinimized = false; // The window was restored
+}
+#endif
+
+#if defined(PLATFORM_DESKTOP)
+// GLFW3 Window Drop Callback, runs when drop files into window
+// NOTE: Paths are stored in dinamic memory for further retrieval
+// Everytime new files are dropped, old ones are discarded
+static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
+{
+ ClearDroppedFiles();
+
+ dropFilesPath = (char **)malloc(sizeof(char *)*count);
+
+ for (int i = 0; i < count; i++)
+ {
+ dropFilesPath[i] = (char *)malloc(sizeof(char)*256); // Max path length set to 256 char
+ strcpy(dropFilesPath[i], paths[i]);
+ }
+
+ dropFilesCount = count;
+}
+#endif
+
+#if defined(PLATFORM_ANDROID)
+// Android: Process activity lifecycle commands
+static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
+{
+ switch (cmd)
+ {
+ case APP_CMD_START:
+ {
+ //rendering = true;
+ TraceLog(LOG_INFO, "APP_CMD_START");
+ } break;
+ case APP_CMD_RESUME:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_RESUME");
+ } break;
+ case APP_CMD_INIT_WINDOW:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_INIT_WINDOW");
+
+ if (app->window != NULL)
+ {
+ if (contextRebindRequired)
+ {
+ // Reset screen scaling to full display size
+ EGLint displayFormat;
+ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &displayFormat);
+ ANativeWindow_setBuffersGeometry(app->window, renderWidth, renderHeight, displayFormat);
+
+ // Recreate display surface and re-attach OpenGL context
+ surface = eglCreateWindowSurface(display, config, app->window, NULL);
+ eglMakeCurrent(display, surface, surface, context);
+
+ contextRebindRequired = false;
+ }
+ else
+ {
+ // Init graphics device (display device and OpenGL context)
+ InitGraphicsDevice(screenWidth, screenHeight);
+
+ #if defined(SUPPORT_DEFAULT_FONT)
+ // Load default font
+ // NOTE: External function (defined in module: text)
+ LoadDefaultFont();
+ #endif
+
+ // TODO: GPU assets reload in case of lost focus (lost context)
+ // NOTE: This problem has been solved just unbinding and rebinding context from display
+ /*
+ if (assetsReloadRequired)
+ {
+ for (int i = 0; i < assetsCount; i++)
+ {
+ // TODO: Unload old asset if required
+
+ // Load texture again to pointed texture
+ (*textureAsset + i) = LoadTexture(assetPath[i]);
+ }
+ }
+ */
+
+ // Init hi-res timer
+ InitTimer();
+
+ // raylib logo appearing animation (if enabled)
+ if (showLogo)
+ {
+ SetTargetFPS(60); // Not required on Android
+ LogoAnimation();
+ }
+ }
+ }
+ } break;
+ case APP_CMD_GAINED_FOCUS:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_GAINED_FOCUS");
+ appEnabled = true;
+ //ResumeMusicStream();
+ } break;
+ case APP_CMD_PAUSE:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_PAUSE");
+ } break;
+ case APP_CMD_LOST_FOCUS:
+ {
+ //DrawFrame();
+ TraceLog(LOG_INFO, "APP_CMD_LOST_FOCUS");
+ appEnabled = false;
+ //PauseMusicStream();
+ } break;
+ case APP_CMD_TERM_WINDOW:
+ {
+ // Dettach OpenGL context and destroy display surface
+ // NOTE 1: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
+ // NOTE 2: In some cases (too many context loaded), OS could unload context automatically... :(
+ eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroySurface(display, surface);
+
+ contextRebindRequired = true;
+
+ TraceLog(LOG_INFO, "APP_CMD_TERM_WINDOW");
+ } break;
+ case APP_CMD_SAVE_STATE:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_SAVE_STATE");
+ } break;
+ case APP_CMD_STOP:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_STOP");
+ } break;
+ case APP_CMD_DESTROY:
+ {
+ // TODO: Finish activity?
+ //ANativeActivity_finish(app->activity);
+
+ TraceLog(LOG_INFO, "APP_CMD_DESTROY");
+ } break;
+ case APP_CMD_CONFIG_CHANGED:
+ {
+ //AConfiguration_fromAssetManager(app->config, app->activity->assetManager);
+ //print_cur_config(app);
+
+ // Check screen orientation here!
+
+ TraceLog(LOG_INFO, "APP_CMD_CONFIG_CHANGED");
+ } break;
+ default: break;
+ }
+}
+
+// Android: Get input events
+static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
+{
+ //http://developer.android.com/ndk/reference/index.html
+
+ int type = AInputEvent_getType(event);
+
+ if (type == AINPUT_EVENT_TYPE_MOTION)
+ {
+ // Get first touch position
+ touchPosition[0].x = AMotionEvent_getX(event, 0);
+ touchPosition[0].y = AMotionEvent_getY(event, 0);
+
+ // Get second touch position
+ touchPosition[1].x = AMotionEvent_getX(event, 1);
+ touchPosition[1].y = AMotionEvent_getY(event, 1);
+ }
+ else if (type == AINPUT_EVENT_TYPE_KEY)
+ {
+ int32_t keycode = AKeyEvent_getKeyCode(event);
+ //int32_t AKeyEvent_getMetaState(event);
+
+ // Save current button and its state
+ // NOTE: Android key action is 0 for down and 1 for up
+ if (AKeyEvent_getAction(event) == 0)
+ {
+ currentKeyState[keycode] = 1; // Key down
+ lastKeyPressed = keycode;
+ }
+ else currentKeyState[keycode] = 0; // Key up
+
+ if (keycode == AKEYCODE_POWER)
+ {
+ // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
+ // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
+ // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
+ // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
+ // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
+ return 0;
+ }
+ else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
+ {
+ // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
+ return 1;
+ }
+ else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
+ {
+ // Set default OS behaviour
+ return 0;
+ }
+ }
+
+ int32_t action = AMotionEvent_getAction(event);
+ unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
+
+#if defined(SUPPORT_GESTURES_SYSTEM)
+ GestureEvent gestureEvent;
+
+ // Register touch actions
+ if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_DOWN;
+ else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_UP;
+ else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
+
+ // Register touch points count
+ gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
+
+ // Register touch points id
+ gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0);
+ gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1);
+
+ // Register touch points position
+ // NOTE: Only two points registered
+ gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
+ gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
+
+ // Normalize gestureEvent.position[x] for screenWidth and screenHeight
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+#else
+
+ // TODO: Support only simple touch position
+
+#endif
+
+ return 0; // return 1;
+}
+#endif
+
+#if defined(PLATFORM_WEB)
+
+// Register fullscreen change events
+static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData)
+{
+ //isFullscreen: int e->isFullscreen
+ //fullscreenEnabled: int e->fullscreenEnabled
+ //fs element nodeName: (char *) e->nodeName
+ //fs element id: (char *) e->id
+ //Current element size: (int) e->elementWidth, (int) e->elementHeight
+ //Screen size:(int) e->screenWidth, (int) e->screenHeight
+
+ if (e->isFullscreen)
+ {
+ TraceLog(LOG_INFO, "Canvas scaled to fullscreen. ElementSize: (%ix%i), ScreenSize(%ix%i)", e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
+ }
+ else
+ {
+ TraceLog(LOG_INFO, "Canvas scaled to windowed. ElementSize: (%ix%i), ScreenSize(%ix%i)", e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
+ }
+
+ // TODO: Depending on scaling factor (screen vs element), calculate factor to scale mouse/touch input
+
+ return 0;
+}
+
+// Register keyboard input events
+static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
+{
+ if ((eventType == EMSCRIPTEN_EVENT_KEYPRESS) && (strcmp(keyEvent->code, "Escape") == 0))
+ {
+ emscripten_exit_pointerlock();
+ }
+
+ return 0;
+}
+
+// Register mouse input events
+static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
+{
+ // Lock mouse pointer when click on screen
+ if ((eventType == EMSCRIPTEN_EVENT_CLICK) && toggleCursorLock)
+ {
+ EmscriptenPointerlockChangeEvent plce;
+ emscripten_get_pointerlock_status(&plce);
+
+ if (!plce.isActive) emscripten_request_pointerlock(0, 1);
+ else
+ {
+ emscripten_exit_pointerlock();
+ emscripten_get_pointerlock_status(&plce);
+ //if (plce.isActive) TraceLog(LOG_WARNING, "Pointer lock exit did not work!");
+ }
+
+ toggleCursorLock = false;
+ }
+
+ return 0;
+}
+
+// Register touch input events
+static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
+{
+ /*
+ for (int i = 0; i < touchEvent->numTouches; i++)
+ {
+ long x, y, id;
+
+ if (!touchEvent->touches[i].isChanged) continue;
+
+ id = touchEvent->touches[i].identifier;
+ x = touchEvent->touches[i].canvasX;
+ y = touchEvent->touches[i].canvasY;
+ }
+
+ printf("%s, numTouches: %d %s%s%s%s\n", emscripten_event_type_to_string(eventType), event->numTouches,
+ event->ctrlKey ? " CTRL" : "", event->shiftKey ? " SHIFT" : "", event->altKey ? " ALT" : "", event->metaKey ? " META" : "");
+
+ for (int i = 0; i < event->numTouches; ++i)
+ {
+ const EmscriptenTouchPoint *t = &event->touches[i];
+
+ printf(" %ld: screen: (%ld,%ld), client: (%ld,%ld), page: (%ld,%ld), isChanged: %d, onTarget: %d, canvas: (%ld, %ld)\n",
+ t->identifier, t->screenX, t->screenY, t->clientX, t->clientY, t->pageX, t->pageY, t->isChanged, t->onTarget, t->canvasX, t->canvasY);
+ }
+ */
+
+ GestureEvent gestureEvent;
+
+ // Register touch actions
+ if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_DOWN;
+ else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_UP;
+ else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_MOVE;
+
+ // Register touch points count
+ gestureEvent.pointCount = touchEvent->numTouches;
+
+ // Register touch points id
+ gestureEvent.pointerId[0] = touchEvent->touches[0].identifier;
+ gestureEvent.pointerId[1] = touchEvent->touches[1].identifier;
+
+ // Register touch points position
+ // NOTE: Only two points registered
+ // TODO: Touch data should be scaled accordingly!
+ //gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].canvasX, touchEvent->touches[0].canvasY };
+ //gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].canvasX, touchEvent->touches[1].canvasY };
+ gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].targetX, touchEvent->touches[0].targetY };
+ gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].targetX, touchEvent->touches[1].targetY };
+
+ touchPosition[0] = gestureEvent.position[0];
+ touchPosition[1] = gestureEvent.position[1];
+
+ // Normalize gestureEvent.position[x] for screenWidth and screenHeight
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+
+ return 1;
+}
+
+// Register connected/disconnected gamepads events
+static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
+{
+ /*
+ printf("%s: timeStamp: %g, connected: %d, index: %ld, numAxes: %d, numButtons: %d, id: \"%s\", mapping: \"%s\"\n",
+ eventType != 0 ? emscripten_event_type_to_string(eventType) : "Gamepad state",
+ gamepadEvent->timestamp, gamepadEvent->connected, gamepadEvent->index, gamepadEvent->numAxes, gamepadEvent->numButtons, gamepadEvent->id, gamepadEvent->mapping);
+
+ for(int i = 0; i < gamepadEvent->numAxes; ++i) printf("Axis %d: %g\n", i, gamepadEvent->axis[i]);
+ for(int i = 0; i < gamepadEvent->numButtons; ++i) printf("Button %d: Digital: %d, Analog: %g\n", i, gamepadEvent->digitalButton[i], gamepadEvent->analogButton[i]);
+ */
+
+ if ((gamepadEvent->connected) && (gamepadEvent->index < MAX_GAMEPADS)) gamepadReady[gamepadEvent->index] = true;
+ else gamepadReady[gamepadEvent->index] = false;
+
+ // TODO: Test gamepadEvent->index
+
+ return 0;
+}
+#endif
+
+#if defined(PLATFORM_RPI)
+// Initialize Keyboard system (using standard input)
+static void InitKeyboard(void)
+{
+ // NOTE: We read directly from Standard Input (stdin) - STDIN_FILENO file descriptor
+
+ // Make stdin non-blocking (not enough, need to configure to non-canonical mode)
+ int flags = fcntl(STDIN_FILENO, F_GETFL, 0); // F_GETFL: Get the file access mode and the file status flags
+ fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK); // F_SETFL: Set the file status flags to the value specified
+
+ // Save terminal keyboard settings and reconfigure terminal with new settings
+ struct termios keyboardNewSettings;
+ tcgetattr(STDIN_FILENO, &defaultKeyboardSettings); // Get current keyboard settings
+ keyboardNewSettings = defaultKeyboardSettings;
+
+ // New terminal settings for keyboard: turn off buffering (non-canonical mode), echo and key processing
+ // NOTE: ISIG controls if ^C and ^Z generate break signals or not
+ keyboardNewSettings.c_lflag &= ~(ICANON | ECHO | ISIG);
+ //keyboardNewSettings.c_iflag &= ~(ISTRIP | INLCR | ICRNL | IGNCR | IXON | IXOFF);
+ keyboardNewSettings.c_cc[VMIN] = 1;
+ keyboardNewSettings.c_cc[VTIME] = 0;
+
+ // Set new keyboard settings (change occurs immediately)
+ tcsetattr(STDIN_FILENO, TCSANOW, &keyboardNewSettings);
+
+ // NOTE: Reading directly from stdin will give chars already key-mapped by kernel to ASCII or UNICODE, we change that! -> WHY???
+
+ // Save old keyboard mode to restore it at the end
+ if (ioctl(STDIN_FILENO, KDGKBMODE, &defaultKeyboardMode) < 0)
+ {
+ // NOTE: It could mean we are using a remote keyboard through ssh!
+ TraceLog(LOG_WARNING, "Could not change keyboard mode (SSH keyboard?)");
+ }
+ else
+ {
+ // We reconfigure keyboard mode to get:
+ // - scancodes (K_RAW)
+ // - keycodes (K_MEDIUMRAW)
+ // - ASCII chars (K_XLATE)
+ // - UNICODE chars (K_UNICODE)
+ ioctl(STDIN_FILENO, KDSKBMODE, K_XLATE);
+ }
+
+ // Register keyboard restore when program finishes
+ atexit(RestoreKeyboard);
+}
+
+// Process keyboard inputs
+// TODO: Most probably input reading and processing should be in a separate thread
+static void ProcessKeyboard(void)
+{
+ #define MAX_KEYBUFFER_SIZE 32 // Max size in bytes to read
+
+ // Keyboard input polling (fill keys[256] array with status)
+ int bufferByteCount = 0; // Bytes available on the buffer
+ char keysBuffer[MAX_KEYBUFFER_SIZE]; // Max keys to be read at a time
+
+ // Reset pressed keys array
+ for (int i = 0; i < 512; i++) currentKeyState[i] = 0;
+
+ // Read availables keycodes from stdin
+ bufferByteCount = read(STDIN_FILENO, keysBuffer, MAX_KEYBUFFER_SIZE); // POSIX system call
+
+ // Fill all read bytes (looking for keys)
+ for (int i = 0; i < bufferByteCount; i++)
+ {
+ TraceLog(LOG_DEBUG, "Bytes on keysBuffer: %i", bufferByteCount);
+
+ //printf("Key(s) bytes: ");
+ //for (int i = 0; i < bufferByteCount; i++) printf("0x%02x ", keysBuffer[i]);
+ //printf("\n");
+
+ // NOTE: If (key == 0x1b), depending on next key, it could be a special keymap code!
+ // Up -> 1b 5b 41 / Left -> 1b 5b 44 / Right -> 1b 5b 43 / Down -> 1b 5b 42
+ if (keysBuffer[i] == 0x1b)
+ {
+ // Detect ESC to stop program
+ if (bufferByteCount == 1) currentKeyState[256] = 1; // raylib key: KEY_ESCAPE
+ else
+ {
+ if (keysBuffer[i + 1] == 0x5b) // Special function key
+ {
+ if ((keysBuffer[i + 2] == 0x5b) || (keysBuffer[i + 2] == 0x31) || (keysBuffer[i + 2] == 0x32))
+ {
+ // Process special function keys (F1 - F12)
+ switch (keysBuffer[i + 3])
+ {
+ case 0x41: currentKeyState[290] = 1; break; // raylib KEY_F1
+ case 0x42: currentKeyState[291] = 1; break; // raylib KEY_F2
+ case 0x43: currentKeyState[292] = 1; break; // raylib KEY_F3
+ case 0x44: currentKeyState[293] = 1; break; // raylib KEY_F4
+ case 0x45: currentKeyState[294] = 1; break; // raylib KEY_F5
+ case 0x37: currentKeyState[295] = 1; break; // raylib KEY_F6
+ case 0x38: currentKeyState[296] = 1; break; // raylib KEY_F7
+ case 0x39: currentKeyState[297] = 1; break; // raylib KEY_F8
+ case 0x30: currentKeyState[298] = 1; break; // raylib KEY_F9
+ case 0x31: currentKeyState[299] = 1; break; // raylib KEY_F10
+ case 0x33: currentKeyState[300] = 1; break; // raylib KEY_F11
+ case 0x34: currentKeyState[301] = 1; break; // raylib KEY_F12
+ default: break;
+ }
+
+ if (keysBuffer[i + 2] == 0x5b) i += 4;
+ else if ((keysBuffer[i + 2] == 0x31) || (keysBuffer[i + 2] == 0x32)) i += 5;
+ }
+ else
+ {
+ switch (keysBuffer[i + 2])
+ {
+ case 0x41: currentKeyState[265] = 1; break; // raylib KEY_UP
+ case 0x42: currentKeyState[264] = 1; break; // raylib KEY_DOWN
+ case 0x43: currentKeyState[262] = 1; break; // raylib KEY_RIGHT
+ case 0x44: currentKeyState[263] = 1; break; // raylib KEY_LEFT
+ default: break;
+ }
+
+ i += 3; // Jump to next key
+ }
+
+ // NOTE: Some keys are not directly keymapped (CTRL, ALT, SHIFT)
+ }
+ }
+ }
+ else if (keysBuffer[i] == 0x0a) currentKeyState[257] = 1; // raylib KEY_ENTER (don't mix with <linux/input.h> KEY_*)
+ else if (keysBuffer[i] == 0x7f) currentKeyState[259] = 1; // raylib KEY_BACKSPACE
+ else
+ {
+ TraceLog(LOG_DEBUG, "Pressed key (ASCII): 0x%02x", keysBuffer[i]);
+
+ // Translate lowercase a-z letters to A-Z
+ if ((keysBuffer[i] >= 97) && (keysBuffer[i] <= 122))
+ {
+ currentKeyState[(int)keysBuffer[i] - 32] = 1;
+ }
+ else currentKeyState[(int)keysBuffer[i]] = 1;
+ }
+ }
+
+ // Check exit key (same functionality as GLFW3 KeyCallback())
+ if (currentKeyState[exitKey] == 1) windowShouldClose = true;
+
+ // Check screen capture key (raylib key: KEY_F12)
+ if (currentKeyState[301] == 1)
+ {
+ TakeScreenshot(FormatText("screenshot%03i.png", screenshotCounter));
+ screenshotCounter++;
+ }
+}
+
+// Restore default keyboard input
+static void RestoreKeyboard(void)
+{
+ // Reset to default keyboard settings
+ tcsetattr(STDIN_FILENO, TCSANOW, &defaultKeyboardSettings);
+
+ // Reconfigure keyboard to default mode
+ ioctl(STDIN_FILENO, KDSKBMODE, defaultKeyboardMode);
+}
+
+// Mouse initialization (including mouse thread)
+static void InitMouse(void)
+{
+ // NOTE: We can use /dev/input/mice to read from all available mice
+ if ((mouseStream = open(DEFAULT_MOUSE_DEV, O_RDONLY|O_NONBLOCK)) < 0)
+ {
+ TraceLog(LOG_WARNING, "Mouse device could not be opened, no mouse available");
+ }
+ else
+ {
+ mouseReady = true;
+
+ int error = pthread_create(&mouseThreadId, NULL, &MouseThread, NULL);
+
+ if (error != 0) TraceLog(LOG_WARNING, "Error creating mouse input event thread");
+ else TraceLog(LOG_INFO, "Mouse device initialized successfully");
+ }
+}
+
+// Mouse reading thread
+// NOTE: We need a separate thread to avoid loosing mouse events,
+// if too much time passes between reads, queue gets full and new events override older ones...
+static void *MouseThread(void *arg)
+{
+ const unsigned char XSIGN = (1 << 4);
+ const unsigned char YSIGN = (1 << 5);
+
+ typedef struct {
+ char buttons;
+ char dx, dy;
+ } MouseEvent;
+
+ MouseEvent mouse;
+
+ int mouseRelX = 0;
+ int mouseRelY = 0;
+
+ while (!windowShouldClose)
+ {
+ if (read(mouseStream, &mouse, sizeof(MouseEvent)) == (int)sizeof(MouseEvent))
+ {
+ if ((mouse.buttons & 0x08) == 0) break; // This bit should always be set
+
+ // Check Left button pressed
+ if ((mouse.buttons & 0x01) > 0) currentMouseState[0] = 1;
+ else currentMouseState[0] = 0;
+
+ // Check Right button pressed
+ if ((mouse.buttons & 0x02) > 0) currentMouseState[1] = 1;
+ else currentMouseState[1] = 0;
+
+ // Check Middle button pressed
+ if ((mouse.buttons & 0x04) > 0) currentMouseState[2] = 1;
+ else currentMouseState[2] = 0;
+
+ mouseRelX = (int)mouse.dx;
+ mouseRelY = (int)mouse.dy;
+
+ if ((mouse.buttons & XSIGN) > 0) mouseRelX = -1*(255 - mouseRelX);
+ if ((mouse.buttons & YSIGN) > 0) mouseRelY = -1*(255 - mouseRelY);
+
+ // NOTE: Mouse movement is normalized to not be screen resolution dependant
+ // We suppose 2*255 (max relative movement) is equivalent to screenWidth (max pixels width)
+ // Result after normalization is multiplied by MOUSE_SENSITIVITY factor
+
+ mousePosition.x += (float)mouseRelX*((float)screenWidth/(2*255))*MOUSE_SENSITIVITY;
+ mousePosition.y -= (float)mouseRelY*((float)screenHeight/(2*255))*MOUSE_SENSITIVITY;
+
+ if (mousePosition.x < 0) mousePosition.x = 0;
+ if (mousePosition.y < 0) mousePosition.y = 0;
+
+ if (mousePosition.x > screenWidth) mousePosition.x = screenWidth;
+ if (mousePosition.y > screenHeight) mousePosition.y = screenHeight;
+ }
+ //else read(mouseStream, &mouse, 1); // Try to sync up again
+ }
+
+ return NULL;
+}
+
+// Touch initialization (including touch thread)
+static void InitTouch(void)
+{
+ if ((touchStream = open(DEFAULT_TOUCH_DEV, O_RDONLY|O_NONBLOCK)) < 0)
+ {
+ TraceLog(LOG_WARNING, "Touch device could not be opened, no touchscreen available");
+ }
+ else
+ {
+ touchReady = true;
+
+ int error = pthread_create(&touchThreadId, NULL, &TouchThread, NULL);
+
+ if (error != 0) TraceLog(LOG_WARNING, "Error creating touch input event thread");
+ else TraceLog(LOG_INFO, "Touch device initialized successfully");
+ }
+}
+
+// Touch reading thread.
+// This reads from a Virtual Input Event /dev/input/event4 which is
+// created by the ts_uinput daemon. This takes, filters and scales
+// raw input from the Touchscreen (which appears in /dev/input/event3)
+// based on the Calibration data referenced by tslib.
+static void *TouchThread(void *arg)
+{
+ struct input_event ev;
+ GestureEvent gestureEvent;
+
+ while (!windowShouldClose)
+ {
+ if (read(touchStream, &ev, sizeof(ev)) == (int)sizeof(ev))
+ {
+ // if pressure > 0 then simulate left mouse button click
+ if (ev.type == EV_ABS && ev.code == 24 && ev.value == 0 && currentMouseState[0] == 1)
+ {
+ currentMouseState[0] = 0;
+ gestureEvent.touchAction = TOUCH_UP;
+ gestureEvent.pointCount = 1;
+ gestureEvent.pointerId[0] = 0;
+ gestureEvent.pointerId[1] = 1;
+ gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+ ProcessGestureEvent(gestureEvent);
+ }
+ if (ev.type == EV_ABS && ev.code == 24 && ev.value > 0 && currentMouseState[0] == 0)
+ {
+ currentMouseState[0] = 1;
+ gestureEvent.touchAction = TOUCH_DOWN;
+ gestureEvent.pointCount = 1;
+ gestureEvent.pointerId[0] = 0;
+ gestureEvent.pointerId[1] = 1;
+ gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+ ProcessGestureEvent(gestureEvent);
+ }
+ // x & y values supplied by event4 have been scaled & de-jittered using tslib calibration data
+ if (ev.type == EV_ABS && ev.code == 0)
+ {
+ mousePosition.x = ev.value;
+ if (mousePosition.x < 0) mousePosition.x = 0;
+ if (mousePosition.x > screenWidth) mousePosition.x = screenWidth;
+ gestureEvent.touchAction = TOUCH_MOVE;
+ gestureEvent.pointCount = 1;
+ gestureEvent.pointerId[0] = 0;
+ gestureEvent.pointerId[1] = 1;
+ gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+ ProcessGestureEvent(gestureEvent);
+ }
+ if (ev.type == EV_ABS && ev.code == 1)
+ {
+ mousePosition.y = ev.value;
+ if (mousePosition.y < 0) mousePosition.y = 0;
+ if (mousePosition.y > screenHeight) mousePosition.y = screenHeight;
+ gestureEvent.touchAction = TOUCH_MOVE;
+ gestureEvent.pointCount = 1;
+ gestureEvent.pointerId[0] = 0;
+ gestureEvent.pointerId[1] = 1;
+ gestureEvent.position[0] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[1] = (Vector2){ mousePosition.x, mousePosition.y };
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+ ProcessGestureEvent(gestureEvent);
+ }
+
+ }
+ }
+ return NULL;
+}
+
+// Init gamepad system
+static void InitGamepad(void)
+{
+ char gamepadDev[128] = "";
+
+ for (int i = 0; i < MAX_GAMEPADS; i++)
+ {
+ sprintf(gamepadDev, "%s%i", DEFAULT_GAMEPAD_DEV, i);
+
+ if ((gamepadStream[i] = open(gamepadDev, O_RDONLY|O_NONBLOCK)) < 0)
+ {
+ // NOTE: Only show message for first gamepad
+ if (i == 0) TraceLog(LOG_WARNING, "Gamepad device could not be opened, no gamepad available");
+ }
+ else
+ {
+ gamepadReady[i] = true;
+
+ // NOTE: Only create one thread
+ if (i == 0)
+ {
+ int error = pthread_create(&gamepadThreadId, NULL, &GamepadThread, NULL);
+
+ if (error != 0) TraceLog(LOG_WARNING, "Error creating gamepad input event thread");
+ else TraceLog(LOG_INFO, "Gamepad device initialized successfully");
+ }
+ }
+ }
+}
+
+// Process Gamepad (/dev/input/js0)
+static void *GamepadThread(void *arg)
+{
+ #define JS_EVENT_BUTTON 0x01 // Button pressed/released
+ #define JS_EVENT_AXIS 0x02 // Joystick axis moved
+ #define JS_EVENT_INIT 0x80 // Initial state of device
+
+ struct js_event {
+ unsigned int time; // event timestamp in milliseconds
+ short value; // event value
+ unsigned char type; // event type
+ unsigned char number; // event axis/button number
+ };
+
+ // Read gamepad event
+ struct js_event gamepadEvent;
+
+ while (!windowShouldClose)
+ {
+ for (int i = 0; i < MAX_GAMEPADS; i++)
+ {
+ if (read(gamepadStream[i], &gamepadEvent, sizeof(struct js_event)) == (int)sizeof(struct js_event))
+ {
+ gamepadEvent.type &= ~JS_EVENT_INIT; // Ignore synthetic events
+
+ // Process gamepad events by type
+ if (gamepadEvent.type == JS_EVENT_BUTTON)
+ {
+ TraceLog(LOG_DEBUG, "Gamepad button: %i, value: %i", gamepadEvent.number, gamepadEvent.value);
+
+ if (gamepadEvent.number < MAX_GAMEPAD_BUTTONS)
+ {
+ // 1 - button pressed, 0 - button released
+ 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)
+ {
+ TraceLog(LOG_DEBUG, "Gamepad axis: %i, value: %i", gamepadEvent.number, gamepadEvent.value);
+
+ if (gamepadEvent.number < MAX_GAMEPAD_AXIS)
+ {
+ // NOTE: Scaling of gamepadEvent.value to get values between -1..1
+ gamepadAxisState[i][gamepadEvent.number] = (float)gamepadEvent.value/32768;
+ }
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+#endif // PLATFORM_RPI
+
+// Plays raylib logo appearing animation
+static void LogoAnimation(void)
+{
+#if !defined(PLATFORM_WEB)
+ int logoPositionX = screenWidth/2 - 128;
+ int logoPositionY = screenHeight/2 - 128;
+
+ int framesCounter = 0;
+ int lettersCount = 0;
+
+ int topSideRecWidth = 16;
+ int leftSideRecHeight = 16;
+
+ int bottomSideRecWidth = 16;
+ int rightSideRecHeight = 16;
+
+ int state = 0; // Tracking animation states (State Machine)
+ float alpha = 1.0f; // Useful for fading
+
+ while (!WindowShouldClose() && (state != 4)) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (state == 0) // State 0: Small box blinking
+ {
+ framesCounter++;
+
+ if (framesCounter == 84)
+ {
+ state = 1;
+ framesCounter = 0; // Reset counter... will be used later...
+ }
+ }
+ else if (state == 1) // State 1: Top and left bars growing
+ {
+ topSideRecWidth += 4;
+ leftSideRecHeight += 4;
+
+ if (topSideRecWidth == 256) state = 2;
+ }
+ else if (state == 2) // State 2: Bottom and right bars growing
+ {
+ bottomSideRecWidth += 4;
+ rightSideRecHeight += 4;
+
+ if (bottomSideRecWidth == 256) state = 3;
+ }
+ else if (state == 3) // State 3: Letters appearing (one by one)
+ {
+ framesCounter++;
+
+ if (framesCounter/12) // Every 12 frames, one more letter!
+ {
+ lettersCount++;
+ framesCounter = 0;
+ }
+
+ if (lettersCount >= 10) // When all letters have appeared, just fade out everything
+ {
+ alpha -= 0.02f;
+
+ if (alpha <= 0.0f)
+ {
+ alpha = 0.0f;
+ state = 4;
+ }
+ }
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ if (state == 0)
+ {
+ if ((framesCounter/12)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
+ }
+ else if (state == 1)
+ {
+ DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
+ DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
+ }
+ else if (state == 2)
+ {
+ DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
+ DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
+
+ DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
+ DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
+ }
+ else if (state == 3)
+ {
+ DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
+ DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
+
+ DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
+ DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
+
+ DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
+
+ DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
+ }
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+#endif
+
+ showLogo = false; // Prevent for repeating when reloading window (Android)
+}
diff --git a/templates/android_project/src/game_crash.c b/templates/android_project/src/game_crash.c
new file mode 100644
index 00000000..43611d22
--- /dev/null
+++ b/templates/android_project/src/game_crash.c
@@ -0,0 +1,58 @@
+/*******************************************************************************************
+*
+* raylib - Android Basic Game template
+*
+* <Game title>
+* <Game description>
+*
+* This game has been created using raylib v1.2 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include "android_native_app_glue.h"
+
+//----------------------------------------------------------------------------------
+// Android Main entry point
+//----------------------------------------------------------------------------------
+void android_main(struct android_app *app)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, app);
+
+ // TODO: Initialize all required variables and load all required data here!
+
+ SetTargetFPS(60); // Not required on Android, already locked to 60 fps
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // ...
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+} \ No newline at end of file
diff --git a/templates/android_project/src/game_ok.c b/templates/android_project/src/game_ok.c
new file mode 100644
index 00000000..eb83a6bf
--- /dev/null
+++ b/templates/android_project/src/game_ok.c
@@ -0,0 +1,684 @@
+
+//#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
+#include <errno.h>
+#include <android/log.h>
+#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
+#include <android/asset_manager.h>
+#include <android_native_app_glue.h> // Defines basic app state struct and manages activity
+
+#include <EGL/egl.h> // Khronos EGL library - Native platform display device control functions
+#include <GLES2/gl2.h> // Khronos OpenGL ES 2.0 library
+
+#include <stdio.h> // Standard input / output lib
+#include <stdlib.h> // Required for: malloc(), free(), rand(), atexit()
+#include <stdint.h> // Required for: typedef unsigned long long int uint64_t, used by hi-res timer
+#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
+#include <time.h> // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!)
+#include <math.h> // Required for: tan() [Used in Begin3dMode() to set perspective]
+#include <string.h> // Required for: strlen(), strrchr(), strcmp()
+
+//#define RLGL_STANDALONE
+//#include "rlgl.h" // rlgl library: OpenGL 1.1 immediate-mode style coding
+
+#ifndef __cplusplus
+// Boolean type
+ #if !defined(_STDBOOL_H) || !defined(__STDBOOL_H) // CLang uses second form
+ typedef enum { false, true } bool;
+ #endif
+#endif
+
+// Trace log type
+typedef enum {
+ LOG_INFO = 0,
+ LOG_WARNING,
+ LOG_ERROR,
+ LOG_DEBUG,
+ LOG_OTHER
+} LogType;
+
+static int screenWidth;
+static int screenHeight;
+
+static struct android_app *app; // Android activity
+static struct android_poll_source *source; // Android events polling source
+static int ident, events; // Android ALooper_pollAll() variables
+static const char *internalDataPath; // Android internal data path to write data (/data/data/<package>/files)
+
+static bool windowReady = false; // Used to detect display initialization
+static bool appEnabled = true; // Used to detec if app is active
+static bool contextRebindRequired = false; // Used to know context rebind required
+
+static EGLDisplay display; // Native display device (physical screen connection)
+static EGLSurface surface; // Surface to draw on, framebuffers (connected to context)
+static EGLContext context; // Graphic context, mode in which drawing can be done
+static EGLConfig config; // Graphic config
+static uint64_t baseTime; // Base time measure for hi-res timer
+static bool windowShouldClose = false; // Flag to set window for closing
+
+static AAssetManager *assetManager;
+
+static void AndroidCommandCallback(struct android_app *app, int32_t cmd); // Process Android activity lifecycle commands
+static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event); // Process Android inputs
+
+static void TraceLog(int msgType, const char *text, ...);
+
+static int android_read(void *cookie, char *buf, int size);
+static int android_write(void *cookie, const char *buf, int size);
+static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
+static int android_close(void *cookie);
+
+static void InitWindow(int width, int height, void *state); // Initialize Android activity
+static void InitGraphicsDevice(int width, int height); // Initialize graphic device
+static void CloseWindow(void); // Close window and unload OpenGL context
+static bool WindowShouldClose(void); // Check if KEY_ESCAPE pressed or Close icon pressed
+
+static void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing
+static void EndDrawing(void); // End canvas drawing and swap buffers (double buffering)
+static void SwapBuffers(void); // Copy back buffer to front buffers
+static void PollInputEvents(void); // Poll all input events
+
+//----------------------------------------------------------------------------------
+// Android Main entry point
+//----------------------------------------------------------------------------------
+void android_main(struct android_app *app)
+{
+ InitWindow(1280, 720, app);
+
+ while (!WindowShouldClose())
+ {
+ BeginDrawing();
+
+
+ EndDrawing();
+ }
+
+ CloseWindow();
+}
+
+// Initialize Android activity
+static void InitWindow(int width, int height, void *state)
+{
+ TraceLog(LOG_INFO, "Initializing raylib stripped");
+
+ screenWidth = width;
+ screenHeight = height;
+
+ app = (struct android_app *)state;
+ internalDataPath = app->activity->internalDataPath;
+
+ // Set desired windows flags before initializing anything
+ ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
+ //ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FORCE_NOT_FULLSCREEN, AWINDOW_FLAG_FULLSCREEN);
+
+ int orientation = AConfiguration_getOrientation(app->config);
+
+ if (orientation == ACONFIGURATION_ORIENTATION_PORT) TraceLog(LOG_INFO, "PORTRAIT window orientation");
+ else if (orientation == ACONFIGURATION_ORIENTATION_LAND) TraceLog(LOG_INFO, "LANDSCAPE window orientation");
+
+ // TODO: Automatic orientation doesn't seem to work
+ if (width <= height)
+ {
+ AConfiguration_setOrientation(app->config, ACONFIGURATION_ORIENTATION_PORT);
+ TraceLog(LOG_WARNING, "Window set to portraid mode");
+ }
+ else
+ {
+ AConfiguration_setOrientation(app->config, ACONFIGURATION_ORIENTATION_LAND);
+ TraceLog(LOG_WARNING, "Window set to landscape mode");
+ }
+
+ //AConfiguration_getDensity(app->config);
+ //AConfiguration_getKeyboard(app->config);
+ //AConfiguration_getScreenSize(app->config);
+ //AConfiguration_getScreenLong(app->config);
+
+ //state->userData = &engine;
+ app->onAppCmd = AndroidCommandCallback;
+ app->onInputEvent = AndroidInputCallback;
+
+ assetManager = app->activity->assetManager;
+
+ TraceLog(LOG_INFO, "Android app initialized successfully");
+
+ // Wait for window to be initialized (display and context)
+ while (!windowReady)
+ {
+ // Process events loop
+ while ((ident = ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0)
+ {
+ // Process this event
+ if (source != NULL) source->process(app, source);
+
+ // NOTE: Never close window, native activity is controlled by the system!
+ //if (app->destroyRequested != 0) windowShouldClose = true;
+ }
+ }
+}
+
+// Close window and unload OpenGL context
+static void CloseWindow(void)
+{
+ //rlglClose(); // De-init rlgl
+
+ // Close surface, context and display
+ if (display != EGL_NO_DISPLAY)
+ {
+ eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+
+ if (surface != EGL_NO_SURFACE)
+ {
+ eglDestroySurface(display, surface);
+ surface = EGL_NO_SURFACE;
+ }
+
+ if (context != EGL_NO_CONTEXT)
+ {
+ eglDestroyContext(display, context);
+ context = EGL_NO_CONTEXT;
+ }
+
+ eglTerminate(display);
+ display = EGL_NO_DISPLAY;
+ }
+
+ TraceLog(LOG_INFO, "Window closed successfully");
+}
+
+// Check if KEY_ESCAPE pressed or Close icon pressed
+static bool WindowShouldClose(void)
+{
+ return windowShouldClose;
+}
+
+static void InitGraphicsDevice(int width, int height)
+{
+ screenWidth = width; // User desired width
+ screenHeight = height; // User desired height
+
+ EGLint samples = 0;
+ EGLint sampleBuffer = 0;
+
+ const EGLint framebufferAttribs[] =
+ {
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> Required on RPI?
+ //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android!
+ EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5)
+ EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6)
+ EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5)
+ //EGL_ALPHA_SIZE, 8, // ALPHA bit depth (required for transparent framebuffer)
+ //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI)
+ EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!)
+ //EGL_STENCIL_SIZE, 8, // Stencil buffer size
+ EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA
+ EGL_SAMPLES, samples, // 4x Antialiasing if activated (Free on MALI GPUs)
+ EGL_NONE
+ };
+
+ EGLint contextAttribs[] =
+ {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ EGLint numConfigs;
+
+ // Get an EGL display connection
+ display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+
+ // Initialize the EGL display connection
+ eglInitialize(display, NULL, NULL);
+
+ // Get an appropriate EGL framebuffer configuration
+ eglChooseConfig(display, framebufferAttribs, &config, 1, &numConfigs);
+
+ // Set rendering API
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ // Create an EGL rendering context
+ context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
+
+ // Create an EGL window surface
+ //---------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+ EGLint displayFormat;
+
+ int displayWidth = ANativeWindow_getWidth(app->window);
+ int displayHeight = ANativeWindow_getHeight(app->window);
+
+ // EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is guaranteed to be accepted by ANativeWindow_setBuffersGeometry()
+ // As soon as we picked a EGLConfig, we can safely reconfigure the ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID
+ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &displayFormat);
+
+ // At this point we need to manage render size vs screen size
+ // NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
+
+ //SetupFramebufferSize(displayWidth, displayHeight);
+
+ //ANativeWindow_setBuffersGeometry(app->window, renderWidth, renderHeight, displayFormat);
+ ANativeWindow_setBuffersGeometry(app->window, 0, 0, displayFormat); // Force use of native display size
+
+ surface = eglCreateWindowSurface(display, config, app->window, NULL);
+#endif // defined(PLATFORM_ANDROID)
+
+ //eglSwapInterval(display, 1);
+
+ if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
+ {
+ TraceLog(LOG_ERROR, "Unable to attach EGL rendering context to EGL surface");
+ }
+ else
+ {
+ // Grab the width and height of the surface
+ //eglQuerySurface(display, surface, EGL_WIDTH, &renderWidth);
+ //eglQuerySurface(display, surface, EGL_HEIGHT, &renderHeight);
+
+ TraceLog(LOG_INFO, "Display device initialized successfully");
+ TraceLog(LOG_INFO, "Display size: %i x %i", displayWidth, displayHeight);
+ }
+/*
+ // Initialize OpenGL context (states and resources)
+ // NOTE: screenWidth and screenHeight not used, just stored as globals
+ rlglInit(screenWidth, screenHeight);
+
+ // Setup default viewport
+ rlViewport(0, 0, screenWidth, screenHeight);
+
+ // Initialize internal projection and modelview matrices
+ // NOTE: Default to orthographic projection mode with top-left corner at (0,0)
+ rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
+ rlLoadIdentity(); // Reset current matrix (PROJECTION)
+ rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f);
+ rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
+ rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ // Clear full framebuffer (not only render area) to color
+ rlClearColor(245, 245, 245, 255);
+*/
+ glClearColor(1, 0, 0, 1);
+
+#if defined(PLATFORM_ANDROID)
+ windowReady = true; // IMPORTANT!
+#endif
+}
+
+// Copy back buffer to front buffers
+static void SwapBuffers(void)
+{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
+ eglSwapBuffers(display, surface);
+#endif
+}
+
+#if defined(PLATFORM_ANDROID)
+// Android: Process activity lifecycle commands
+static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
+{
+ switch (cmd)
+ {
+ case APP_CMD_START:
+ {
+ //rendering = true;
+ TraceLog(LOG_INFO, "APP_CMD_START");
+ } break;
+ case APP_CMD_RESUME:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_RESUME");
+ } break;
+ case APP_CMD_INIT_WINDOW:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_INIT_WINDOW");
+
+ if (app->window != NULL)
+ {
+ if (contextRebindRequired)
+ {
+ // Reset screen scaling to full display size
+ EGLint displayFormat;
+ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &displayFormat);
+ ANativeWindow_setBuffersGeometry(app->window, screenWidth, screenHeight, displayFormat);
+
+ // Recreate display surface and re-attach OpenGL context
+ surface = eglCreateWindowSurface(display, config, app->window, NULL);
+ eglMakeCurrent(display, surface, surface, context);
+
+ contextRebindRequired = false;
+ }
+ else
+ {
+ // Init graphics device (display device and OpenGL context)
+ InitGraphicsDevice(screenWidth, screenHeight);
+
+ // TODO: GPU assets reload in case of lost focus (lost context)
+ // NOTE: This problem has been solved just unbinding and rebinding context from display
+ /*
+ if (assetsReloadRequired)
+ {
+ for (int i = 0; i < assetsCount; i++)
+ {
+ // TODO: Unload old asset if required
+
+ // Load texture again to pointed texture
+ (*textureAsset + i) = LoadTexture(assetPath[i]);
+ }
+ }
+ */
+
+ // Init hi-res timer
+ //InitTimer(); // TODO.
+ }
+ }
+ } break;
+ case APP_CMD_GAINED_FOCUS:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_GAINED_FOCUS");
+ appEnabled = true;
+ //ResumeMusicStream();
+ } break;
+ case APP_CMD_PAUSE:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_PAUSE");
+ } break;
+ case APP_CMD_LOST_FOCUS:
+ {
+ //DrawFrame();
+ TraceLog(LOG_INFO, "APP_CMD_LOST_FOCUS");
+ appEnabled = false;
+ //PauseMusicStream();
+ } break;
+ case APP_CMD_TERM_WINDOW:
+ {
+ // Dettach OpenGL context and destroy display surface
+ // NOTE 1: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
+ // NOTE 2: In some cases (too many context loaded), OS could unload context automatically... :(
+ eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroySurface(display, surface);
+
+ contextRebindRequired = true;
+
+ TraceLog(LOG_INFO, "APP_CMD_TERM_WINDOW");
+ } break;
+ case APP_CMD_SAVE_STATE:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_SAVE_STATE");
+ } break;
+ case APP_CMD_STOP:
+ {
+ TraceLog(LOG_INFO, "APP_CMD_STOP");
+ } break;
+ case APP_CMD_DESTROY:
+ {
+ // TODO: Finish activity?
+ //ANativeActivity_finish(app->activity);
+
+ TraceLog(LOG_INFO, "APP_CMD_DESTROY");
+ } break;
+ case APP_CMD_CONFIG_CHANGED:
+ {
+ //AConfiguration_fromAssetManager(app->config, app->activity->assetManager);
+ //print_cur_config(app);
+
+ // Check screen orientation here!
+
+ TraceLog(LOG_INFO, "APP_CMD_CONFIG_CHANGED");
+ } break;
+ default: break;
+ }
+}
+
+// Android: Get input events
+static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
+{
+ //http://developer.android.com/ndk/reference/index.html
+
+ int type = AInputEvent_getType(event);
+
+ if (type == AINPUT_EVENT_TYPE_MOTION)
+ {
+ /*
+ // Get first touch position
+ touchPosition[0].x = AMotionEvent_getX(event, 0);
+ touchPosition[0].y = AMotionEvent_getY(event, 0);
+
+ // Get second touch position
+ touchPosition[1].x = AMotionEvent_getX(event, 1);
+ touchPosition[1].y = AMotionEvent_getY(event, 1);
+ */
+ }
+ else if (type == AINPUT_EVENT_TYPE_KEY)
+ {
+ int32_t keycode = AKeyEvent_getKeyCode(event);
+ //int32_t AKeyEvent_getMetaState(event);
+
+ // Save current button and its state
+ // NOTE: Android key action is 0 for down and 1 for up
+ if (AKeyEvent_getAction(event) == 0)
+ {
+ //currentKeyState[keycode] = 1; // Key down
+ //lastKeyPressed = keycode;
+ }
+ //else currentKeyState[keycode] = 0; // Key up
+
+ if (keycode == AKEYCODE_POWER)
+ {
+ // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
+ // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
+ // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
+ // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
+ // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
+ return 0;
+ }
+ else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
+ {
+ // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
+ return 1;
+ }
+ else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
+ {
+ // Set default OS behaviour
+ return 0;
+ }
+ }
+
+ int32_t action = AMotionEvent_getAction(event);
+ unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
+/*
+ GestureEvent gestureEvent;
+
+ // Register touch actions
+ if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_DOWN;
+ else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_UP;
+ else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
+
+ // Register touch points count
+ gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
+
+ // Register touch points id
+ gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0);
+ gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1);
+
+ // Register touch points position
+ // NOTE: Only two points registered
+ gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
+ gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
+
+ // Normalize gestureEvent.position[x] for screenWidth and screenHeight
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+*/
+ return 0; // return 1;
+}
+#endif
+
+#if defined(PLATFORM_ANDROID)
+/*
+// Initialize asset manager from android app
+void InitAssetManager(AAssetManager *manager)
+{
+ assetManager = manager;
+}
+
+// Replacement for fopen
+FILE *android_fopen(const char *fileName, const char *mode)
+{
+ if (mode[0] == 'w') return NULL;
+
+ AAsset *asset = AAssetManager_open(assetManager, fileName, 0);
+
+ if (!asset) return NULL;
+
+ return funopen(asset, android_read, android_write, android_seek, android_close);
+}
+*/
+#endif
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Definition
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+static int android_read(void *cookie, char *buf, int size)
+{
+ return AAsset_read((AAsset *)cookie, buf, size);
+}
+
+static int android_write(void *cookie, const char *buf, int size)
+{
+ TraceLog(LOG_ERROR, "Can't provide write access to the APK");
+
+ return EACCES;
+}
+
+static fpos_t android_seek(void *cookie, fpos_t offset, int whence)
+{
+ return AAsset_seek((AAsset *)cookie, offset, whence);
+}
+
+static int android_close(void *cookie)
+{
+ AAsset_close((AAsset *)cookie);
+ return 0;
+}
+#endif
+
+// Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
+static void TraceLog(int msgType, const char *text, ...)
+{
+ static char buffer[128];
+ int traceDebugMsgs = 0;
+
+#if defined(SUPPORT_TRACELOG_DEBUG)
+ traceDebugMsgs = 1;
+#endif
+
+ switch(msgType)
+ {
+ case LOG_INFO: strcpy(buffer, "INFO: "); break;
+ case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
+ case LOG_WARNING: strcpy(buffer, "WARNING: "); break;
+ case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break;
+ default: break;
+ }
+
+ strcat(buffer, text);
+ strcat(buffer, "\n");
+
+ va_list args;
+ va_start(args, text);
+
+#if defined(PLATFORM_ANDROID)
+ switch(msgType)
+ {
+ case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
+ case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break;
+ case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break;
+ case LOG_DEBUG: if (traceDebugMsgs) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
+ default: break;
+ }
+#else
+ if ((msgType != LOG_DEBUG) || ((msgType == LOG_DEBUG) && (traceDebugMsgs))) vprintf(buffer, args);
+#endif
+
+ va_end(args);
+
+ if (msgType == LOG_ERROR) exit(1); // If LOG_ERROR message, exit program
+}
+
+// Setup canvas (framebuffer) to start drawing
+static void BeginDrawing(void)
+{
+/*
+ currentTime = GetTime(); // Number of elapsed seconds since InitTimer() was called
+ updateTime = currentTime - previousTime;
+ previousTime = currentTime;
+*/
+ //rlClearScreenBuffers(); // Clear current framebuffers
+ //rlLoadIdentity(); // Reset current matrix (MODELVIEW)
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+}
+
+// End canvas drawing and swap buffers (double buffering)
+static void EndDrawing(void)
+{
+ //rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
+
+ SwapBuffers(); // Copy back buffer to front buffer
+ PollInputEvents(); // Poll user events
+
+/*
+ // Frame time control system
+ currentTime = GetTime();
+ drawTime = currentTime - previousTime;
+ previousTime = currentTime;
+
+ frameTime = updateTime + drawTime;
+
+ // Wait for some milliseconds...
+ if (frameTime < targetTime)
+ {
+ Wait((targetTime - frameTime)*1000.0f);
+
+ currentTime = GetTime();
+ double extraTime = currentTime - previousTime;
+ previousTime = currentTime;
+
+ frameTime += extraTime;
+ }
+*/
+}
+
+// Poll (store) all input events
+static void PollInputEvents(void)
+{
+ // Reset last key pressed registered
+ //lastKeyPressed = -1;
+
+#if defined(PLATFORM_ANDROID)
+ // Register previous keys states
+ // NOTE: Android supports up to 260 keys
+ //for (int i = 0; i < 260; i++) previousKeyState[i] = currentKeyState[i];
+
+ // Poll Events (registered events)
+ // NOTE: Activity is paused if not enabled (appEnabled)
+ while ((ident = ALooper_pollAll(appEnabled ? 0 : -1, NULL, &events,(void**)&source)) >= 0)
+ {
+ // Process this event
+ if (source != NULL) source->process(app, source);
+
+ // NOTE: Never close window, native activity is controlled by the system!
+ if (app->destroyRequested != 0)
+ {
+ //TraceLog(LOG_INFO, "Closing Window...");
+ //windowShouldClose = true;
+ //ANativeActivity_finish(app->activity);
+ }
+ }
+#endif
+}
+
+
diff --git a/templates/android_project/jni/libs/libopenal.so b/templates/android_project/src/libs/libopenal.so
index dac5f118..dac5f118 100644
--- a/templates/android_project/jni/libs/libopenal.so
+++ b/templates/android_project/src/libs/libopenal.so
Binary files differ
diff --git a/templates/android_project/jni/include/raylib.h b/templates/android_project/src/raylib.h
index 07674531..07674531 100644
--- a/templates/android_project/jni/include/raylib.h
+++ b/templates/android_project/src/raylib.h
diff --git a/templates/android_project/src/raymath.h b/templates/android_project/src/raymath.h
new file mode 100644
index 00000000..fe0b8947
--- /dev/null
+++ b/templates/android_project/src/raymath.h
@@ -0,0 +1,1367 @@
+/**********************************************************************************************
+*
+* raymath v1.1 - Math functions to work with Vector3, Matrix and Quaternions
+*
+* CONFIGURATION:
+*
+* #define RAYMATH_IMPLEMENTATION
+* Generates the implementation of the library into the included file.
+* If not defined, the library is in header only mode and can be included in other headers
+* or source files without problems. But only ONE file should hold the implementation.
+*
+* #define RAYMATH_EXTERN_INLINE
+* Inlines all functions code, so it runs faster. This requires lots of memory on system.
+*
+* #define RAYMATH_STANDALONE
+* Avoid raylib.h header inclusion in this file.
+* Vector3 and Matrix data types are defined internally in raymath module.
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2015-2017 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef RAYMATH_H
+#define RAYMATH_H
+
+//#define RAYMATH_STANDALONE // NOTE: To use raymath as standalone lib, just uncomment this line
+//#define RAYMATH_EXTERN_INLINE // NOTE: To compile functions as static inline, uncomment this line
+
+#ifndef RAYMATH_STANDALONE
+ #include "raylib.h" // Required for structs: Vector3, Matrix
+#endif
+
+#ifdef __cplusplus
+ #define RMEXTERN extern "C" // Functions visible from other files (no name mangling of functions in C++)
+#else
+ #define RMEXTERN extern // Functions visible from other files
+#endif
+
+#if defined(RAYMATH_EXTERN_INLINE)
+ #define RMDEF RMEXTERN inline // Functions are embeded inline (compiler generated code)
+#else
+ #define RMDEF RMEXTERN
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#ifndef PI
+ #define PI 3.14159265358979323846
+#endif
+
+#ifndef DEG2RAD
+ #define DEG2RAD (PI/180.0f)
+#endif
+
+#ifndef RAD2DEG
+ #define RAD2DEG (180.0f/PI)
+#endif
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+
+#if defined(RAYMATH_STANDALONE)
+ // Vector2 type
+ typedef struct Vector2 {
+ float x;
+ float y;
+ } Vector2;
+
+ // Vector3 type
+ typedef struct Vector3 {
+ float x;
+ float y;
+ float z;
+ } Vector3;
+
+ // Matrix type (OpenGL style 4x4 - right handed, column major)
+ typedef struct Matrix {
+ float m0, m4, m8, m12;
+ float m1, m5, m9, m13;
+ float m2, m6, m10, m14;
+ float m3, m7, m11, m15;
+ } Matrix;
+#endif
+
+// Quaternion type
+typedef struct Quaternion {
+ float x;
+ float y;
+ float z;
+ float w;
+} Quaternion;
+
+#ifndef RAYMATH_EXTERN_INLINE
+
+//------------------------------------------------------------------------------------
+// Functions Declaration - math utils
+//------------------------------------------------------------------------------------
+RMDEF float Clamp(float value, float min, float max); // Clamp float value
+
+//------------------------------------------------------------------------------------
+// Functions Declaration to work with Vector2
+//------------------------------------------------------------------------------------
+RMDEF Vector2 Vector2Zero(void); // Vector with components value 0.0f
+RMDEF Vector2 Vector2One(void); // Vector with components value 1.0f
+RMDEF Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Add two vectors (v1 + v2)
+RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Subtract two vectors (v1 - v2)
+RMDEF float Vector2Length(Vector2 v); // Calculate vector length
+RMDEF float Vector2DotProduct(Vector2 v1, Vector2 v2); // Calculate two vectors dot product
+RMDEF float Vector2Distance(Vector2 v1, Vector2 v2); // Calculate distance between two vectors
+RMDEF float Vector2Angle(Vector2 v1, Vector2 v2); // Calculate angle between two vectors in X-axis
+RMDEF void Vector2Scale(Vector2 *v, float scale); // Scale vector (multiply by value)
+RMDEF void Vector2Negate(Vector2 *v); // Negate vector
+RMDEF void Vector2Divide(Vector2 *v, float div); // Divide vector by a float value
+RMDEF void Vector2Normalize(Vector2 *v); // Normalize provided vector
+
+//------------------------------------------------------------------------------------
+// Functions Declaration to work with Vector3
+//------------------------------------------------------------------------------------
+RMDEF Vector3 Vector3Zero(void); // Vector with components value 0.0f
+RMDEF Vector3 Vector3One(void); // Vector with components value 1.0f
+RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2); // Add two vectors
+RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar); // Multiply vector by scalar
+RMDEF Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2); // Multiply vector by vector
+RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); // Substract two vectors
+RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); // Calculate two vectors cross product
+RMDEF Vector3 Vector3Perpendicular(Vector3 v); // Calculate one vector perpendicular vector
+RMDEF float Vector3Length(const Vector3 v); // Calculate vector length
+RMDEF float Vector3DotProduct(Vector3 v1, Vector3 v2); // Calculate two vectors dot product
+RMDEF float Vector3Distance(Vector3 v1, Vector3 v2); // Calculate distance between two points
+RMDEF void Vector3Scale(Vector3 *v, float scale); // Scale provided vector
+RMDEF void Vector3Negate(Vector3 *v); // Negate provided vector (invert direction)
+RMDEF void Vector3Normalize(Vector3 *v); // Normalize provided vector
+RMDEF void Vector3Transform(Vector3 *v, Matrix mat); // Transforms a Vector3 by a given Matrix
+RMDEF Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); // Calculate linear interpolation between two vectors
+RMDEF Vector3 Vector3Reflect(Vector3 vector, Vector3 normal); // Calculate reflected vector to normal
+RMDEF Vector3 Vector3Min(Vector3 vec1, Vector3 vec2); // Return min value for each pair of components
+RMDEF Vector3 Vector3Max(Vector3 vec1, Vector3 vec2); // Return max value for each pair of components
+RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); // Barycenter coords for p in triangle abc
+RMDEF float *Vector3ToFloat(Vector3 vec); // Returns Vector3 as float array
+
+//------------------------------------------------------------------------------------
+// Functions Declaration to work with Matrix
+//------------------------------------------------------------------------------------
+RMDEF float MatrixDeterminant(Matrix mat); // Compute matrix determinant
+RMDEF float MatrixTrace(Matrix mat); // Returns the trace of the matrix (sum of the values along the diagonal)
+RMDEF void MatrixTranspose(Matrix *mat); // Transposes provided matrix
+RMDEF void MatrixInvert(Matrix *mat); // Invert provided matrix
+RMDEF void MatrixNormalize(Matrix *mat); // Normalize provided matrix
+RMDEF Matrix MatrixIdentity(void); // Returns identity matrix
+RMDEF Matrix MatrixAdd(Matrix left, Matrix right); // Add two matrices
+RMDEF Matrix MatrixSubstract(Matrix left, Matrix right); // Substract two matrices (left - right)
+RMDEF Matrix MatrixTranslate(float x, float y, float z); // Returns translation matrix
+RMDEF Matrix MatrixRotate(Vector3 axis, float angle); // Returns rotation matrix for an angle around an specified axis (angle in radians)
+RMDEF Matrix MatrixRotateX(float angle); // Returns x-rotation matrix (angle in radians)
+RMDEF Matrix MatrixRotateY(float angle); // Returns y-rotation matrix (angle in radians)
+RMDEF Matrix MatrixRotateZ(float angle); // Returns z-rotation matrix (angle in radians)
+RMDEF Matrix MatrixScale(float x, float y, float z); // Returns scaling matrix
+RMDEF Matrix MatrixMultiply(Matrix left, Matrix right); // Returns two matrix multiplication
+RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far); // Returns perspective projection matrix
+RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far); // Returns perspective projection matrix
+RMDEF Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); // Returns orthographic projection matrix
+RMDEF Matrix MatrixLookAt(Vector3 position, Vector3 target, Vector3 up); // Returns camera look-at matrix (view matrix)
+RMDEF float *MatrixToFloat(Matrix mat); // Returns float array of Matrix data
+
+//------------------------------------------------------------------------------------
+// Functions Declaration to work with Quaternions
+//------------------------------------------------------------------------------------
+RMDEF Quaternion QuaternionIdentity(void); // Returns identity quaternion
+RMDEF float QuaternionLength(Quaternion quat); // Compute the length of a quaternion
+RMDEF void QuaternionNormalize(Quaternion *q); // Normalize provided quaternion
+RMDEF void QuaternionInvert(Quaternion *quat); // Invert provided quaternion
+RMDEF Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); // Calculate two quaternion multiplication
+RMDEF Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); // Calculate linear interpolation between two quaternions
+RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); // Calculates spherical linear interpolation between two quaternions
+RMDEF Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); // Calculate slerp-optimized interpolation between two quaternions
+RMDEF Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); // Calculate quaternion based on the rotation from one vector to another
+RMDEF Quaternion QuaternionFromMatrix(Matrix matrix); // Returns a quaternion for a given rotation matrix
+RMDEF Matrix QuaternionToMatrix(Quaternion q); // Returns a matrix for a given quaternion
+RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); // Returns rotation quaternion for an angle and axis
+RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle); // Returns the rotation angle and axis for a given quaternion
+RMDEF Quaternion QuaternionFromEuler(float roll, float pitch, float yaw); // Returns he quaternion equivalent to Euler angles
+RMDEF Vector3 QuaternionToEuler(Quaternion q); // Return the Euler angles equivalent to quaternion (roll, pitch, yaw)
+RMDEF void QuaternionTransform(Quaternion *q, Matrix mat); // Transform a quaternion given a transformation matrix
+
+#endif // notdef RAYMATH_EXTERN_INLINE
+
+#endif // RAYMATH_H
+//////////////////////////////////////////////////////////////////// end of header file
+
+#if defined(RAYMATH_IMPLEMENTATION) || defined(RAYMATH_EXTERN_INLINE)
+
+#include <math.h> // Required for: sinf(), cosf(), tan(), fabs()
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Utils math
+//----------------------------------------------------------------------------------
+
+// Clamp float value
+RMDEF float Clamp(float value, float min, float max)
+{
+ const float res = value < min ? min : value;
+ return res > max ? max : res;
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Vector2 math
+//----------------------------------------------------------------------------------
+
+// Vector with components value 0.0f
+RMDEF Vector2 Vector2Zero(void) { return (Vector2){ 0.0f, 0.0f }; }
+
+// Vector with components value 1.0f
+RMDEF Vector2 Vector2One(void) { return (Vector2){ 1.0f, 1.0f }; }
+
+// Add two vectors (v1 + v2)
+RMDEF Vector2 Vector2Add(Vector2 v1, Vector2 v2)
+{
+ return (Vector2){ v1.x + v2.x, v1.y + v2.y };
+}
+
+// Subtract two vectors (v1 - v2)
+RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
+{
+ return (Vector2){ v1.x - v2.x, v1.y - v2.y };
+}
+
+// Calculate vector length
+RMDEF float Vector2Length(Vector2 v)
+{
+ return sqrtf((v.x*v.x) + (v.y*v.y));
+}
+
+// Calculate two vectors dot product
+RMDEF float Vector2DotProduct(Vector2 v1, Vector2 v2)
+{
+ return (v1.x*v2.x + v1.y*v2.y);
+}
+
+// Calculate distance between two vectors
+RMDEF float Vector2Distance(Vector2 v1, Vector2 v2)
+{
+ return sqrtf((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
+}
+
+// Calculate angle from two vectors in X-axis
+RMDEF float Vector2Angle(Vector2 v1, Vector2 v2)
+{
+ float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
+
+ if (angle < 0) angle += 360.0f;
+
+ return angle;
+}
+
+// Scale vector (multiply by value)
+RMDEF void Vector2Scale(Vector2 *v, float scale)
+{
+ v->x *= scale;
+ v->y *= scale;
+}
+
+// Negate vector
+RMDEF void Vector2Negate(Vector2 *v)
+{
+ v->x = -v->x;
+ v->y = -v->y;
+}
+
+// Divide vector by a float value
+RMDEF void Vector2Divide(Vector2 *v, float div)
+{
+ *v = (Vector2){v->x/div, v->y/div};
+}
+
+// Normalize provided vector
+RMDEF void Vector2Normalize(Vector2 *v)
+{
+ Vector2Divide(v, Vector2Length(*v));
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Vector3 math
+//----------------------------------------------------------------------------------
+
+// Vector with components value 0.0f
+RMDEF Vector3 Vector3Zero(void) { return (Vector3){ 0.0f, 0.0f, 0.0f }; }
+
+// Vector with components value 1.0f
+RMDEF Vector3 Vector3One(void) { return (Vector3){ 1.0f, 1.0f, 1.0f }; }
+
+// Add two vectors
+RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2)
+{
+ return (Vector3){ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
+}
+
+// Substract two vectors
+RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
+{
+ return (Vector3){ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
+}
+
+// Multiply vector by scalar
+RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar)
+{
+ v.x *= scalar;
+ v.y *= scalar;
+ v.z *= scalar;
+
+ return v;
+}
+
+// Multiply vector by vector
+RMDEF Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2)
+{
+ Vector3 result;
+
+ result.x = v1.x * v2.x;
+ result.y = v1.y * v2.y;
+ result.z = v1.z * v2.z;
+
+ return result;
+}
+
+// Calculate two vectors cross product
+RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2)
+{
+ Vector3 result;
+
+ result.x = v1.y*v2.z - v1.z*v2.y;
+ result.y = v1.z*v2.x - v1.x*v2.z;
+ result.z = v1.x*v2.y - v1.y*v2.x;
+
+ return result;
+}
+
+// Calculate one vector perpendicular vector
+RMDEF Vector3 Vector3Perpendicular(Vector3 v)
+{
+ Vector3 result;
+
+ float min = fabsf(v.x);
+ Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f};
+
+ if (fabsf(v.y) < min)
+ {
+ min = fabsf(v.y);
+ cardinalAxis = (Vector3){0.0f, 1.0f, 0.0f};
+ }
+
+ if (fabsf(v.z) < min)
+ {
+ cardinalAxis = (Vector3){0.0f, 0.0f, 1.0f};
+ }
+
+ result = Vector3CrossProduct(v, cardinalAxis);
+
+ return result;
+}
+
+// Calculate vector length
+RMDEF float Vector3Length(const Vector3 v)
+{
+ return sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
+}
+
+// Calculate two vectors dot product
+RMDEF float Vector3DotProduct(Vector3 v1, Vector3 v2)
+{
+ return (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
+}
+
+// Calculate distance between two vectors
+RMDEF float Vector3Distance(Vector3 v1, Vector3 v2)
+{
+ float dx = v2.x - v1.x;
+ float dy = v2.y - v1.y;
+ float dz = v2.z - v1.z;
+
+ return sqrtf(dx*dx + dy*dy + dz*dz);
+}
+
+// Scale provided vector
+RMDEF void Vector3Scale(Vector3 *v, float scale)
+{
+ v->x *= scale;
+ v->y *= scale;
+ v->z *= scale;
+}
+
+// Negate provided vector (invert direction)
+RMDEF void Vector3Negate(Vector3 *v)
+{
+ v->x = -v->x;
+ v->y = -v->y;
+ v->z = -v->z;
+}
+
+// Normalize provided vector
+RMDEF void Vector3Normalize(Vector3 *v)
+{
+ float length, ilength;
+
+ length = Vector3Length(*v);
+
+ if (length == 0.0f) length = 1.0f;
+
+ ilength = 1.0f/length;
+
+ v->x *= ilength;
+ v->y *= ilength;
+ v->z *= ilength;
+}
+
+// Transforms a Vector3 by a given Matrix
+RMDEF void Vector3Transform(Vector3 *v, Matrix mat)
+{
+ float x = v->x;
+ float y = v->y;
+ float z = v->z;
+
+ v->x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
+ v->y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
+ v->z = mat.m2*x + mat.m6*y + mat.m10*z + mat.m14;
+};
+
+// Calculate linear interpolation between two vectors
+RMDEF Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
+{
+ Vector3 result;
+
+ result.x = v1.x + amount*(v2.x - v1.x);
+ result.y = v1.y + amount*(v2.y - v1.y);
+ result.z = v1.z + amount*(v2.z - v1.z);
+
+ return result;
+}
+
+// Calculate reflected vector to normal
+RMDEF Vector3 Vector3Reflect(Vector3 vector, Vector3 normal)
+{
+ // I is the original vector
+ // N is the normal of the incident plane
+ // R = I - (2*N*( DotProduct[ I,N] ))
+
+ Vector3 result;
+
+ float dotProduct = Vector3DotProduct(vector, normal);
+
+ result.x = vector.x - (2.0f*normal.x)*dotProduct;
+ result.y = vector.y - (2.0f*normal.y)*dotProduct;
+ result.z = vector.z - (2.0f*normal.z)*dotProduct;
+
+ return result;
+}
+
+// Return min value for each pair of components
+RMDEF Vector3 Vector3Min(Vector3 vec1, Vector3 vec2)
+{
+ Vector3 result;
+
+ result.x = fminf(vec1.x, vec2.x);
+ result.y = fminf(vec1.y, vec2.y);
+ result.z = fminf(vec1.z, vec2.z);
+
+ return result;
+}
+
+// Return max value for each pair of components
+RMDEF Vector3 Vector3Max(Vector3 vec1, Vector3 vec2)
+{
+ Vector3 result;
+
+ result.x = fmaxf(vec1.x, vec2.x);
+ result.y = fmaxf(vec1.y, vec2.y);
+ result.z = fmaxf(vec1.z, vec2.z);
+
+ return result;
+}
+
+// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
+// NOTE: Assumes P is on the plane of the triangle
+RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
+{
+ //Vector v0 = b - a, v1 = c - a, v2 = p - a;
+
+ Vector3 v0 = Vector3Subtract(b, a);
+ Vector3 v1 = Vector3Subtract(c, a);
+ Vector3 v2 = Vector3Subtract(p, a);
+ float d00 = Vector3DotProduct(v0, v0);
+ float d01 = Vector3DotProduct(v0, v1);
+ float d11 = Vector3DotProduct(v1, v1);
+ float d20 = Vector3DotProduct(v2, v0);
+ float d21 = Vector3DotProduct(v2, v1);
+
+ float denom = d00*d11 - d01*d01;
+
+ Vector3 result;
+
+ result.y = (d11*d20 - d01*d21)/denom;
+ result.z = (d00*d21 - d01*d20)/denom;
+ result.x = 1.0f - (result.z + result.y);
+
+ return result;
+}
+
+// Returns Vector3 as float array
+RMDEF float *Vector3ToFloat(Vector3 vec)
+{
+ static float buffer[3];
+
+ buffer[0] = vec.x;
+ buffer[1] = vec.y;
+ buffer[2] = vec.z;
+
+ return buffer;
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Matrix math
+//----------------------------------------------------------------------------------
+
+// Compute matrix determinant
+RMDEF float MatrixDeterminant(Matrix mat)
+{
+ float result;
+
+ // Cache the matrix values (speed optimization)
+ float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
+ float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
+ float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
+ float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
+
+ result = a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
+ a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
+ a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
+ a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
+ a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
+ a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
+
+ return result;
+}
+
+// Returns the trace of the matrix (sum of the values along the diagonal)
+RMDEF float MatrixTrace(Matrix mat)
+{
+ return (mat.m0 + mat.m5 + mat.m10 + mat.m15);
+}
+
+// Transposes provided matrix
+RMDEF void MatrixTranspose(Matrix *mat)
+{
+ Matrix temp;
+
+ temp.m0 = mat->m0;
+ temp.m1 = mat->m4;
+ temp.m2 = mat->m8;
+ temp.m3 = mat->m12;
+ temp.m4 = mat->m1;
+ temp.m5 = mat->m5;
+ temp.m6 = mat->m9;
+ temp.m7 = mat->m13;
+ temp.m8 = mat->m2;
+ temp.m9 = mat->m6;
+ temp.m10 = mat->m10;
+ temp.m11 = mat->m14;
+ temp.m12 = mat->m3;
+ temp.m13 = mat->m7;
+ temp.m14 = mat->m11;
+ temp.m15 = mat->m15;
+
+ *mat = temp;
+}
+
+// Invert provided matrix
+RMDEF void MatrixInvert(Matrix *mat)
+{
+ Matrix temp;
+
+ // Cache the matrix values (speed optimization)
+ float a00 = mat->m0, a01 = mat->m1, a02 = mat->m2, a03 = mat->m3;
+ float a10 = mat->m4, a11 = mat->m5, a12 = mat->m6, a13 = mat->m7;
+ float a20 = mat->m8, a21 = mat->m9, a22 = mat->m10, a23 = mat->m11;
+ float a30 = mat->m12, a31 = mat->m13, a32 = mat->m14, a33 = mat->m15;
+
+ float b00 = a00*a11 - a01*a10;
+ float b01 = a00*a12 - a02*a10;
+ float b02 = a00*a13 - a03*a10;
+ float b03 = a01*a12 - a02*a11;
+ float b04 = a01*a13 - a03*a11;
+ float b05 = a02*a13 - a03*a12;
+ float b06 = a20*a31 - a21*a30;
+ float b07 = a20*a32 - a22*a30;
+ float b08 = a20*a33 - a23*a30;
+ float b09 = a21*a32 - a22*a31;
+ float b10 = a21*a33 - a23*a31;
+ float b11 = a22*a33 - a23*a32;
+
+ // Calculate the invert determinant (inlined to avoid double-caching)
+ float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
+
+ temp.m0 = (a11*b11 - a12*b10 + a13*b09)*invDet;
+ temp.m1 = (-a01*b11 + a02*b10 - a03*b09)*invDet;
+ temp.m2 = (a31*b05 - a32*b04 + a33*b03)*invDet;
+ temp.m3 = (-a21*b05 + a22*b04 - a23*b03)*invDet;
+ temp.m4 = (-a10*b11 + a12*b08 - a13*b07)*invDet;
+ temp.m5 = (a00*b11 - a02*b08 + a03*b07)*invDet;
+ temp.m6 = (-a30*b05 + a32*b02 - a33*b01)*invDet;
+ temp.m7 = (a20*b05 - a22*b02 + a23*b01)*invDet;
+ temp.m8 = (a10*b10 - a11*b08 + a13*b06)*invDet;
+ temp.m9 = (-a00*b10 + a01*b08 - a03*b06)*invDet;
+ temp.m10 = (a30*b04 - a31*b02 + a33*b00)*invDet;
+ temp.m11 = (-a20*b04 + a21*b02 - a23*b00)*invDet;
+ temp.m12 = (-a10*b09 + a11*b07 - a12*b06)*invDet;
+ temp.m13 = (a00*b09 - a01*b07 + a02*b06)*invDet;
+ temp.m14 = (-a30*b03 + a31*b01 - a32*b00)*invDet;
+ temp.m15 = (a20*b03 - a21*b01 + a22*b00)*invDet;
+
+ *mat = temp;
+}
+
+// Normalize provided matrix
+RMDEF void MatrixNormalize(Matrix *mat)
+{
+ float det = MatrixDeterminant(*mat);
+
+ mat->m0 /= det;
+ mat->m1 /= det;
+ mat->m2 /= det;
+ mat->m3 /= det;
+ mat->m4 /= det;
+ mat->m5 /= det;
+ mat->m6 /= det;
+ mat->m7 /= det;
+ mat->m8 /= det;
+ mat->m9 /= det;
+ mat->m10 /= det;
+ mat->m11 /= det;
+ mat->m12 /= det;
+ mat->m13 /= det;
+ mat->m14 /= det;
+ mat->m15 /= det;
+}
+
+// Returns identity matrix
+RMDEF Matrix MatrixIdentity(void)
+{
+ Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f };
+
+ return result;
+}
+
+// Add two matrices
+RMDEF Matrix MatrixAdd(Matrix left, Matrix right)
+{
+ Matrix result = MatrixIdentity();
+
+ result.m0 = left.m0 + right.m0;
+ result.m1 = left.m1 + right.m1;
+ result.m2 = left.m2 + right.m2;
+ result.m3 = left.m3 + right.m3;
+ result.m4 = left.m4 + right.m4;
+ result.m5 = left.m5 + right.m5;
+ result.m6 = left.m6 + right.m6;
+ result.m7 = left.m7 + right.m7;
+ result.m8 = left.m8 + right.m8;
+ result.m9 = left.m9 + right.m9;
+ result.m10 = left.m10 + right.m10;
+ result.m11 = left.m11 + right.m11;
+ result.m12 = left.m12 + right.m12;
+ result.m13 = left.m13 + right.m13;
+ result.m14 = left.m14 + right.m14;
+ result.m15 = left.m15 + right.m15;
+
+ return result;
+}
+
+// Substract two matrices (left - right)
+RMDEF Matrix MatrixSubstract(Matrix left, Matrix right)
+{
+ Matrix result = MatrixIdentity();
+
+ result.m0 = left.m0 - right.m0;
+ result.m1 = left.m1 - right.m1;
+ result.m2 = left.m2 - right.m2;
+ result.m3 = left.m3 - right.m3;
+ result.m4 = left.m4 - right.m4;
+ result.m5 = left.m5 - right.m5;
+ result.m6 = left.m6 - right.m6;
+ result.m7 = left.m7 - right.m7;
+ result.m8 = left.m8 - right.m8;
+ result.m9 = left.m9 - right.m9;
+ result.m10 = left.m10 - right.m10;
+ result.m11 = left.m11 - right.m11;
+ result.m12 = left.m12 - right.m12;
+ result.m13 = left.m13 - right.m13;
+ result.m14 = left.m14 - right.m14;
+ result.m15 = left.m15 - right.m15;
+
+ return result;
+}
+
+// Returns translation matrix
+RMDEF Matrix MatrixTranslate(float x, float y, float z)
+{
+ Matrix result = { 1.0f, 0.0f, 0.0f, x,
+ 0.0f, 1.0f, 0.0f, y,
+ 0.0f, 0.0f, 1.0f, z,
+ 0.0f, 0.0f, 0.0f, 1.0f };
+
+ return result;
+}
+
+// Create rotation matrix from axis and angle
+// NOTE: Angle should be provided in radians
+RMDEF Matrix MatrixRotate(Vector3 axis, float angle)
+{
+ Matrix result;
+
+ Matrix mat = MatrixIdentity();
+
+ float x = axis.x, y = axis.y, z = axis.z;
+
+ float length = sqrtf(x*x + y*y + z*z);
+
+ if ((length != 1.0f) && (length != 0.0f))
+ {
+ length = 1.0f/length;
+ x *= length;
+ y *= length;
+ z *= length;
+ }
+
+ float sinres = sinf(angle);
+ float cosres = cosf(angle);
+ float t = 1.0f - cosres;
+
+ // Cache some matrix values (speed optimization)
+ float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
+ float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
+ float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
+
+ // Construct the elements of the rotation matrix
+ float b00 = x*x*t + cosres, b01 = y*x*t + z*sinres, b02 = z*x*t - y*sinres;
+ float b10 = x*y*t - z*sinres, b11 = y*y*t + cosres, b12 = z*y*t + x*sinres;
+ float b20 = x*z*t + y*sinres, b21 = y*z*t - x*sinres, b22 = z*z*t + cosres;
+
+ // Perform rotation-specific matrix multiplication
+ result.m0 = a00*b00 + a10*b01 + a20*b02;
+ result.m1 = a01*b00 + a11*b01 + a21*b02;
+ result.m2 = a02*b00 + a12*b01 + a22*b02;
+ result.m3 = a03*b00 + a13*b01 + a23*b02;
+ result.m4 = a00*b10 + a10*b11 + a20*b12;
+ result.m5 = a01*b10 + a11*b11 + a21*b12;
+ result.m6 = a02*b10 + a12*b11 + a22*b12;
+ result.m7 = a03*b10 + a13*b11 + a23*b12;
+ result.m8 = a00*b20 + a10*b21 + a20*b22;
+ result.m9 = a01*b20 + a11*b21 + a21*b22;
+ result.m10 = a02*b20 + a12*b21 + a22*b22;
+ result.m11 = a03*b20 + a13*b21 + a23*b22;
+ result.m12 = mat.m12;
+ result.m13 = mat.m13;
+ result.m14 = mat.m14;
+ result.m15 = mat.m15;
+
+ return result;
+}
+
+// Returns x-rotation matrix (angle in radians)
+RMDEF Matrix MatrixRotateX(float angle)
+{
+ Matrix result = MatrixIdentity();
+
+ float cosres = cosf(angle);
+ float sinres = sinf(angle);
+
+ result.m5 = cosres;
+ result.m6 = -sinres;
+ result.m9 = sinres;
+ result.m10 = cosres;
+
+ return result;
+}
+
+// Returns y-rotation matrix (angle in radians)
+RMDEF Matrix MatrixRotateY(float angle)
+{
+ Matrix result = MatrixIdentity();
+
+ float cosres = cosf(angle);
+ float sinres = sinf(angle);
+
+ result.m0 = cosres;
+ result.m2 = sinres;
+ result.m8 = -sinres;
+ result.m10 = cosres;
+
+ return result;
+}
+
+// Returns z-rotation matrix (angle in radians)
+RMDEF Matrix MatrixRotateZ(float angle)
+{
+ Matrix result = MatrixIdentity();
+
+ float cosres = cosf(angle);
+ float sinres = sinf(angle);
+
+ result.m0 = cosres;
+ result.m1 = -sinres;
+ result.m4 = sinres;
+ result.m5 = cosres;
+
+ return result;
+}
+
+// Returns scaling matrix
+RMDEF Matrix MatrixScale(float x, float y, float z)
+{
+ Matrix result = { x, 0.0f, 0.0f, 0.0f,
+ 0.0f, y, 0.0f, 0.0f,
+ 0.0f, 0.0f, z, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f };
+
+ return result;
+}
+
+// Returns two matrix multiplication
+// NOTE: When multiplying matrices... the order matters!
+RMDEF Matrix MatrixMultiply(Matrix left, Matrix right)
+{
+ Matrix result;
+
+ result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
+ result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
+ result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
+ result.m3 = left.m0*right.m3 + left.m1*right.m7 + left.m2*right.m11 + left.m3*right.m15;
+ result.m4 = left.m4*right.m0 + left.m5*right.m4 + left.m6*right.m8 + left.m7*right.m12;
+ result.m5 = left.m4*right.m1 + left.m5*right.m5 + left.m6*right.m9 + left.m7*right.m13;
+ result.m6 = left.m4*right.m2 + left.m5*right.m6 + left.m6*right.m10 + left.m7*right.m14;
+ result.m7 = left.m4*right.m3 + left.m5*right.m7 + left.m6*right.m11 + left.m7*right.m15;
+ result.m8 = left.m8*right.m0 + left.m9*right.m4 + left.m10*right.m8 + left.m11*right.m12;
+ result.m9 = left.m8*right.m1 + left.m9*right.m5 + left.m10*right.m9 + left.m11*right.m13;
+ result.m10 = left.m8*right.m2 + left.m9*right.m6 + left.m10*right.m10 + left.m11*right.m14;
+ result.m11 = left.m8*right.m3 + left.m9*right.m7 + left.m10*right.m11 + left.m11*right.m15;
+ result.m12 = left.m12*right.m0 + left.m13*right.m4 + left.m14*right.m8 + left.m15*right.m12;
+ result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13;
+ result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14;
+ result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15;
+
+ return result;
+}
+
+// Returns perspective projection matrix
+RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far)
+{
+ Matrix result;
+
+ float rl = (right - left);
+ float tb = (top - bottom);
+ float fn = (far - near);
+
+ result.m0 = (near*2.0f)/rl;
+ result.m1 = 0.0f;
+ result.m2 = 0.0f;
+ result.m3 = 0.0f;
+
+ result.m4 = 0.0f;
+ result.m5 = (near*2.0f)/tb;
+ result.m6 = 0.0f;
+ result.m7 = 0.0f;
+
+ result.m8 = (right + left)/rl;
+ result.m9 = (top + bottom)/tb;
+ result.m10 = -(far + near)/fn;
+ result.m11 = -1.0f;
+
+ result.m12 = 0.0f;
+ result.m13 = 0.0f;
+ result.m14 = -(far*near*2.0f)/fn;
+ result.m15 = 0.0f;
+
+ return result;
+}
+
+// Returns perspective projection matrix
+// NOTE: Angle should be provided in radians
+RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
+{
+ double top = near*tan(fovy*0.5);
+ double right = top*aspect;
+
+ return MatrixFrustum(-right, right, -top, top, near, far);
+}
+
+// Returns orthographic projection matrix
+RMDEF Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far)
+{
+ Matrix result;
+
+ float rl = (right - left);
+ float tb = (top - bottom);
+ float fn = (far - near);
+
+ result.m0 = 2.0f/rl;
+ result.m1 = 0.0f;
+ result.m2 = 0.0f;
+ result.m3 = 0.0f;
+ result.m4 = 0.0f;
+ result.m5 = 2.0f/tb;
+ result.m6 = 0.0f;
+ result.m7 = 0.0f;
+ result.m8 = 0.0f;
+ result.m9 = 0.0f;
+ result.m10 = -2.0f/fn;
+ result.m11 = 0.0f;
+ result.m12 = -(left + right)/rl;
+ result.m13 = -(top + bottom)/tb;
+ result.m14 = -(far + near)/fn;
+ result.m15 = 1.0f;
+
+ return result;
+}
+
+// Returns camera look-at matrix (view matrix)
+RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
+{
+ Matrix result;
+
+ Vector3 z = Vector3Subtract(eye, target);
+ Vector3Normalize(&z);
+ Vector3 x = Vector3CrossProduct(up, z);
+ Vector3Normalize(&x);
+ Vector3 y = Vector3CrossProduct(z, x);
+ Vector3Normalize(&y);
+
+ result.m0 = x.x;
+ result.m1 = x.y;
+ result.m2 = x.z;
+ result.m3 = 0.0f;
+ result.m4 = y.x;
+ result.m5 = y.y;
+ result.m6 = y.z;
+ result.m7 = 0.0f;
+ result.m8 = z.x;
+ result.m9 = z.y;
+ result.m10 = z.z;
+ result.m11 = 0.0f;
+ result.m12 = eye.x;
+ result.m13 = eye.y;
+ result.m14 = eye.z;
+ result.m15 = 1.0f;
+
+ MatrixInvert(&result);
+
+ return result;
+}
+
+// Returns float array of matrix data
+RMDEF float *MatrixToFloat(Matrix mat)
+{
+ static float buffer[16];
+
+ buffer[0] = mat.m0;
+ buffer[1] = mat.m1;
+ buffer[2] = mat.m2;
+ buffer[3] = mat.m3;
+ buffer[4] = mat.m4;
+ buffer[5] = mat.m5;
+ buffer[6] = mat.m6;
+ buffer[7] = mat.m7;
+ buffer[8] = mat.m8;
+ buffer[9] = mat.m9;
+ buffer[10] = mat.m10;
+ buffer[11] = mat.m11;
+ buffer[12] = mat.m12;
+ buffer[13] = mat.m13;
+ buffer[14] = mat.m14;
+ buffer[15] = mat.m15;
+
+ return buffer;
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Quaternion math
+//----------------------------------------------------------------------------------
+
+// Returns identity quaternion
+RMDEF Quaternion QuaternionIdentity(void)
+{
+ return (Quaternion){ 0.0f, 0.0f, 0.0f, 1.0f };
+}
+
+// Computes the length of a quaternion
+RMDEF float QuaternionLength(Quaternion quat)
+{
+ return sqrt(quat.x*quat.x + quat.y*quat.y + quat.z*quat.z + quat.w*quat.w);
+}
+
+// Normalize provided quaternion
+RMDEF void QuaternionNormalize(Quaternion *q)
+{
+ float length, ilength;
+
+ length = QuaternionLength(*q);
+
+ if (length == 0.0f) length = 1.0f;
+
+ ilength = 1.0f/length;
+
+ q->x *= ilength;
+ q->y *= ilength;
+ q->z *= ilength;
+ q->w *= ilength;
+}
+
+// Invert provided quaternion
+RMDEF void QuaternionInvert(Quaternion *quat)
+{
+ float length = QuaternionLength(*quat);
+ float lengthSq = length*length;
+
+ if (lengthSq != 0.0)
+ {
+ float i = 1.0f/lengthSq;
+
+ quat->x *= -i;
+ quat->y *= -i;
+ quat->z *= -i;
+ quat->w *= i;
+ }
+}
+
+// Calculate two quaternion multiplication
+RMDEF Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2)
+{
+ Quaternion result;
+
+ float qax = q1.x, qay = q1.y, qaz = q1.z, qaw = q1.w;
+ float qbx = q2.x, qby = q2.y, qbz = q2.z, qbw = q2.w;
+
+ result.x = qax*qbw + qaw*qbx + qay*qbz - qaz*qby;
+ result.y = qay*qbw + qaw*qby + qaz*qbx - qax*qbz;
+ result.z = qaz*qbw + qaw*qbz + qax*qby - qay*qbx;
+ result.w = qaw*qbw - qax*qbx - qay*qby - qaz*qbz;
+
+ return result;
+}
+
+// Calculate linear interpolation between two quaternions
+RMDEF Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount)
+{
+ Quaternion result;
+
+ result.x = q1.x + amount*(q2.x - q1.x);
+ result.y = q1.y + amount*(q2.y - q1.y);
+ result.z = q1.z + amount*(q2.z - q1.z);
+ result.w = q1.w + amount*(q2.w - q1.w);
+
+ return result;
+}
+
+// Calculates spherical linear interpolation between two quaternions
+RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
+{
+ Quaternion result;
+
+ float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;
+
+ if (fabs(cosHalfTheta) >= 1.0f) result = q1;
+ else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount);
+ else
+ {
+ float halfTheta = acos(cosHalfTheta);
+ float sinHalfTheta = sqrt(1.0f - cosHalfTheta*cosHalfTheta);
+
+ if (fabs(sinHalfTheta) < 0.001f)
+ {
+ result.x = (q1.x*0.5f + q2.x*0.5f);
+ result.y = (q1.y*0.5f + q2.y*0.5f);
+ result.z = (q1.z*0.5f + q2.z*0.5f);
+ result.w = (q1.w*0.5f + q2.w*0.5f);
+ }
+ else
+ {
+ float ratioA = sinf((1 - amount)*halfTheta)/sinHalfTheta;
+ float ratioB = sinf(amount*halfTheta)/sinHalfTheta;
+
+ result.x = (q1.x*ratioA + q2.x*ratioB);
+ result.y = (q1.y*ratioA + q2.y*ratioB);
+ result.z = (q1.z*ratioA + q2.z*ratioB);
+ result.w = (q1.w*ratioA + q2.w*ratioB);
+ }
+ }
+
+ return result;
+}
+
+// Calculate slerp-optimized interpolation between two quaternions
+RMDEF Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount)
+{
+ Quaternion result = QuaternionLerp(q1, q2, amount);
+ QuaternionNormalize(&result);
+
+ return result;
+}
+
+// Calculate quaternion based on the rotation from one vector to another
+RMDEF Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to)
+{
+ Quaternion q = { 0 };
+
+ float cos2Theta = Vector3DotProduct(from, to);
+ Vector3 cross = Vector3CrossProduct(from, to);
+
+ q.x = cross.x;
+ q.y = cross.y;
+ q.z = cross.y;
+ q.w = 1.0f + cos2Theta; // NOTE: Added QuaternioIdentity()
+
+ // Normalize to essentially nlerp the original and identity to 0.5
+ QuaternionNormalize(&q);
+
+ // Above lines are equivalent to:
+ //Quaternion result = QuaternionNlerp(q, QuaternionIdentity(), 0.5f);
+
+ return q;
+}
+
+// Returns a quaternion for a given rotation matrix
+RMDEF Quaternion QuaternionFromMatrix(Matrix matrix)
+{
+ Quaternion result;
+
+ float trace = MatrixTrace(matrix);
+
+ if (trace > 0.0f)
+ {
+ float s = (float)sqrt(trace + 1)*2.0f;
+ float invS = 1.0f/s;
+
+ result.w = s*0.25f;
+ result.x = (matrix.m6 - matrix.m9)*invS;
+ result.y = (matrix.m8 - matrix.m2)*invS;
+ result.z = (matrix.m1 - matrix.m4)*invS;
+ }
+ else
+ {
+ float m00 = matrix.m0, m11 = matrix.m5, m22 = matrix.m10;
+
+ if (m00 > m11 && m00 > m22)
+ {
+ float s = (float)sqrt(1.0f + m00 - m11 - m22)*2.0f;
+ float invS = 1.0f/s;
+
+ result.w = (matrix.m6 - matrix.m9)*invS;
+ result.x = s*0.25f;
+ result.y = (matrix.m4 + matrix.m1)*invS;
+ result.z = (matrix.m8 + matrix.m2)*invS;
+ }
+ else if (m11 > m22)
+ {
+ float s = (float)sqrt(1.0f + m11 - m00 - m22)*2.0f;
+ float invS = 1.0f/s;
+
+ result.w = (matrix.m8 - matrix.m2)*invS;
+ result.x = (matrix.m4 + matrix.m1)*invS;
+ result.y = s*0.25f;
+ result.z = (matrix.m9 + matrix.m6)*invS;
+ }
+ else
+ {
+ float s = (float)sqrt(1.0f + m22 - m00 - m11)*2.0f;
+ float invS = 1.0f/s;
+
+ result.w = (matrix.m1 - matrix.m4)*invS;
+ result.x = (matrix.m8 + matrix.m2)*invS;
+ result.y = (matrix.m9 + matrix.m6)*invS;
+ result.z = s*0.25f;
+ }
+ }
+
+ return result;
+}
+
+// Returns a matrix for a given quaternion
+RMDEF Matrix QuaternionToMatrix(Quaternion q)
+{
+ Matrix result;
+
+ float x = q.x, y = q.y, z = q.z, w = q.w;
+
+ float x2 = x + x;
+ float y2 = y + y;
+ float z2 = z + z;
+
+ float length = QuaternionLength(q);
+ float lengthSquared = length*length;
+
+ float xx = x*x2/lengthSquared;
+ float xy = x*y2/lengthSquared;
+ float xz = x*z2/lengthSquared;
+
+ float yy = y*y2/lengthSquared;
+ float yz = y*z2/lengthSquared;
+ float zz = z*z2/lengthSquared;
+
+ float wx = w*x2/lengthSquared;
+ float wy = w*y2/lengthSquared;
+ float wz = w*z2/lengthSquared;
+
+ result.m0 = 1.0f - (yy + zz);
+ result.m1 = xy - wz;
+ result.m2 = xz + wy;
+ result.m3 = 0.0f;
+ result.m4 = xy + wz;
+ result.m5 = 1.0f - (xx + zz);
+ result.m6 = yz - wx;
+ result.m7 = 0.0f;
+ result.m8 = xz - wy;
+ result.m9 = yz + wx;
+ result.m10 = 1.0f - (xx + yy);
+ result.m11 = 0.0f;
+ result.m12 = 0.0f;
+ result.m13 = 0.0f;
+ result.m14 = 0.0f;
+ result.m15 = 1.0f;
+
+ return result;
+}
+
+// Returns rotation quaternion for an angle and axis
+// NOTE: angle must be provided in radians
+RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
+{
+ Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
+
+ if (Vector3Length(axis) != 0.0f)
+
+ angle *= 0.5f;
+
+ Vector3Normalize(&axis);
+
+ float sinres = sinf(angle);
+ float cosres = cosf(angle);
+
+ result.x = axis.x*sinres;
+ result.y = axis.y*sinres;
+ result.z = axis.z*sinres;
+ result.w = cosres;
+
+ QuaternionNormalize(&result);
+
+ return result;
+}
+
+// Returns the rotation angle and axis for a given quaternion
+RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
+{
+ if (fabs(q.w) > 1.0f) QuaternionNormalize(&q);
+
+ Vector3 resAxis = { 0.0f, 0.0f, 0.0f };
+ float resAngle = 0.0f;
+
+ resAngle = 2.0f*(float)acos(q.w);
+ float den = (float)sqrt(1.0f - q.w*q.w);
+
+ if (den > 0.0001f)
+ {
+ resAxis.x = q.x/den;
+ resAxis.y = q.y/den;
+ resAxis.z = q.z/den;
+ }
+ else
+ {
+ // This occurs when the angle is zero.
+ // Not a problem: just set an arbitrary normalized axis.
+ resAxis.x = 1.0f;
+ }
+
+ *outAxis = resAxis;
+ *outAngle = resAngle;
+}
+
+// Returns he quaternion equivalent to Euler angles
+RMDEF Quaternion QuaternionFromEuler(float roll, float pitch, float yaw)
+{
+ Quaternion q = { 0 };
+
+ float x0 = cosf(roll*0.5f);
+ float x1 = sinf(roll*0.5f);
+ float y0 = cosf(pitch*0.5f);
+ float y1 = sinf(pitch*0.5f);
+ float z0 = cosf(yaw*0.5f);
+ float z1 = sinf(yaw*0.5f);
+
+ q.x = x1*y0*z0 - x0*y1*z1;
+ q.y = x0*y1*z0 + x1*y0*z1;
+ q.z = x0*y0*z1 - x1*y1*z0;
+ q.w = x0*y0*z0 + x1*y1*z1;
+
+ return q;
+}
+
+// Return the Euler angles equivalent to quaternion (roll, pitch, yaw)
+// NOTE: Angles are returned in a Vector3 struct in degrees
+RMDEF Vector3 QuaternionToEuler(Quaternion q)
+{
+ Vector3 v = { 0 };
+
+ // roll (x-axis rotation)
+ float x0 = 2.0f*(q.w*q.x + q.y*q.z);
+ float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
+ v.x = atan2f(x0, x1)*RAD2DEG;
+
+ // pitch (y-axis rotation)
+ float y0 = 2.0f*(q.w*q.y - q.z*q.x);
+ y0 = y0 > 1.0f ? 1.0f : y0;
+ y0 = y0 < -1.0f ? -1.0f : y0;
+ v.y = asinf(y0)*RAD2DEG;
+
+ // yaw (z-axis rotation)
+ float z0 = 2.0f*(q.w*q.z + q.x*q.y);
+ float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z);
+ v.z = atan2f(z0, z1)*RAD2DEG;
+
+ return v;
+}
+
+// Transform a quaternion given a transformation matrix
+RMDEF void QuaternionTransform(Quaternion *q, Matrix mat)
+{
+ float x = q->x;
+ float y = q->y;
+ float z = q->z;
+ float w = q->w;
+
+ q->x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12*w;
+ q->y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13*w;
+ q->z = mat.m2*x + mat.m6*y + mat.m10*z + mat.m14*w;
+ q->w = mat.m3*x + mat.m7*y + mat.m11*z + mat.m15*w;
+}
+
+#endif // RAYMATH_IMPLEMENTATION
diff --git a/templates/android_project/src/rlgl.c b/templates/android_project/src/rlgl.c
new file mode 100644
index 00000000..2782b493
--- /dev/null
+++ b/templates/android_project/src/rlgl.c
@@ -0,0 +1,4184 @@
+/**********************************************************************************************
+*
+* rlgl - raylib OpenGL abstraction layer
+*
+* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to
+* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...).
+*
+* 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
+*
+* CONFIGURATION:
+*
+* #define GRAPHICS_API_OPENGL_11
+* #define GRAPHICS_API_OPENGL_21
+* #define GRAPHICS_API_OPENGL_33
+* #define GRAPHICS_API_OPENGL_ES2
+* Use selected OpenGL backend
+*
+* #define RLGL_STANDALONE
+* Use rlgl as standalone library (no raylib dependency)
+*
+* #define SUPPORT_VR_SIMULATOR
+* Support VR simulation functionality (stereo rendering)
+*
+* #define SUPPORT_DISTORTION_SHADER
+* Include stereo rendering distortion shader (shader_distortion.h)
+*
+* DEPENDENCIES:
+* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
+* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only)
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2014-2017 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+// Default configuration flags (supported features)
+//-------------------------------------------------
+//#define SUPPORT_VR_SIMULATOR
+//#define SUPPORT_DISTORTION_SHADER
+//-------------------------------------------------
+
+#include "rlgl.h"
+
+#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
+#include <stdlib.h> // Required for: malloc(), free(), rand()
+#include <string.h> // Required for: strcmp(), strlen(), strtok() [Used only in extensions loading]
+#include <math.h> // Required for: atan2()
+
+#if !defined(RLGL_STANDALONE)
+ #include "raymath.h" // Required for: Vector3 and Matrix functions
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_11)
+ #if defined(__APPLE__)
+ #include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
+ #else
+ #include <GL/gl.h> // OpenGL 1.1 library
+ #endif
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_21)
+ #define GRAPHICS_API_OPENGL_33
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_33)
+ #if defined(__APPLE__)
+ #include <OpenGL/gl3.h> // OpenGL 3 library for OSX
+ #else
+ #define GLAD_IMPLEMENTATION
+ #if defined(RLGL_STANDALONE)
+ #include "glad.h" // GLAD extensions loading library, includes OpenGL headers
+ #else
+ #include "external/glad.h" // GLAD extensions loading library, includes OpenGL headers
+ #endif
+ #endif
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ #include <EGL/egl.h> // EGL library
+ #include <GLES2/gl2.h> // OpenGL ES 2.0 library
+ #include <GLES2/gl2ext.h> // OpenGL ES 2.0 extensions library
+#endif
+
+#if defined(RLGL_STANDALONE)
+ #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used only on TraceLog()]
+#endif
+
+#if !defined(GRAPHICS_API_OPENGL_11) && defined(SUPPORT_DISTORTION_SHADER)
+ #include "shader_distortion.h" // Distortion shader to be embedded
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#define MATRIX_STACK_SIZE 16 // Matrix stack max size
+#define MAX_DRAWS_BY_TEXTURE 256 // Draws are organized by texture changes
+#define TEMP_VERTEX_BUFFER_SIZE 4096 // Temporal Vertex Buffer (required for vertex-transformations)
+ // NOTE: Every vertex are 3 floats (12 bytes)
+
+#ifndef GL_SHADING_LANGUAGE_VERSION
+ #define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#endif
+
+#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
+ #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#endif
+#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
+ #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#endif
+#ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
+ #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
+#endif
+#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
+ #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
+#endif
+#ifndef GL_ETC1_RGB8_OES
+ #define GL_ETC1_RGB8_OES 0x8D64
+#endif
+#ifndef GL_COMPRESSED_RGB8_ETC2
+ #define GL_COMPRESSED_RGB8_ETC2 0x9274
+#endif
+#ifndef GL_COMPRESSED_RGBA8_ETC2_EAC
+ #define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
+#endif
+#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
+ #define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
+#endif
+#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
+ #define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
+#endif
+#ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
+ #define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93b0
+#endif
+#ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR
+ #define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93b7
+#endif
+
+#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
+ #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#endif
+
+#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
+ #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_11)
+ #define GL_UNSIGNED_SHORT_5_6_5 0x8363
+ #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+ #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ #define glClearDepth glClearDepthf
+ #define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
+ #define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER
+#endif
+
+// Default vertex attribute names on shader to set location points
+#define DEFAULT_ATTRIB_POSITION_NAME "vertexPosition" // shader-location = 0
+#define DEFAULT_ATTRIB_TEXCOORD_NAME "vertexTexCoord" // shader-location = 1
+#define DEFAULT_ATTRIB_NORMAL_NAME "vertexNormal" // shader-location = 2
+#define DEFAULT_ATTRIB_COLOR_NAME "vertexColor" // shader-location = 3
+#define DEFAULT_ATTRIB_TANGENT_NAME "vertexTangent" // shader-location = 4
+#define DEFAULT_ATTRIB_TEXCOORD2_NAME "vertexTexCoord2" // shader-location = 5
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+
+// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
+typedef struct DynamicBuffer {
+ int vCounter; // vertex position counter to process (and draw) from full buffer
+ int tcCounter; // vertex texcoord counter to process (and draw) from full buffer
+ int cCounter; // vertex color counter to process (and draw) from full buffer
+ float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
+ float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
+ unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
+#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
+ unsigned int *indices; // vertex indices (in case vertex data comes indexed) (6 indices per quad)
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ unsigned short *indices; // vertex indices (in case vertex data comes indexed) (6 indices per quad)
+ // NOTE: 6*2 byte = 12 byte, not alignment problem!
+#endif
+ unsigned int vaoId; // OpenGL Vertex Array Object id
+ unsigned int vboId[4]; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
+} DynamicBuffer;
+
+// Draw call type
+// NOTE: Used to track required draw-calls, organized by texture
+typedef struct DrawCall {
+ int vertexCount;
+ GLuint vaoId;
+ GLuint textureId;
+ GLuint shaderId;
+
+ Matrix projection;
+ Matrix modelview;
+
+ // TODO: Store additional draw state data
+ //int blendMode;
+ //Guint fboId;
+} DrawCall;
+
+#if defined(SUPPORT_VR_SIMULATOR)
+// Head-Mounted-Display device parameters
+typedef struct VrDeviceInfo {
+ int hResolution; // HMD horizontal resolution in pixels
+ int vResolution; // HMD vertical resolution in pixels
+ float hScreenSize; // HMD horizontal size in meters
+ float vScreenSize; // HMD vertical size in meters
+ float vScreenCenter; // HMD screen center in meters
+ float eyeToScreenDistance; // HMD distance between eye and display in meters
+ float lensSeparationDistance; // HMD lens separation distance in meters
+ float interpupillaryDistance; // HMD IPD (distance between pupils) in meters
+ float distortionK[4]; // HMD lens distortion constant parameters
+ float chromaAbCorrection[4]; // HMD chromatic aberration correction parameters
+} VrDeviceInfo;
+
+// VR Stereo rendering configuration for simulator
+typedef struct VrStereoConfig {
+ RenderTexture2D stereoFbo; // VR stereo rendering framebuffer
+ Shader distortionShader; // VR stereo rendering distortion shader
+ //Rectangle eyesViewport[2]; // VR stereo rendering eyes viewports
+ Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
+ Matrix eyesViewOffset[2]; // VR stereo rendering eyes view offset matrices
+} VrStereoConfig;
+#endif
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+static Matrix stack[MATRIX_STACK_SIZE];
+static int stackCounter = 0;
+
+static Matrix modelview;
+static Matrix projection;
+static Matrix *currentMatrix;
+static int currentMatrixMode;
+
+static int currentDrawMode;
+
+static float currentDepth = -1.0f;
+
+static DynamicBuffer lines; // Default dynamic buffer for lines data
+static DynamicBuffer triangles; // Default dynamic buffer for triangles data
+static DynamicBuffer quads; // Default dynamic buffer for quads data (used to draw textures)
+
+// Default buffers draw calls
+static DrawCall *draws;
+static int drawsCounter;
+
+// Temp vertex buffer to be used with rlTranslate, rlRotate, rlScale
+static Vector3 *tempBuffer;
+static int tempBufferCount = 0;
+static bool useTempBuffer = false;
+
+// Shader Programs
+static Shader defaultShader; // Basic shader, support vertex color and diffuse texture
+static Shader currentShader; // Shader to be used on rendering (by default, defaultShader)
+
+// Extension supported flag: VAO
+static bool vaoSupported = false; // VAO support (OpenGL ES2 could not support VAO extension)
+
+// Extension supported flag: Compressed textures
+static bool texCompETC1Supported = false; // ETC1 texture compression support
+static bool texCompETC2Supported = false; // ETC2/EAC texture compression support
+static bool texCompPVRTSupported = false; // PVR texture compression support
+static bool texCompASTCSupported = false; // ASTC texture compression support
+
+#if defined(SUPPORT_VR_SIMULATOR)
+// VR global variables
+static VrDeviceInfo hmd; // Current VR device info
+static VrStereoConfig vrConfig; // VR stereo configuration for simulator
+static bool vrSimulatorReady = false; // VR simulator ready flag
+static bool vrStereoRender = false; // VR stereo rendering enabled/disabled flag
+ // NOTE: This flag is useful to render data over stereo image (i.e. FPS)
+#endif // defined(SUPPORT_VR_SIMULATOR)
+
+#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+
+// Extension supported flag: Anisotropic filtering
+static bool texAnisotropicFilterSupported = false; // Anisotropic texture filtering support
+static float maxAnisotropicLevel = 0.0f; // Maximum anisotropy level supported (minimum is 2.0f)
+
+// Extension supported flag: Clamp mirror wrap mode
+static bool texClampMirrorSupported = false; // Clamp mirror wrap mode supported
+
+#if defined(GRAPHICS_API_OPENGL_ES2)
+// NOTE: VAO functionality is exposed through extensions (OES)
+static PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays;
+static PFNGLBINDVERTEXARRAYOESPROC glBindVertexArray;
+static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays;
+//static PFNGLISVERTEXARRAYOESPROC glIsVertexArray; // NOTE: Fails in WebGL, omitted
+#endif
+
+// Compressed textures support flags
+static bool texCompDXTSupported = false; // DDS texture compression support
+static bool texNPOTSupported = false; // NPOT textures full support
+static bool texFloatSupported = false; // float textures support (32 bit per channel)
+
+static int blendMode = 0; // Track current blending mode
+
+// White texture useful for plain color polys (required by shader)
+static unsigned int whiteTexture;
+
+// Default framebuffer size
+static int screenWidth; // Default framebuffer width
+static int screenHeight; // Default framebuffer height
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Declaration
+//----------------------------------------------------------------------------------
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+static void LoadTextureCompressed(unsigned char *data, int width, int height, int compressedFormat, int mipmapCount);
+static unsigned int LoadShaderProgram(const char *vShaderStr, const char *fShaderStr); // Load custom shader strings and return program id
+
+static Shader LoadShaderDefault(void); // Load default shader (just vertex positioning and texture coloring)
+static void SetShaderDefaultLocations(Shader *shader); // Bind default shader locations (attributes and uniforms)
+static void UnloadShaderDefault(void); // Unload default shader
+
+static void LoadBuffersDefault(void); // Load default internal buffers (lines, triangles, quads)
+static void UpdateBuffersDefault(void); // Update default internal buffers (VAOs/VBOs) with vertex data
+static void DrawBuffersDefault(void); // Draw default internal buffers vertex data
+static void UnloadBuffersDefault(void); // Unload default internal buffers vertex data from CPU and GPU
+
+static void GenDrawCube(void); // Generate and draw cube
+static void GenDrawQuad(void); // Generate and draw quad
+
+#if defined(SUPPORT_VR_SIMULATOR)
+static void SetStereoConfig(VrDeviceInfo info); // Configure stereo rendering (including distortion shader) with HMD device parameters
+static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView); // Set internal projection and modelview matrix depending on eye
+#endif
+
+#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+
+#if defined(GRAPHICS_API_OPENGL_11)
+static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight);
+static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
+#endif
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Matrix operations
+//----------------------------------------------------------------------------------
+
+#if defined(GRAPHICS_API_OPENGL_11)
+
+// Fallback to OpenGL 1.1 function calls
+//---------------------------------------
+void rlMatrixMode(int mode)
+{
+ switch (mode)
+ {
+ case RL_PROJECTION: glMatrixMode(GL_PROJECTION); break;
+ case RL_MODELVIEW: glMatrixMode(GL_MODELVIEW); break;
+ case RL_TEXTURE: glMatrixMode(GL_TEXTURE); break;
+ default: break;
+ }
+}
+
+void rlFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
+{
+ glFrustum(left, right, bottom, top, zNear, zFar);
+}
+
+void rlOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
+{
+ glOrtho(left, right, bottom, top, zNear, zFar);
+}
+
+void rlPushMatrix(void) { glPushMatrix(); }
+void rlPopMatrix(void) { glPopMatrix(); }
+void rlLoadIdentity(void) { glLoadIdentity(); }
+void rlTranslatef(float x, float y, float z) { glTranslatef(x, y, z); }
+void rlRotatef(float angleDeg, float x, float y, float z) { glRotatef(angleDeg, x, y, z); }
+void rlScalef(float x, float y, float z) { glScalef(x, y, z); }
+void rlMultMatrixf(float *matf) { glMultMatrixf(matf); }
+
+#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+
+// Choose the current matrix to be transformed
+void rlMatrixMode(int mode)
+{
+ if (mode == RL_PROJECTION) currentMatrix = &projection;
+ else if (mode == RL_MODELVIEW) currentMatrix = &modelview;
+ //else if (mode == RL_TEXTURE) // Not supported
+
+ currentMatrixMode = mode;
+}
+
+// Push the current matrix to stack
+void rlPushMatrix(void)
+{
+ if (stackCounter == MATRIX_STACK_SIZE - 1)
+ {
+ TraceLog(LOG_ERROR, "Stack Buffer Overflow (MAX %i Matrix)", MATRIX_STACK_SIZE);
+ }
+
+ stack[stackCounter] = *currentMatrix;
+ stackCounter++;
+
+ if (currentMatrixMode == RL_MODELVIEW) useTempBuffer = true;
+}
+
+// Pop lattest inserted matrix from stack
+void rlPopMatrix(void)
+{
+ if (stackCounter > 0)
+ {
+ Matrix mat = stack[stackCounter - 1];
+ *currentMatrix = mat;
+ stackCounter--;
+ }
+}
+
+// Reset current matrix to identity matrix
+void rlLoadIdentity(void)
+{
+ *currentMatrix = MatrixIdentity();
+}
+
+// Multiply the current matrix by a translation matrix
+void rlTranslatef(float x, float y, float z)
+{
+ Matrix matTranslation = MatrixTranslate(x, y, z);
+
+ // NOTE: We transpose matrix with multiplication order
+ *currentMatrix = MatrixMultiply(matTranslation, *currentMatrix);
+}
+
+// Multiply the current matrix by a rotation matrix
+void rlRotatef(float angleDeg, float x, float y, float z)
+{
+ Matrix matRotation = MatrixIdentity();
+
+ Vector3 axis = (Vector3){ x, y, z };
+ Vector3Normalize(&axis);
+ matRotation = MatrixRotate(axis, angleDeg*DEG2RAD);
+
+ // NOTE: We transpose matrix with multiplication order
+ *currentMatrix = MatrixMultiply(matRotation, *currentMatrix);
+}
+
+// Multiply the current matrix by a scaling matrix
+void rlScalef(float x, float y, float z)
+{
+ Matrix matScale = MatrixScale(x, y, z);
+
+ // NOTE: We transpose matrix with multiplication order
+ *currentMatrix = MatrixMultiply(matScale, *currentMatrix);
+}
+
+// Multiply the current matrix by another matrix
+void rlMultMatrixf(float *matf)
+{
+ // Matrix creation from array
+ Matrix mat = { matf[0], matf[4], matf[8], matf[12],
+ matf[1], matf[5], matf[9], matf[13],
+ matf[2], matf[6], matf[10], matf[14],
+ matf[3], matf[7], matf[11], matf[15] };
+
+ *currentMatrix = MatrixMultiply(*currentMatrix, mat);
+}
+
+// Multiply the current matrix by a perspective matrix generated by parameters
+void rlFrustum(double left, double right, double bottom, double top, double near, double far)
+{
+ Matrix matPerps = MatrixFrustum(left, right, bottom, top, near, far);
+
+ *currentMatrix = MatrixMultiply(*currentMatrix, matPerps);
+}
+
+// Multiply the current matrix by an orthographic matrix generated by parameters
+void rlOrtho(double left, double right, double bottom, double top, double near, double far)
+{
+ Matrix matOrtho = MatrixOrtho(left, right, bottom, top, near, far);
+
+ *currentMatrix = MatrixMultiply(*currentMatrix, matOrtho);
+}
+
+#endif
+
+// Set the viewport area (transformation from normalized device coordinates to window coordinates)
+// NOTE: Updates global variables: screenWidth, screenHeight
+void rlViewport(int x, int y, int width, int height)
+{
+ glViewport(x, y, width, height);
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Vertex level operations
+//----------------------------------------------------------------------------------
+#if defined(GRAPHICS_API_OPENGL_11)
+
+// Fallback to OpenGL 1.1 function calls
+//---------------------------------------
+void rlBegin(int mode)
+{
+ switch (mode)
+ {
+ case RL_LINES: glBegin(GL_LINES); break;
+ case RL_TRIANGLES: glBegin(GL_TRIANGLES); break;
+ case RL_QUADS: glBegin(GL_QUADS); break;
+ default: break;
+ }
+}
+
+void rlEnd() { glEnd(); }
+void rlVertex2i(int x, int y) { glVertex2i(x, y); }
+void rlVertex2f(float x, float y) { glVertex2f(x, y); }
+void rlVertex3f(float x, float y, float z) { glVertex3f(x, y, z); }
+void rlTexCoord2f(float x, float y) { glTexCoord2f(x, y); }
+void rlNormal3f(float x, float y, float z) { glNormal3f(x, y, z); }
+void rlColor4ub(byte r, byte g, byte b, byte a) { glColor4ub(r, g, b, a); }
+void rlColor3f(float x, float y, float z) { glColor3f(x, y, z); }
+void rlColor4f(float x, float y, float z, float w) { glColor4f(x, y, z, w); }
+
+#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+
+// Initialize drawing mode (how to organize vertex)
+void rlBegin(int mode)
+{
+ // Draw mode can only be RL_LINES, RL_TRIANGLES and RL_QUADS
+ currentDrawMode = mode;
+}
+
+// Finish vertex providing
+void rlEnd(void)
+{
+ if (useTempBuffer)
+ {
+ // NOTE: In this case, *currentMatrix is already transposed because transposing has been applied
+ // independently to translation-scale-rotation matrices -> t(M1 x M2) = t(M2) x t(M1)
+ // This way, rlTranslatef(), rlRotatef()... behaviour is the same than OpenGL 1.1
+
+ // Apply transformation matrix to all temp vertices
+ for (int i = 0; i < tempBufferCount; i++) Vector3Transform(&tempBuffer[i], *currentMatrix);
+
+ // Deactivate tempBuffer usage to allow rlVertex3f do its job
+ useTempBuffer = false;
+
+ // Copy all transformed vertices to right VAO
+ for (int i = 0; i < tempBufferCount; i++) rlVertex3f(tempBuffer[i].x, tempBuffer[i].y, tempBuffer[i].z);
+
+ // Reset temp buffer
+ tempBufferCount = 0;
+ }
+
+ // Make sure vertexCount is the same for vertices-texcoords-normals-colors
+ // NOTE: In OpenGL 1.1, one glColor call can be made for all the subsequent glVertex calls.
+ switch (currentDrawMode)
+ {
+ case RL_LINES:
+ {
+ if (lines.vCounter != lines.cCounter)
+ {
+ int addColors = lines.vCounter - lines.cCounter;
+
+ for (int i = 0; i < addColors; i++)
+ {
+ lines.colors[4*lines.cCounter] = lines.colors[4*lines.cCounter - 4];
+ lines.colors[4*lines.cCounter + 1] = lines.colors[4*lines.cCounter - 3];
+ lines.colors[4*lines.cCounter + 2] = lines.colors[4*lines.cCounter - 2];
+ lines.colors[4*lines.cCounter + 3] = lines.colors[4*lines.cCounter - 1];
+
+ lines.cCounter++;
+ }
+ }
+ } break;
+ case RL_TRIANGLES:
+ {
+ if (triangles.vCounter != triangles.cCounter)
+ {
+ int addColors = triangles.vCounter - triangles.cCounter;
+
+ for (int i = 0; i < addColors; i++)
+ {
+ triangles.colors[4*triangles.cCounter] = triangles.colors[4*triangles.cCounter - 4];
+ triangles.colors[4*triangles.cCounter + 1] = triangles.colors[4*triangles.cCounter - 3];
+ triangles.colors[4*triangles.cCounter + 2] = triangles.colors[4*triangles.cCounter - 2];
+ triangles.colors[4*triangles.cCounter + 3] = triangles.colors[4*triangles.cCounter - 1];
+
+ triangles.cCounter++;
+ }
+ }
+ } break;
+ case RL_QUADS:
+ {
+ // Make sure colors count match vertex count
+ if (quads.vCounter != quads.cCounter)
+ {
+ int addColors = quads.vCounter - quads.cCounter;
+
+ for (int i = 0; i < addColors; i++)
+ {
+ quads.colors[4*quads.cCounter] = quads.colors[4*quads.cCounter - 4];
+ quads.colors[4*quads.cCounter + 1] = quads.colors[4*quads.cCounter - 3];
+ quads.colors[4*quads.cCounter + 2] = quads.colors[4*quads.cCounter - 2];
+ quads.colors[4*quads.cCounter + 3] = quads.colors[4*quads.cCounter - 1];
+
+ quads.cCounter++;
+ }
+ }
+
+ // Make sure texcoords count match vertex count
+ if (quads.vCounter != quads.tcCounter)
+ {
+ int addTexCoords = quads.vCounter - quads.tcCounter;
+
+ for (int i = 0; i < addTexCoords; i++)
+ {
+ quads.texcoords[2*quads.tcCounter] = 0.0f;
+ quads.texcoords[2*quads.tcCounter + 1] = 0.0f;
+
+ quads.tcCounter++;
+ }
+ }
+
+ // TODO: Make sure normals count match vertex count... if normals support is added in a future... :P
+
+ } break;
+ default: break;
+ }
+
+ // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
+ // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
+ // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
+ currentDepth += (1.0f/20000.0f);
+}
+
+// Define one vertex (position)
+void rlVertex3f(float x, float y, float z)
+{
+ if (useTempBuffer)
+ {
+ tempBuffer[tempBufferCount].x = x;
+ tempBuffer[tempBufferCount].y = y;
+ tempBuffer[tempBufferCount].z = z;
+ tempBufferCount++;
+ }
+ else
+ {
+ switch (currentDrawMode)
+ {
+ case RL_LINES:
+ {
+ // Verify that MAX_LINES_BATCH limit not reached
+ if (lines.vCounter/2 < MAX_LINES_BATCH)
+ {
+ lines.vertices[3*lines.vCounter] = x;
+ lines.vertices[3*lines.vCounter + 1] = y;
+ lines.vertices[3*lines.vCounter + 2] = z;
+
+ lines.vCounter++;
+ }
+ else TraceLog(LOG_ERROR, "MAX_LINES_BATCH overflow");
+
+ } break;
+ case RL_TRIANGLES:
+ {
+ // Verify that MAX_TRIANGLES_BATCH limit not reached
+ if (triangles.vCounter/3 < MAX_TRIANGLES_BATCH)
+ {
+ triangles.vertices[3*triangles.vCounter] = x;
+ triangles.vertices[3*triangles.vCounter + 1] = y;
+ triangles.vertices[3*triangles.vCounter + 2] = z;
+
+ triangles.vCounter++;
+ }
+ else TraceLog(LOG_ERROR, "MAX_TRIANGLES_BATCH overflow");
+
+ } break;
+ case RL_QUADS:
+ {
+ // Verify that MAX_QUADS_BATCH limit not reached
+ if (quads.vCounter/4 < MAX_QUADS_BATCH)
+ {
+ quads.vertices[3*quads.vCounter] = x;
+ quads.vertices[3*quads.vCounter + 1] = y;
+ quads.vertices[3*quads.vCounter + 2] = z;
+
+ quads.vCounter++;
+
+ draws[drawsCounter - 1].vertexCount++;
+ }
+ else TraceLog(LOG_ERROR, "MAX_QUADS_BATCH overflow");
+
+ } break;
+ default: break;
+ }
+ }
+}
+
+// Define one vertex (position)
+void rlVertex2f(float x, float y)
+{
+ rlVertex3f(x, y, currentDepth);
+}
+
+// Define one vertex (position)
+void rlVertex2i(int x, int y)
+{
+ rlVertex3f((float)x, (float)y, currentDepth);
+}
+
+// Define one vertex (texture coordinate)
+// NOTE: Texture coordinates are limited to QUADS only
+void rlTexCoord2f(float x, float y)
+{
+ if (currentDrawMode == RL_QUADS)
+ {
+ quads.texcoords[2*quads.tcCounter] = x;
+ quads.texcoords[2*quads.tcCounter + 1] = y;
+
+ quads.tcCounter++;
+ }
+}
+
+// Define one vertex (normal)
+// NOTE: Normals limited to TRIANGLES only ?
+void rlNormal3f(float x, float y, float z)
+{
+ // TODO: Normals usage...
+}
+
+// Define one vertex (color)
+void rlColor4ub(byte x, byte y, byte z, byte w)
+{
+ switch (currentDrawMode)
+ {
+ case RL_LINES:
+ {
+ lines.colors[4*lines.cCounter] = x;
+ lines.colors[4*lines.cCounter + 1] = y;
+ lines.colors[4*lines.cCounter + 2] = z;
+ lines.colors[4*lines.cCounter + 3] = w;
+
+ lines.cCounter++;
+
+ } break;
+ case RL_TRIANGLES:
+ {
+ triangles.colors[4*triangles.cCounter] = x;
+ triangles.colors[4*triangles.cCounter + 1] = y;
+ triangles.colors[4*triangles.cCounter + 2] = z;
+ triangles.colors[4*triangles.cCounter + 3] = w;
+
+ triangles.cCounter++;
+
+ } break;
+ case RL_QUADS:
+ {
+ quads.colors[4*quads.cCounter] = x;
+ quads.colors[4*quads.cCounter + 1] = y;
+ quads.colors[4*quads.cCounter + 2] = z;
+ quads.colors[4*quads.cCounter + 3] = w;
+
+ quads.cCounter++;
+
+ } break;
+ default: break;
+ }
+}
+
+// Define one vertex (color)
+void rlColor4f(float r, float g, float b, float a)
+{
+ rlColor4ub((byte)(r*255), (byte)(g*255), (byte)(b*255), (byte)(a*255));
+}
+
+// Define one vertex (color)
+void rlColor3f(float x, float y, float z)
+{
+ rlColor4ub((byte)(x*255), (byte)(y*255), (byte)(z*255), 255);
+}
+
+#endif
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
+//----------------------------------------------------------------------------------
+
+// Enable texture usage
+void rlEnableTexture(unsigned int id)
+{
+#if defined(GRAPHICS_API_OPENGL_11)
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, id);
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (draws[drawsCounter - 1].textureId != id)
+ {
+ if (draws[drawsCounter - 1].vertexCount > 0) drawsCounter++;
+
+ if (drawsCounter >= MAX_DRAWS_BY_TEXTURE)
+ {
+ rlglDraw();
+ drawsCounter = 1;
+ }
+
+ draws[drawsCounter - 1].textureId = id;
+ draws[drawsCounter - 1].vertexCount = 0;
+ }
+#endif
+}
+
+// Disable texture usage
+void rlDisableTexture(void)
+{
+#if defined(GRAPHICS_API_OPENGL_11)
+ glDisable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, 0);
+#else
+ // NOTE: If quads batch limit is reached,
+ // we force a draw call and next batch starts
+ if (quads.vCounter/4 >= MAX_QUADS_BATCH) rlglDraw();
+#endif
+}
+
+// Set texture parameters (wrap mode/filter mode)
+void rlTextureParameters(unsigned int id, int param, int value)
+{
+ glBindTexture(GL_TEXTURE_2D, id);
+
+ switch (param)
+ {
+ case RL_TEXTURE_WRAP_S:
+ case RL_TEXTURE_WRAP_T:
+ {
+ if ((value == RL_WRAP_CLAMP_MIRROR) && !texClampMirrorSupported) TraceLog(LOG_WARNING, "Clamp mirror wrap mode not supported");
+ else glTexParameteri(GL_TEXTURE_2D, param, value);
+ } break;
+ case RL_TEXTURE_MAG_FILTER:
+ case RL_TEXTURE_MIN_FILTER: glTexParameteri(GL_TEXTURE_2D, param, value); break;
+ case RL_TEXTURE_ANISOTROPIC_FILTER:
+ {
+ if (value <= maxAnisotropicLevel) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
+ else if (maxAnisotropicLevel > 0.0f)
+ {
+ TraceLog(LOG_WARNING, "[TEX ID %i] Maximum anisotropic filter level supported is %iX", id, maxAnisotropicLevel);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
+ }
+ else TraceLog(LOG_WARNING, "Anisotropic filtering not supported");
+ } break;
+ default: break;
+ }
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+// Enable rendering to texture (fbo)
+void rlEnableRenderTexture(unsigned int id)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ glBindFramebuffer(GL_FRAMEBUFFER, id);
+
+ //glDisable(GL_CULL_FACE); // Allow double side drawing for texture flipping
+ //glCullFace(GL_FRONT);
+#endif
+}
+
+// Disable rendering to texture
+void rlDisableRenderTexture(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ //glEnable(GL_CULL_FACE);
+ //glCullFace(GL_BACK);
+#endif
+}
+
+// Enable depth test
+void rlEnableDepthTest(void)
+{
+ glEnable(GL_DEPTH_TEST);
+}
+
+// Disable depth test
+void rlDisableDepthTest(void)
+{
+ glDisable(GL_DEPTH_TEST);
+}
+
+// Enable wire mode
+void rlEnableWireMode(void)
+{
+#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
+ // NOTE: glPolygonMode() not available on OpenGL ES
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+#endif
+}
+
+// Disable wire mode
+void rlDisableWireMode(void)
+{
+#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
+ // NOTE: glPolygonMode() not available on OpenGL ES
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+#endif
+}
+
+// Unload texture from GPU memory
+void rlDeleteTextures(unsigned int id)
+{
+ if (id > 0) glDeleteTextures(1, &id);
+}
+
+// Unload render texture from GPU memory
+void rlDeleteRenderTextures(RenderTexture2D target)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (target.id > 0) glDeleteFramebuffers(1, &target.id);
+ if (target.texture.id > 0) glDeleteTextures(1, &target.texture.id);
+ if (target.depth.id > 0) glDeleteTextures(1, &target.depth.id);
+
+ TraceLog(LOG_INFO, "[FBO ID %i] Unloaded render texture data from VRAM (GPU)", target.id);
+#endif
+}
+
+// Unload shader from GPU memory
+void rlDeleteShader(unsigned int id)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (id != 0) glDeleteProgram(id);
+#endif
+}
+
+// Unload vertex data (VAO) from GPU memory
+void rlDeleteVertexArrays(unsigned int id)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (vaoSupported)
+ {
+ if (id != 0) glDeleteVertexArrays(1, &id);
+ TraceLog(LOG_INFO, "[VAO ID %i] Unloaded model data from VRAM (GPU)", id);
+ }
+#endif
+}
+
+// Unload vertex data (VBO) from GPU memory
+void rlDeleteBuffers(unsigned int id)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (id != 0)
+ {
+ glDeleteBuffers(1, &id);
+ if (!vaoSupported) TraceLog(LOG_INFO, "[VBO ID %i] Unloaded model vertex data from VRAM (GPU)", id);
+ }
+#endif
+}
+
+// Clear color buffer with color
+void rlClearColor(byte r, byte g, byte b, byte a)
+{
+ // Color values clamp to 0.0f(0) and 1.0f(255)
+ float cr = (float)r/255;
+ float cg = (float)g/255;
+ float cb = (float)b/255;
+ float ca = (float)a/255;
+
+ glClearColor(cr, cg, cb, ca);
+}
+
+// Clear used screen buffers (color and depth)
+void rlClearScreenBuffers(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear used buffers: Color and Depth (Depth is used for 3D)
+ //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Stencil buffer not used...
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - rlgl Functions
+//----------------------------------------------------------------------------------
+
+// Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
+void rlglInit(int width, int height)
+{
+ // Check OpenGL information and capabilities
+ //------------------------------------------------------------------------------
+
+ // Print current OpenGL and GLSL version
+ TraceLog(LOG_INFO, "GPU: Vendor: %s", glGetString(GL_VENDOR));
+ TraceLog(LOG_INFO, "GPU: Renderer: %s", glGetString(GL_RENDERER));
+ TraceLog(LOG_INFO, "GPU: Version: %s", glGetString(GL_VERSION));
+ TraceLog(LOG_INFO, "GPU: GLSL: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
+
+ // NOTE: We can get a bunch of extra information about GPU capabilities (glGet*)
+ //int maxTexSize;
+ //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
+ //TraceLog(LOG_INFO, "GL_MAX_TEXTURE_SIZE: %i", maxTexSize);
+
+ //GL_MAX_TEXTURE_IMAGE_UNITS
+ //GL_MAX_VIEWPORT_DIMS
+
+ //int numAuxBuffers;
+ //glGetIntegerv(GL_AUX_BUFFERS, &numAuxBuffers);
+ //TraceLog(LOG_INFO, "GL_AUX_BUFFERS: %i", numAuxBuffers);
+
+ //GLint numComp = 0;
+ //GLint format[32] = { 0 };
+ //glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numComp);
+ //glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, format);
+ //for (int i = 0; i < numComp; i++) TraceLog(LOG_INFO, "Supported compressed format: 0x%x", format[i]);
+
+ // NOTE: We don't need that much data on screen... right now...
+
+#if defined(GRAPHICS_API_OPENGL_11)
+ //TraceLog(LOG_INFO, "OpenGL 1.1 (or driver default) profile initialized");
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ // Get supported extensions list
+ GLint numExt = 0;
+
+#if defined(GRAPHICS_API_OPENGL_33)
+
+ // NOTE: On OpenGL 3.3 VAO and NPOT are supported by default
+ vaoSupported = true;
+ texNPOTSupported = true;
+ texFloatSupported = true;
+
+ // We get a list of available extensions and we check for some of them (compressed textures)
+ // NOTE: We don't need to check again supported extensions but we do (GLAD already dealt with that)
+ glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);
+
+#ifdef _MSC_VER
+ const char **extList = malloc(sizeof(const char *)*numExt);
+#else
+ const char *extList[numExt];
+#endif
+
+ for (int i = 0; i < numExt; i++) extList[i] = (char *)glGetStringi(GL_EXTENSIONS, i);
+
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ char *extensions = (char *)glGetString(GL_EXTENSIONS); // One big const string
+
+ // NOTE: We have to duplicate string because glGetString() returns a const value
+ // If not duplicated, it fails in some systems (Raspberry Pi)
+ // Equivalent to function: char *strdup(const char *str)
+ char *extensionsDup;
+ size_t len = strlen(extensions) + 1;
+ void *newstr = malloc(len);
+ if (newstr == NULL) extensionsDup = NULL;
+ extensionsDup = (char *)memcpy(newstr, extensions, len);
+
+ // NOTE: String could be splitted using strtok() function (string.h)
+ // NOTE: strtok() modifies the received string, it can not be const
+
+ char *extList[512]; // Allocate 512 strings pointers (2 KB)
+
+ extList[numExt] = strtok(extensionsDup, " ");
+
+ while (extList[numExt] != NULL)
+ {
+ numExt++;
+ extList[numExt] = strtok(NULL, " ");
+ }
+
+ free(extensionsDup); // Duplicated string must be deallocated
+
+ numExt -= 1;
+#endif
+
+ TraceLog(LOG_INFO, "Number of supported extensions: %i", numExt);
+
+ // Show supported extensions
+ //for (int i = 0; i < numExt; i++) TraceLog(LOG_INFO, "Supported extension: %s", extList[i]);
+
+ // Check required extensions
+ for (int i = 0; i < numExt; i++)
+ {
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ // Check VAO support
+ // NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
+ if (strcmp(extList[i], (const char *)"GL_OES_vertex_array_object") == 0)
+ {
+ vaoSupported = true;
+
+ // The extension is supported by our hardware and driver, try to get related functions pointers
+ // NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
+ glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
+ glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
+ glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
+ //glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted
+ }
+
+ // Check NPOT textures support
+ // NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
+ if (strcmp(extList[i], (const char *)"GL_OES_texture_npot") == 0) texNPOTSupported = true;
+
+ // Check texture float support
+ if (strcmp(extList[i], (const char *)"OES_texture_float") == 0) texFloatSupported = true;
+#endif
+
+ // DDS texture compression support
+ if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
+ (strcmp(extList[i], (const char *)"GL_WEBGL_compressed_texture_s3tc") == 0) ||
+ (strcmp(extList[i], (const char *)"GL_WEBKIT_WEBGL_compressed_texture_s3tc") == 0)) texCompDXTSupported = true;
+
+ // ETC1 texture compression support
+ if ((strcmp(extList[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) ||
+ (strcmp(extList[i], (const char *)"GL_WEBGL_compressed_texture_etc1") == 0)) texCompETC1Supported = true;
+
+ // ETC2/EAC texture compression support
+ if (strcmp(extList[i], (const char *)"GL_ARB_ES3_compatibility") == 0) texCompETC2Supported = true;
+
+ // PVR texture compression support
+ if (strcmp(extList[i], (const char *)"GL_IMG_texture_compression_pvrtc") == 0) texCompPVRTSupported = true;
+
+ // ASTC texture compression support
+ if (strcmp(extList[i], (const char *)"GL_KHR_texture_compression_astc_hdr") == 0) texCompASTCSupported = true;
+
+ // Anisotropic texture filter support
+ if (strcmp(extList[i], (const char *)"GL_EXT_texture_filter_anisotropic") == 0)
+ {
+ texAnisotropicFilterSupported = true;
+ glGetFloatv(0x84FF, &maxAnisotropicLevel); // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
+ }
+
+ // Clamp mirror wrap mode supported
+ if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texClampMirrorSupported = true;
+ }
+
+#ifdef _MSC_VER
+ free(extList);
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ if (vaoSupported) TraceLog(LOG_INFO, "[EXTENSION] VAO extension detected, VAO functions initialized successfully");
+ else TraceLog(LOG_WARNING, "[EXTENSION] VAO extension not found, VAO usage not supported");
+
+ if (texNPOTSupported) TraceLog(LOG_INFO, "[EXTENSION] NPOT textures extension detected, full NPOT textures supported");
+ else TraceLog(LOG_WARNING, "[EXTENSION] NPOT textures extension not found, limited NPOT support (no-mipmaps, no-repeat)");
+#endif
+
+ if (texCompDXTSupported) TraceLog(LOG_INFO, "[EXTENSION] DXT compressed textures supported");
+ if (texCompETC1Supported) TraceLog(LOG_INFO, "[EXTENSION] ETC1 compressed textures supported");
+ if (texCompETC2Supported) TraceLog(LOG_INFO, "[EXTENSION] ETC2/EAC compressed textures supported");
+ if (texCompPVRTSupported) TraceLog(LOG_INFO, "[EXTENSION] PVRT compressed textures supported");
+ if (texCompASTCSupported) TraceLog(LOG_INFO, "[EXTENSION] ASTC compressed textures supported");
+
+ if (texAnisotropicFilterSupported) TraceLog(LOG_INFO, "[EXTENSION] Anisotropic textures filtering supported (max: %.0fX)", maxAnisotropicLevel);
+ if (texClampMirrorSupported) TraceLog(LOG_INFO, "[EXTENSION] Clamp mirror wrap texture mode supported");
+
+ // Initialize buffers, default shaders and default textures
+ //----------------------------------------------------------
+
+ // Init default white texture
+ unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
+
+ whiteTexture = rlLoadTexture(pixels, 1, 1, UNCOMPRESSED_R8G8B8A8, 1);
+
+ if (whiteTexture != 0) TraceLog(LOG_INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture);
+ else TraceLog(LOG_WARNING, "Base white texture could not be loaded");
+
+ // Init default Shader (customized for GL 3.3 and ES2)
+ defaultShader = LoadShaderDefault();
+ currentShader = defaultShader;
+
+ // Init default vertex arrays buffers (lines, triangles, quads)
+ LoadBuffersDefault();
+
+ // Init temp vertex buffer, used when transformation required (translate, rotate, scale)
+ tempBuffer = (Vector3 *)malloc(sizeof(Vector3)*TEMP_VERTEX_BUFFER_SIZE);
+
+ for (int i = 0; i < TEMP_VERTEX_BUFFER_SIZE; i++) tempBuffer[i] = Vector3Zero();
+
+ // Init draw calls tracking system
+ draws = (DrawCall *)malloc(sizeof(DrawCall)*MAX_DRAWS_BY_TEXTURE);
+
+ for (int i = 0; i < MAX_DRAWS_BY_TEXTURE; i++)
+ {
+ draws[i].textureId = 0;
+ draws[i].vertexCount = 0;
+ }
+
+ drawsCounter = 1;
+ draws[drawsCounter - 1].textureId = whiteTexture;
+ currentDrawMode = RL_TRIANGLES; // Set default draw mode
+
+ // Init internal matrix stack (emulating OpenGL 1.1)
+ for (int i = 0; i < MATRIX_STACK_SIZE; i++) stack[i] = MatrixIdentity();
+
+ // Init internal projection and modelview matrices
+ projection = MatrixIdentity();
+ modelview = MatrixIdentity();
+ currentMatrix = &modelview;
+#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+
+ // Initialize OpenGL default states
+ //----------------------------------------------------------
+
+ // Init state: Depth test
+ glDepthFunc(GL_LEQUAL); // Type of depth testing to apply
+ glDisable(GL_DEPTH_TEST); // Disable depth testing for 2D (only used for 3D)
+
+ // Init state: Blending mode
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Color blending function (how colors are mixed)
+ glEnable(GL_BLEND); // Enable color blending (required to work with transparencies)
+
+ // Init state: Culling
+ // NOTE: All shapes/models triangles are drawn CCW
+ glCullFace(GL_BACK); // Cull the back face (default)
+ glFrontFace(GL_CCW); // Front face are defined counter clockwise (default)
+ glEnable(GL_CULL_FACE); // Enable backface culling
+
+#if defined(GRAPHICS_API_OPENGL_11)
+ // Init state: Color hints (deprecated in OpenGL 3.0+)
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Improve quality of color and texture coordinate interpolation
+ glShadeModel(GL_SMOOTH); // Smooth shading between vertex (vertex colors interpolation)
+#endif
+
+ // Init state: Color/Depth buffers clear
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set clear color (black)
+ glClearDepth(1.0f); // Set clear depth value (default)
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers (depth buffer required for 3D)
+
+ // Store screen size into global variables
+ screenWidth = width;
+ screenHeight = height;
+
+ TraceLog(LOG_INFO, "OpenGL default states initialized successfully");
+}
+
+// Vertex Buffer Object deinitialization (memory free)
+void rlglClose(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ UnloadShaderDefault(); // Unload default shader
+ UnloadBuffersDefault(); // Unload default buffers (lines, triangles, quads)
+ glDeleteTextures(1, &whiteTexture); // Unload default texture
+
+ TraceLog(LOG_INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture);
+
+ free(draws);
+#endif
+}
+
+// Drawing batches: triangles, quads, lines
+void rlglDraw(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: In a future version, models could be stored in a stack...
+ //for (int i = 0; i < modelsCount; i++) rlDrawMesh(models[i]->mesh, models[i]->material, models[i]->transform);
+
+ // NOTE: Default buffers upload and draw
+ UpdateBuffersDefault();
+ DrawBuffersDefault(); // NOTE: Stereo rendering is checked inside
+#endif
+}
+
+// Returns current OpenGL version
+int rlGetVersion(void)
+{
+#if defined(GRAPHICS_API_OPENGL_11)
+ return OPENGL_11;
+#elif defined(GRAPHICS_API_OPENGL_21)
+ #if defined(__APPLE__)
+ return OPENGL_33; // NOTE: Force OpenGL 3.3 on OSX
+ #else
+ return OPENGL_21;
+ #endif
+#elif defined(GRAPHICS_API_OPENGL_33)
+ return OPENGL_33;
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ return OPENGL_ES_20;
+#endif
+}
+
+// Load OpenGL extensions
+// NOTE: External loader function could be passed as a pointer
+void rlLoadExtensions(void *loader)
+{
+#if defined(GRAPHICS_API_OPENGL_21) || defined(GRAPHICS_API_OPENGL_33)
+ // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
+ #if !defined(__APPLE__)
+ if (!gladLoadGLLoader((GLADloadproc)loader)) TraceLog(LOG_WARNING, "GLAD: Cannot load OpenGL extensions");
+ else TraceLog(LOG_INFO, "GLAD: OpenGL extensions loaded successfully");
+
+ #if defined(GRAPHICS_API_OPENGL_21)
+ if (GLAD_GL_VERSION_2_1) TraceLog(LOG_INFO, "OpenGL 2.1 profile supported");
+ #elif defined(GRAPHICS_API_OPENGL_33)
+ if(GLAD_GL_VERSION_3_3) TraceLog(LOG_INFO, "OpenGL 3.3 Core profile supported");
+ else TraceLog(LOG_ERROR, "OpenGL 3.3 Core profile not supported");
+ #endif
+ #endif
+
+ // With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
+ //if (GLAD_GL_ARB_vertex_array_object) // Use GL_ARB_vertex_array_object
+#endif
+}
+
+// Get world coordinates from screen coordinates
+Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view)
+{
+ Vector3 result = { 0.0f, 0.0f, 0.0f };
+
+ // Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
+ Matrix matViewProj = MatrixMultiply(view, proj);
+ MatrixInvert(&matViewProj);
+
+ // Create quaternion from source point
+ Quaternion quat = { source.x, source.y, source.z, 1.0f };
+
+ // Multiply quat point by unproject matrix
+ QuaternionTransform(&quat, matViewProj);
+
+ // Normalized world points in vectors
+ result.x = quat.x/quat.w;
+ result.y = quat.y/quat.w;
+ result.z = quat.z/quat.w;
+
+ return result;
+}
+
+// Convert image data to OpenGL texture (returns OpenGL valid Id)
+unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
+{
+ glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding
+
+ GLuint id = 0;
+
+ // Check texture format support by OpenGL 1.1 (compressed textures not supported)
+#if defined(GRAPHICS_API_OPENGL_11)
+ if (format >= COMPRESSED_DXT1_RGB)
+ {
+ TraceLog(LOG_WARNING, "OpenGL 1.1 does not support GPU compressed texture formats");
+ return id;
+ }
+#endif
+
+ if ((!texCompDXTSupported) && ((format == COMPRESSED_DXT1_RGB) || (format == COMPRESSED_DXT1_RGBA) ||
+ (format == COMPRESSED_DXT3_RGBA) || (format == COMPRESSED_DXT5_RGBA)))
+ {
+ TraceLog(LOG_WARNING, "DXT compressed texture format not supported");
+ return id;
+ }
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if ((!texCompETC1Supported) && (format == COMPRESSED_ETC1_RGB))
+ {
+ TraceLog(LOG_WARNING, "ETC1 compressed texture format not supported");
+ return id;
+ }
+
+ if ((!texCompETC2Supported) && ((format == COMPRESSED_ETC2_RGB) || (format == COMPRESSED_ETC2_EAC_RGBA)))
+ {
+ TraceLog(LOG_WARNING, "ETC2 compressed texture format not supported");
+ return id;
+ }
+
+ if ((!texCompPVRTSupported) && ((format == COMPRESSED_PVRT_RGB) || (format == COMPRESSED_PVRT_RGBA)))
+ {
+ TraceLog(LOG_WARNING, "PVRT compressed texture format not supported");
+ return id;
+ }
+
+ if ((!texCompASTCSupported) && ((format == COMPRESSED_ASTC_4x4_RGBA) || (format == COMPRESSED_ASTC_8x8_RGBA)))
+ {
+ TraceLog(LOG_WARNING, "ASTC compressed texture format not supported");
+ return id;
+ }
+#endif
+
+ glGenTextures(1, &id); // Generate Pointer to the texture
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ //glActiveTexture(GL_TEXTURE0); // If not defined, using GL_TEXTURE0 by default (shader texture)
+#endif
+
+ glBindTexture(GL_TEXTURE_2D, id);
+
+#if defined(GRAPHICS_API_OPENGL_33)
+ // NOTE: We define internal (GPU) format as GL_RGBA8 (probably BGRA8 in practice, driver takes care)
+ // NOTE: On embedded systems, we let the driver choose the best internal format
+
+ // Support for multiple color modes (16bit color modes and grayscale)
+ // (sized)internalFormat format type
+ // GL_R GL_RED GL_UNSIGNED_BYTE
+ // GL_RGB565 GL_RGB GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5
+ // GL_RGB5_A1 GL_RGBA GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_5_5_1
+ // GL_RGBA4 GL_RGBA GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_4_4_4_4
+ // GL_RGBA8 GL_RGBA GL_UNSIGNED_BYTE
+ // GL_RGB8 GL_RGB GL_UNSIGNED_BYTE
+
+ switch (format)
+ {
+ case UNCOMPRESSED_GRAYSCALE:
+ {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, (unsigned char *)data);
+
+ // With swizzleMask we define how a one channel texture will be mapped to RGBA
+ // Required GL >= 3.3 or EXT_texture_swizzle/ARB_texture_swizzle
+ GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
+
+ TraceLog(LOG_INFO, "[TEX ID %i] Grayscale texture loaded and swizzled", id);
+ } break;
+ case UNCOMPRESSED_GRAY_ALPHA:
+ {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, (unsigned char *)data);
+
+ GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN };
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
+ } break;
+
+ case UNCOMPRESSED_R5G6B5: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G5B5A1: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break;
+ case UNCOMPRESSED_R4G4B4A4: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8A8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R32G32B32: if (texFloatSupported) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, (float *)data); break;
+ case COMPRESSED_DXT1_RGB: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, mipmapCount); break;
+ case COMPRESSED_DXT1_RGBA: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, mipmapCount); break;
+ case COMPRESSED_DXT3_RGBA: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, mipmapCount); break;
+ case COMPRESSED_DXT5_RGBA: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, mipmapCount); break;
+ case COMPRESSED_ETC1_RGB: if (texCompETC1Supported) LoadTextureCompressed((unsigned char *)data, width, height, GL_ETC1_RGB8_OES, mipmapCount); break; // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
+ case COMPRESSED_ETC2_RGB: if (texCompETC2Supported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGB8_ETC2, mipmapCount); break; // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
+ case COMPRESSED_ETC2_EAC_RGBA: if (texCompETC2Supported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA8_ETC2_EAC, mipmapCount); break; // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
+ case COMPRESSED_PVRT_RGB: if (texCompPVRTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, mipmapCount); break; // NOTE: Requires PowerVR GPU
+ case COMPRESSED_PVRT_RGBA: if (texCompPVRTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, mipmapCount); break; // NOTE: Requires PowerVR GPU
+ case COMPRESSED_ASTC_4x4_RGBA: if (texCompASTCSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, mipmapCount); break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
+ case COMPRESSED_ASTC_8x8_RGBA: if (texCompASTCSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, mipmapCount); break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
+ default: TraceLog(LOG_WARNING, "Texture format not recognized"); break;
+ }
+#elif defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
+ switch (format)
+ {
+ case UNCOMPRESSED_GRAYSCALE: glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_GRAY_ALPHA: glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G6B5: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G5B5A1: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break;
+ case UNCOMPRESSED_R4G4B4A4: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8A8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ case UNCOMPRESSED_R32G32B32: if (texFloatSupported) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, (float *)data); break; // NOTE: Requires extension OES_texture_float
+ case COMPRESSED_DXT1_RGB: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, mipmapCount); break;
+ case COMPRESSED_DXT1_RGBA: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, mipmapCount); break;
+ case COMPRESSED_DXT3_RGBA: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, mipmapCount); break; // NOTE: Not supported by WebGL
+ case COMPRESSED_DXT5_RGBA: if (texCompDXTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, mipmapCount); break; // NOTE: Not supported by WebGL
+ case COMPRESSED_ETC1_RGB: if (texCompETC1Supported) LoadTextureCompressed((unsigned char *)data, width, height, GL_ETC1_RGB8_OES, mipmapCount); break; // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
+ case COMPRESSED_ETC2_RGB: if (texCompETC2Supported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGB8_ETC2, mipmapCount); break; // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
+ case COMPRESSED_ETC2_EAC_RGBA: if (texCompETC2Supported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA8_ETC2_EAC, mipmapCount); break; // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
+ case COMPRESSED_PVRT_RGB: if (texCompPVRTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, mipmapCount); break; // NOTE: Requires PowerVR GPU
+ case COMPRESSED_PVRT_RGBA: if (texCompPVRTSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, mipmapCount); break; // NOTE: Requires PowerVR GPU
+ case COMPRESSED_ASTC_4x4_RGBA: if (texCompASTCSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, mipmapCount); break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
+ case COMPRESSED_ASTC_8x8_RGBA: if (texCompASTCSupported) LoadTextureCompressed((unsigned char *)data, width, height, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, mipmapCount); break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
+#endif
+ default: TraceLog(LOG_WARNING, "Texture format not supported"); break;
+ }
+#endif
+
+ // Texture parameters configuration
+ // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used
+ if (texNPOTSupported)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
+ }
+ else
+ {
+ // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Set texture to clamp on x-axis
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Set texture to clamp on y-axis
+ }
+#else
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
+#endif
+
+ // Magnification and minification filters
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Alternative: GL_LINEAR
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Alternative: GL_LINEAR
+
+#if defined(GRAPHICS_API_OPENGL_33)
+ if (mipmapCount > 1)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps (must be available)
+ }
+#endif
+
+ // At this point we have the texture loaded in GPU and texture parameters configured
+
+ // NOTE: If mipmaps were not in data, they are not generated automatically
+
+ // Unbind current texture
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ if (id > 0) TraceLog(LOG_INFO, "[TEX ID %i] Texture created successfully (%ix%i)", id, width, height);
+ else TraceLog(LOG_WARNING, "Texture could not be created");
+
+ return id;
+}
+
+// Update already loaded texture in GPU with new data
+void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data)
+{
+ glBindTexture(GL_TEXTURE_2D, id);
+
+#if defined(GRAPHICS_API_OPENGL_33)
+ switch (format)
+ {
+ case UNCOMPRESSED_GRAYSCALE: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RED, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_GRAY_ALPHA: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RG, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G6B5: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G5B5A1: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break;
+ case UNCOMPRESSED_R4G4B4A4: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8A8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ default: TraceLog(LOG_WARNING, "Texture format updating not supported"); break;
+ }
+#elif defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
+ switch (format)
+ {
+ case UNCOMPRESSED_GRAYSCALE: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_GRAY_ALPHA: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G6B5: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ case UNCOMPRESSED_R5G5B5A1: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break;
+ case UNCOMPRESSED_R4G4B4A4: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break;
+ case UNCOMPRESSED_R8G8B8A8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break;
+ default: TraceLog(LOG_WARNING, "Texture format updating not supported"); break;
+ }
+#endif
+}
+
+// Unload texture from GPU memory
+void rlUnloadTexture(unsigned int id)
+{
+ if (id > 0) glDeleteTextures(1, &id);
+}
+
+
+// Load a texture to be used for rendering (fbo with color and depth attachments)
+RenderTexture2D rlLoadRenderTexture(int width, int height)
+{
+ RenderTexture2D target;
+
+ target.id = 0;
+
+ target.texture.id = 0;
+ target.texture.width = width;
+ target.texture.height = height;
+ target.texture.format = UNCOMPRESSED_R8G8B8A8;
+ target.texture.mipmaps = 1;
+
+ target.depth.id = 0;
+ target.depth.width = width;
+ target.depth.height = height;
+ target.depth.format = 19; //DEPTH_COMPONENT_24BIT
+ target.depth.mipmaps = 1;
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ // Create the texture that will serve as the color attachment for the framebuffer
+ glGenTextures(1, &target.texture.id);
+ glBindTexture(GL_TEXTURE_2D, target.texture.id);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+#if defined(GRAPHICS_API_OPENGL_33)
+ #define USE_DEPTH_TEXTURE
+#else
+ #define USE_DEPTH_RENDERBUFFER
+#endif
+
+#if defined(USE_DEPTH_RENDERBUFFER)
+ // Create the renderbuffer that will serve as the depth attachment for the framebuffer.
+ glGenRenderbuffers(1, &target.depth.id);
+ glBindRenderbuffer(GL_RENDERBUFFER, target.depth.id);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); // GL_DEPTH_COMPONENT24 not supported on Android
+#elif defined(USE_DEPTH_TEXTURE)
+ // NOTE: We can also use a texture for depth buffer (GL_ARB_depth_texture/GL_OES_depth_texture extension required)
+ // A renderbuffer is simpler than a texture and could offer better performance on embedded devices
+ glGenTextures(1, &target.depth.id);
+ glBindTexture(GL_TEXTURE_2D, target.depth.id);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ glBindTexture(GL_TEXTURE_2D, 0);
+#endif
+
+ // Create the framebuffer object
+ glGenFramebuffers(1, &target.id);
+ glBindFramebuffer(GL_FRAMEBUFFER, target.id);
+
+ // Attach color texture and depth renderbuffer to FBO
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, target.texture.id, 0);
+#if defined(USE_DEPTH_RENDERBUFFER)
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, target.depth.id);
+#elif defined(USE_DEPTH_TEXTURE)
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, target.depth.id, 0);
+#endif
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE)
+ {
+ TraceLog(LOG_WARNING, "Framebuffer object could not be created...");
+
+ switch (status)
+ {
+ case GL_FRAMEBUFFER_UNSUPPORTED: TraceLog(LOG_WARNING, "Framebuffer is unsupported"); break;
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: TraceLog(LOG_WARNING, "Framebuffer incomplete attachment"); break;
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: TraceLog(LOG_WARNING, "Framebuffer incomplete dimensions"); break;
+#endif
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: TraceLog(LOG_WARNING, "Framebuffer incomplete missing attachment"); break;
+ default: break;
+ }
+
+ glDeleteTextures(1, &target.texture.id);
+ glDeleteTextures(1, &target.depth.id);
+ glDeleteFramebuffers(1, &target.id);
+ }
+ else TraceLog(LOG_INFO, "[FBO ID %i] Framebuffer object created successfully", target.id);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+#endif
+
+ return target;
+}
+
+// Generate mipmap data for selected texture
+void rlGenerateMipmaps(Texture2D *texture)
+{
+ glBindTexture(GL_TEXTURE_2D, texture->id);
+
+ // Check if texture is power-of-two (POT)
+ bool texIsPOT = false;
+
+ if (((texture->width > 0) && ((texture->width & (texture->width - 1)) == 0)) &&
+ ((texture->height > 0) && ((texture->height & (texture->height - 1)) == 0))) texIsPOT = true;
+
+ if ((texIsPOT) || (texNPOTSupported))
+ {
+#if defined(GRAPHICS_API_OPENGL_11)
+ // Compute required mipmaps
+ void *data = rlReadTexturePixels(*texture);
+
+ // NOTE: data size is reallocated to fit mipmaps data
+ // NOTE: CPU mipmap generation only supports RGBA 32bit data
+ int mipmapCount = GenerateMipmaps(data, texture->width, texture->height);
+
+ int size = texture->width*texture->height*4; // RGBA 32bit only
+ int offset = size;
+
+ int mipWidth = texture->width/2;
+ int mipHeight = texture->height/2;
+
+ // Load the mipmaps
+ for (int level = 1; level < mipmapCount; level++)
+ {
+ glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, mipWidth, mipHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data + offset);
+
+ size = mipWidth*mipHeight*4;
+ offset += size;
+
+ mipWidth /= 2;
+ mipHeight /= 2;
+ }
+
+ TraceLog(LOG_WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture->id);
+
+ // NOTE: Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
+ free(data);
+
+ texture->mipmaps = mipmapCount + 1;
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ //glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
+ glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
+ TraceLog(LOG_INFO, "[TEX ID %i] Mipmaps generated automatically", texture->id);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps
+
+ #define MIN(a,b) (((a)<(b))?(a):(b))
+ #define MAX(a,b) (((a)>(b))?(a):(b))
+
+ texture->mipmaps = 1 + (int)floor(log(MAX(texture->width, texture->height))/log(2));
+#endif
+ }
+ else TraceLog(LOG_WARNING, "[TEX ID %i] Mipmaps can not be generated", texture->id);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+// Upload vertex data into a VAO (if supported) and VBO
+// TODO: Check if mesh has already been loaded in GPU
+void rlLoadMesh(Mesh *mesh, bool dynamic)
+{
+ mesh->vaoId = 0; // Vertex Array Object
+ mesh->vboId[0] = 0; // Vertex positions VBO
+ mesh->vboId[1] = 0; // Vertex texcoords VBO
+ mesh->vboId[2] = 0; // Vertex normals VBO
+ mesh->vboId[3] = 0; // Vertex colors VBO
+ mesh->vboId[4] = 0; // Vertex tangents VBO
+ mesh->vboId[5] = 0; // Vertex texcoords2 VBO
+ mesh->vboId[6] = 0; // Vertex indices VBO
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ int drawHint = GL_STATIC_DRAW;
+ if (dynamic) drawHint = GL_DYNAMIC_DRAW;
+
+ if (vaoSupported)
+ {
+ // Initialize Quads VAO (Buffer A)
+ glGenVertexArrays(1, &mesh->vaoId);
+ glBindVertexArray(mesh->vaoId);
+ }
+
+ // NOTE: Attributes must be uploaded considering default locations points
+
+ // Enable vertex attributes: position (shader-location = 0)
+ glGenBuffers(1, &mesh->vboId[0]);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[0]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh->vertexCount, mesh->vertices, drawHint);
+ glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(0);
+
+ // Enable vertex attributes: texcoords (shader-location = 1)
+ glGenBuffers(1, &mesh->vboId[1]);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[1]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh->vertexCount, mesh->texcoords, drawHint);
+ glVertexAttribPointer(1, 2, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(1);
+
+ // Enable vertex attributes: normals (shader-location = 2)
+ if (mesh->normals != NULL)
+ {
+ glGenBuffers(1, &mesh->vboId[2]);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[2]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh->vertexCount, mesh->normals, drawHint);
+ glVertexAttribPointer(2, 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(2);
+ }
+ else
+ {
+ // Default color vertex attribute set to WHITE
+ glVertexAttrib3f(2, 1.0f, 1.0f, 1.0f);
+ glDisableVertexAttribArray(2);
+ }
+
+ // Default color vertex attribute (shader-location = 3)
+ if (mesh->colors != NULL)
+ {
+ glGenBuffers(1, &mesh->vboId[3]);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[3]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*mesh->vertexCount, mesh->colors, drawHint);
+ glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+ glEnableVertexAttribArray(3);
+ }
+ else
+ {
+ // Default color vertex attribute set to WHITE
+ glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f);
+ glDisableVertexAttribArray(3);
+ }
+
+ // Default tangent vertex attribute (shader-location = 4)
+ if (mesh->tangents != NULL)
+ {
+ glGenBuffers(1, &mesh->vboId[4]);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[4]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh->vertexCount, mesh->tangents, drawHint);
+ glVertexAttribPointer(4, 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(4);
+ }
+ else
+ {
+ // Default tangents vertex attribute
+ glVertexAttrib3f(4, 0.0f, 0.0f, 0.0f);
+ glDisableVertexAttribArray(4);
+ }
+
+ // Default texcoord2 vertex attribute (shader-location = 5)
+ if (mesh->texcoords2 != NULL)
+ {
+ glGenBuffers(1, &mesh->vboId[5]);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId[5]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh->vertexCount, mesh->texcoords2, drawHint);
+ glVertexAttribPointer(5, 2, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(5);
+ }
+ else
+ {
+ // Default tangents vertex attribute
+ glVertexAttrib2f(5, 0.0f, 0.0f);
+ glDisableVertexAttribArray(5);
+ }
+
+ if (mesh->indices != NULL)
+ {
+ glGenBuffers(1, &mesh->vboId[6]);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->vboId[6]);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*mesh->triangleCount*3, mesh->indices, GL_STATIC_DRAW);
+ }
+
+ if (vaoSupported)
+ {
+ if (mesh->vaoId > 0) TraceLog(LOG_INFO, "[VAO ID %i] Mesh uploaded successfully to VRAM (GPU)", mesh->vaoId);
+ else TraceLog(LOG_WARNING, "Mesh could not be uploaded to VRAM (GPU)");
+ }
+ else
+ {
+ TraceLog(LOG_INFO, "[VBOs] Mesh uploaded successfully to VRAM (GPU)");
+ }
+#endif
+}
+
+// Update vertex data on GPU (upload new data to one buffer)
+void rlUpdateMesh(Mesh mesh, int buffer, int numVertex)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ // Activate mesh VAO
+ if (vaoSupported) glBindVertexArray(mesh.vaoId);
+
+ switch (buffer)
+ {
+ case 0: // Update vertices (vertex position)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
+ if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*numVertex, mesh.vertices, GL_DYNAMIC_DRAW);
+ else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*numVertex, mesh.vertices);
+
+ } break;
+ case 1: // Update texcoords (vertex texture coordinates)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[1]);
+ if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*numVertex, mesh.texcoords, GL_DYNAMIC_DRAW);
+ else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*numVertex, mesh.texcoords);
+
+ } break;
+ case 2: // Update normals (vertex normals)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[2]);
+ if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*numVertex, mesh.normals, GL_DYNAMIC_DRAW);
+ else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*numVertex, mesh.normals);
+
+ } break;
+ case 3: // Update colors (vertex colors)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[3]);
+ if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*numVertex, mesh.colors, GL_DYNAMIC_DRAW);
+ else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*numVertex, mesh.colors);
+
+ } break;
+ case 4: // Update tangents (vertex tangents)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[4]);
+ if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*numVertex, mesh.tangents, GL_DYNAMIC_DRAW);
+ else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*numVertex, mesh.tangents);
+ } break;
+ case 5: // Update texcoords2 (vertex second texture coordinates)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[5]);
+ if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*numVertex, mesh.texcoords2, GL_DYNAMIC_DRAW);
+ else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*numVertex, mesh.texcoords2);
+ } break;
+ default: break;
+ }
+
+ // Unbind the current VAO
+ if (vaoSupported) glBindVertexArray(0);
+
+ // Another option would be using buffer mapping...
+ //mesh.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
+ // Now we can modify vertices
+ //glUnmapBuffer(GL_ARRAY_BUFFER);
+#endif
+}
+
+// Draw a 3d mesh with material and transform
+void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
+{
+#if defined(GRAPHICS_API_OPENGL_11)
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, material.maps[MAP_DIFFUSE].texture.id);
+
+ // NOTE: On OpenGL 1.1 we use Vertex Arrays to draw model
+ glEnableClientState(GL_VERTEX_ARRAY); // Enable vertex array
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Enable texture coords array
+ if (mesh.normals != NULL) glEnableClientState(GL_NORMAL_ARRAY); // Enable normals array
+ if (mesh.colors != NULL) glEnableClientState(GL_COLOR_ARRAY); // Enable colors array
+
+ glVertexPointer(3, GL_FLOAT, 0, mesh.vertices); // Pointer to vertex coords array
+ glTexCoordPointer(2, GL_FLOAT, 0, mesh.texcoords); // Pointer to texture coords array
+ if (mesh.normals != NULL) glNormalPointer(GL_FLOAT, 0, mesh.normals); // Pointer to normals array
+ if (mesh.colors != NULL) glColorPointer(4, GL_UNSIGNED_BYTE, 0, mesh.colors); // Pointer to colors array
+
+ rlPushMatrix();
+ rlMultMatrixf(MatrixToFloat(transform));
+ rlColor4ub(material.maps[MAP_DIFFUSE].color.r, material.maps[MAP_DIFFUSE].color.g, material.maps[MAP_DIFFUSE].color.b, material.maps[MAP_DIFFUSE].color.a);
+
+ if (mesh.indices != NULL) glDrawElements(GL_TRIANGLES, mesh.triangleCount*3, GL_UNSIGNED_SHORT, mesh.indices);
+ else glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);
+ rlPopMatrix();
+
+ glDisableClientState(GL_VERTEX_ARRAY); // Disable vertex array
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY); // Disable texture coords array
+ if (mesh.normals != NULL) glDisableClientState(GL_NORMAL_ARRAY); // Disable normals array
+ if (mesh.colors != NULL) glDisableClientState(GL_NORMAL_ARRAY); // Disable colors array
+
+ glDisable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, 0);
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ // Bind shader program
+ glUseProgram(material.shader.id);
+
+ // Matrices and other values required by shader
+ //-----------------------------------------------------
+ // Calculate and send to shader model matrix (used by PBR shader)
+ SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_MODEL], transform);
+
+ // Upload to shader material.colDiffuse
+ if (material.shader.locs[LOC_COLOR_DIFFUSE] != -1)
+ glUniform4f(material.shader.locs[LOC_COLOR_DIFFUSE], (float)material.maps[MAP_DIFFUSE].color.r/255,
+ (float)material.maps[MAP_DIFFUSE].color.g/255,
+ (float)material.maps[MAP_DIFFUSE].color.b/255,
+ (float)material.maps[MAP_DIFFUSE].color.a/255);
+
+ // Upload to shader material.colSpecular (if available)
+ if (material.shader.locs[LOC_COLOR_SPECULAR] != -1)
+ glUniform4f(material.shader.locs[LOC_COLOR_SPECULAR], (float)material.maps[MAP_SPECULAR].color.r/255,
+ (float)material.maps[MAP_SPECULAR].color.g/255,
+ (float)material.maps[MAP_SPECULAR].color.b/255,
+ (float)material.maps[MAP_SPECULAR].color.a/255);
+
+ if (material.shader.locs[LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_VIEW], modelview);
+ if (material.shader.locs[LOC_MATRIX_PROJECTION] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_PROJECTION], projection);
+
+ // At this point the modelview matrix just contains the view matrix (camera)
+ // That's because Begin3dMode() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
+ Matrix matView = modelview; // View matrix (camera)
+ Matrix matProjection = projection; // Projection matrix (perspective)
+
+ // Calculate model-view matrix combining matModel and matView
+ Matrix matModelView = MatrixMultiply(transform, matView); // Transform to camera-space coordinates
+ //-----------------------------------------------------
+
+ // Bind active texture maps (if available)
+ for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
+ {
+ if (material.maps[i].texture.id > 0)
+ {
+ glActiveTexture(GL_TEXTURE0 + i);
+ if ((i == MAP_IRRADIANCE) || (i == MAP_PREFILTER) || (i == MAP_CUBEMAP)) glBindTexture(GL_TEXTURE_CUBE_MAP, material.maps[i].texture.id);
+ else glBindTexture(GL_TEXTURE_2D, material.maps[i].texture.id);
+
+ glUniform1i(material.shader.locs[LOC_MAP_DIFFUSE + i], i);
+ }
+ }
+
+ // Bind vertex array objects (or VBOs)
+ if (vaoSupported) glBindVertexArray(mesh.vaoId);
+ else
+ {
+ // TODO: Simplify VBO binding into a for loop
+
+ // Bind mesh VBO data: vertex position (shader-location = 0)
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
+ glVertexAttribPointer(material.shader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_POSITION]);
+
+ // Bind mesh VBO data: vertex texcoords (shader-location = 1)
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[1]);
+ glVertexAttribPointer(material.shader.locs[LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_TEXCOORD01]);
+
+ // Bind mesh VBO data: vertex normals (shader-location = 2, if available)
+ if (material.shader.locs[LOC_VERTEX_NORMAL] != -1)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[2]);
+ glVertexAttribPointer(material.shader.locs[LOC_VERTEX_NORMAL], 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_NORMAL]);
+ }
+
+ // Bind mesh VBO data: vertex colors (shader-location = 3, if available)
+ if (material.shader.locs[LOC_VERTEX_COLOR] != -1)
+ {
+ if (mesh.vboId[3] != 0)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[3]);
+ glVertexAttribPointer(material.shader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+ glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_COLOR]);
+ }
+ else
+ {
+ // Set default value for unused attribute
+ // NOTE: Required when using default shader and no VAO support
+ glVertexAttrib4f(material.shader.locs[LOC_VERTEX_COLOR], 1.0f, 1.0f, 1.0f, 1.0f);
+ glDisableVertexAttribArray(material.shader.locs[LOC_VERTEX_COLOR]);
+ }
+ }
+
+ // Bind mesh VBO data: vertex tangents (shader-location = 4, if available)
+ if (material.shader.locs[LOC_VERTEX_TANGENT] != -1)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[4]);
+ glVertexAttribPointer(material.shader.locs[LOC_VERTEX_TANGENT], 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_TANGENT]);
+ }
+
+ // Bind mesh VBO data: vertex texcoords2 (shader-location = 5, if available)
+ if (material.shader.locs[LOC_VERTEX_TEXCOORD02] != -1)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[5]);
+ glVertexAttribPointer(material.shader.locs[LOC_VERTEX_TEXCOORD02], 2, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(material.shader.locs[LOC_VERTEX_TEXCOORD02]);
+ }
+
+ if (mesh.indices != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.vboId[6]);
+ }
+
+ int eyesCount = 1;
+#if defined(SUPPORT_VR_SIMULATOR)
+ if (vrStereoRender) eyesCount = 2;
+#endif
+
+ for (int eye = 0; eye < eyesCount; eye++)
+ {
+ if (eyesCount == 1) modelview = matModelView;
+ #if defined(SUPPORT_VR_SIMULATOR)
+ else SetStereoView(eye, matProjection, matModelView);
+ #endif
+
+ // Calculate model-view-projection matrix (MVP)
+ Matrix matMVP = MatrixMultiply(modelview, projection); // Transform to screen-space coordinates
+
+ // Send combined model-view-projection matrix to shader
+ glUniformMatrix4fv(material.shader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP));
+
+ // Draw call!
+ if (mesh.indices != NULL) glDrawElements(GL_TRIANGLES, mesh.triangleCount*3, GL_UNSIGNED_SHORT, 0); // Indexed vertices draw
+ else glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);
+ }
+
+ // Unbind all binded texture maps
+ for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
+ {
+ glActiveTexture(GL_TEXTURE0 + i); // Set shader active texture
+ if ((i == MAP_IRRADIANCE) || (i == MAP_PREFILTER) || (i == MAP_CUBEMAP)) glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+ else glBindTexture(GL_TEXTURE_2D, 0); // Unbind current active texture
+ }
+
+ // Unind vertex array objects (or VBOs)
+ if (vaoSupported) glBindVertexArray(0);
+ else
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ if (mesh.indices != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ }
+
+ // Unbind shader program
+ glUseProgram(0);
+
+ // Restore projection/modelview matrices
+ // NOTE: In stereo rendering matrices are being modified to fit every eye
+ projection = matProjection;
+ modelview = matView;
+#endif
+}
+
+// Unload mesh data from CPU and GPU
+void rlUnloadMesh(Mesh *mesh)
+{
+ if (mesh->vertices != NULL) free(mesh->vertices);
+ if (mesh->texcoords != NULL) free(mesh->texcoords);
+ if (mesh->normals != NULL) free(mesh->normals);
+ if (mesh->colors != NULL) free(mesh->colors);
+ if (mesh->tangents != NULL) free(mesh->tangents);
+ if (mesh->texcoords2 != NULL) free(mesh->texcoords2);
+ if (mesh->indices != NULL) free(mesh->indices);
+
+ rlDeleteBuffers(mesh->vboId[0]); // vertex
+ rlDeleteBuffers(mesh->vboId[1]); // texcoords
+ rlDeleteBuffers(mesh->vboId[2]); // normals
+ rlDeleteBuffers(mesh->vboId[3]); // colors
+ rlDeleteBuffers(mesh->vboId[4]); // tangents
+ rlDeleteBuffers(mesh->vboId[5]); // texcoords2
+ rlDeleteBuffers(mesh->vboId[6]); // indices
+
+ rlDeleteVertexArrays(mesh->vaoId);
+}
+
+// Read screen pixel data (color buffer)
+unsigned char *rlReadScreenPixels(int width, int height)
+{
+ unsigned char *screenData = (unsigned char *)calloc(width*height*4, sizeof(unsigned char));
+
+ // NOTE: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
+ glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, screenData);
+
+ // Flip image vertically!
+ unsigned char *imgData = (unsigned char *)malloc(width*height*sizeof(unsigned char)*4);
+
+ for (int y = height - 1; y >= 0; y--)
+ {
+ for (int x = 0; x < (width*4); x++)
+ {
+ // Flip line
+ imgData[((height - 1) - y)*width*4 + x] = screenData[(y*width*4) + x];
+
+ // Set alpha component value to 255 (no trasparent image retrieval)
+ // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
+ if (((x + 1)%4) == 0) imgData[((height - 1) - y)*width*4 + x] = 255;
+ }
+ }
+
+ free(screenData);
+
+ return imgData; // NOTE: image data should be freed
+}
+
+// Read texture pixel data
+// NOTE: glGetTexImage() is not available on OpenGL ES 2.0
+// Texture2D width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
+void *rlReadTexturePixels(Texture2D texture)
+{
+ void *pixels = NULL;
+
+#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
+ glBindTexture(GL_TEXTURE_2D, texture.id);
+
+ // NOTE: Using texture.id, we can retrieve some texture info (but not on OpenGL ES 2.0)
+ /*
+ int width, height, format;
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
+ // Other texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
+ */
+
+ int glFormat = 0, glType = 0;
+
+ unsigned int size = texture.width*texture.height;
+
+ // NOTE: GL_LUMINANCE and GL_LUMINANCE_ALPHA are removed since OpenGL 3.1
+ // Must be replaced by GL_RED and GL_RG on Core OpenGL 3.3
+
+ switch (texture.format)
+ {
+#if defined(GRAPHICS_API_OPENGL_11)
+ case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_LUMINANCE; glType = GL_UNSIGNED_BYTE; break; // 8 bit per pixel (no alpha)
+ case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_LUMINANCE_ALPHA; glType = GL_UNSIGNED_BYTE; break; // 16 bpp (2 channels)
+#elif defined(GRAPHICS_API_OPENGL_33)
+ case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_RED; glType = GL_UNSIGNED_BYTE; break;
+ case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_RG; glType = GL_UNSIGNED_BYTE; break;
+#endif
+ case UNCOMPRESSED_R5G6B5: pixels = (unsigned short *)malloc(size); glFormat = GL_RGB; glType = GL_UNSIGNED_SHORT_5_6_5; break; // 16 bpp
+ case UNCOMPRESSED_R8G8B8: pixels = (unsigned char *)malloc(size*3); glFormat = GL_RGB; glType = GL_UNSIGNED_BYTE; break; // 24 bpp
+ case UNCOMPRESSED_R5G5B5A1: pixels = (unsigned short *)malloc(size); glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_5_5_5_1; break; // 16 bpp (1 bit alpha)
+ case UNCOMPRESSED_R4G4B4A4: pixels = (unsigned short *)malloc(size); glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_4_4_4_4; break; // 16 bpp (4 bit alpha)
+ case UNCOMPRESSED_R8G8B8A8: pixels = (unsigned char *)malloc(size*4); glFormat = GL_RGBA; glType = GL_UNSIGNED_BYTE; break; // 32 bpp
+ default: TraceLog(LOG_WARNING, "Texture data retrieval, format not suported"); break;
+ }
+
+ // NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding.
+ // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
+ // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
+ // GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+
+ glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_ES2)
+
+ RenderTexture2D fbo = rlLoadRenderTexture(texture.width, texture.height);
+
+ // NOTE: Two possible Options:
+ // 1 - Bind texture to color fbo attachment and glReadPixels()
+ // 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
+
+#define GET_TEXTURE_FBO_OPTION_1 // It works
+#if defined(GET_TEXTURE_FBO_OPTION_1)
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo.id);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ // Attach our texture to FBO -> Texture must be RGB
+ // NOTE: Previoust attached texture is automatically detached
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id, 0);
+
+ pixels = (unsigned char *)malloc(texture.width*texture.height*4*sizeof(unsigned char));
+
+ // NOTE: We read data as RGBA because FBO texture is configured as RGBA, despite binding a RGB texture...
+ glReadPixels(0, 0, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+ // Re-attach internal FBO color texture before deleting it
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo.texture.id, 0);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+#elif defined(GET_TEXTURE_FBO_OPTION_2)
+ // Render texture to fbo
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo.id);
+
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ glClearDepthf(1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glViewport(0, 0, width, height);
+ //glMatrixMode(GL_PROJECTION);
+ //glLoadIdentity();
+ rlOrtho(0.0, width, height, 0.0, 0.0, 1.0);
+ //glMatrixMode(GL_MODELVIEW);
+ //glLoadIdentity();
+ //glDisable(GL_TEXTURE_2D);
+ //glDisable(GL_BLEND);
+ glEnable(GL_DEPTH_TEST);
+
+ Model quad;
+ //quad.mesh = GenMeshQuad(width, height);
+ quad.transform = MatrixIdentity();
+ quad.shader = defaultShader;
+
+ DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE);
+
+ pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char));
+
+ glReadPixels(0, 0, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+
+ // Bind framebuffer 0, which means render to back buffer
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ UnloadModel(quad);
+#endif // GET_TEXTURE_FBO_OPTION
+
+ // Clean up temporal fbo
+ rlDeleteRenderTextures(fbo);
+
+#endif
+
+ return pixels;
+}
+
+/*
+// TODO: Record draw calls to be processed in batch
+// NOTE: Global state must be kept
+void rlRecordDraw(void)
+{
+ // TODO: Before adding a new draw, check if anything changed from last stored draw
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ draws[drawsCounter].vaoId = currentState.vaoId; // lines.id, trangles.id, quads.id?
+ draws[drawsCounter].textureId = currentState.textureId; // whiteTexture?
+ draws[drawsCounter].shaderId = currentState.shaderId; // defaultShader.id
+ draws[drawsCounter].projection = projection;
+ draws[drawsCounter].modelview = modelview;
+ draws[drawsCounter].vertexCount = currentState.vertexCount;
+
+ drawsCounter++;
+#endif
+}
+*/
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Shaders Functions
+// NOTE: Those functions are exposed directly to the user in raylib.h
+//----------------------------------------------------------------------------------
+
+// Get default internal texture (white texture)
+Texture2D GetTextureDefault(void)
+{
+ Texture2D texture;
+
+ texture.id = whiteTexture;
+ texture.width = 1;
+ texture.height = 1;
+ texture.mipmaps = 1;
+ texture.format = UNCOMPRESSED_R8G8B8A8;
+
+ return texture;
+}
+
+// Get default shader
+Shader GetShaderDefault(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ return defaultShader;
+#else
+ Shader shader = { 0 };
+ return shader;
+#endif
+}
+
+// Load text data from file
+// NOTE: text chars array should be freed manually
+char *LoadText(const char *fileName)
+{
+ FILE *textFile;
+ char *text = NULL;
+
+ int count = 0;
+
+ if (fileName != NULL)
+ {
+ textFile = fopen(fileName,"rt");
+
+ if (textFile != NULL)
+ {
+ fseek(textFile, 0, SEEK_END);
+ count = ftell(textFile);
+ rewind(textFile);
+
+ if (count > 0)
+ {
+ text = (char *)malloc(sizeof(char)*(count + 1));
+ count = fread(text, sizeof(char), count, textFile);
+ text[count] = '\0';
+ }
+
+ fclose(textFile);
+ }
+ else TraceLog(LOG_WARNING, "[%s] Text file could not be opened", fileName);
+ }
+
+ return text;
+}
+
+// Load shader from files and bind default locations
+Shader LoadShader(char *vsFileName, char *fsFileName)
+{
+ Shader shader = { 0 };
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ // Shaders loading from external text file
+ char *vShaderStr = LoadText(vsFileName);
+ char *fShaderStr = LoadText(fsFileName);
+
+ if ((vShaderStr != NULL) && (fShaderStr != NULL))
+ {
+ shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
+
+ // After shader loading, we TRY to set default location names
+ if (shader.id > 0) SetShaderDefaultLocations(&shader);
+
+ // Shader strings must be freed
+ free(vShaderStr);
+ free(fShaderStr);
+ }
+
+ if (shader.id == 0)
+ {
+ TraceLog(LOG_WARNING, "Custom shader could not be loaded");
+ shader = defaultShader;
+ }
+
+
+ // Get available shader uniforms
+ // NOTE: This information is useful for debug...
+ int uniformCount = -1;
+
+ glGetProgramiv(shader.id, GL_ACTIVE_UNIFORMS, &uniformCount);
+
+ for(int i = 0; i < uniformCount; i++)
+ {
+ int namelen = -1;
+ int num = -1;
+ char name[256]; // Assume no variable names longer than 256
+ GLenum type = GL_ZERO;
+
+ // Get the name of the uniforms
+ glGetActiveUniform(shader.id, i,sizeof(name) - 1, &namelen, &num, &type, name);
+
+ name[namelen] = 0;
+
+ // Get the location of the named uniform
+ GLuint location = glGetUniformLocation(shader.id, name);
+
+ TraceLog(LOG_DEBUG, "[SHDR ID %i] Active uniform [%s] set at location: %i", shader.id, name, location);
+ }
+
+#endif
+
+ return shader;
+}
+
+// Unload shader from GPU memory (VRAM)
+void UnloadShader(Shader shader)
+{
+ if (shader.id > 0)
+ {
+ rlDeleteShader(shader.id);
+ TraceLog(LOG_INFO, "[SHDR ID %i] Unloaded shader program data", shader.id);
+ }
+}
+
+// Begin custom shader mode
+void BeginShaderMode(Shader shader)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (currentShader.id != shader.id)
+ {
+ rlglDraw();
+ currentShader = shader;
+ }
+#endif
+}
+
+// End custom shader mode (returns to default shader)
+void EndShaderMode(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ BeginShaderMode(defaultShader);
+#endif
+}
+
+// Get shader uniform location
+int GetShaderLocation(Shader shader, const char *uniformName)
+{
+ int location = -1;
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ location = glGetUniformLocation(shader.id, uniformName);
+
+ if (location == -1) TraceLog(LOG_WARNING, "[SHDR ID %i] Shader uniform [%s] COULD NOT BE FOUND", shader.id, uniformName);
+ else TraceLog(LOG_INFO, "[SHDR ID %i] Shader uniform [%s] set at location: %i", shader.id, uniformName, location);
+#endif
+ return location;
+}
+
+// Set shader uniform value (float)
+void SetShaderValue(Shader shader, int uniformLoc, float *value, int size)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ glUseProgram(shader.id);
+
+ if (size == 1) glUniform1fv(uniformLoc, 1, value); // Shader uniform type: float
+ else if (size == 2) glUniform2fv(uniformLoc, 1, value); // Shader uniform type: vec2
+ else if (size == 3) glUniform3fv(uniformLoc, 1, value); // Shader uniform type: vec3
+ else if (size == 4) glUniform4fv(uniformLoc, 1, value); // Shader uniform type: vec4
+ else TraceLog(LOG_WARNING, "Shader value float array size not supported");
+
+ //glUseProgram(0); // Avoid reseting current shader program, in case other uniforms are set
+#endif
+}
+
+// Set shader uniform value (int)
+void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ glUseProgram(shader.id);
+
+ if (size == 1) glUniform1iv(uniformLoc, 1, value); // Shader uniform type: int
+ else if (size == 2) glUniform2iv(uniformLoc, 1, value); // Shader uniform type: ivec2
+ else if (size == 3) glUniform3iv(uniformLoc, 1, value); // Shader uniform type: ivec3
+ else if (size == 4) glUniform4iv(uniformLoc, 1, value); // Shader uniform type: ivec4
+ else TraceLog(LOG_WARNING, "Shader value int array size not supported");
+
+ //glUseProgram(0);
+#endif
+}
+
+// Set shader uniform value (matrix 4x4)
+void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ glUseProgram(shader.id);
+
+ glUniformMatrix4fv(uniformLoc, 1, false, MatrixToFloat(mat));
+
+ //glUseProgram(0);
+#endif
+}
+
+// Set a custom projection matrix (replaces internal projection matrix)
+void SetMatrixProjection(Matrix proj)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ projection = proj;
+#endif
+}
+
+// Set a custom modelview matrix (replaces internal modelview matrix)
+void SetMatrixModelview(Matrix view)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ modelview = view;
+#endif
+}
+
+// Generate cubemap texture from HDR texture
+// TODO: OpenGL ES 2.0 does not support GL_RGB16F texture format, neither GL_DEPTH_COMPONENT24
+Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size)
+{
+ Texture2D cubemap = { 0 };
+#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader
+ // Other locations should be setup externally in shader before calling the function
+
+ // Set up depth face culling and cubemap seamless
+ glDisable(GL_CULL_FACE);
+#if defined(GRAPHICS_API_OPENGL_33)
+ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // Flag not supported on OpenGL ES 2.0
+#endif
+
+
+ // Setup framebuffer
+ unsigned int fbo, rbo;
+ glGenFramebuffers(1, &fbo);
+ glGenRenderbuffers(1, &rbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glBindRenderbuffer(GL_RENDERBUFFER, rbo);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
+
+ // Set up cubemap to render and attach to framebuffer
+ // NOTE: faces are stored with 16 bit floating point values
+ glGenTextures(1, &cubemap.id);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
+ for (unsigned int i = 0; i < 6; i++)
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+#if defined(GRAPHICS_API_OPENGL_33)
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); // Flag not supported on OpenGL ES 2.0
+#endif
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // Create projection (transposed) and different views for each face
+ Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0);
+ //MatrixTranspose(&fboProjection);
+ Matrix fboViews[6] = {
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 1.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 1.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f })
+ };
+
+ // Convert HDR equirectangular environment map to cubemap equivalent
+ glUseProgram(shader.id);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, skyHDR.id);
+ SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_PROJECTION], fboProjection);
+
+ // Note: don't forget to configure the viewport to the capture dimensions
+ glViewport(0, 0, size, size);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ for (unsigned int i = 0; i < 6; i++)
+ {
+ SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_VIEW], fboViews[i]);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubemap.id, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ GenDrawCube();
+ }
+
+ // Unbind framebuffer and textures
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ // Reset viewport dimensions to default
+ glViewport(0, 0, screenWidth, screenHeight);
+ //glEnable(GL_CULL_FACE);
+
+ cubemap.width = size;
+ cubemap.height = size;
+#endif
+ return cubemap;
+}
+
+// Generate irradiance texture using cubemap data
+// TODO: OpenGL ES 2.0 does not support GL_RGB16F texture format, neither GL_DEPTH_COMPONENT24
+Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size)
+{
+ Texture2D irradiance = { 0 };
+
+#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader
+ // Other locations should be setup externally in shader before calling the function
+
+ // Setup framebuffer
+ unsigned int fbo, rbo;
+ glGenFramebuffers(1, &fbo);
+ glGenRenderbuffers(1, &rbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glBindRenderbuffer(GL_RENDERBUFFER, rbo);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
+
+ // Create an irradiance cubemap, and re-scale capture FBO to irradiance scale
+ glGenTextures(1, &irradiance.id);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, irradiance.id);
+ for (unsigned int i = 0; i < 6; i++)
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // Create projection (transposed) and different views for each face
+ Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0);
+ //MatrixTranspose(&fboProjection);
+ Matrix fboViews[6] = {
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 1.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 1.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f })
+ };
+
+ // Solve diffuse integral by convolution to create an irradiance cubemap
+ glUseProgram(shader.id);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
+ SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_PROJECTION], fboProjection);
+
+ // Note: don't forget to configure the viewport to the capture dimensions
+ glViewport(0, 0, size, size);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ for (unsigned int i = 0; i < 6; i++)
+ {
+ SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_VIEW], fboViews[i]);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, irradiance.id, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ GenDrawCube();
+ }
+
+ // Unbind framebuffer and textures
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ // Reset viewport dimensions to default
+ glViewport(0, 0, screenWidth, screenHeight);
+
+ irradiance.width = size;
+ irradiance.height = size;
+#endif
+ return irradiance;
+}
+
+// Generate prefilter texture using cubemap data
+// TODO: OpenGL ES 2.0 does not support GL_RGB16F texture format, neither GL_DEPTH_COMPONENT24
+Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size)
+{
+ Texture2D prefilter = { 0 };
+
+#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader
+ // Other locations should be setup externally in shader before calling the function
+ // TODO: Locations should be taken out of this function... too shader dependant...
+ int roughnessLoc = GetShaderLocation(shader, "roughness");
+
+ // Setup framebuffer
+ unsigned int fbo, rbo;
+ glGenFramebuffers(1, &fbo);
+ glGenRenderbuffers(1, &rbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glBindRenderbuffer(GL_RENDERBUFFER, rbo);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
+
+ // Create a prefiltered HDR environment map
+ glGenTextures(1, &prefilter.id);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, prefilter.id);
+ for (unsigned int i = 0; i < 6; i++)
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // Generate mipmaps for the prefiltered HDR texture
+ glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
+
+ // Create projection (transposed) and different views for each face
+ Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0);
+ //MatrixTranspose(&fboProjection);
+ Matrix fboViews[6] = {
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 1.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 1.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }),
+ MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f })
+ };
+
+ // Prefilter HDR and store data into mipmap levels
+ glUseProgram(shader.id);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
+ SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_PROJECTION], fboProjection);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ #define MAX_MIPMAP_LEVELS 5 // Max number of prefilter texture mipmaps
+
+ for (unsigned int mip = 0; mip < MAX_MIPMAP_LEVELS; mip++)
+ {
+ // Resize framebuffer according to mip-level size.
+ unsigned int mipWidth = size*powf(0.5f, mip);
+ unsigned int mipHeight = size*powf(0.5f, mip);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, rbo);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mipWidth, mipHeight);
+ glViewport(0, 0, mipWidth, mipHeight);
+
+ float roughness = (float)mip/(float)(MAX_MIPMAP_LEVELS - 1);
+ glUniform1f(roughnessLoc, roughness);
+
+ for (unsigned int i = 0; i < 6; ++i)
+ {
+ SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_VIEW], fboViews[i]);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, prefilter.id, mip);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ GenDrawCube();
+ }
+ }
+
+ // Unbind framebuffer and textures
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ // Reset viewport dimensions to default
+ glViewport(0, 0, screenWidth, screenHeight);
+
+ prefilter.width = size;
+ prefilter.height = size;
+#endif
+ return prefilter;
+}
+
+// Generate BRDF texture using cubemap data
+// TODO: OpenGL ES 2.0 does not support GL_RGB16F texture format, neither GL_DEPTH_COMPONENT24
+Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size)
+{
+ Texture2D brdf = { 0 };
+#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2)
+ // Generate BRDF convolution texture
+ glGenTextures(1, &brdf.id);
+ glBindTexture(GL_TEXTURE_2D, brdf.id);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, size, size, 0, GL_RG, GL_FLOAT, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // Render BRDF LUT into a quad using FBO
+ unsigned int fbo, rbo;
+ glGenFramebuffers(1, &fbo);
+ glGenRenderbuffers(1, &rbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glBindRenderbuffer(GL_RENDERBUFFER, rbo);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, brdf.id, 0);
+
+ glViewport(0, 0, size, size);
+ glUseProgram(shader.id);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ GenDrawQuad();
+
+ // Unbind framebuffer and textures
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ // Reset viewport dimensions to default
+ glViewport(0, 0, screenWidth, screenHeight);
+
+ brdf.width = size;
+ brdf.height = size;
+#endif
+ return brdf;
+}
+
+// Begin blending mode (alpha, additive, multiplied)
+// NOTE: Only 3 blending modes supported, default blend mode is alpha
+void BeginBlendMode(int mode)
+{
+ if ((blendMode != mode) && (mode < 3))
+ {
+ rlglDraw();
+
+ switch (mode)
+ {
+ case BLEND_ALPHA: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break;
+ case BLEND_ADDITIVE: glBlendFunc(GL_SRC_ALPHA, GL_ONE); break; // Alternative: glBlendFunc(GL_ONE, GL_ONE);
+ case BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); break;
+ default: break;
+ }
+
+ blendMode = mode;
+ }
+}
+
+// End blending mode (reset to default: alpha blending)
+void EndBlendMode(void)
+{
+ BeginBlendMode(BLEND_ALPHA);
+}
+
+#if defined(SUPPORT_VR_SIMULATOR)
+// Init VR simulator for selected device
+// NOTE: It modifies the global variable: VrDeviceInfo hmd
+void InitVrSimulator(int vrDevice)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (vrDevice == HMD_OCULUS_RIFT_DK2)
+ {
+ // Oculus Rift DK2 parameters
+ hmd.hResolution = 1280; // HMD horizontal resolution in pixels
+ hmd.vResolution = 800; // HMD vertical resolution in pixels
+ hmd.hScreenSize = 0.14976f; // HMD horizontal size in meters
+ hmd.vScreenSize = 0.09356f; // HMD vertical size in meters
+ hmd.vScreenCenter = 0.04678f; // HMD screen center in meters
+ hmd.eyeToScreenDistance = 0.041f; // HMD distance between eye and display in meters
+ hmd.lensSeparationDistance = 0.0635f; // HMD lens separation distance in meters
+ hmd.interpupillaryDistance = 0.064f; // HMD IPD (distance between pupils) in meters
+ hmd.distortionK[0] = 1.0f; // HMD lens distortion constant parameter 0
+ hmd.distortionK[1] = 0.22f; // HMD lens distortion constant parameter 1
+ hmd.distortionK[2] = 0.24f; // HMD lens distortion constant parameter 2
+ hmd.distortionK[3] = 0.0f; // HMD lens distortion constant parameter 3
+ hmd.chromaAbCorrection[0] = 0.996f; // HMD chromatic aberration correction parameter 0
+ hmd.chromaAbCorrection[1] = -0.004f; // HMD chromatic aberration correction parameter 1
+ hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2
+ hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3
+
+ TraceLog(LOG_INFO, "Initializing VR Simulator (Oculus Rift DK2)");
+ }
+ else if ((vrDevice == HMD_DEFAULT_DEVICE) || (vrDevice == HMD_OCULUS_RIFT_CV1))
+ {
+ // Oculus Rift CV1 parameters
+ // NOTE: CV1 represents a complete HMD redesign compared to previous versions,
+ // new Fresnel-hybrid-asymmetric lenses have been added and, consequently,
+ // previous parameters (DK2) and distortion shader (DK2) doesn't work any more.
+ // I just defined a set of parameters for simulator that approximate to CV1 stereo rendering
+ // but result is not the same obtained with Oculus PC SDK.
+ hmd.hResolution = 2160; // HMD horizontal resolution in pixels
+ hmd.vResolution = 1200; // HMD vertical resolution in pixels
+ hmd.hScreenSize = 0.133793f; // HMD horizontal size in meters
+ hmd.vScreenSize = 0.0669f; // HMD vertical size in meters
+ hmd.vScreenCenter = 0.04678f; // HMD screen center in meters
+ hmd.eyeToScreenDistance = 0.041f; // HMD distance between eye and display in meters
+ hmd.lensSeparationDistance = 0.07f; // HMD lens separation distance in meters
+ hmd.interpupillaryDistance = 0.07f; // HMD IPD (distance between pupils) in meters
+ hmd.distortionK[0] = 1.0f; // HMD lens distortion constant parameter 0
+ hmd.distortionK[1] = 0.22f; // HMD lens distortion constant parameter 1
+ hmd.distortionK[2] = 0.24f; // HMD lens distortion constant parameter 2
+ hmd.distortionK[3] = 0.0f; // HMD lens distortion constant parameter 3
+ hmd.chromaAbCorrection[0] = 0.996f; // HMD chromatic aberration correction parameter 0
+ hmd.chromaAbCorrection[1] = -0.004f; // HMD chromatic aberration correction parameter 1
+ hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2
+ hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3
+
+ TraceLog(LOG_INFO, "Initializing VR Simulator (Oculus Rift CV1)");
+ }
+ else
+ {
+ TraceLog(LOG_WARNING, "VR Simulator doesn't support selected device parameters,");
+ TraceLog(LOG_WARNING, "using default VR Simulator parameters");
+ }
+
+ // Initialize framebuffer and textures for stereo rendering
+ // NOTE: screen size should match HMD aspect ratio
+ vrConfig.stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight);
+
+#if defined(SUPPORT_DISTORTION_SHADER)
+ // Load distortion shader (initialized by default with Oculus Rift CV1 parameters)
+ vrConfig.distortionShader.id = LoadShaderProgram(vDistortionShaderStr, fDistortionShaderStr);
+ if (vrConfig.distortionShader.id > 0) SetShaderDefaultLocations(&vrConfig.distortionShader);
+#endif
+
+ SetStereoConfig(hmd);
+
+ vrSimulatorReady = true;
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_11)
+ TraceLog(LOG_WARNING, "VR Simulator not supported on OpenGL 1.1");
+#endif
+}
+
+// Close VR simulator for current device
+void CloseVrSimulator(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (vrSimulatorReady)
+ {
+ rlDeleteRenderTextures(vrConfig.stereoFbo); // Unload stereo framebuffer and texture
+ #if defined(SUPPORT_DISTORTION_SHADER)
+ UnloadShader(vrConfig.distortionShader); // Unload distortion shader
+ #endif
+ }
+#endif
+}
+
+// Detect if VR simulator is running
+bool IsVrSimulatorReady(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ return vrSimulatorReady;
+#else
+ return false;
+#endif
+}
+
+// Enable/Disable VR experience (device or simulator)
+void ToggleVrMode(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ vrSimulatorReady = !vrSimulatorReady;
+
+ if (!vrSimulatorReady)
+ {
+ vrStereoRender = false;
+
+ // Reset viewport and default projection-modelview matrices
+ rlViewport(0, 0, screenWidth, screenHeight);
+ projection = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
+ modelview = MatrixIdentity();
+ }
+ else vrStereoRender = true;
+#endif
+}
+
+// Update VR tracking (position and orientation) and camera
+// NOTE: Camera (position, target, up) gets update with head tracking information
+void UpdateVrTracking(Camera *camera)
+{
+ // TODO: Simulate 1st person camera system
+}
+
+// Begin Oculus drawing configuration
+void BeginVrDrawing(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (vrSimulatorReady)
+ {
+ // Setup framebuffer for stereo rendering
+ rlEnableRenderTexture(vrConfig.stereoFbo.id);
+
+ // NOTE: If your application is configured to treat the texture as a linear format (e.g. GL_RGBA)
+ // and performs linear-to-gamma conversion in GLSL or does not care about gamma-correction, then:
+ // - Require OculusBuffer format to be OVR_FORMAT_R8G8B8A8_UNORM_SRGB
+ // - Do NOT enable GL_FRAMEBUFFER_SRGB
+ //glEnable(GL_FRAMEBUFFER_SRGB);
+
+ //glViewport(0, 0, buffer.width, buffer.height); // Useful if rendering to separate framebuffers (every eye)
+ rlClearScreenBuffers(); // Clear current framebuffer(s)
+
+ vrStereoRender = true;
+ }
+#endif
+}
+
+// End Oculus drawing process (and desktop mirror)
+void EndVrDrawing(void)
+{
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ if (vrSimulatorReady)
+ {
+ vrStereoRender = false; // Disable stereo render
+
+ rlDisableRenderTexture(); // Unbind current framebuffer
+
+ rlClearScreenBuffers(); // Clear current framebuffer
+
+ // Set viewport to default framebuffer size (screen size)
+ rlViewport(0, 0, screenWidth, screenHeight);
+
+ // Let rlgl reconfigure internal matrices
+ rlMatrixMode(RL_PROJECTION); // Enable internal projection matrix
+ rlLoadIdentity(); // Reset internal projection matrix
+ rlOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); // Recalculate internal projection matrix
+ rlMatrixMode(RL_MODELVIEW); // Enable internal modelview matrix
+ rlLoadIdentity(); // Reset internal modelview matrix
+
+#if defined(SUPPORT_DISTORTION_SHADER)
+ // Draw RenderTexture (stereoFbo) using distortion shader
+ currentShader = vrConfig.distortionShader;
+#else
+ currentShader = GetShaderDefault();
+#endif
+
+ rlEnableTexture(vrConfig.stereoFbo.texture.id);
+
+ rlPushMatrix();
+ rlBegin(RL_QUADS);
+ rlColor4ub(255, 255, 255, 255);
+ rlNormal3f(0.0f, 0.0f, 1.0f);
+
+ // Bottom-left corner for texture and quad
+ rlTexCoord2f(0.0f, 1.0f);
+ rlVertex2f(0.0f, 0.0f);
+
+ // Bottom-right corner for texture and quad
+ rlTexCoord2f(0.0f, 0.0f);
+ rlVertex2f(0.0f, vrConfig.stereoFbo.texture.height);
+
+ // Top-right corner for texture and quad
+ rlTexCoord2f(1.0f, 0.0f);
+ rlVertex2f(vrConfig.stereoFbo.texture.width, vrConfig.stereoFbo.texture.height);
+
+ // Top-left corner for texture and quad
+ rlTexCoord2f(1.0f, 1.0f);
+ rlVertex2f(vrConfig.stereoFbo.texture.width, 0.0f);
+ rlEnd();
+ rlPopMatrix();
+
+ rlDisableTexture();
+
+ // Update and draw render texture fbo with distortion to backbuffer
+ UpdateBuffersDefault();
+ DrawBuffersDefault();
+
+ // Restore defaultShader
+ currentShader = defaultShader;
+
+ // Reset viewport and default projection-modelview matrices
+ rlViewport(0, 0, screenWidth, screenHeight);
+ projection = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
+ modelview = MatrixIdentity();
+
+ rlDisableDepthTest();
+ }
+#endif
+}
+#endif // SUPPORT_VR_SIMULATOR
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Definition
+//----------------------------------------------------------------------------------
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+// Convert image data to OpenGL texture (returns OpenGL valid Id)
+// NOTE: Expected compressed image data and POT image
+static void LoadTextureCompressed(unsigned char *data, int width, int height, int compressedFormat, int mipmapCount)
+{
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ int blockSize = 0; // Bytes every block
+ int offset = 0;
+
+ if ((compressedFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) ||
+ (compressedFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ||
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ (compressedFormat == GL_ETC1_RGB8_OES) ||
+#endif
+ (compressedFormat == GL_COMPRESSED_RGB8_ETC2)) blockSize = 8;
+ else blockSize = 16;
+
+ // Load the mipmap levels
+ for (int level = 0; level < mipmapCount && (width || height); level++)
+ {
+ unsigned int size = 0;
+
+ size = ((width + 3)/4)*((height + 3)/4)*blockSize;
+
+ glCompressedTexImage2D(GL_TEXTURE_2D, level, compressedFormat, width, height, 0, size, data + offset);
+
+ offset += size;
+ width /= 2;
+ height /= 2;
+
+ // Security check for NPOT textures
+ if (width < 1) width = 1;
+ if (height < 1) height = 1;
+ }
+}
+
+// Load custom shader strings and return program id
+static unsigned int LoadShaderProgram(const char *vShaderStr, const char *fShaderStr)
+{
+ unsigned int program = 0;
+
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+ GLuint vertexShader;
+ GLuint fragmentShader;
+
+ vertexShader = glCreateShader(GL_VERTEX_SHADER);
+ fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
+
+ const char *pvs = vShaderStr;
+ const char *pfs = fShaderStr;
+
+ glShaderSource(vertexShader, 1, &pvs, NULL);
+ glShaderSource(fragmentShader, 1, &pfs, NULL);
+
+ GLint success = 0;
+
+ glCompileShader(vertexShader);
+
+ glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
+
+ if (success != GL_TRUE)
+ {
+ TraceLog(LOG_WARNING, "[VSHDR ID %i] Failed to compile vertex shader...", vertexShader);
+
+ int maxLength = 0;
+ int length;
+
+ glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &maxLength);
+
+#ifdef _MSC_VER
+ char *log = malloc(maxLength);
+#else
+ char log[maxLength];
+#endif
+ glGetShaderInfoLog(vertexShader, maxLength, &length, log);
+
+ TraceLog(LOG_INFO, "%s", log);
+
+#ifdef _MSC_VER
+ free(log);
+#endif
+ }
+ else TraceLog(LOG_INFO, "[VSHDR ID %i] Vertex shader compiled successfully", vertexShader);
+
+ glCompileShader(fragmentShader);
+
+ glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
+
+ if (success != GL_TRUE)
+ {
+ TraceLog(LOG_WARNING, "[FSHDR ID %i] Failed to compile fragment shader...", fragmentShader);
+
+ int maxLength = 0;
+ int length;
+
+ glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &maxLength);
+
+#ifdef _MSC_VER
+ char *log = malloc(maxLength);
+#else
+ char log[maxLength];
+#endif
+ glGetShaderInfoLog(fragmentShader, maxLength, &length, log);
+
+ TraceLog(LOG_INFO, "%s", log);
+
+#ifdef _MSC_VER
+ free(log);
+#endif
+ }
+ else TraceLog(LOG_INFO, "[FSHDR ID %i] Fragment shader compiled successfully", fragmentShader);
+
+ program = glCreateProgram();
+
+ glAttachShader(program, vertexShader);
+ glAttachShader(program, fragmentShader);
+
+ // NOTE: Default attribute shader locations must be binded before linking
+ glBindAttribLocation(program, 0, DEFAULT_ATTRIB_POSITION_NAME);
+ glBindAttribLocation(program, 1, DEFAULT_ATTRIB_TEXCOORD_NAME);
+ glBindAttribLocation(program, 2, DEFAULT_ATTRIB_NORMAL_NAME);
+ glBindAttribLocation(program, 3, DEFAULT_ATTRIB_COLOR_NAME);
+ glBindAttribLocation(program, 4, DEFAULT_ATTRIB_TANGENT_NAME);
+ glBindAttribLocation(program, 5, DEFAULT_ATTRIB_TEXCOORD2_NAME);
+
+ // NOTE: If some attrib name is no found on the shader, it locations becomes -1
+
+ glLinkProgram(program);
+
+ // NOTE: All uniform variables are intitialised to 0 when a program links
+
+ glGetProgramiv(program, GL_LINK_STATUS, &success);
+
+ if (success == GL_FALSE)
+ {
+ TraceLog(LOG_WARNING, "[SHDR ID %i] Failed to link shader program...", program);
+
+ int maxLength = 0;
+ int length;
+
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
+
+#ifdef _MSC_VER
+ char *log = malloc(maxLength);
+#else
+ char log[maxLength];
+#endif
+ glGetProgramInfoLog(program, maxLength, &length, log);
+
+ TraceLog(LOG_INFO, "%s", log);
+
+#ifdef _MSC_VER
+ free(log);
+#endif
+ glDeleteProgram(program);
+
+ program = 0;
+ }
+ else TraceLog(LOG_INFO, "[SHDR ID %i] Shader program loaded successfully", program);
+
+ glDeleteShader(vertexShader);
+ glDeleteShader(fragmentShader);
+#endif
+ return program;
+}
+
+
+// Load default shader (just vertex positioning and texture coloring)
+// NOTE: This shader program is used for batch buffers (lines, triangles, quads)
+static Shader LoadShaderDefault(void)
+{
+ Shader shader;
+
+ // Vertex shader directly defined, no external file required
+ char vDefaultShaderStr[] =
+#if defined(GRAPHICS_API_OPENGL_21)
+ "#version 120 \n"
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ "#version 100 \n"
+#endif
+#if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21)
+ "attribute vec3 vertexPosition; \n"
+ "attribute vec2 vertexTexCoord; \n"
+ "attribute vec4 vertexColor; \n"
+ "varying vec2 fragTexCoord; \n"
+ "varying vec4 fragColor; \n"
+#elif defined(GRAPHICS_API_OPENGL_33)
+ "#version 330 \n"
+ "in vec3 vertexPosition; \n"
+ "in vec2 vertexTexCoord; \n"
+ "in vec4 vertexColor; \n"
+ "out vec2 fragTexCoord; \n"
+ "out vec4 fragColor; \n"
+#endif
+ "uniform mat4 mvp; \n"
+ "void main() \n"
+ "{ \n"
+ " fragTexCoord = vertexTexCoord; \n"
+ " fragColor = vertexColor; \n"
+ " gl_Position = mvp*vec4(vertexPosition, 1.0); \n"
+ "} \n";
+
+ // Fragment shader directly defined, no external file required
+ char fDefaultShaderStr[] =
+#if defined(GRAPHICS_API_OPENGL_21)
+ "#version 120 \n"
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ "#version 100 \n"
+ "precision mediump float; \n" // precision required for OpenGL ES2 (WebGL)
+#endif
+#if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21)
+ "varying vec2 fragTexCoord; \n"
+ "varying vec4 fragColor; \n"
+#elif defined(GRAPHICS_API_OPENGL_33)
+ "#version 330 \n"
+ "in vec2 fragTexCoord; \n"
+ "in vec4 fragColor; \n"
+ "out vec4 finalColor; \n"
+#endif
+ "uniform sampler2D texture0; \n"
+ "uniform vec4 colDiffuse; \n"
+ "void main() \n"
+ "{ \n"
+#if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21)
+ " vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0
+ " gl_FragColor = texelColor*colDiffuse*fragColor; \n"
+#elif defined(GRAPHICS_API_OPENGL_33)
+ " vec4 texelColor = texture(texture0, fragTexCoord); \n"
+ " finalColor = texelColor*colDiffuse*fragColor; \n"
+#endif
+ "} \n";
+
+ shader.id = LoadShaderProgram(vDefaultShaderStr, fDefaultShaderStr);
+
+ if (shader.id > 0)
+ {
+ TraceLog(LOG_INFO, "[SHDR ID %i] Default shader loaded successfully", shader.id);
+
+ // Set default shader locations
+ // Get handles to GLSL input attibute locations
+ shader.locs[LOC_VERTEX_POSITION] = glGetAttribLocation(shader.id, "vertexPosition");
+ shader.locs[LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(shader.id, "vertexTexCoord");
+ shader.locs[LOC_VERTEX_COLOR] = glGetAttribLocation(shader.id, "vertexColor");
+
+ // Get handles to GLSL uniform locations
+ shader.locs[LOC_MATRIX_MVP] = glGetUniformLocation(shader.id, "mvp");
+ shader.locs[LOC_COLOR_DIFFUSE] = glGetUniformLocation(shader.id, "colDiffuse");
+ shader.locs[LOC_MAP_DIFFUSE] = glGetUniformLocation(shader.id, "texture0");
+ }
+ else TraceLog(LOG_WARNING, "[SHDR ID %i] Default shader could not be loaded", shader.id);
+
+ return shader;
+}
+
+// Get location handlers to for shader attributes and uniforms
+// NOTE: If any location is not found, loc point becomes -1
+static void SetShaderDefaultLocations(Shader *shader)
+{
+ // NOTE: Default shader attrib locations have been fixed before linking:
+ // vertex position location = 0
+ // vertex texcoord location = 1
+ // vertex normal location = 2
+ // vertex color location = 3
+ // vertex tangent location = 4
+ // vertex texcoord2 location = 5
+
+ // Get handles to GLSL input attibute locations
+ shader->locs[LOC_VERTEX_POSITION] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_POSITION_NAME);
+ shader->locs[LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD_NAME);
+ shader->locs[LOC_VERTEX_TEXCOORD02] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD2_NAME);
+ shader->locs[LOC_VERTEX_NORMAL] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_NORMAL_NAME);
+ shader->locs[LOC_VERTEX_TANGENT] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TANGENT_NAME);
+ shader->locs[LOC_VERTEX_COLOR] = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_COLOR_NAME);
+
+ // Get handles to GLSL uniform locations (vertex shader)
+ shader->locs[LOC_MATRIX_MVP] = glGetUniformLocation(shader->id, "mvp");
+ shader->locs[LOC_MATRIX_PROJECTION] = glGetUniformLocation(shader->id, "projection");
+ shader->locs[LOC_MATRIX_VIEW] = glGetUniformLocation(shader->id, "view");
+
+ // Get handles to GLSL uniform locations (fragment shader)
+ shader->locs[LOC_COLOR_DIFFUSE] = glGetUniformLocation(shader->id, "colDiffuse");
+ shader->locs[LOC_MAP_DIFFUSE] = glGetUniformLocation(shader->id, "texture0");
+ shader->locs[LOC_MAP_NORMAL] = glGetUniformLocation(shader->id, "texture1");
+ shader->locs[LOC_MAP_SPECULAR] = glGetUniformLocation(shader->id, "texture2");
+
+ // TODO: Try to find all expected/recognized shader locations (predefined names, must be documented)
+}
+
+// Unload default shader
+static void UnloadShaderDefault(void)
+{
+ glUseProgram(0);
+
+ //glDetachShader(defaultShader, vertexShader);
+ //glDetachShader(defaultShader, fragmentShader);
+ //glDeleteShader(vertexShader); // Already deleted on shader compilation
+ //glDeleteShader(fragmentShader); // Already deleted on shader compilation
+ glDeleteProgram(defaultShader.id);
+}
+
+// Load default internal buffers (lines, triangles, quads)
+static void LoadBuffersDefault(void)
+{
+ // [CPU] Allocate and initialize float array buffers to store vertex data (lines, triangles, quads)
+ //--------------------------------------------------------------------------------------------
+
+ // Lines - Initialize arrays (vertex position and color data)
+ lines.vertices = (float *)malloc(sizeof(float)*3*2*MAX_LINES_BATCH); // 3 float by vertex, 2 vertex by line
+ lines.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*2*MAX_LINES_BATCH); // 4 float by color, 2 colors by line
+ lines.texcoords = NULL;
+ lines.indices = NULL;
+
+ for (int i = 0; i < (3*2*MAX_LINES_BATCH); i++) lines.vertices[i] = 0.0f;
+ for (int i = 0; i < (4*2*MAX_LINES_BATCH); i++) lines.colors[i] = 0;
+
+ lines.vCounter = 0;
+ lines.cCounter = 0;
+ lines.tcCounter = 0;
+
+ // Triangles - Initialize arrays (vertex position and color data)
+ triangles.vertices = (float *)malloc(sizeof(float)*3*3*MAX_TRIANGLES_BATCH); // 3 float by vertex, 3 vertex by triangle
+ triangles.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*3*MAX_TRIANGLES_BATCH); // 4 float by color, 3 colors by triangle
+ triangles.texcoords = NULL;
+ triangles.indices = NULL;
+
+ for (int i = 0; i < (3*3*MAX_TRIANGLES_BATCH); i++) triangles.vertices[i] = 0.0f;
+ for (int i = 0; i < (4*3*MAX_TRIANGLES_BATCH); i++) triangles.colors[i] = 0;
+
+ triangles.vCounter = 0;
+ triangles.cCounter = 0;
+ triangles.tcCounter = 0;
+
+ // Quads - Initialize arrays (vertex position, texcoord, color data and indexes)
+ quads.vertices = (float *)malloc(sizeof(float)*3*4*MAX_QUADS_BATCH); // 3 float by vertex, 4 vertex by quad
+ quads.texcoords = (float *)malloc(sizeof(float)*2*4*MAX_QUADS_BATCH); // 2 float by texcoord, 4 texcoord by quad
+ quads.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*4*MAX_QUADS_BATCH); // 4 float by color, 4 colors by quad
+#if defined(GRAPHICS_API_OPENGL_33)
+ quads.indices = (unsigned int *)malloc(sizeof(int)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ quads.indices = (unsigned short *)malloc(sizeof(short)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
+#endif
+
+ for (int i = 0; i < (3*4*MAX_QUADS_BATCH); i++) quads.vertices[i] = 0.0f;
+ for (int i = 0; i < (2*4*MAX_QUADS_BATCH); i++) quads.texcoords[i] = 0.0f;
+ for (int i = 0; i < (4*4*MAX_QUADS_BATCH); i++) quads.colors[i] = 0;
+
+ int k = 0;
+
+ // Indices can be initialized right now
+ for (int i = 0; i < (6*MAX_QUADS_BATCH); i+=6)
+ {
+ quads.indices[i] = 4*k;
+ quads.indices[i+1] = 4*k+1;
+ quads.indices[i+2] = 4*k+2;
+ quads.indices[i+3] = 4*k;
+ quads.indices[i+4] = 4*k+2;
+ quads.indices[i+5] = 4*k+3;
+
+ k++;
+ }
+
+ quads.vCounter = 0;
+ quads.tcCounter = 0;
+ quads.cCounter = 0;
+
+ TraceLog(LOG_INFO, "[CPU] Default buffers initialized successfully (lines, triangles, quads)");
+ //--------------------------------------------------------------------------------------------
+
+ // [GPU] Upload vertex data and initialize VAOs/VBOs (lines, triangles, quads)
+ // NOTE: Default buffers are linked to use currentShader (defaultShader)
+ //--------------------------------------------------------------------------------------------
+
+ // Upload and link lines vertex buffers
+ if (vaoSupported)
+ {
+ // Initialize Lines VAO
+ glGenVertexArrays(1, &lines.vaoId);
+ glBindVertexArray(lines.vaoId);
+ }
+
+ // Lines - Vertex buffers binding and attributes enable
+ // Vertex position buffer (shader-location = 0)
+ glGenBuffers(2, &lines.vboId[0]);
+ glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[0]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*2*MAX_LINES_BATCH, lines.vertices, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_POSITION]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+
+ // Vertex color buffer (shader-location = 3)
+ glGenBuffers(2, &lines.vboId[1]);
+ glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[1]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*2*MAX_LINES_BATCH, lines.colors, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_COLOR]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+
+ if (vaoSupported) TraceLog(LOG_INFO, "[VAO ID %i] Default buffers VAO initialized successfully (lines)", lines.vaoId);
+ else TraceLog(LOG_INFO, "[VBO ID %i][VBO ID %i] Default buffers VBOs initialized successfully (lines)", lines.vboId[0], lines.vboId[1]);
+
+ // Upload and link triangles vertex buffers
+ if (vaoSupported)
+ {
+ // Initialize Triangles VAO
+ glGenVertexArrays(1, &triangles.vaoId);
+ glBindVertexArray(triangles.vaoId);
+ }
+
+ // Triangles - Vertex buffers binding and attributes enable
+ // Vertex position buffer (shader-location = 0)
+ glGenBuffers(1, &triangles.vboId[0]);
+ glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[0]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*3*MAX_TRIANGLES_BATCH, triangles.vertices, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_POSITION]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+
+ // Vertex color buffer (shader-location = 3)
+ glGenBuffers(1, &triangles.vboId[1]);
+ glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[1]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*3*MAX_TRIANGLES_BATCH, triangles.colors, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_COLOR]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+
+ if (vaoSupported) TraceLog(LOG_INFO, "[VAO ID %i] Default buffers VAO initialized successfully (triangles)", triangles.vaoId);
+ else TraceLog(LOG_INFO, "[VBO ID %i][VBO ID %i] Default buffers VBOs initialized successfully (triangles)", triangles.vboId[0], triangles.vboId[1]);
+
+ // Upload and link quads vertex buffers
+ if (vaoSupported)
+ {
+ // Initialize Quads VAO
+ glGenVertexArrays(1, &quads.vaoId);
+ glBindVertexArray(quads.vaoId);
+ }
+
+ // Quads - Vertex buffers binding and attributes enable
+ // Vertex position buffer (shader-location = 0)
+ glGenBuffers(1, &quads.vboId[0]);
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[0]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*MAX_QUADS_BATCH, quads.vertices, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_POSITION]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+
+ // Vertex texcoord buffer (shader-location = 1)
+ glGenBuffers(1, &quads.vboId[1]);
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[1]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*MAX_QUADS_BATCH, quads.texcoords, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_TEXCOORD01]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
+
+ // Vertex color buffer (shader-location = 3)
+ glGenBuffers(1, &quads.vboId[2]);
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[2]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*4*MAX_QUADS_BATCH, quads.colors, GL_DYNAMIC_DRAW);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_COLOR]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+
+ // Fill index buffer
+ glGenBuffers(1, &quads.vboId[3]);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quads.vboId[3]);
+#if defined(GRAPHICS_API_OPENGL_33)
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int)*6*MAX_QUADS_BATCH, quads.indices, GL_STATIC_DRAW);
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short)*6*MAX_QUADS_BATCH, quads.indices, GL_STATIC_DRAW);
+#endif
+
+ if (vaoSupported) TraceLog(LOG_INFO, "[VAO ID %i] Default buffers VAO initialized successfully (quads)", quads.vaoId);
+ else TraceLog(LOG_INFO, "[VBO ID %i][VBO ID %i][VBO ID %i][VBO ID %i] Default buffers VBOs initialized successfully (quads)", quads.vboId[0], quads.vboId[1], quads.vboId[2], quads.vboId[3]);
+
+ // Unbind the current VAO
+ if (vaoSupported) glBindVertexArray(0);
+ //--------------------------------------------------------------------------------------------
+}
+
+// Update default internal buffers (VAOs/VBOs) with vertex array data
+// NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
+// TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
+static void UpdateBuffersDefault(void)
+{
+ // Update lines vertex buffers
+ if (lines.vCounter > 0)
+ {
+ // Activate Lines VAO
+ if (vaoSupported) glBindVertexArray(lines.vaoId);
+
+ // Lines - vertex positions buffer
+ glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[0]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*2*MAX_LINES_BATCH, lines.vertices, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*lines.vCounter, lines.vertices); // target - offset (in bytes) - size (in bytes) - data pointer
+
+ // Lines - colors buffer
+ glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[1]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*2*MAX_LINES_BATCH, lines.colors, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*lines.cCounter, lines.colors);
+ }
+
+ // Update triangles vertex buffers
+ if (triangles.vCounter > 0)
+ {
+ // Activate Triangles VAO
+ if (vaoSupported) glBindVertexArray(triangles.vaoId);
+
+ // Triangles - vertex positions buffer
+ glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[0]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*3*MAX_TRIANGLES_BATCH, triangles.vertices, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*triangles.vCounter, triangles.vertices);
+
+ // Triangles - colors buffer
+ glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[1]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*3*MAX_TRIANGLES_BATCH, triangles.colors, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*triangles.cCounter, triangles.colors);
+ }
+
+ // Update quads vertex buffers
+ if (quads.vCounter > 0)
+ {
+ // Activate Quads VAO
+ if (vaoSupported) glBindVertexArray(quads.vaoId);
+
+ // Quads - vertex positions buffer
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[0]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*MAX_QUADS_BATCH, quads.vertices, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*quads.vCounter, quads.vertices);
+
+ // Quads - texture coordinates buffer
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[1]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*MAX_QUADS_BATCH, quads.texcoords, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*quads.vCounter, quads.texcoords);
+
+ // Quads - colors buffer
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[2]);
+ //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*MAX_QUADS_BATCH, quads.colors, GL_DYNAMIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*quads.vCounter, quads.colors);
+
+ // Another option would be using buffer mapping...
+ //quads.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
+ // Now we can modify vertices
+ //glUnmapBuffer(GL_ARRAY_BUFFER);
+ }
+ //--------------------------------------------------------------
+
+ // Unbind the current VAO
+ if (vaoSupported) glBindVertexArray(0);
+}
+
+// Draw default internal buffers vertex data
+// NOTE: We draw in this order: lines, triangles, quads
+static void DrawBuffersDefault(void)
+{
+ Matrix matProjection = projection;
+ Matrix matModelView = modelview;
+
+ int eyesCount = 1;
+#if defined(SUPPORT_VR_SIMULATOR)
+ if (vrStereoRender) eyesCount = 2;
+#endif
+
+ for (int eye = 0; eye < eyesCount; eye++)
+ {
+ #if defined(SUPPORT_VR_SIMULATOR)
+ if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView);
+ #endif
+
+ // Set current shader and upload current MVP matrix
+ if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
+ {
+ glUseProgram(currentShader.id);
+
+ // Create modelview-projection matrix
+ Matrix matMVP = MatrixMultiply(modelview, projection);
+
+ glUniformMatrix4fv(currentShader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP));
+ glUniform4f(currentShader.locs[LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f);
+ glUniform1i(currentShader.locs[LOC_MAP_DIFFUSE], 0);
+
+ // NOTE: Additional map textures not considered for default buffers drawing
+ }
+
+ // Draw lines buffers
+ if (lines.vCounter > 0)
+ {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, whiteTexture);
+
+ if (vaoSupported)
+ {
+ glBindVertexArray(lines.vaoId);
+ }
+ else
+ {
+ // Bind vertex attrib: position (shader-location = 0)
+ glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[0]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_POSITION]);
+
+ // Bind vertex attrib: color (shader-location = 3)
+ glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[1]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_COLOR]);
+ }
+
+ glDrawArrays(GL_LINES, 0, lines.vCounter);
+
+ if (!vaoSupported) glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
+ // Draw triangles buffers
+ if (triangles.vCounter > 0)
+ {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, whiteTexture);
+
+ if (vaoSupported)
+ {
+ glBindVertexArray(triangles.vaoId);
+ }
+ else
+ {
+ // Bind vertex attrib: position (shader-location = 0)
+ glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[0]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_POSITION]);
+
+ // Bind vertex attrib: color (shader-location = 3)
+ glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[1]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_COLOR]);
+ }
+
+ glDrawArrays(GL_TRIANGLES, 0, triangles.vCounter);
+
+ if (!vaoSupported) glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
+ // Draw quads buffers
+ if (quads.vCounter > 0)
+ {
+ int quadsCount = 0;
+ int numIndicesToProcess = 0;
+ int indicesOffset = 0;
+
+ if (vaoSupported)
+ {
+ glBindVertexArray(quads.vaoId);
+ }
+ else
+ {
+ // Bind vertex attrib: position (shader-location = 0)
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[0]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_POSITION]);
+
+ // Bind vertex attrib: texcoord (shader-location = 1)
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[1]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_TEXCOORD01]);
+
+ // Bind vertex attrib: color (shader-location = 3)
+ glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[2]);
+ glVertexAttribPointer(currentShader.locs[LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
+ glEnableVertexAttribArray(currentShader.locs[LOC_VERTEX_COLOR]);
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quads.vboId[3]);
+ }
+
+ //TraceLog(LOG_DEBUG, "Draws required per frame: %i", drawsCounter);
+
+ for (int i = 0; i < drawsCounter; i++)
+ {
+ quadsCount = draws[i].vertexCount/4;
+ numIndicesToProcess = quadsCount*6; // Get number of Quads*6 index by Quad
+
+ //TraceLog(LOG_DEBUG, "Quads to render: %i - Vertex Count: %i", quadsCount, draws[i].vertexCount);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, draws[i].textureId);
+
+ // NOTE: The final parameter tells the GPU the offset in bytes from the start of the index buffer to the location of the first index to process
+ #if defined(GRAPHICS_API_OPENGL_33)
+ glDrawElements(GL_TRIANGLES, numIndicesToProcess, GL_UNSIGNED_INT, (GLvoid *)(sizeof(GLuint)*indicesOffset));
+ #elif defined(GRAPHICS_API_OPENGL_ES2)
+ glDrawElements(GL_TRIANGLES, numIndicesToProcess, GL_UNSIGNED_SHORT, (GLvoid *)(sizeof(GLushort)*indicesOffset));
+ #endif
+ //GLenum err;
+ //if ((err = glGetError()) != GL_NO_ERROR) TraceLog(LOG_INFO, "OpenGL error: %i", (int)err); //GL_INVALID_ENUM!
+
+ indicesOffset += draws[i].vertexCount/4*6;
+ }
+
+ if (!vaoSupported)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ }
+
+ glBindTexture(GL_TEXTURE_2D, 0); // Unbind textures
+ }
+
+ if (vaoSupported) glBindVertexArray(0); // Unbind VAO
+
+ glUseProgram(0); // Unbind shader program
+ }
+
+ // Reset draws counter
+ drawsCounter = 1;
+ draws[0].textureId = whiteTexture;
+ draws[0].vertexCount = 0;
+
+ // Reset vertex counters for next frame
+ lines.vCounter = 0;
+ lines.cCounter = 0;
+ triangles.vCounter = 0;
+ triangles.cCounter = 0;
+ quads.vCounter = 0;
+ quads.tcCounter = 0;
+ quads.cCounter = 0;
+
+ // Reset depth for next draw
+ currentDepth = -1.0f;
+
+ // Restore projection/modelview matrices
+ projection = matProjection;
+ modelview = matModelView;
+}
+
+// Unload default internal buffers vertex data from CPU and GPU
+static void UnloadBuffersDefault(void)
+{
+ // Unbind everything
+ if (vaoSupported) glBindVertexArray(0);
+ glDisableVertexAttribArray(0);
+ glDisableVertexAttribArray(1);
+ glDisableVertexAttribArray(2);
+ glDisableVertexAttribArray(3);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ // Delete VBOs from GPU (VRAM)
+ glDeleteBuffers(1, &lines.vboId[0]);
+ glDeleteBuffers(1, &lines.vboId[1]);
+ glDeleteBuffers(1, &triangles.vboId[0]);
+ glDeleteBuffers(1, &triangles.vboId[1]);
+ glDeleteBuffers(1, &quads.vboId[0]);
+ glDeleteBuffers(1, &quads.vboId[1]);
+ glDeleteBuffers(1, &quads.vboId[2]);
+ glDeleteBuffers(1, &quads.vboId[3]);
+
+ if (vaoSupported)
+ {
+ // Delete VAOs from GPU (VRAM)
+ glDeleteVertexArrays(1, &lines.vaoId);
+ glDeleteVertexArrays(1, &triangles.vaoId);
+ glDeleteVertexArrays(1, &quads.vaoId);
+ }
+
+ // Free vertex arrays memory from CPU (RAM)
+ free(lines.vertices);
+ free(lines.colors);
+
+ free(triangles.vertices);
+ free(triangles.colors);
+
+ free(quads.vertices);
+ free(quads.texcoords);
+ free(quads.colors);
+ free(quads.indices);
+}
+
+// Renders a 1x1 XY quad in NDC
+static void GenDrawQuad(void)
+{
+ unsigned int quadVAO = 0;
+ unsigned int quadVBO = 0;
+
+ float vertices[] = {
+ // Positions // Texture Coords
+ -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
+ };
+
+ // Set up plane VAO
+ glGenVertexArrays(1, &quadVAO);
+ glGenBuffers(1, &quadVBO);
+ glBindVertexArray(quadVAO);
+
+ // Fill buffer
+ glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
+
+ // Link vertex attributes
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float)));
+
+ // Draw quad
+ glBindVertexArray(quadVAO);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ glBindVertexArray(0);
+
+ glDeleteBuffers(1, &quadVBO);
+ glDeleteVertexArrays(1, &quadVAO);
+}
+
+// Renders a 1x1 3D cube in NDC
+static void GenDrawCube(void)
+{
+ unsigned int cubeVAO = 0;
+ unsigned int cubeVBO = 0;
+
+ float vertices[] = {
+ -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
+ 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
+ -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
+ -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
+ -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ -1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+ -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
+ -1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
+ -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, 1.0f , 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
+ -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f
+ };
+
+ // Set up cube VAO
+ glGenVertexArrays(1, &cubeVAO);
+ glGenBuffers(1, &cubeVBO);
+
+ // Fill buffer
+ glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+
+ // Link vertex attributes
+ glBindVertexArray(cubeVAO);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float)));
+ glEnableVertexAttribArray(2);
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float)));
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindVertexArray(0);
+
+ // Draw cube
+ glBindVertexArray(cubeVAO);
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+ glBindVertexArray(0);
+
+ glDeleteBuffers(1, &cubeVBO);
+ glDeleteVertexArrays(1, &cubeVAO);
+}
+
+#if defined(SUPPORT_VR_SIMULATOR)
+// Configure stereo rendering (including distortion shader) with HMD device parameters
+static void SetStereoConfig(VrDeviceInfo hmd)
+{
+ // Compute aspect ratio
+ float aspect = ((float)hmd.hResolution*0.5f)/(float)hmd.vResolution;
+
+ // Compute lens parameters
+ float lensShift = (hmd.hScreenSize*0.25f - hmd.lensSeparationDistance*0.5f)/hmd.hScreenSize;
+ float leftLensCenter[2] = { 0.25f + lensShift, 0.5f };
+ float rightLensCenter[2] = { 0.75f - lensShift, 0.5f };
+ float leftScreenCenter[2] = { 0.25f, 0.5f };
+ float rightScreenCenter[2] = { 0.75f, 0.5f };
+
+ // Compute distortion scale parameters
+ // NOTE: To get lens max radius, lensShift must be normalized to [-1..1]
+ float lensRadius = fabsf(-1.0f - 4.0f*lensShift);
+ float lensRadiusSq = lensRadius*lensRadius;
+ float distortionScale = hmd.distortionK[0] +
+ hmd.distortionK[1]*lensRadiusSq +
+ hmd.distortionK[2]*lensRadiusSq*lensRadiusSq +
+ hmd.distortionK[3]*lensRadiusSq*lensRadiusSq*lensRadiusSq;
+
+ TraceLog(LOG_DEBUG, "VR: Distortion Scale: %f", distortionScale);
+
+ float normScreenWidth = 0.5f;
+ float normScreenHeight = 1.0f;
+ float scaleIn[2] = { 2.0f/normScreenWidth, 2.0f/normScreenHeight/aspect };
+ float scale[2] = { normScreenWidth*0.5f/distortionScale, normScreenHeight*0.5f*aspect/distortionScale };
+
+ TraceLog(LOG_DEBUG, "VR: Distortion Shader: LeftLensCenter = { %f, %f }", leftLensCenter[0], leftLensCenter[1]);
+ TraceLog(LOG_DEBUG, "VR: Distortion Shader: RightLensCenter = { %f, %f }", rightLensCenter[0], rightLensCenter[1]);
+ TraceLog(LOG_DEBUG, "VR: Distortion Shader: Scale = { %f, %f }", scale[0], scale[1]);
+ TraceLog(LOG_DEBUG, "VR: Distortion Shader: ScaleIn = { %f, %f }", scaleIn[0], scaleIn[1]);
+
+#if defined(SUPPORT_DISTORTION_SHADER)
+ // Update distortion shader with lens and distortion-scale parameters
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftLensCenter"), leftLensCenter, 2);
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightLensCenter"), rightLensCenter, 2);
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftScreenCenter"), leftScreenCenter, 2);
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightScreenCenter"), rightScreenCenter, 2);
+
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scale"), scale, 2);
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scaleIn"), scaleIn, 2);
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "hmdWarpParam"), hmd.distortionK, 4);
+ SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "chromaAbParam"), hmd.chromaAbCorrection, 4);
+#endif
+
+ // Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)
+ // ...but with lens distortion it is increased (see Oculus SDK Documentation)
+ //float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale?
+ float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance);
+
+ // Compute camera projection matrices
+ float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
+ Matrix proj = MatrixPerspective(fovy, aspect, 0.01, 1000.0);
+ vrConfig.eyesProjection[0] = MatrixMultiply(proj, MatrixTranslate(projOffset, 0.0f, 0.0f));
+ vrConfig.eyesProjection[1] = MatrixMultiply(proj, MatrixTranslate(-projOffset, 0.0f, 0.0f));
+
+ // Compute camera transformation matrices
+ // NOTE: Camera movement might seem more natural if we model the head.
+ // Our axis of rotation is the base of our head, so we might want to add
+ // some y (base of head to eye level) and -z (center of head to eye protrusion) to the camera positions.
+ vrConfig.eyesViewOffset[0] = MatrixTranslate(-hmd.interpupillaryDistance*0.5f, 0.075f, 0.045f);
+ vrConfig.eyesViewOffset[1] = MatrixTranslate(hmd.interpupillaryDistance*0.5f, 0.075f, 0.045f);
+
+ // Compute eyes Viewports
+ //vrConfig.eyesViewport[0] = (Rectangle){ 0, 0, hmd.hResolution/2, hmd.vResolution };
+ //vrConfig.eyesViewport[1] = (Rectangle){ hmd.hResolution/2, 0, hmd.hResolution/2, hmd.vResolution };
+}
+
+// Set internal projection and modelview matrix depending on eyes tracking data
+static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView)
+{
+ Matrix eyeProjection = matProjection;
+ Matrix eyeModelView = matModelView;
+
+ // Setup viewport and projection/modelview matrices using tracking data
+ rlViewport(eye*screenWidth/2, 0, screenWidth/2, screenHeight);
+
+ // Apply view offset to modelview matrix
+ eyeModelView = MatrixMultiply(matModelView, vrConfig.eyesViewOffset[eye]);
+
+ eyeProjection = vrConfig.eyesProjection[eye];
+
+ SetMatrixModelview(eyeModelView);
+ SetMatrixProjection(eyeProjection);
+}
+#endif // defined(SUPPORT_VR_SIMULATOR)
+
+#endif //defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+
+#if defined(GRAPHICS_API_OPENGL_11)
+// Mipmaps data is generated after image data
+static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight)
+{
+ int mipmapCount = 1; // Required mipmap levels count (including base level)
+ int width = baseWidth;
+ int height = baseHeight;
+ int size = baseWidth*baseHeight*4; // Size in bytes (will include mipmaps...), RGBA only
+
+ // Count mipmap levels required
+ while ((width != 1) && (height != 1))
+ {
+ if (width != 1) width /= 2;
+ if (height != 1) height /= 2;
+
+ TraceLog(LOG_DEBUG, "Next mipmap size: %i x %i", width, height);
+
+ mipmapCount++;
+
+ size += (width*height*4); // Add mipmap size (in bytes)
+ }
+
+ TraceLog(LOG_DEBUG, "Total mipmaps required: %i", mipmapCount);
+ TraceLog(LOG_DEBUG, "Total size of data required: %i", size);
+
+ unsigned char *temp = realloc(data, size);
+
+ if (temp != NULL) data = temp;
+ else TraceLog(LOG_WARNING, "Mipmaps required memory could not be allocated");
+
+ width = baseWidth;
+ height = baseHeight;
+ size = (width*height*4);
+
+ // Generate mipmaps
+ // NOTE: Every mipmap data is stored after data
+ Color *image = (Color *)malloc(width*height*sizeof(Color));
+ Color *mipmap = NULL;
+ int offset = 0;
+ int j = 0;
+
+ for (int i = 0; i < size; i += 4)
+ {
+ image[j].r = data[i];
+ image[j].g = data[i + 1];
+ image[j].b = data[i + 2];
+ image[j].a = data[i + 3];
+ j++;
+ }
+
+ TraceLog(LOG_DEBUG, "Mipmap base (%ix%i)", width, height);
+
+ for (int mip = 1; mip < mipmapCount; mip++)
+ {
+ mipmap = GenNextMipmap(image, width, height);
+
+ offset += (width*height*4); // Size of last mipmap
+ j = 0;
+
+ width /= 2;
+ height /= 2;
+ size = (width*height*4); // Mipmap size to store after offset
+
+ // Add mipmap to data
+ for (int i = 0; i < size; i += 4)
+ {
+ data[offset + i] = mipmap[j].r;
+ data[offset + i + 1] = mipmap[j].g;
+ data[offset + i + 2] = mipmap[j].b;
+ data[offset + i + 3] = mipmap[j].a;
+ j++;
+ }
+
+ free(image);
+
+ image = mipmap;
+ mipmap = NULL;
+ }
+
+ free(mipmap); // free mipmap data
+
+ return mipmapCount;
+}
+
+// Manual mipmap generation (basic scaling algorithm)
+static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight)
+{
+ int x2, y2;
+ Color prow, pcol;
+
+ int width = srcWidth/2;
+ int height = srcHeight/2;
+
+ Color *mipmap = (Color *)malloc(width*height*sizeof(Color));
+
+ // Scaling algorithm works perfectly (box-filter)
+ for (int y = 0; y < height; y++)
+ {
+ y2 = 2*y;
+
+ for (int x = 0; x < width; x++)
+ {
+ x2 = 2*x;
+
+ prow.r = (srcData[y2*srcWidth + x2].r + srcData[y2*srcWidth + x2 + 1].r)/2;
+ prow.g = (srcData[y2*srcWidth + x2].g + srcData[y2*srcWidth + x2 + 1].g)/2;
+ prow.b = (srcData[y2*srcWidth + x2].b + srcData[y2*srcWidth + x2 + 1].b)/2;
+ prow.a = (srcData[y2*srcWidth + x2].a + srcData[y2*srcWidth + x2 + 1].a)/2;
+
+ pcol.r = (srcData[(y2+1)*srcWidth + x2].r + srcData[(y2+1)*srcWidth + x2 + 1].r)/2;
+ pcol.g = (srcData[(y2+1)*srcWidth + x2].g + srcData[(y2+1)*srcWidth + x2 + 1].g)/2;
+ pcol.b = (srcData[(y2+1)*srcWidth + x2].b + srcData[(y2+1)*srcWidth + x2 + 1].b)/2;
+ pcol.a = (srcData[(y2+1)*srcWidth + x2].a + srcData[(y2+1)*srcWidth + x2 + 1].a)/2;
+
+ mipmap[y*width + x].r = (prow.r + pcol.r)/2;
+ mipmap[y*width + x].g = (prow.g + pcol.g)/2;
+ mipmap[y*width + x].b = (prow.b + pcol.b)/2;
+ mipmap[y*width + x].a = (prow.a + pcol.a)/2;
+ }
+ }
+
+ TraceLog(LOG_DEBUG, "Mipmap generated successfully (%ix%i)", width, height);
+
+ return mipmap;
+}
+#endif
+
+#if defined(RLGL_STANDALONE)
+// Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
+void TraceLog(int msgType, const char *text, ...)
+{
+ va_list args;
+ va_start(args, text);
+
+ switch (msgType)
+ {
+ case LOG_INFO: fprintf(stdout, "INFO: "); break;
+ case LOG_ERROR: fprintf(stdout, "ERROR: "); break;
+ case LOG_WARNING: fprintf(stdout, "WARNING: "); break;
+ case LOG_DEBUG: fprintf(stdout, "DEBUG: "); break;
+ default: break;
+ }
+
+ vfprintf(stdout, text, args);
+ fprintf(stdout, "\n");
+
+ va_end(args);
+
+ if (msgType == LOG_ERROR) exit(1);
+}
+#endif
diff --git a/templates/android_project/src/rlgl.h b/templates/android_project/src/rlgl.h
new file mode 100644
index 00000000..b9ea0f43
--- /dev/null
+++ b/templates/android_project/src/rlgl.h
@@ -0,0 +1,474 @@
+/**********************************************************************************************
+*
+* rlgl - raylib OpenGL abstraction layer
+*
+* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to
+* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...).
+*
+* 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
+*
+* CONFIGURATION:
+*
+* #define GRAPHICS_API_OPENGL_11
+* #define GRAPHICS_API_OPENGL_21
+* #define GRAPHICS_API_OPENGL_33
+* #define GRAPHICS_API_OPENGL_ES2
+* Use selected OpenGL graphics backend, should be supported by platform
+* Those preprocessor defines are only used on rlgl module, if OpenGL version is
+* required by any other module, use rlGetVersion() tocheck it
+*
+* #define RLGL_STANDALONE
+* Use rlgl as standalone library (no raylib dependency)
+*
+* #define SUPPORT_VR_SIMULATION / SUPPORT_STEREO_RENDERING
+* Support VR simulation functionality (stereo rendering)
+*
+* #define SUPPORT_SHADER_DISTORTION
+* Include stereo rendering distortion shader (shader_distortion.h)
+*
+* DEPENDENCIES:
+* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
+* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only)
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2014-2017 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef RLGL_H
+#define RLGL_H
+
+#if defined(RLGL_STANDALONE)
+ #define RAYMATH_STANDALONE
+#else
+ #include "raylib.h" // Required for: Model, Shader, Texture2D, TraceLog()
+#endif
+
+#include "raymath.h" // Required for: Vector3, Matrix
+
+// Security check in case no GRAPHICS_API_OPENGL_* defined
+#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_21) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
+ #define GRAPHICS_API_OPENGL_11
+#endif
+
+// Security check in case multiple GRAPHICS_API_OPENGL_* defined
+#if defined(GRAPHICS_API_OPENGL_11)
+ #if defined(GRAPHICS_API_OPENGL_21)
+ #undef GRAPHICS_API_OPENGL_21
+ #endif
+ #if defined(GRAPHICS_API_OPENGL_33)
+ #undef GRAPHICS_API_OPENGL_33
+ #endif
+ #if defined(GRAPHICS_API_OPENGL_ES2)
+ #undef GRAPHICS_API_OPENGL_ES2
+ #endif
+#endif
+
+#if defined(GRAPHICS_API_OPENGL_21)
+ #define GRAPHICS_API_OPENGL_33
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
+ // NOTE: This is the maximum amount of lines, triangles and quads per frame, be careful!
+ #define MAX_LINES_BATCH 8192
+ #define MAX_TRIANGLES_BATCH 4096
+ #define MAX_QUADS_BATCH 8192
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: Reduce memory sizes for embedded systems (RPI and HTML5)
+ // NOTE: On HTML5 (emscripten) this is allocated on heap, by default it's only 16MB!...just take care...
+ #define MAX_LINES_BATCH 1024 // Critical for wire shapes (sphere)
+ #define MAX_TRIANGLES_BATCH 2048 // Critical for some shapes (sphere)
+ #define MAX_QUADS_BATCH 1024 // Be careful with text, every letter maps a quad
+#endif
+
+// Texture parameters (equivalent to OpenGL defines)
+#define RL_TEXTURE_WRAP_S 0x2802 // GL_TEXTURE_WRAP_S
+#define RL_TEXTURE_WRAP_T 0x2803 // GL_TEXTURE_WRAP_T
+#define RL_TEXTURE_MAG_FILTER 0x2800 // GL_TEXTURE_MAG_FILTER
+#define RL_TEXTURE_MIN_FILTER 0x2801 // GL_TEXTURE_MIN_FILTER
+#define RL_TEXTURE_ANISOTROPIC_FILTER 0x3000 // Anisotropic filter (custom identifier)
+
+#define RL_FILTER_NEAREST 0x2600 // GL_NEAREST
+#define RL_FILTER_LINEAR 0x2601 // GL_LINEAR
+#define RL_FILTER_MIP_NEAREST 0x2700 // GL_NEAREST_MIPMAP_NEAREST
+#define RL_FILTER_NEAREST_MIP_LINEAR 0x2702 // GL_NEAREST_MIPMAP_LINEAR
+#define RL_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST
+#define RL_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR
+
+#define RL_WRAP_REPEAT 0x2901 // GL_REPEAT
+#define RL_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE
+#define RL_WRAP_CLAMP_MIRROR 0x8742 // GL_MIRROR_CLAMP_EXT
+
+// Matrix modes (equivalent to OpenGL)
+#define RL_MODELVIEW 0x1700 // GL_MODELVIEW
+#define RL_PROJECTION 0x1701 // GL_PROJECTION
+#define RL_TEXTURE 0x1702 // GL_TEXTURE
+
+// Primitive assembly draw modes
+#define RL_LINES 0x0001 // GL_LINES
+#define RL_TRIANGLES 0x0004 // GL_TRIANGLES
+#define RL_QUADS 0x0007 // GL_QUADS
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+typedef enum { OPENGL_11 = 1, OPENGL_21, OPENGL_33, OPENGL_ES_20 } GlVersion;
+
+typedef unsigned char byte;
+
+#if defined(RLGL_STANDALONE)
+ #ifndef __cplusplus
+ // Boolean type
+ typedef enum { false, true } bool;
+ #endif
+
+ // Shader location point type
+ typedef enum {
+ LOC_VERTEX_POSITION = 0,
+ LOC_VERTEX_TEXCOORD01,
+ LOC_VERTEX_TEXCOORD02,
+ LOC_VERTEX_NORMAL,
+ LOC_VERTEX_TANGENT,
+ LOC_VERTEX_COLOR,
+ LOC_MATRIX_MVP,
+ LOC_MATRIX_MODEL,
+ LOC_MATRIX_VIEW,
+ LOC_MATRIX_PROJECTION,
+ LOC_VECTOR_VIEW,
+ LOC_COLOR_DIFFUSE,
+ LOC_COLOR_SPECULAR,
+ LOC_COLOR_AMBIENT,
+ LOC_MAP_ALBEDO, // LOC_MAP_DIFFUSE
+ LOC_MAP_METALNESS, // LOC_MAP_SPECULAR
+ LOC_MAP_NORMAL,
+ LOC_MAP_ROUGHNESS,
+ LOC_MAP_OCCUSION,
+ LOC_MAP_EMISSION,
+ LOC_MAP_HEIGHT,
+ LOC_MAP_CUBEMAP,
+ LOC_MAP_IRRADIANCE,
+ LOC_MAP_PREFILTER,
+ LOC_MAP_BRDF
+ } ShaderLocationIndex;
+
+ #define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
+ #define LOC_MAP_SPECULAR LOC_MAP_METALNESS
+
+ // Material map type
+ typedef enum {
+ MAP_ALBEDO = 0, // MAP_DIFFUSE
+ MAP_METALNESS = 1, // MAP_SPECULAR
+ MAP_NORMAL = 2,
+ MAP_ROUGHNESS = 3,
+ MAP_OCCLUSION,
+ MAP_EMISSION,
+ MAP_HEIGHT,
+ MAP_CUBEMAP, // NOTE: Uses GL_TEXTURE_CUBE_MAP
+ MAP_IRRADIANCE, // NOTE: Uses GL_TEXTURE_CUBE_MAP
+ MAP_PREFILTER, // NOTE: Uses GL_TEXTURE_CUBE_MAP
+ MAP_BRDF
+ } TexmapIndex;
+
+ #define MAP_DIFFUSE MAP_ALBEDO
+ #define MAP_SPECULAR MAP_METALNESS
+
+ // Color type, RGBA (32bit)
+ typedef struct Color {
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+ unsigned char a;
+ } Color;
+
+ // Texture2D type
+ // NOTE: Data stored in GPU memory
+ typedef struct Texture2D {
+ unsigned int id; // OpenGL texture id
+ int width; // Texture base width
+ int height; // Texture base height
+ int mipmaps; // Mipmap levels, 1 by default
+ int format; // Data format (TextureFormat)
+ } Texture2D;
+
+ // RenderTexture2D type, for texture rendering
+ typedef struct RenderTexture2D {
+ unsigned int id; // Render texture (fbo) id
+ Texture2D texture; // Color buffer attachment texture
+ Texture2D depth; // Depth buffer attachment texture
+ } RenderTexture2D;
+
+ // Vertex data definning a mesh
+ typedef struct Mesh {
+ int vertexCount; // number of vertices stored in arrays
+ int triangleCount; // number of triangles stored (indexed or not)
+ float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
+ float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
+ float *texcoords2; // vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
+ float *normals; // vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
+ float *tangents; // vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
+ unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
+ unsigned short *indices;// vertex indices (in case vertex data comes indexed)
+
+ unsigned int vaoId; // OpenGL Vertex Array Object id
+ unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
+ } Mesh;
+
+ // Shader and material limits
+ #define MAX_SHADER_LOCATIONS 32
+ #define MAX_MATERIAL_MAPS 12
+
+ // Shader type (generic)
+ typedef struct Shader {
+ unsigned int id; // Shader program id
+ int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
+ } Shader;
+
+ // Material texture map
+ typedef struct MaterialMap {
+ Texture2D texture; // Material map texture
+ Color color; // Material map color
+ float value; // Material map value
+ } MaterialMap;
+
+ // Material type (generic)
+ typedef struct Material {
+ Shader shader; // Material shader
+ MaterialMap maps[MAX_MATERIAL_MAPS]; // Material maps
+ float *params; // Material generic parameters (if required)
+ } Material;
+
+ // Camera type, defines a camera position/orientation in 3d space
+ typedef struct Camera {
+ Vector3 position; // Camera position
+ Vector3 target; // Camera target it looks-at
+ Vector3 up; // Camera up vector (rotation over its axis)
+ float fovy; // Camera field-of-view apperture in Y (degrees)
+ } Camera;
+
+ // TraceLog message types
+ typedef enum {
+ LOG_INFO = 0,
+ LOG_ERROR,
+ LOG_WARNING,
+ LOG_DEBUG,
+ LOG_OTHER
+ } TraceLogType;
+
+ // Texture formats (support depends on OpenGL version)
+ typedef enum {
+ UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
+ UNCOMPRESSED_GRAY_ALPHA,
+ UNCOMPRESSED_R5G6B5, // 16 bpp
+ UNCOMPRESSED_R8G8B8, // 24 bpp
+ UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
+ UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
+ UNCOMPRESSED_R8G8B8A8, // 32 bpp
+ UNCOMPRESSED_R32G32B32, // 32 bit per channel (float) - HDR
+ COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
+ COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
+ COMPRESSED_DXT3_RGBA, // 8 bpp
+ COMPRESSED_DXT5_RGBA, // 8 bpp
+ COMPRESSED_ETC1_RGB, // 4 bpp
+ COMPRESSED_ETC2_RGB, // 4 bpp
+ COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
+ COMPRESSED_PVRT_RGB, // 4 bpp
+ COMPRESSED_PVRT_RGBA, // 4 bpp
+ COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
+ COMPRESSED_ASTC_8x8_RGBA // 2 bpp
+ } TextureFormat;
+
+ // Texture parameters: filter mode
+ // NOTE 1: Filtering considers mipmaps if available in the texture
+ // NOTE 2: Filter is accordingly set for minification and magnification
+ typedef enum {
+ FILTER_POINT = 0, // No filter, just pixel aproximation
+ FILTER_BILINEAR, // Linear filtering
+ FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
+ FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x
+ FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x
+ FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x
+ } TextureFilterMode;
+
+ // Texture parameters: wrap mode
+ typedef enum {
+ WRAP_REPEAT = 0,
+ WRAP_CLAMP,
+ WRAP_MIRROR
+ } TextureWrapMode;
+
+ // Color blending modes (pre-defined)
+ typedef enum {
+ BLEND_ALPHA = 0,
+ BLEND_ADDITIVE,
+ BLEND_MULTIPLIED
+ } BlendMode;
+
+ // VR Head Mounted Display devices
+ typedef enum {
+ HMD_DEFAULT_DEVICE = 0,
+ HMD_OCULUS_RIFT_DK2,
+ HMD_OCULUS_RIFT_CV1,
+ HMD_VALVE_HTC_VIVE,
+ HMD_SAMSUNG_GEAR_VR,
+ HMD_GOOGLE_CARDBOARD,
+ HMD_SONY_PLAYSTATION_VR,
+ HMD_RAZER_OSVR,
+ HMD_FOVE_VR,
+ } VrDevice;
+#endif
+
+#ifdef __cplusplus
+extern "C" { // Prevents name mangling of functions
+#endif
+
+//------------------------------------------------------------------------------------
+// Functions Declaration - Matrix operations
+//------------------------------------------------------------------------------------
+void rlMatrixMode(int mode); // Choose the current matrix to be transformed
+void rlPushMatrix(void); // Push the current matrix to stack
+void rlPopMatrix(void); // Pop lattest inserted matrix from stack
+void rlLoadIdentity(void); // Reset current matrix to identity matrix
+void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
+void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix
+void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
+void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix
+void rlFrustum(double left, double right, double bottom, double top, double near, double far);
+void rlOrtho(double left, double right, double bottom, double top, double near, double far);
+void rlViewport(int x, int y, int width, int height); // Set the viewport area
+
+//------------------------------------------------------------------------------------
+// Functions Declaration - Vertex level operations
+//------------------------------------------------------------------------------------
+void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
+void rlEnd(void); // Finish vertex providing
+void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
+void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
+void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
+void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
+void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
+void rlColor4ub(byte r, byte g, byte b, byte a); // Define one vertex (color) - 4 byte
+void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
+void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
+
+//------------------------------------------------------------------------------------
+// Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
+// NOTE: This functions are used to completely abstract raylib code from OpenGL layer
+//------------------------------------------------------------------------------------
+void rlEnableTexture(unsigned int id); // Enable texture usage
+void rlDisableTexture(void); // Disable texture usage
+void rlTextureParameters(unsigned int id, int param, int value); // Set texture parameters (filter, wrap)
+void rlEnableRenderTexture(unsigned int id); // Enable render texture (fbo)
+void rlDisableRenderTexture(void); // Disable render texture (fbo), return to default framebuffer
+void rlEnableDepthTest(void); // Enable depth test
+void rlDisableDepthTest(void); // Disable depth test
+void rlEnableWireMode(void); // Enable wire mode
+void rlDisableWireMode(void); // Disable wire mode
+void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
+void rlDeleteRenderTextures(RenderTexture2D target); // Delete render textures (fbo) from GPU
+void rlDeleteShader(unsigned int id); // Delete OpenGL shader program from GPU
+void rlDeleteVertexArrays(unsigned int id); // Unload vertex data (VAO) from GPU memory
+void rlDeleteBuffers(unsigned int id); // Unload vertex data (VBO) from GPU memory
+void rlClearColor(byte r, byte g, byte b, byte a); // Clear color buffer with color
+void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
+
+//------------------------------------------------------------------------------------
+// Functions Declaration - rlgl functionality
+//------------------------------------------------------------------------------------
+void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
+void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures)
+void rlglDraw(void); // Update and Draw default buffers (lines, triangles, quads)
+
+int rlGetVersion(void); // Returns current OpenGL version
+void rlLoadExtensions(void *loader); // Load OpenGL extensions
+Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
+
+// Textures data management
+unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
+void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data); // Update GPU texture with new data
+void rlUnloadTexture(unsigned int id);
+void rlGenerateMipmaps(Texture2D *texture); // Generate mipmap data for selected texture
+void *rlReadTexturePixels(Texture2D texture); // Read texture pixel data
+unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
+RenderTexture2D rlLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments)
+
+// Vertex data management
+void rlLoadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids
+void rlUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update vertex data on GPU (upload new data to one buffer)
+void rlDrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
+void rlUnloadMesh(Mesh *mesh); // Unload mesh data from CPU and GPU
+
+// NOTE: There is a set of shader related functions that are available to end user,
+// to avoid creating function wrappers through core module, they have been directly declared in raylib.h
+
+#if defined(RLGL_STANDALONE)
+//------------------------------------------------------------------------------------
+// Shaders System Functions (Module: rlgl)
+// NOTE: This functions are useless when using OpenGL 1.1
+//------------------------------------------------------------------------------------
+Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
+void UnloadShader(Shader shader); // Unload a custom shader from memory
+
+Shader GetShaderDefault(void); // Get default shader
+Texture2D GetTextureDefault(void); // Get default texture
+
+// Shader configuration functions
+int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
+void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
+void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
+void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
+void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
+void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
+
+// Texture maps generation (PBR)
+// NOTE: Required shaders should be provided
+Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size); // Generate cubemap texture from HDR texture
+Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size); // Generate irradiance texture using cubemap data
+Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size); // Generate prefilter texture using cubemap data
+Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size); // Generate BRDF texture using cubemap data
+
+// Shading and blending
+void BeginShaderMode(Shader shader); // Begin custom shader drawing
+void EndShaderMode(void); // End custom shader drawing (use default shader)
+void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
+void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
+
+// VR simulator functionality
+void InitVrSimulator(int vrDevice); // Init VR simulator for selected device
+void CloseVrSimulator(void); // Close VR simulator for current device
+void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
+void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
+void BeginVrDrawing(void); // Begin VR stereo rendering
+void EndVrDrawing(void); // End VR stereo rendering
+
+void TraceLog(int msgType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // RLGL_H \ No newline at end of file
diff --git a/templates/android_project/src/utils.c b/templates/android_project/src/utils.c
new file mode 100644
index 00000000..59bf19e4
--- /dev/null
+++ b/templates/android_project/src/utils.c
@@ -0,0 +1,214 @@
+/**********************************************************************************************
+*
+* raylib.utils - Some common utility functions
+*
+* CONFIGURATION:
+*
+* #define SUPPORT_SAVE_PNG (defined by default)
+* Support saving image data as PNG fileformat
+* NOTE: Requires stb_image_write library
+*
+* #define SUPPORT_SAVE_BMP
+* Support saving image data as BMP fileformat
+* NOTE: Requires stb_image_write library
+*
+* #define SUPPORT_TRACELOG
+* Show TraceLog() output messages
+* NOTE: By default LOG_DEBUG traces not shown
+*
+* #define SUPPORT_TRACELOG_DEBUG
+* Show TraceLog() LOG_DEBUG messages
+*
+* DEPENDENCIES:
+* stb_image_write - BMP/PNG writting functions
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2014-2017 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#define SUPPORT_TRACELOG // Output tracelog messages
+//#define SUPPORT_TRACELOG_DEBUG // Avoid LOG_DEBUG messages tracing
+
+#include "raylib.h" // Required for: LogType enum
+#include "utils.h"
+
+#if defined(PLATFORM_ANDROID)
+ #include <errno.h>
+ #include <android/log.h>
+ #include <android/asset_manager.h>
+#endif
+
+#include <stdlib.h> // Required for: malloc(), free()
+#include <stdio.h> // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen()
+#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
+#include <string.h> // Required for: strlen(), strrchr(), strcmp()
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
+ #define STB_IMAGE_WRITE_IMPLEMENTATION
+ #include "external/stb_image_write.h" // Required for: stbi_write_bmp(), stbi_write_png()
+#endif
+
+//#define RRES_IMPLEMENTATION
+//#include "rres.h"
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+AAssetManager *assetManager;
+#endif
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Declaration
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+static int android_read(void *cookie, char *buf, int size);
+static int android_write(void *cookie, const char *buf, int size);
+static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
+static int android_close(void *cookie);
+#endif
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition - Utilities
+//----------------------------------------------------------------------------------
+
+// Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
+void TraceLog(int msgType, const char *text, ...)
+{
+#if defined(SUPPORT_TRACELOG)
+ static char buffer[128];
+ int traceDebugMsgs = 0;
+
+#if defined(SUPPORT_TRACELOG_DEBUG)
+ traceDebugMsgs = 1;
+#endif
+
+ switch(msgType)
+ {
+ case LOG_INFO: strcpy(buffer, "INFO: "); break;
+ case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
+ case LOG_WARNING: strcpy(buffer, "WARNING: "); break;
+ case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break;
+ default: break;
+ }
+
+ strcat(buffer, text);
+ strcat(buffer, "\n");
+
+ va_list args;
+ va_start(args, text);
+
+#if defined(PLATFORM_ANDROID)
+ switch(msgType)
+ {
+ case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
+ case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break;
+ case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break;
+ case LOG_DEBUG: if (traceDebugMsgs) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
+ default: break;
+ }
+#else
+ if ((msgType != LOG_DEBUG) || ((msgType == LOG_DEBUG) && (traceDebugMsgs))) vprintf(buffer, args);
+#endif
+
+ va_end(args);
+
+ if (msgType == LOG_ERROR) exit(1); // If LOG_ERROR message, exit program
+
+#endif // SUPPORT_TRACELOG
+}
+
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
+
+#if defined(SUPPORT_SAVE_BMP)
+// Creates a BMP image file from an array of pixel data
+void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize)
+{
+ stbi_write_bmp(fileName, width, height, compSize, imgData);
+}
+#endif
+
+#if defined(SUPPORT_SAVE_PNG)
+// Creates a PNG image file from an array of pixel data
+void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize)
+{
+ stbi_write_png(fileName, width, height, compSize, imgData, width*compSize);
+}
+#endif
+#endif
+
+// Keep track of memory allocated
+// NOTE: mallocType defines the type of data allocated
+/*
+void RecordMalloc(int mallocType, int mallocSize, const char *msg)
+{
+ // TODO: Investigate how to record memory allocation data...
+ // Maybe creating my own malloc function...
+}
+*/
+
+#if defined(PLATFORM_ANDROID)
+// Initialize asset manager from android app
+void InitAssetManager(AAssetManager *manager)
+{
+ assetManager = manager;
+}
+
+// Replacement for fopen
+FILE *android_fopen(const char *fileName, const char *mode)
+{
+ if (mode[0] == 'w') return NULL;
+
+ AAsset *asset = AAssetManager_open(assetManager, fileName, 0);
+
+ if (!asset) return NULL;
+
+ return funopen(asset, android_read, android_write, android_seek, android_close);
+}
+#endif
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Definition
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+static int android_read(void *cookie, char *buf, int size)
+{
+ return AAsset_read((AAsset *)cookie, buf, size);
+}
+
+static int android_write(void *cookie, const char *buf, int size)
+{
+ TraceLog(LOG_ERROR, "Can't provide write access to the APK");
+
+ return EACCES;
+}
+
+static fpos_t android_seek(void *cookie, fpos_t offset, int whence)
+{
+ return AAsset_seek((AAsset *)cookie, offset, whence);
+}
+
+static int android_close(void *cookie)
+{
+ AAsset_close((AAsset *)cookie);
+ return 0;
+}
+#endif
diff --git a/templates/android_project/src/utils.h b/templates/android_project/src/utils.h
new file mode 100644
index 00000000..0d5e4a1c
--- /dev/null
+++ b/templates/android_project/src/utils.h
@@ -0,0 +1,79 @@
+/**********************************************************************************************
+*
+* raylib.utils - Some common utility functions
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2014-2017 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#if defined(PLATFORM_ANDROID)
+ #include <stdio.h> // Required for: FILE
+ #include <android/asset_manager.h> // Required for: AAssetManager
+#endif
+
+//#include "rres.h"
+
+#define SUPPORT_SAVE_PNG
+
+//----------------------------------------------------------------------------------
+// Some basic Defines
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_ANDROID)
+ #define fopen(name, mode) android_fopen(name, mode)
+#endif
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+#ifdef __cplusplus
+extern "C" { // Prevents name mangling of functions
+#endif
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+// Nop...
+
+//----------------------------------------------------------------------------------
+// Module Functions Declaration
+//----------------------------------------------------------------------------------
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
+#if defined(SUPPORT_SAVE_BMP)
+void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize);
+#endif
+#if defined(SUPPORT_SAVE_PNG)
+void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize);
+#endif
+#endif
+
+#if defined(PLATFORM_ANDROID)
+void InitAssetManager(AAssetManager *manager); // Initialize asset manager from android app
+FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen()
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // UTILS_H \ No newline at end of file