@ -1,44 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<!-- | |||
* raylib Android project template | |||
* | |||
* This template has been created using raylib 1.8 (www.raylib.com) | |||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
* | |||
* Copyright (c) 2014-2017 Ramon Santamaria (@raysan5) | |||
* | |||
--> | |||
<!-- NOTE: Game package name must be unique for every app/game --> | |||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |||
package="com.raylib.game_sample" | |||
android:versionCode="1" | |||
android:versionName="1.0" > | |||
<uses-sdk android:minSdkVersion="16" /> | |||
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> | |||
<!--<supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" android:required="true"/>--> | |||
<!-- We do not have Java code. Therefore android:hasCode is set to false. --> | |||
<!-- <application android:allowBackup="false" android:hasCode="false" --> | |||
<application android:allowBackup="false" | |||
android:label="@string/app_name" | |||
android:icon="@drawable/icon" > | |||
<!-- Our activity is the built-in NativeActivity framework class. --> | |||
<!-- <activity android:name="android.app.NativeActivity" --> | |||
<activity android:name="com.raylib.game_sample.NativeLoader" | |||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" | |||
android:configChanges="orientation|keyboardHidden|screenSize" | |||
android:screenOrientation="landscape" | |||
android:launchMode="singleTask" | |||
android:clearTaskOnLaunch="true" > | |||
<!-- android:screenOrientation="portrait" --> | |||
<!-- Tell NativeActivity the name of our .so --> | |||
<meta-data android:name="android.app.lib_name" android:value="raylib_game" /> | |||
<intent-filter> | |||
<action android:name="android.intent.action.MAIN" /> | |||
<category android:name="android.intent.category.LAUNCHER" /> | |||
</intent-filter> | |||
</activity> | |||
</application> | |||
</manifest> |
@ -1,229 +0,0 @@ | |||
#************************************************************************************************** | |||
# | |||
# raylib makefile for Android project (APK building) | |||
# | |||
# Copyright (c) 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 raylib platform to compile for | |||
PLATFORM ?= PLATFORM_ANDROID | |||
RAYLIB_PATH ?= C:\Github\raylib | |||
# Android project configuration variables | |||
# Generated shared library name should match the name defined in the AndroidManifest.xml | |||
PROJECT_NAME ?= raylib_game | |||
LIBRARY_NAME ?= raylib_game | |||
OUTPUT_PATH ?= output | |||
SOURCE_PATH ?= src | |||
# define libtype for raylib and OpenAL Soft: STATIC (.a) or SHARED (.so/.dll) | |||
RAYLIB_LIBTYPE ?= SHARED | |||
OPENAL_LIBTYPE ?= SHARED | |||
RAYLIB_LIB_PATH = $(RAYLIB_PATH)\release\libs\android\armeabi-v7a | |||
OPENAL_LIB_PATH = $(RAYLIB_PATH)\release\libs\android\armeabi-v7a | |||
# Generated key pass | |||
KEYSTORE_PASS = raylib | |||
# add shared libs to APK if required | |||
ifeq ($(RAYLIB_LIBTYPE),SHARED) | |||
PROJECT_SHARED_LIBS = lib/armeabi-v7a/libraylib.so | |||
endif | |||
ifeq ($(OPENAL_LIBTYPE),SHARED) | |||
PROJECT_SHARED_LIBS += lib/armeabi-v7a/libopenal.so | |||
endif | |||
# Required path variables | |||
# NOTE: JAVA_HOME must be set to JDK | |||
ANDROID_HOME = C:/android-sdk | |||
ANDROID_NDK = C:/android-ndk | |||
ANDROID_TOOLCHAIN = C:/android_toolchain_arm_api16 | |||
ANDROID_BUILD_TOOLS = $(ANDROID_HOME)/build-tools/26.0.1 | |||
ANDROID_PLATFORM_TOOLS = $(ANDROID_HOME)/platform-tools | |||
JAVA_HOME = C:/PROGRA~1/Java/jdk1.8.0_144 | |||
# Compilers | |||
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-gcc | |||
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar | |||
# Compiler flags for arquitecture | |||
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 | |||
# Compilation functions attributes options | |||
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC | |||
# Compiler options for the linker | |||
CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes | |||
# Preprocessor macro definitions | |||
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16 | |||
# Paths containing required header files | |||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/release/include -I$(ANDROID_NDK)/sources/android/native_app_glue | |||
# Linker options | |||
LDFLAGS = -Wl,-soname,lib$(LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a | |||
LDFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings | |||
# Force linking of library module to define symbol | |||
LDFLAGS += -u ANativeActivity_onCreate | |||
# Library paths containing required libs | |||
LDFLAGS += -L. -L$(SOURCE_PATH) -L$(OUTPUT_PATH)/obj -L$(OUTPUT_PATH)/lib/armeabi-v7a | |||
# Define any libraries to link into executable | |||
# if you want to link libraries (libname.so or libname.a), use the -lname | |||
LDLIBS = -lraylib -lnative_app_glue -lopenal -llog -landroid -lEGL -lGLESv2 -lOpenSLES -latomic -lc -lm -ldl | |||
# Building APK | |||
# NOTE: typing 'make' will invoke the default target entry called 'all', | |||
all: create_temp_project_dirs \ | |||
copy_project_required_libs \ | |||
compile_native_app_glue \ | |||
compile_project_code \ | |||
generate_loader_script \ | |||
copy_project_resources \ | |||
config_project_package \ | |||
compile_project_class \ | |||
compile_project_class_dex \ | |||
create_project_apk_package \ | |||
generate_apk_keystore \ | |||
sign_project_apk_package \ | |||
zipalign_project_apk_package | |||
# Create required temp directories for APK building | |||
create_temp_project_dirs: | |||
if not exist $(OUTPUT_PATH) mkdir $(OUTPUT_PATH) | |||
if not exist $(OUTPUT_PATH)\obj mkdir $(OUTPUT_PATH)\obj | |||
if not exist $(OUTPUT_PATH)\src mkdir $(OUTPUT_PATH)\src | |||
if not exist $(OUTPUT_PATH)\lib mkdir $(OUTPUT_PATH)\lib | |||
if not exist $(OUTPUT_PATH)\lib\armeabi-v7a mkdir $(OUTPUT_PATH)\lib\armeabi-v7a | |||
if not exist $(OUTPUT_PATH)\bin mkdir $(OUTPUT_PATH)\bin | |||
if not exist $(OUTPUT_PATH)\res mkdir $(OUTPUT_PATH)\res | |||
if not exist $(OUTPUT_PATH)\assets mkdir $(OUTPUT_PATH)\assets | |||
# Compile native_app_glue as static library | |||
# OUTPUT: $(PROJECT_DIR)/obj/libnative_app_glue.a | |||
compile_native_app_glue: | |||
$(CC) -c $(ANDROID_NDK)/sources/android/native_app_glue/android_native_app_glue.c -o $(OUTPUT_PATH)/obj/native_app_glue.o $(CFLAGS) | |||
$(AR) rcs $(OUTPUT_PATH)/obj/libnative_app_glue.a $(OUTPUT_PATH)/obj/native_app_glue.o | |||
# Compile project code as shared libraries | |||
# OUTPUT: $(PROJECT_DIR)/lib/lib$(LIBRARY_NAME).so | |||
compile_project_code: | |||
$(CC) -c $(SOURCE_PATH)/game_basic.c -o $(OUTPUT_PATH)/obj/game_basic.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot | |||
$(CC) -o $(OUTPUT_PATH)/lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(OUTPUT_PATH)/obj/game_basic.o -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) | |||
compile_project_code_raylib_stripped: | |||
$(CC) -c $(SOURCE_PATH)/raylib_stripped/core.c -o $(OUTPUT_PATH)/obj/core.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot | |||
$(CC) -c $(SOURCE_PATH)/raylib_stripped/rlgl.c -o $(OUTPUT_PATH)/obj/rlgl.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot -DGRAPHICS_API_OPENGL_ES2 | |||
$(CC) -c $(SOURCE_PATH)/raylib_stripped/utils.c -o $(OUTPUT_PATH)/obj/utils.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot | |||
$(CC) -c $(SOURCE_PATH)/game_raylib_stripped.c -o $(OUTPUT_PATH)/obj/game_raylib_stripped.o $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot | |||
$(CC) -o lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(OUTPUT_PATH)/obj/game_raylib_stripped.o $(OUTPUT_PATH)/obj/core.o $(OUTPUT_PATH)/obj/rlgl.o $(OUTPUT_PATH)/obj/utils.o -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) | |||
copy_project_required_libs: | |||
ifeq ($(RAYLIB_LIBTYPE),SHARED) | |||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.so $(OUTPUT_PATH)\lib\armeabi-v7a\libraylib.so | |||
endif | |||
ifeq ($(OPENAL_LIBTYPE),SHARED) | |||
copy /Y $(OPENAL_LIB_PATH)\libopenal.so $(OUTPUT_PATH)\lib\armeabi-v7a\libopenal.so | |||
endif | |||
ifeq ($(RAYLIB_LIBTYPE),STATIC) | |||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.a $(OUTPUT_PATH)\lib\armeabi-v7a\libraylib.a | |||
endif | |||
ifeq ($(OPENAL_LIBTYPE),STATIC) | |||
copy /Y $(OPENAL_LIB_PATH)\libopenal.a $(OUTPUT_PATH)\lib\armeabi-v7a\libopenal.a | |||
endif | |||
copy_project_resources: | |||
xcopy res $(OUTPUT_PATH)\res /Y /E /F | |||
xcopy src\resources $(OUTPUT_PATH)\assets /Y /E /F | |||
xcopy AndroidManifest.xml $(OUTPUT_PATH)\AndroidManifest.xml* /Y /F | |||
generate_loader_script: | |||
@echo package com.raylib.game_sample; > $(OUTPUT_PATH)/obj/NativeLoader.java | |||
@echo. >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
@echo public class NativeLoader extends android.app.NativeActivity { >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
@echo static { >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
ifeq ($(OPENAL_LIBTYPE),SHARED) | |||
@echo System.loadLibrary("openal"); >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
endif | |||
ifeq ($(RAYLIB_LIBTYPE),SHARED) | |||
@echo System.loadLibrary("raylib"); >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
endif | |||
@echo System.loadLibrary("raylib_game"); >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
@echo } >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
@echo } >> $(OUTPUT_PATH)/obj/NativeLoader.java | |||
# Generate key for APK signing | |||
# OUTPUT: $(PROJECT_DIR)/temp/$(PROJECT_NAME).keystore | |||
generate_apk_keystore: | |||
$(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=raylib,O=Android,C=JPN" -keystore $(OUTPUT_PATH)/$(PROJECT_NAME).keystore -storepass $(KEYSTORE_PASS) -keypass $(KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA | |||
# Create temp/src/com/raylib/$(LIBRARY_NAME)/R.java | |||
# OUTPUT: $(PROJECT_DIR)/temp/src/com/raylib/$(LIBRARY_NAME)/R.java | |||
# NOTE: DEPENDS on res/values/strings.xml | |||
config_project_package: | |||
$(ANDROID_BUILD_TOOLS)/aapt package -f -m -S $(OUTPUT_PATH)/res -J $(OUTPUT_PATH)/src -M $(OUTPUT_PATH)/AndroidManifest.xml -I $(ANDROID_HOME)/platforms/android-16/android.jar | |||
# Create temp/obj/com/raylib/$(LIBRARY_NAME)/R.class | |||
# OUTPUT: $(PROJECT_DIR)/temp/obj/com/raylib/$(LIBRARY_NAME)/R.class | |||
compile_project_class: | |||
$(JAVA_HOME)/bin/javac -verbose -source 1.7 -target 1.7 -d $(OUTPUT_PATH)/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-16/android.jar;$(OUTPUT_PATH)/obj -sourcepath $(OUTPUT_PATH)/src $(OUTPUT_PATH)/src/com/raylib/game_sample/R.java $(OUTPUT_PATH)/obj/NativeLoader.java | |||
#$(JAVA_HOME)/bin/javac -source 1.7 -target 1.7 -d temp/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-16/android.jar -sourcepath temp/src temp/src/com/raylib/game_sample/R.java | |||
# Create temp/bin/classes.dex | |||
# OUTPUT: $(PROJECT_DIR)/bin/classes.dex | |||
# NOTE: DEPENDS on temp/obj/com/raylib/$(LIBRARY_NAME)/R.class | |||
compile_project_class_dex: | |||
$(ANDROID_BUILD_TOOLS)/dx --verbose --dex --output=$(OUTPUT_PATH)/bin/classes.dex $(OUTPUT_PATH)/obj | |||
# Create temp/bin/$(PROJECT_NAME).unsigned.apk | |||
# NOTE: DEPENDS on temp/bin/classes.dex and lib/lib$(LIBRARY_NAME).so | |||
# NOTE: Use -A resources to define additional directory in which to find raw asset files | |||
create_project_apk_package: | |||
$(ANDROID_BUILD_TOOLS)/aapt package -f -M $(OUTPUT_PATH)/AndroidManifest.xml -S $(OUTPUT_PATH)/res -A $(OUTPUT_PATH)/assets -I $(ANDROID_HOME)/platforms/android-16/android.jar -F $(OUTPUT_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(OUTPUT_PATH)/bin | |||
cd $(OUTPUT_PATH) && $(ANDROID_BUILD_TOOLS)/aapt add bin/$(PROJECT_NAME).unsigned.apk lib/armeabi-v7a/lib$(LIBRARY_NAME).so $(PROJECT_SHARED_LIBS) | |||
# Create temp/bin/$(PROJECT_NAME).signed.apk | |||
sign_project_apk_package: | |||
$(JAVA_HOME)/bin/jarsigner -keystore $(OUTPUT_PATH)/$(PROJECT_NAME).keystore -storepass $(KEYSTORE_PASS) -keypass $(KEYSTORE_PASS) -signedjar $(OUTPUT_PATH)/bin/$(PROJECT_NAME).signed.apk $(OUTPUT_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_NAME)Key | |||
# Create temp/bin/$(PROJECT_NAME).apk | |||
zipalign_project_apk_package: | |||
$(ANDROID_BUILD_TOOLS)/zipalign -f 4 $(OUTPUT_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_NAME).apk | |||
# Deploy $(PROJECT_NAME).apk to device | |||
install_project_apk_package: | |||
$(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk | |||
logcat_project_apk_package: | |||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c | |||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S | |||
deploy: | |||
$(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk | |||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c | |||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S | |||
#$(ANDROID_PLATFORM_TOOLS)/adb logcat *:W | |||
#$(ANDROID_PLATFORM_TOOLS)/adb -d logcat raylib:V *:S | |||
# Clean everything | |||
clean: | |||
del temp\bin\* lib\* temp\obj\* temp\src\* /f/s/q | |||
del temp\*.keystore | |||
rmdir temp /s /q | |||
@echo Cleaning done |
@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<resources> | |||
<string name="app_name">rGame</string> | |||
</resources> |
@ -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 | |||
//-------------------------------------------------------------------------------------- | |||
} |
@ -1,58 +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" | |||
//---------------------------------------------------------------------------------- | |||
// 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 | |||
//-------------------------------------------------------------------------------------- | |||
} |
@ -1,684 +0,0 @@ | |||
//#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 | |||
} | |||
@ -1,735 +0,0 @@ | |||
/********************************************************************************************** | |||
* | |||
* raylib v1.8.0 stripped | |||
* | |||
* A simple and easy-to-use library to learn videogames programming (www.raylib.com) | |||
* | |||
* FEATURES: | |||
* - Library written in plain C code (C99) | |||
* - Multiple platforms supported: Windows, Linux, Mac, Android, Raspberry Pi, HTML5. | |||
* - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0) | |||
* - Unique OpenGL abstraction layer (usable as standalone module): [rlgl] | |||
* - Powerful fonts module with SpriteFonts support (XNA bitmap fonts, AngelCode fonts, TTF) | |||
* - Multiple textures support, including compressed formats and mipmaps generation | |||
* - Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps | |||
* - Powerful math module for Vector2, Vector3, Matrix and Quaternion operations: [raymath] | |||
* - Audio loading and playing with streaming support and mixing channels: [audio] | |||
* - VR stereo rendering support with configurable HMD device parameters | |||
* - Minimal external dependencies (GLFW3, OpenGL, OpenAL) | |||
* - Complete bindings for Lua, Go and Pascal | |||
* | |||
* NOTES: | |||
* 32bit Colors - Any defined Color is always RGBA (4 byte) | |||
* One custom font is loaded by default when InitWindow() [core] | |||
* If using OpenGL 3.3 or ES2, one default shader is loaded automatically (internally defined) [rlgl] | |||
* If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads | |||
* | |||
* DEPENDENCIES: | |||
* GLFW3 (www.glfw.org) for window/context management and input [core] | |||
* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl] | |||
* OpenAL Soft for audio device/context management [audio] | |||
* | |||
* OPTIONAL DEPENDENCIES: | |||
* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures] | |||
* stb_image_write (Sean Barret) for image writting (PNG) [utils] | |||
* stb_truetype (Sean Barret) for ttf fonts loading [text] | |||
* stb_vorbis (Sean Barret) for ogg audio loading [audio] | |||
* jar_xm (Joshua Reisenauer) for XM audio module loading [audio] | |||
* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] | |||
* dr_flac (David Reid) for FLAC audio file loading [audio] | |||
* tinfl for data decompression (DEFLATE algorithm) [rres] | |||
* | |||
* | |||
* LICENSE: zlib/libpng | |||
* | |||
* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, | |||
* BSD-like license that allows static linking with closed source software: | |||
* | |||
* Copyright (c) 2013-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 RAYLIB_H | |||
#define RAYLIB_H | |||
// Choose your platform here or just define it at compile time: -DPLATFORM_DESKTOP | |||
//#define PLATFORM_DESKTOP // Windows, Linux or OSX | |||
//#define PLATFORM_ANDROID // Android device | |||
//#define PLATFORM_RPI // Raspberry Pi | |||
//#define PLATFORM_WEB // HTML5 (emscripten, asm.js) | |||
// Security check in case no PLATFORM_* defined | |||
#if !defined(PLATFORM_DESKTOP) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_RPI) && !defined(PLATFORM_WEB) | |||
#define PLATFORM_DESKTOP | |||
#endif | |||
#if defined(_WIN32) && defined(BUILDING_DLL) | |||
#define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL | |||
#elif defined(_WIN32) && defined(RAYLIB_DLL) | |||
#define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL | |||
#else | |||
#define RLAPI // We are building or using raylib as a static library (or Linux shared library) | |||
#endif | |||
//---------------------------------------------------------------------------------- | |||
// Some basic Defines | |||
//---------------------------------------------------------------------------------- | |||
#ifndef PI | |||
#define PI 3.14159265358979323846f | |||
#endif | |||
#define DEG2RAD (PI/180.0f) | |||
#define RAD2DEG (180.0f/PI) | |||
// raylib Config Flags | |||
#define FLAG_SHOW_LOGO 1 // Set to show raylib logo at startup | |||
#define FLAG_FULLSCREEN_MODE 2 // Set to run program in fullscreen | |||
#define FLAG_WINDOW_RESIZABLE 4 // Set to allow resizable window | |||
#define FLAG_WINDOW_DECORATED 8 // Set to show window decoration (frame and buttons) | |||
#define FLAG_WINDOW_TRANSPARENT 16 // Set to allow transparent window | |||
#define FLAG_MSAA_4X_HINT 32 // Set to try enabling MSAA 4X | |||
#define FLAG_VSYNC_HINT 64 // Set to try enabling V-Sync on GPU | |||
// Keyboard Function Keys | |||
#define KEY_SPACE 32 | |||
#define KEY_ESCAPE 256 | |||
#define KEY_ENTER 257 | |||
#define KEY_BACKSPACE 259 | |||
#define KEY_RIGHT 262 | |||
#define KEY_LEFT 263 | |||
#define KEY_DOWN 264 | |||
#define KEY_UP 265 | |||
#define KEY_F1 290 | |||
#define KEY_F2 291 | |||
#define KEY_F3 292 | |||
#define KEY_F4 293 | |||
#define KEY_F5 294 | |||
#define KEY_F6 295 | |||
#define KEY_F7 296 | |||
#define KEY_F8 297 | |||
#define KEY_F9 298 | |||
#define KEY_F10 299 | |||
#define KEY_F11 300 | |||
#define KEY_F12 301 | |||
#define KEY_LEFT_SHIFT 340 | |||
#define KEY_LEFT_CONTROL 341 | |||
#define KEY_LEFT_ALT 342 | |||
#define KEY_RIGHT_SHIFT 344 | |||
#define KEY_RIGHT_CONTROL 345 | |||
#define KEY_RIGHT_ALT 346 | |||
// Keyboard Alpha Numeric Keys | |||
#define KEY_ZERO 48 | |||
#define KEY_ONE 49 | |||
#define KEY_TWO 50 | |||
#define KEY_THREE 51 | |||
#define KEY_FOUR 52 | |||
#define KEY_FIVE 53 | |||
#define KEY_SIX 54 | |||
#define KEY_SEVEN 55 | |||
#define KEY_EIGHT 56 | |||
#define KEY_NINE 57 | |||
#define KEY_A 65 | |||
#define KEY_B 66 | |||
#define KEY_C 67 | |||
#define KEY_D 68 | |||
#define KEY_E 69 | |||
#define KEY_F 70 | |||
#define KEY_G 71 | |||
#define KEY_H 72 | |||
#define KEY_I 73 | |||
#define KEY_J 74 | |||
#define KEY_K 75 | |||
#define KEY_L 76 | |||
#define KEY_M 77 | |||
#define KEY_N 78 | |||
#define KEY_O 79 | |||
#define KEY_P 80 | |||
#define KEY_Q 81 | |||
#define KEY_R 82 | |||
#define KEY_S 83 | |||
#define KEY_T 84 | |||
#define KEY_U 85 | |||
#define KEY_V 86 | |||
#define KEY_W 87 | |||
#define KEY_X 88 | |||
#define KEY_Y 89 | |||
#define KEY_Z 90 | |||
#if defined(PLATFORM_ANDROID) | |||
// Android Physical Buttons | |||
#define KEY_BACK 4 | |||
#define KEY_MENU 82 | |||
#define KEY_VOLUME_UP 24 | |||
#define KEY_VOLUME_DOWN 25 | |||
#endif | |||
// Mouse Buttons | |||
#define MOUSE_LEFT_BUTTON 0 | |||
#define MOUSE_RIGHT_BUTTON 1 | |||
#define MOUSE_MIDDLE_BUTTON 2 | |||
// Touch points registered | |||
#define MAX_TOUCH_POINTS 2 | |||
// Gamepad Number | |||
#define GAMEPAD_PLAYER1 0 | |||
#define GAMEPAD_PLAYER2 1 | |||
#define GAMEPAD_PLAYER3 2 | |||
#define GAMEPAD_PLAYER4 3 | |||
// Gamepad Buttons/Axis | |||
// PS3 USB Controller Buttons | |||
#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 | |||
#define GAMEPAD_PS3_BUTTON_CIRCLE 1 | |||
#define GAMEPAD_PS3_BUTTON_CROSS 2 | |||
#define GAMEPAD_PS3_BUTTON_SQUARE 3 | |||
#define GAMEPAD_PS3_BUTTON_L1 6 | |||
#define GAMEPAD_PS3_BUTTON_R1 7 | |||
#define GAMEPAD_PS3_BUTTON_L2 4 | |||
#define GAMEPAD_PS3_BUTTON_R2 5 | |||
#define GAMEPAD_PS3_BUTTON_START 8 | |||
#define GAMEPAD_PS3_BUTTON_SELECT 9 | |||
#define GAMEPAD_PS3_BUTTON_UP 24 | |||
#define GAMEPAD_PS3_BUTTON_RIGHT 25 | |||
#define GAMEPAD_PS3_BUTTON_DOWN 26 | |||
#define GAMEPAD_PS3_BUTTON_LEFT 27 | |||
#define GAMEPAD_PS3_BUTTON_PS 12 | |||
// PS3 USB Controller Axis | |||
#define GAMEPAD_PS3_AXIS_LEFT_X 0 | |||
#define GAMEPAD_PS3_AXIS_LEFT_Y 1 | |||
#define GAMEPAD_PS3_AXIS_RIGHT_X 2 | |||
#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 | |||
#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) | |||
#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) | |||
// Xbox360 USB Controller Buttons | |||
#define GAMEPAD_XBOX_BUTTON_A 0 | |||
#define GAMEPAD_XBOX_BUTTON_B 1 | |||
#define GAMEPAD_XBOX_BUTTON_X 2 | |||
#define GAMEPAD_XBOX_BUTTON_Y 3 | |||
#define GAMEPAD_XBOX_BUTTON_LB 4 | |||
#define GAMEPAD_XBOX_BUTTON_RB 5 | |||
#define GAMEPAD_XBOX_BUTTON_SELECT 6 | |||
#define GAMEPAD_XBOX_BUTTON_START 7 | |||
#define GAMEPAD_XBOX_BUTTON_UP 10 | |||
#define GAMEPAD_XBOX_BUTTON_RIGHT 11 | |||
#define GAMEPAD_XBOX_BUTTON_DOWN 12 | |||
#define GAMEPAD_XBOX_BUTTON_LEFT 13 | |||
#define GAMEPAD_XBOX_BUTTON_HOME 8 | |||
// Xbox360 USB Controller Axis | |||
// NOTE: For Raspberry Pi, axis must be reconfigured | |||
#if defined(PLATFORM_RPI) | |||
#define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) | |||
#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) | |||
#define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) | |||
#define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) | |||
#define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) | |||
#define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) | |||
#else | |||
#define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) | |||
#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) | |||
#define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) | |||
#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) | |||
#define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) | |||
#define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) | |||
#endif | |||
// NOTE: MSC C++ compiler does not support compound literals (C99 feature) | |||
// Plain structures in C++ (without constructors) can be initialized from { } initializers. | |||
#ifdef __cplusplus | |||
#define CLITERAL | |||
#else | |||
#define CLITERAL (Color) | |||
#endif | |||
// Some Basic Colors | |||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background | |||
#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray | |||
#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray | |||
#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray | |||
#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow | |||
#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold | |||
#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange | |||
#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink | |||
#define RED CLITERAL{ 230, 41, 55, 255 } // Red | |||
#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon | |||
#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green | |||
#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime | |||
#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green | |||
#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue | |||
#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue | |||
#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue | |||
#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple | |||
#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet | |||
#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple | |||
#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige | |||
#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown | |||
#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown | |||
#define WHITE CLITERAL{ 255, 255, 255, 255 } // White | |||
#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black | |||
#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent) | |||
#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta | |||
#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo) | |||
// Shader and material limits | |||
#define MAX_SHADER_LOCATIONS 32 // Maximum number of predefined locations stored in shader struct | |||
#define MAX_MATERIAL_MAPS 12 // Maximum number of texture maps stored in shader struct | |||
//---------------------------------------------------------------------------------- | |||
// Structures Definition | |||
//---------------------------------------------------------------------------------- | |||
#ifndef __cplusplus | |||
// Boolean type | |||
#if !defined(_STDBOOL_H) || !defined(__STDBOOL_H) // CLang uses second form | |||
typedef enum { false, true } bool; | |||
#endif | |||
#endif | |||
// 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; | |||
// Color type, RGBA (32bit) | |||
typedef struct Color { | |||
unsigned char r; | |||
unsigned char g; | |||
unsigned char b; | |||
unsigned char a; | |||
} Color; | |||
// Rectangle type | |||
typedef struct Rectangle { | |||
int x; | |||
int y; | |||
int width; | |||
int height; | |||
} Rectangle; | |||
// Image type, bpp always RGBA (32bit) | |||
// NOTE: Data stored in CPU memory (RAM) | |||
typedef struct Image { | |||
void *data; // Image raw data | |||
int width; // Image base width | |||
int height; // Image base height | |||
int mipmaps; // Mipmap levels, 1 by default | |||
int format; // Data format (TextureFormat type) | |||
} Image; | |||
// 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 type) | |||
} Texture2D; | |||
// RenderTexture2D type, for texture rendering | |||
typedef struct RenderTexture2D { | |||
unsigned int id; // OpenGL Framebuffer Object (FBO) id | |||
Texture2D texture; // Color buffer attachment texture | |||
Texture2D depth; // Depth buffer attachment texture | |||
} RenderTexture2D; | |||
// SpriteFont character info | |||
typedef struct CharInfo { | |||
int value; // Character value (Unicode) | |||
Rectangle rec; // Character rectangle in sprite font | |||
int offsetX; // Character offset X when drawing | |||
int offsetY; // Character offset Y when drawing | |||
int advanceX; // Character advance position X | |||
} CharInfo; | |||
// SpriteFont type, includes texture and charSet array data | |||
typedef struct SpriteFont { | |||
Texture2D texture; // Font texture | |||
int baseSize; // Base size (default chars height) | |||
int charsCount; // Number of characters | |||
CharInfo *chars; // Characters info data | |||
} SpriteFont; | |||
// 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; | |||
// Camera2D type, defines a 2d camera | |||
typedef struct Camera2D { | |||
Vector2 offset; // Camera offset (displacement from target) | |||
Vector2 target; // Camera target (rotation and zoom origin) | |||
float rotation; // Camera rotation in degrees | |||
float zoom; // Camera zoom (scaling), should be 1.0f by default | |||
} Camera2D; | |||
// Bounding box type | |||
typedef struct BoundingBox { | |||
Vector3 min; // Minimum vertex box-corner | |||
Vector3 max; // Maximum vertex box-corner | |||
} BoundingBox; | |||
// Vertex data definning a mesh | |||
// NOTE: Data stored in CPU memory (and GPU) | |||
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 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; | |||
// Model type | |||
typedef struct Model { | |||
Mesh mesh; // Vertex data buffers (RAM and VRAM) | |||
Matrix transform; // Local transform matrix | |||
Material material; // Shader and textures data | |||
} Model; | |||
// Ray type (useful for raycast) | |||
typedef struct Ray { | |||
Vector3 position; // Ray position (origin) | |||
Vector3 direction; // Ray direction | |||
} Ray; | |||
//---------------------------------------------------------------------------------- | |||
// Enumerators Definition | |||
//---------------------------------------------------------------------------------- | |||
// Trace log type | |||
typedef enum { | |||
LOG_INFO = 0, | |||
LOG_WARNING, | |||
LOG_ERROR, | |||
LOG_DEBUG, | |||
LOG_OTHER | |||
} LogType; | |||
// 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 | |||
// Texture formats | |||
// NOTE: Support depends on OpenGL version and platform | |||
typedef enum { | |||
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha) | |||
UNCOMPRESSED_GRAY_ALPHA, // 16 bpp (2 channels) | |||
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; | |||
#ifdef __cplusplus | |||
extern "C" { // Prevents name mangling of functions | |||
#endif | |||
//------------------------------------------------------------------------------------ | |||
// Global Variables Definition | |||
//------------------------------------------------------------------------------------ | |||
// It's lonely here... | |||
//------------------------------------------------------------------------------------ | |||
// Window and Graphics Device Functions (Module: core) | |||
//------------------------------------------------------------------------------------ | |||
// Window-related functions | |||
RLAPI void InitWindow(int width, int height, void *state); // Initialize Android activity | |||
RLAPI void CloseWindow(void); // Close window and unload OpenGL context | |||
RLAPI bool WindowShouldClose(void); // Check if KEY_ESCAPE pressed or Close icon pressed | |||
RLAPI bool IsWindowMinimized(void); // Check if window has been minimized (or lost focus) | |||
RLAPI void ToggleFullscreen(void); // Toggle fullscreen mode (only PLATFORM_DESKTOP) | |||
RLAPI void SetWindowIcon(Image image); // Set icon for window (only PLATFORM_DESKTOP) | |||
RLAPI void SetWindowTitle(const char *title); // Set title for window (only PLATFORM_DESKTOP) | |||
RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP) | |||
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode) | |||
RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) | |||
RLAPI int GetScreenWidth(void); // Get current screen width | |||
RLAPI int GetScreenHeight(void); // Get current screen height | |||
// Drawing-related functions | |||
RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color) | |||
RLAPI void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing | |||
RLAPI void EndDrawing(void); // End canvas drawing and swap buffers (double buffering) | |||
RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera (2D) | |||
RLAPI void End2dMode(void); // Ends 2D mode with custom camera | |||
RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode with custom camera (3D) | |||
RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode | |||
RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing | |||
RLAPI void EndTextureMode(void); // Ends drawing to render texture | |||
// Screen-space-related functions | |||
RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position | |||
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position for a 3d world space position | |||
RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) | |||
// Timming-related functions | |||
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) | |||
RLAPI int GetFPS(void); // Returns current FPS | |||
RLAPI float GetFrameTime(void); // Returns time in seconds for last frame drawn | |||
// Color-related functions | |||
RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color | |||
RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value | |||
RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f | |||
RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes | |||
// Math useful functions (available from raymath.h) | |||
RLAPI float *VectorToFloat(Vector3 vec); // Returns Vector3 as float array | |||
RLAPI float *MatrixToFloat(Matrix mat); // Returns Matrix as float array | |||
RLAPI Vector3 Vector3Zero(void); // Vector with components value 0.0f | |||
RLAPI Vector3 Vector3One(void); // Vector with components value 1.0f | |||
RLAPI Matrix MatrixIdentity(void); // Returns identity matrix | |||
// Misc. functions | |||
RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags) | |||
RLAPI void SetConfigFlags(char flags); // Setup window configuration flags (view FLAGS) | |||
RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG) | |||
RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (saved a .png) | |||
RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) | |||
// Files management functions | |||
RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension | |||
RLAPI const char *GetExtension(const char *fileName); // Get file extension | |||
RLAPI const char *GetDirectoryPath(const char *fileName); // Get directory for a given fileName (with path) | |||
RLAPI const char *GetWorkingDirectory(void); // Get current working directory | |||
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, returns true if success | |||
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window | |||
RLAPI char **GetDroppedFiles(int *count); // Get dropped files names | |||
RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer | |||
// Persistent storage management | |||
RLAPI void StorageSaveValue(int position, int value); // Save integer value to storage file (to defined position) | |||
RLAPI int StorageLoadValue(int position); // Load integer value from storage file (from defined position) | |||
//------------------------------------------------------------------------------------ | |||
// Input Handling Functions (Module: core) | |||
//------------------------------------------------------------------------------------ | |||
// Input-related functions: keyboard | |||
RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once | |||
RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed | |||
RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once | |||
RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed | |||
RLAPI int GetKeyPressed(void); // Get latest key pressed | |||
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) | |||
// Input-related functions: gamepads | |||
RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available | |||
RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) | |||
RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id | |||
RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once | |||
RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed | |||
RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once | |||
RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed | |||
RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed | |||
RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad | |||
RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis | |||
// Input-related functions: mouse | |||
RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once | |||
RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed | |||
RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once | |||
RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed | |||
RLAPI int GetMouseX(void); // Returns mouse position X | |||
RLAPI int GetMouseY(void); // Returns mouse position Y | |||
RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY | |||
RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY | |||
RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y | |||
// Input-related functions: touch | |||
RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size) | |||
RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size) | |||
RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size) | |||
//------------------------------------------------------------------------------ | |||
// Shaders System Functions (Module: rlgl) | |||
// NOTE: This functions are useless when using OpenGL 1.1 | |||
//------------------------------------------------------------------------------------ | |||
// Shader loading/unloading functions | |||
RLAPI char *LoadText(const char *fileName); // Load chars array from text file | |||
RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load shader from files and bind default locations | |||
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM) | |||
RLAPI Shader GetShaderDefault(void); // Get default shader | |||
RLAPI Texture2D GetTextureDefault(void); // Get default texture | |||
// Shader configuration functions | |||
RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location | |||
RLAPI void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) | |||
RLAPI void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) | |||
RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) | |||
RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) | |||
RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) | |||
// Texture maps generation (PBR) | |||
// NOTE: Required shaders should be provided | |||
RLAPI Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size); // Generate cubemap texture from HDR texture | |||
RLAPI Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size); // Generate irradiance texture using cubemap data | |||
RLAPI Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size); // Generate prefilter texture using cubemap data | |||
RLAPI Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size); // Generate BRDF texture using cubemap data | |||
// Shading begin/end functions | |||
RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing | |||
RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader) | |||
RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) | |||
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif // RAYLIB_H |
@ -1,474 +0,0 @@ | |||
/********************************************************************************************** | |||
* | |||
* 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 |
@ -1,214 +0,0 @@ | |||
/********************************************************************************************** | |||
* | |||
* 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 |
@ -1,79 +0,0 @@ | |||
/********************************************************************************************** | |||
* | |||
* 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 |