raylib 1.2
This is a huge update. Check CHANGELOG for details
This commit is contained in:
parent
01651af08a
commit
fc6081fe70
21 changed files with 2742 additions and 758 deletions
32
CHANGELOG
32
CHANGELOG
|
@ -1,11 +1,41 @@
|
||||||
changelog
|
changelog
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Current Release: raylib 1.1.1 (22 July 2014)
|
Current Release: raylib 1.2 (16 September 2014)
|
||||||
|
|
||||||
NOTE: Only versions marked as 'Release' are available on release folder, updates are only available as source.
|
NOTE: Only versions marked as 'Release' are available on release folder, updates are only available as source.
|
||||||
NOTE: Current Release includes all previous updates.
|
NOTE: Current Release includes all previous updates.
|
||||||
|
|
||||||
|
-----------------------------------------------
|
||||||
|
Release: raylib 1.2 (16 September 2014)
|
||||||
|
-----------------------------------------------
|
||||||
|
NOTE:
|
||||||
|
This version supposed a complete redesign of the [core] module to support Android and Raspberry Pi.
|
||||||
|
Multiples modules have also been tweaked to accomodate to the new platforms, specially [rlgl]
|
||||||
|
|
||||||
|
[core] Added multiple platforms support: Android and Raspberry Pi
|
||||||
|
[core] InitWindow() - Complete rewrite and split for Android
|
||||||
|
[core] InitDisplay() - Internal function added to calculate proper display size
|
||||||
|
[core] InitGraphics() - Internal function where OpenGL graphics are initialized
|
||||||
|
[core] Complete refactoring of input functions to accomodate to new platforms
|
||||||
|
[core] Mouse and Keyboard raw data reading functions added for Raspberry Pi
|
||||||
|
[core] GetTouchX(), GetTouchY() - Added for Android
|
||||||
|
[core] Added Android callbacks to process inputs and Android activity commands
|
||||||
|
[rlgl] Adjusted buffers depending on platform
|
||||||
|
[rlgl] Added security check in case deployed vertex excess buffer size
|
||||||
|
[rlgl] Adjusted indices type depending on GL version (int or short)
|
||||||
|
[rlgl] Fallback to VBOs only usage if VAOs not supported on ES2
|
||||||
|
[rlgl] rlglLoadModel() stores vbo ids on new Model struct
|
||||||
|
[textures] Added support for PKM files (ETC1, ETC2 compression support)
|
||||||
|
[shapes] DrawRectangleV() - Modified, depending on OGL version uses TRIANGLES or QUADS
|
||||||
|
[text] LoadSpriteFont() - Modified to use LoadImage()
|
||||||
|
[models] Minor changes on models loading to accomodate to new Model struct
|
||||||
|
[audio] PauseMusicStream(), ResumeMusicStream() - Added
|
||||||
|
[audio] Reduced music buffer size to avoid stalls on Raspberry Pi
|
||||||
|
[src] Added makefile for Windows and RPI
|
||||||
|
[src] Added resources file (raylib icon and executable info)
|
||||||
|
[examples] Added makefile for Windows and RPI
|
||||||
|
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
Release: raylib 1.1.1 (22 July 2014)
|
Release: raylib 1.1.1 (22 July 2014)
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
|
|
160
README.md
160
README.md
|
@ -5,7 +5,7 @@ about
|
||||||
|
|
||||||
raylib is a simple and easy-to-use library to learn videogames programming.
|
raylib is a simple and easy-to-use library to learn videogames programming.
|
||||||
|
|
||||||
raylib is highly inspired by Borland BGI graphics lib (more specifically WinBGI) and by XNA framework.
|
raylib is highly inspired by Borland BGI graphics lib and by XNA framework.
|
||||||
Allegro and SDL have also been analyzed for reference.
|
Allegro and SDL have also been analyzed for reference.
|
||||||
|
|
||||||
Want to see how easy is making games with raylib? Jump to [code examples!] (http://www.raylib.com/examples.htm)
|
Want to see how easy is making games with raylib? Jump to [code examples!] (http://www.raylib.com/examples.htm)
|
||||||
|
@ -55,6 +55,23 @@ Lots of code changes and lot of testing have concluded in this amazing new rayli
|
||||||
|
|
||||||
Enjoy it.
|
Enjoy it.
|
||||||
|
|
||||||
|
notes on raylib 1.2
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
On September 2014, after 5 month of raylib 1.1 release, it comes raylib 1.2. Again, this version presents a
|
||||||
|
complete internal redesign of [core] (https://github.com/raysan5/raylib/blob/master/src/core.h) module to support two new platforms: Android and Raspberry Pi.
|
||||||
|
|
||||||
|
It's been some month of really hard work to accomodate raylib to those new platforms while keeping it easy for the user.
|
||||||
|
On Android, raylib manages internally the activity cicle, as well as the inputs; on Raspberry Pi, a complete raw input
|
||||||
|
system has been written from scratch.
|
||||||
|
|
||||||
|
A new display initialization system has been created to accomodate to multiple resolutions, adding black bars if required;
|
||||||
|
user only defines whatever screen size and it gets properly displayed.
|
||||||
|
|
||||||
|
Now raylib can easily deploy games to Android devices and Raspberry Pi (console mode).
|
||||||
|
|
||||||
|
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.2.
|
||||||
|
|
||||||
features
|
features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -63,18 +80,27 @@ features
|
||||||
* Hardware accelerated with OpenGL (1.1, 3.3+ or ES2)
|
* Hardware accelerated with OpenGL (1.1, 3.3+ or ES2)
|
||||||
* Unique OpenGL abstraction layer [rlgl]
|
* Unique OpenGL abstraction layer [rlgl]
|
||||||
* Powerful fonts module with SpriteFonts support
|
* Powerful fonts module with SpriteFonts support
|
||||||
* Multiple textures support, including DDS and mipmaps generation
|
* Multiple textures support, including DDS, PKM and mipmaps generation
|
||||||
* Basic 3d support for Shapes, Models, Heightmaps and Billboards
|
* Basic 3d support for Shapes, Models, Heightmaps and Billboards
|
||||||
* Powerful math module for Vector and Matrix operations [raymath]
|
* Powerful math module for Vector and Matrix operations [raymath]
|
||||||
* Audio loading and playing with streaming support
|
* Audio loading and playing with streaming support (WAV and OGG)
|
||||||
* Custom color palette for fancy visuals on raywhite background
|
* Custom color palette for fancy visuals on raywhite background
|
||||||
|
* Multiple platforms support: Windows, Linux, Mac, Android, Raspberry Pi
|
||||||
|
|
||||||
raylib uses on its core module the outstanding [GLFW3] (http://www.glfw.org/) library. The best option by far I found for
|
raylib uses on its core module the outstanding [GLFW3] (http://www.glfw.org/) library. The best option by far I found for
|
||||||
window/context and input management (clean, focused, great license, well documented, modern, ...).
|
multiplatform (Windows, Linux, Mac) window/context and input management (clean, focused, great license, well documented, modern, ...).
|
||||||
|
|
||||||
raylib is licensed under a zlib/libpng license like GLFW3. View [LICENSE] (https://github.com/raysan5/raylib/blob/master/LICENSE.md).
|
raylib uses on its audio module [OpenAL Soft] (http://kcat.strangesoft.net/openal.html) audio library, in multiple flavours,
|
||||||
|
to accomodate to Android and Raspberry Pi.
|
||||||
|
|
||||||
tool requirements
|
On Android, raylib uses native_app_glue module (provided on Android NDK) and native Android libraries to manage window/context,
|
||||||
|
inputs and activity cycle.
|
||||||
|
|
||||||
|
On Raspberry Pi, raylib uses Videocore API and EGL for window/context management and raw inputs reading.
|
||||||
|
|
||||||
|
raylib is licensed under a zlib/libpng license. View [LICENSE] (https://github.com/raysan5/raylib/blob/master/LICENSE.md).
|
||||||
|
|
||||||
|
tools requirements
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
raylib has been developed using exclusively two tools:
|
raylib has been developed using exclusively two tools:
|
||||||
|
@ -90,39 +116,107 @@ to allow writing small-mid size programs with a printf-based debugging. All rayl
|
||||||
|
|
||||||
Since raylib v1.1, you can download a windows Installer package for easy installation and configuration. Check [raylib Webpage](http://www.raylib.com/)
|
Since raylib v1.1, you can download a windows Installer package for easy installation and configuration. Check [raylib Webpage](http://www.raylib.com/)
|
||||||
|
|
||||||
building
|
building source (generate libraylib.a)
|
||||||
--------
|
--------------------------------------
|
||||||
|
|
||||||
raylib could be build with the following command lines (Using GCC compiler):
|
Building raylib sources on desktop platforms:
|
||||||
|
|
||||||
cd raylib/src
|
Step 1: Using MinGW make tool, just navigate from command line to raylib/src/ folder and type:
|
||||||
gcc -c core.c -std=c99 -Wall
|
|
||||||
gcc -c shapes.c -std=c99 -Wall
|
|
||||||
gcc -c textures.c -std=c99 -Wall
|
|
||||||
gcc -c text.c -std=c99 -Wall
|
|
||||||
gcc -c models.c -std=c99 -Wall
|
|
||||||
gcc -c raymath.c -std=c99 -Wall
|
|
||||||
gcc -c rlgl.c -std=c99 -Wall
|
|
||||||
gcc -c audio.c -std=c99 -Wall
|
|
||||||
gcc -c utils.c -std=c99 -Wall
|
|
||||||
gcc -c stb_image.c -std=c99 -Wall
|
|
||||||
gcc -c stb_vorbis.c -std=c99 -Wall
|
|
||||||
|
|
||||||
ar rcs libraylib.a core.o shapes.o textures.o stb_image.o text.o models.o raymath.o rlgl.o utils.o stb_vorbis.o audio.o
|
mingw32-make PLATFORM=PLATFORM_DESKTOP
|
||||||
|
|
||||||
To compile examples, make sure raylib.h is placed in the include path and the following libraries are placed in the libraries path:
|
* NOTE: By default raylib compiles using OpenGL 1.1 to maximize compatibility; to use OpenGL 3.3 just type:
|
||||||
|
|
||||||
|
mingw32-make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_33
|
||||||
|
|
||||||
|
Building raylib sources on Raspberry Pi:
|
||||||
|
|
||||||
|
Step 1. Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
|
||||||
|
|
||||||
|
sudo apt-get install openal1
|
||||||
|
|
||||||
|
Step 2. Navigate from command line to raylib/src/ folder and type:
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
Building raylib sources for Android:
|
||||||
|
|
||||||
|
Step 1. Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
|
||||||
|
|
||||||
|
- Download and decompress on C: [Android SDK r23] (http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
|
||||||
|
- Download and decompress on C: [Android NDK r10b] (http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
|
||||||
|
- Download and decompress on C: [Apache Ant 1.9.4] (http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
|
||||||
|
|
||||||
|
Step 2. Create the following environment variables with the correct paths:
|
||||||
|
|
||||||
|
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
|
||||||
|
ANDROID_NDK_ROOT = C:\android-ndk-r10b
|
||||||
|
ANT_HOME = C:\apache-ant-1.9.4
|
||||||
|
|
||||||
|
Step 3. Navigate from command line to folder raylib/template_android/ and type:
|
||||||
|
|
||||||
|
%ANDROID_NDK_ROOT%\ndk-build
|
||||||
|
|
||||||
|
* NOTE: libraylib.a will be generated in folder raylib/src_android/obj/local/armeabi/, it must be copied
|
||||||
|
to Android project; if using raylib/template_android project, copy it to raylib/template_android/jni/libs/.
|
||||||
|
|
||||||
|
building examples
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Building raylib examples on desktop platforms:
|
||||||
|
|
||||||
|
Step 1: Using MinGW make tool, just navigate from command line to raylib/examples/ folder and type:
|
||||||
|
|
||||||
|
mingw32-make PLATFORM=PLATFORM_DESKTOP
|
||||||
|
|
||||||
|
* NOTE: Make sure the following libs (and their headers) are placed on their respectibe MinGW folders:
|
||||||
|
|
||||||
libraylib.a - raylib
|
|
||||||
libglfw3.a - GLFW3 (static version)
|
libglfw3.a - GLFW3 (static version)
|
||||||
libglew32.a - GLEW, OpenGL extension loading, only required if using OpenGL 3.3+ or ES2
|
libglew32.a - GLEW, OpenGL extension loading, only required if using OpenGL 3.3+ or ES2
|
||||||
libopenal32.a - OpenAL, audio device management
|
libopenal32.a - OpenAL Soft, audio device management
|
||||||
|
|
||||||
It's also recommended to link with file icon.o for fancy raylib icon usage. Linking command:
|
Building raylib examples on Raspberry Pi:
|
||||||
|
|
||||||
cd raylib/examples
|
Step 1. Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
|
||||||
gcc -o test_code.exe test_code.c icon.o -lraylib -lglfw3 -lglew32 -lopenal32 -lopengl32 -lgdi32 -std=c99 -Wl,--subsystem,windows
|
|
||||||
|
|
||||||
If you have any doubt, [let me know][raysan5].
|
sudo apt-get install openal1
|
||||||
|
|
||||||
|
Step 2. Navigate from command line to raylib/examples/ folder and type:
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
Building raylib project for Android (using template):
|
||||||
|
|
||||||
|
Step 1. Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
|
||||||
|
|
||||||
|
- Download and decompress on C: [Android SDK r23] (http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
|
||||||
|
- Download and decompress on C: [Android NDK r10b] (http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
|
||||||
|
- Download and decompress on C: [Apache Ant 1.9.4] (http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
|
||||||
|
|
||||||
|
Step 2. Create the following environment variables with the correct paths:
|
||||||
|
|
||||||
|
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
|
||||||
|
ANDROID_NDK_ROOT = C:\android-ndk-r10b
|
||||||
|
ANT_HOME = C:\apache-ant-1.9.4
|
||||||
|
|
||||||
|
Step 3. To compile project, navigate from command line to folder raylib/template_android/ and type:
|
||||||
|
|
||||||
|
%ANDROID_NDK_ROOT%\ndk-build
|
||||||
|
|
||||||
|
Step 4. To generate APK, navigate to folder raylib/template_android/ and type:
|
||||||
|
|
||||||
|
%ANT_HOME%\bin\ant debug
|
||||||
|
|
||||||
|
Step 5: To install APK into connected device (previously intalled drivers and activated USB debug mode on device):
|
||||||
|
|
||||||
|
%ANT_HOME%\bin\ant installd
|
||||||
|
|
||||||
|
Step 6: To view log output from device:
|
||||||
|
|
||||||
|
%ANDROID_SDK_TOOLS%\adb logcat -c
|
||||||
|
%ANDROID_SDK_TOOLS%\adb -d logcat raylib:V *:S
|
||||||
|
|
||||||
|
If you have any doubt, [just let me know][raysan5].
|
||||||
|
|
||||||
contact
|
contact
|
||||||
-------
|
-------
|
||||||
|
@ -140,9 +234,9 @@ acknowledgments
|
||||||
|
|
||||||
The following people have contributed in some way to make raylib project a reality. Big thanks to them!
|
The following people have contributed in some way to make raylib project a reality. Big thanks to them!
|
||||||
|
|
||||||
- [Zopokx](https://github.com/Zopokx)
|
- [Zopokx](https://github.com/Zopokx) for testing and hosting the web.
|
||||||
- [Elendow](http://www.elendow.com)
|
- [Elendow](http://www.elendow.com) for testing and helping on web development.
|
||||||
- Victor Dual
|
- Victor Dual for implementation and testing of 3D shapes functions.
|
||||||
- Marc Palau
|
- Marc Palau for implementation and testing of 3D shapes functions.
|
||||||
|
|
||||||
[raysan5]: mailto:raysan@raysanweb.com "Ramon Santamaria - Ray San"
|
[raysan5]: mailto:raysan@raysanweb.com "Ramon Santamaria - Ray San"
|
||||||
|
|
193
examples/makefile
Normal file
193
examples/makefile
Normal file
|
@ -0,0 +1,193 @@
|
||||||
|
#**************************************************************************************************
|
||||||
|
#
|
||||||
|
# raylib for Raspberry Pi and Windows desktop
|
||||||
|
#
|
||||||
|
# makefile to compile raylib examples
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
|
#
|
||||||
|
# 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 (by default, compile for RPI)
|
||||||
|
# Other possible platform: PLATFORM_DESKTOP
|
||||||
|
PLATFORM ?= PLATFORM_RPI
|
||||||
|
|
||||||
|
# define compiler: gcc for C program, define as g++ for C++
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
# define compiler flags:
|
||||||
|
# -O2 defines optimization level
|
||||||
|
# -Wall turns on most, but not all, compiler warnings
|
||||||
|
# -std=c99 use standard C from 1999 revision
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
|
||||||
|
else
|
||||||
|
CFLAGS = -O2 -Wall -std=c99
|
||||||
|
endif
|
||||||
|
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|
||||||
|
# define any directories containing required header files
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
INCLUDES = -I. -I../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||||
|
else
|
||||||
|
INCLUDES = -I. -I../src
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define library paths containing required libs
|
||||||
|
LFLAGS = -L. -L../src -L/opt/vc/lib
|
||||||
|
|
||||||
|
# define any libraries to link into executable
|
||||||
|
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
# libraries for Raspberry Pi compiling
|
||||||
|
# NOTE: OpenAL Soft library should be installed (libopenal1 package)
|
||||||
|
LIBS = -lraylib -lGLESv2 -lEGL -lm -lbcm_host -lopenal
|
||||||
|
else
|
||||||
|
# libraries for Windows desktop compiling
|
||||||
|
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
|
||||||
|
LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define additional parameters and flags for windows
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
# resources file contains windows exe icon
|
||||||
|
# -Wl,--subsystem,windows hides the console window
|
||||||
|
WINFLAGS = ../src/resources -Wl,--subsystem,windows
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define all object files required
|
||||||
|
EXAMPLES = \
|
||||||
|
ex01_basic_window \
|
||||||
|
ex02a_logo_raylib \
|
||||||
|
ex02b_basic_shapes \
|
||||||
|
ex02c_color_palette \
|
||||||
|
ex03a_input_keys \
|
||||||
|
ex03b_input_mouse \
|
||||||
|
ex04a_textures \
|
||||||
|
ex04b_texture_rectangle \
|
||||||
|
ex05a_sprite_fonts \
|
||||||
|
ex05b_rbmf_fonts \
|
||||||
|
ex06a_color_select \
|
||||||
|
ex06b_logo_anim \
|
||||||
|
ex06c_font_select \
|
||||||
|
ex07a_3d_mode \
|
||||||
|
ex07b_3d_shapes \
|
||||||
|
ex07c_3d_models \
|
||||||
|
ex08_audio
|
||||||
|
#ex03c_input_gamepad \
|
||||||
|
|
||||||
|
|
||||||
|
# typing 'make' will invoke the first target entry in the file,
|
||||||
|
# in this case, the 'default' target entry is raylib
|
||||||
|
default: examples
|
||||||
|
|
||||||
|
# compile all examples
|
||||||
|
examples: $(EXAMPLES)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex01_basic_window: ex01_basic_window.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex02a_logo_raylib: ex02a_logo_raylib.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex02b_basic_shapes: ex02b_basic_shapes.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex02c_color_palette: ex02c_color_palette.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex03a_input_keys: ex03a_input_keys.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex03b_input_mouse: ex03b_input_mouse.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex03c_input_gamepad: ex03c_input_gamepad.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex04a_textures: ex04a_textures.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex04b_texture_rectangle: ex04b_texture_rectangle.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex05a_sprite_fonts: ex05a_sprite_fonts.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex05b_rbmf_fonts: ex05b_rbmf_fonts.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex06a_color_select: ex06a_color_select.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex06b_logo_anim: ex06b_logo_anim.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex06b_shape_select: ex06b_shape_select.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex06c_font_select: ex06c_font_select.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex07a_3d_mode: ex07a_3d_mode.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex07b_3d_shapes: ex07b_3d_shapes.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex07c_3d_models: ex07c_3d_models.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile example 01 - basic window
|
||||||
|
ex08_audio: ex08_audio.c
|
||||||
|
$(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# clean everything
|
||||||
|
clean:
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
rm -f *.o
|
||||||
|
# find . -executable -delete
|
||||||
|
else
|
||||||
|
del *.o *.exe
|
||||||
|
endif
|
||||||
|
@echo Cleaning done
|
||||||
|
|
||||||
|
# instead of defining every module one by one, we can define a pattern
|
||||||
|
# this pattern below will automatically compile every module defined on $(OBJS)
|
||||||
|
#%.exe : %.c
|
||||||
|
# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM)
|
53
src/audio.c
53
src/audio.c
|
@ -1,14 +1,14 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.audio
|
* raylib.audio
|
||||||
*
|
*
|
||||||
* Basic functions to manage Audio: InitAudioDevice, LoadAudioFiles, PlayAudioFiles
|
* Basic functions to manage Audio: InitAudioDevice, LoadAudioFiles, PlayAudioFiles
|
||||||
*
|
*
|
||||||
* Uses external lib:
|
* Uses external lib:
|
||||||
* OpenAL - Audio device management lib
|
* OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
|
||||||
* stb_vorbis - Ogg audio files loading
|
* stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -29,14 +29,15 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include <AL/al.h> // OpenAL basic header
|
#include "AL/al.h" // OpenAL basic header
|
||||||
#include <AL/alc.h> // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||||
|
|
||||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||||
#include <string.h> // Required for strcmp()
|
#include <string.h> // Required for strcmp()
|
||||||
#include <stdio.h> // Used for .WAV loading
|
#include <stdio.h> // Used for .WAV loading
|
||||||
|
|
||||||
#include "utils.h" // rRES data decompression utility function
|
#include "utils.h" // rRES data decompression utility function
|
||||||
|
// NOTE: Includes Android fopen function map
|
||||||
|
|
||||||
#include "stb_vorbis.h" // OGG loading functions
|
#include "stb_vorbis.h" // OGG loading functions
|
||||||
|
|
||||||
|
@ -44,7 +45,9 @@
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define MUSIC_STREAM_BUFFERS 2
|
#define MUSIC_STREAM_BUFFERS 2
|
||||||
#define MUSIC_BUFFER_SIZE 4096*8 //4096*32
|
#define MUSIC_BUFFER_SIZE 4096*2 // PCM data buffer (short) - 16Kb
|
||||||
|
// NOTE: Reduced to avoid frame-stalls on RPI
|
||||||
|
//#define MUSIC_BUFFER_SIZE 4096*8 // PCM data buffer (short) - 64Kb
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
|
@ -85,9 +88,9 @@ static Music currentMusic; // Current music loaded
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
static Wave LoadWAV(const char *fileName);
|
static Wave LoadWAV(const char *fileName); // Load WAV file
|
||||||
static Wave LoadOGG(char *fileName);
|
static Wave LoadOGG(char *fileName); // Load OGG file
|
||||||
static void UnloadWave(Wave wave);
|
static void UnloadWave(Wave wave); // Unload wave data
|
||||||
|
|
||||||
static bool BufferMusicStream(ALuint buffer); // Fill music buffers with data
|
static bool BufferMusicStream(ALuint buffer); // Fill music buffers with data
|
||||||
static void EmptyMusicStream(void); // Empty music buffers
|
static void EmptyMusicStream(void); // Empty music buffers
|
||||||
|
@ -116,7 +119,7 @@ void InitAudioDevice(void)
|
||||||
TraceLog(ERROR, "Could not setup audio context");
|
TraceLog(ERROR, "Could not setup audio context");
|
||||||
}
|
}
|
||||||
|
|
||||||
TraceLog(INFO, "Audio device and context initialized successfully: %s\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
|
TraceLog(INFO, "Audio device and context initialized successfully: %s", alcGetString(device, ALC_DEVICE_SPECIFIER));
|
||||||
|
|
||||||
// Listener definition (just for 2D)
|
// Listener definition (just for 2D)
|
||||||
alListener3f(AL_POSITION, 0, 0, 0);
|
alListener3f(AL_POSITION, 0, 0, 0);
|
||||||
|
@ -151,6 +154,13 @@ Sound LoadSound(char *fileName)
|
||||||
Sound sound;
|
Sound sound;
|
||||||
Wave wave;
|
Wave wave;
|
||||||
|
|
||||||
|
// Init some default values for wave...
|
||||||
|
wave.data = NULL;
|
||||||
|
wave.dataSize = 0;
|
||||||
|
wave.sampleRate = 0;
|
||||||
|
wave.bitsPerSample = 0;
|
||||||
|
wave.channels = 0;
|
||||||
|
|
||||||
// NOTE: The entire file is loaded to memory to play it all at once (no-streaming)
|
// NOTE: The entire file is loaded to memory to play it all at once (no-streaming)
|
||||||
|
|
||||||
// Audio file loading
|
// Audio file loading
|
||||||
|
@ -297,7 +307,6 @@ Sound LoadSoundFromRES(const char *rresName, int resId)
|
||||||
else if (wave.bitsPerSample == 16) format = AL_FORMAT_STEREO16;
|
else if (wave.bitsPerSample == 16) format = AL_FORMAT_STEREO16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create an audio source
|
// Create an audio source
|
||||||
ALuint source;
|
ALuint source;
|
||||||
alGenSources(1, &source); // Generate pointer to audio source
|
alGenSources(1, &source); // Generate pointer to audio source
|
||||||
|
@ -506,8 +515,23 @@ void StopMusicStream(void)
|
||||||
// Pause music playing
|
// Pause music playing
|
||||||
void PauseMusicStream(void)
|
void PauseMusicStream(void)
|
||||||
{
|
{
|
||||||
// TODO: Record music is paused or check if music available!
|
// Pause music stream if music available!
|
||||||
|
if (musicEnabled)
|
||||||
|
{
|
||||||
|
TraceLog(INFO, "Pausing music stream");
|
||||||
alSourcePause(currentMusic.source);
|
alSourcePause(currentMusic.source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resume music playing
|
||||||
|
void ResumeMusicStream(void)
|
||||||
|
{
|
||||||
|
// Resume music playing... if music available!
|
||||||
|
if (musicEnabled)
|
||||||
|
{
|
||||||
|
TraceLog(INFO, "Resume music stream");
|
||||||
|
alSourcePlay(currentMusic.source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if music is playing
|
// Check if music is playing
|
||||||
|
@ -570,7 +594,7 @@ static bool BufferMusicStream(ALuint buffer)
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TraceLog(DEBUG, "Streaming music data to buffer. Bytes streamed: %i", size);
|
//TraceLog(DEBUG, "Streaming music data to buffer. Bytes streamed: %i", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
|
@ -754,6 +778,7 @@ static Wave LoadWAV(const char *fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load OGG file into Wave structure
|
// Load OGG file into Wave structure
|
||||||
|
// NOTE: Using stb_vorbis library
|
||||||
static Wave LoadOGG(char *fileName)
|
static Wave LoadOGG(char *fileName)
|
||||||
{
|
{
|
||||||
Wave wave;
|
Wave wave;
|
||||||
|
|
1436
src/core.c
1436
src/core.c
File diff suppressed because it is too large
Load diff
130
src/makefile
Normal file
130
src/makefile
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
#**************************************************************************************************
|
||||||
|
#
|
||||||
|
# raylib for Raspberry Pi and Windows desktop
|
||||||
|
#
|
||||||
|
# makefile for library compilation (raylib.a)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
|
#
|
||||||
|
# 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 (by default, compile for RPI)
|
||||||
|
# Other possible platform: PLATFORM_DESKTOP
|
||||||
|
PLATFORM ?= PLATFORM_RPI
|
||||||
|
|
||||||
|
# define raylib graphics api depending on selected platform
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
# define raylib graphics api to use (on RPI, OpenGL ES 2.0 must be used)
|
||||||
|
GRAPHICS = GRAPHICS_API_OPENGL_ES2
|
||||||
|
else
|
||||||
|
# define raylib graphics api to use (on Windows desktop, OpenGL 1.1 by default)
|
||||||
|
GRAPHICS = GRAPHICS_API_OPENGL_11
|
||||||
|
#GRAPHICS = GRAPHICS_API_OPENGL_33 # Uncomment to use OpenGL 3.3
|
||||||
|
endif
|
||||||
|
|
||||||
|
# NOTE: makefiles targets require tab indentation
|
||||||
|
|
||||||
|
# define compiler: gcc for C program, define as g++ for C++
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
# define compiler flags:
|
||||||
|
# -O2 defines optimization level
|
||||||
|
# -Wall turns on most, but not all, compiler warnings
|
||||||
|
# -std=c99 use standard C from 1999 revision
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
|
||||||
|
else
|
||||||
|
CFLAGS = -O2 -Wall -std=c99
|
||||||
|
endif
|
||||||
|
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|
||||||
|
# define any directories containing required header files
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
INCLUDES = -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||||
|
else
|
||||||
|
INCLUDES = -I.
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define all object files required
|
||||||
|
OBJS = core.o rlgl.o raymath.o shapes.o text.o textures.o models.o audio.o utils.o stb_image.o stb_vorbis.o
|
||||||
|
|
||||||
|
# typing 'make' will invoke the first target entry in the file,
|
||||||
|
# in this case, the 'default' target entry is raylib
|
||||||
|
default: raylib
|
||||||
|
|
||||||
|
# compile raylib library
|
||||||
|
raylib: $(OBJS)
|
||||||
|
ar rcs libraylib.a $(OBJS)
|
||||||
|
|
||||||
|
# compile core module
|
||||||
|
core.o: core.c
|
||||||
|
$(CC) -c core.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile rlgl module
|
||||||
|
rlgl.o: rlgl.c
|
||||||
|
$(CC) -c rlgl.c $(CFLAGS) $(INCLUDES) -D$(GRAPHICS)
|
||||||
|
|
||||||
|
# compile raymath module
|
||||||
|
raymath.o: raymath.c
|
||||||
|
$(CC) -c raymath.c $(CFLAGS) $(INCLUDES)
|
||||||
|
|
||||||
|
# compile shapes module
|
||||||
|
shapes.o: shapes.c
|
||||||
|
$(CC) -c shapes.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile textures module
|
||||||
|
textures.o: textures.c
|
||||||
|
$(CC) -c textures.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile text module
|
||||||
|
text.o: text.c
|
||||||
|
$(CC) -c text.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile models module
|
||||||
|
models.o: models.c
|
||||||
|
$(CC) -c models.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile audio module
|
||||||
|
audio.o: audio.c
|
||||||
|
$(CC) -c audio.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile utils module
|
||||||
|
utils.o: utils.c
|
||||||
|
$(CC) -c utils.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile stb_image library
|
||||||
|
stb_image.o: stb_image.c
|
||||||
|
$(CC) -c stb_image.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile stb_vorbis library
|
||||||
|
stb_vorbis.o: stb_vorbis.c
|
||||||
|
$(CC) -c stb_vorbis.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# clean everything
|
||||||
|
clean:
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
rm -f *.o libraylib.a
|
||||||
|
else
|
||||||
|
del *.o libraylib.a
|
||||||
|
endif
|
||||||
|
@echo Cleaning done
|
||||||
|
|
||||||
|
# instead of defining every module one by one, we can define a pattern
|
||||||
|
# this pattern below will automatically compile every module defined on $(OBJS)
|
||||||
|
#%.o : %.c
|
||||||
|
# $(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS)
|
64
src/models.c
64
src/models.c
|
@ -1,10 +1,10 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.models
|
* raylib.models
|
||||||
*
|
*
|
||||||
* Basic functions to draw 3d shapes and load/draw 3d models (.OBJ)
|
* Basic functions to draw 3d shapes and load/draw 3d models (.OBJ)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -25,6 +25,10 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#include "utils.h" // Android fopen function map
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h> // Standard input/output functions, used to read model files data
|
#include <stdio.h> // Standard input/output functions, used to read model files data
|
||||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||||
#include <string.h> // Required for strcmp()
|
#include <string.h> // Required for strcmp()
|
||||||
|
@ -442,9 +446,11 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a plane
|
// Draw a plane
|
||||||
// TODO: Test this function
|
|
||||||
void DrawPlane(Vector3 centerPos, Vector2 size, Vector3 rotation, Color color)
|
void DrawPlane(Vector3 centerPos, Vector2 size, Vector3 rotation, Color color)
|
||||||
{
|
{
|
||||||
|
// NOTE: QUADS usage require defining a texture
|
||||||
|
rlEnableTexture(1); // Default white texture
|
||||||
|
|
||||||
// NOTE: Plane is always created on XZ ground and then rotated
|
// NOTE: Plane is always created on XZ ground and then rotated
|
||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
|
rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
|
||||||
|
@ -459,11 +465,13 @@ void DrawPlane(Vector3 centerPos, Vector2 size, Vector3 rotation, Color color)
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
rlNormal3f(0.0f, 1.0f, 0.0f);
|
rlNormal3f(0.0f, 1.0f, 0.0f);
|
||||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(-0.5f, 0.0f, -0.5f);
|
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(-0.5f, 0.0f, -0.5f);
|
||||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(0.5f, 0.0f, -0.5f);
|
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(-0.5f, 0.0f, 0.5f);
|
||||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(0.5f, 0.0f, 0.5f);
|
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(0.5f, 0.0f, 0.5f);
|
||||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(-0.5f, 0.0f, 0.5f);
|
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(0.5f, 0.0f, -0.5f);
|
||||||
rlEnd();
|
rlEnd();
|
||||||
rlPopMatrix();
|
rlPopMatrix();
|
||||||
|
|
||||||
|
rlDisableTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a plane with divisions
|
// Draw a plane with divisions
|
||||||
|
@ -646,20 +654,15 @@ Model LoadModel(const char *fileName)
|
||||||
if (strcmp(GetExtension(fileName),"obj") == 0) vData = LoadOBJ(fileName);
|
if (strcmp(GetExtension(fileName),"obj") == 0) vData = LoadOBJ(fileName);
|
||||||
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
|
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
|
||||||
|
|
||||||
Model model;
|
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
|
||||||
|
|
||||||
model.mesh = vData; // Model mesh is vertex data
|
Model model = rlglLoadModel(vData); // Upload vertex data to GPU
|
||||||
model.textureId = 0;
|
|
||||||
|
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
|
||||||
model.vaoId = rlglLoadModel(vData); // Use loaded data to generate VAO
|
|
||||||
model.textureId = 1; // Default whiteTexture
|
|
||||||
|
|
||||||
// Now that vertex data is uploaded to GPU, we can free arrays
|
// Now that vertex data is uploaded to GPU, we can free arrays
|
||||||
|
// NOTE: Despite vertex data is useless on OpenGL 3.3 or ES2, we will keep it...
|
||||||
//free(vData.vertices);
|
//free(vData.vertices);
|
||||||
//free(vData.texcoords);
|
//free(vData.texcoords);
|
||||||
//free(vData.normals);
|
//free(vData.normals);
|
||||||
#endif
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -764,25 +767,19 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
|
|
||||||
|
|
||||||
// Fill color data
|
// Fill color data
|
||||||
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
|
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
|
||||||
|
|
||||||
Model model;
|
|
||||||
|
|
||||||
model.mesh = vData; // Model mesh is vertex data
|
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
|
||||||
model.textureId = 0;
|
|
||||||
|
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
Model model = rlglLoadModel(vData);
|
||||||
model.vaoId = rlglLoadModel(vData); // Use loaded data to generate VAO
|
|
||||||
model.textureId = 1; // Default whiteTexture
|
|
||||||
|
|
||||||
// Now that vertex data is uploaded to GPU, we can free arrays
|
// Now that vertex data is uploaded to GPU, we can free arrays
|
||||||
|
// NOTE: Despite vertex data is useless on OpenGL 3.3 or ES2, we will keep it...
|
||||||
//free(vData.vertices);
|
//free(vData.vertices);
|
||||||
//free(vData.texcoords);
|
//free(vData.texcoords);
|
||||||
//free(vData.normals);
|
//free(vData.normals);
|
||||||
#endif
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -1092,20 +1089,13 @@ Model LoadCubesmap(Image cubesmap)
|
||||||
|
|
||||||
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
|
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
|
||||||
|
|
||||||
Model model;
|
Model model = rlglLoadModel(vData);
|
||||||
|
|
||||||
model.mesh = vData; // Model mesh is vertex data
|
|
||||||
model.textureId = 0;
|
|
||||||
|
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
|
||||||
model.vaoId = rlglLoadModel(vData); // Use loaded data to generate VAO
|
|
||||||
model.textureId = 1; // Default whiteTexture
|
|
||||||
|
|
||||||
// Now that vertex data is uploaded to GPU, we can free arrays
|
// Now that vertex data is uploaded to GPU, we can free arrays
|
||||||
|
// NOTE: Despite vertex data is useless on OpenGL 3.3 or ES2, we will keep it...
|
||||||
//free(vData.vertices);
|
//free(vData.vertices);
|
||||||
//free(vData.texcoords);
|
//free(vData.texcoords);
|
||||||
//free(vData.normals);
|
//free(vData.normals);
|
||||||
#endif
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -1117,9 +1107,11 @@ void UnloadModel(Model model)
|
||||||
free(model.mesh.texcoords);
|
free(model.mesh.texcoords);
|
||||||
free(model.mesh.normals);
|
free(model.mesh.normals);
|
||||||
|
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
rlDeleteBuffers(model.vboId[0]);
|
||||||
|
rlDeleteBuffers(model.vboId[1]);
|
||||||
|
rlDeleteBuffers(model.vboId[2]);
|
||||||
|
|
||||||
rlDeleteVertexArrays(model.vaoId);
|
rlDeleteVertexArrays(model.vaoId);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetModelTexture(Model *model, Texture2D texture)
|
void SetModelTexture(Model *model, Texture2D texture)
|
||||||
|
@ -1268,7 +1260,7 @@ static VertexData LoadOBJ(const char *fileName)
|
||||||
int numTexCoords = 0;
|
int numTexCoords = 0;
|
||||||
int numTriangles = 0;
|
int numTriangles = 0;
|
||||||
|
|
||||||
FILE* objFile;
|
FILE *objFile;
|
||||||
|
|
||||||
objFile = fopen(fileName, "rt");
|
objFile = fopen(fileName, "rt");
|
||||||
|
|
||||||
|
@ -1326,9 +1318,9 @@ static VertexData LoadOBJ(const char *fileName)
|
||||||
|
|
||||||
// Once we know the number of vertices to store, we create required arrays
|
// Once we know the number of vertices to store, we create required arrays
|
||||||
Vector3 *midVertices = (Vector3 *)malloc(numVertex*sizeof(Vector3));
|
Vector3 *midVertices = (Vector3 *)malloc(numVertex*sizeof(Vector3));
|
||||||
Vector3 *midNormals;
|
Vector3 *midNormals = NULL;
|
||||||
if (numNormals > 0) midNormals = (Vector3 *)malloc(numNormals*sizeof(Vector3));
|
if (numNormals > 0) midNormals = (Vector3 *)malloc(numNormals*sizeof(Vector3));
|
||||||
Vector2 *midTexCoords;
|
Vector2 *midTexCoords = NULL;
|
||||||
if (numTexCoords > 0) midTexCoords = (Vector2 *)malloc(numTexCoords*sizeof(Vector2));
|
if (numTexCoords > 0) midTexCoords = (Vector2 *)malloc(numTexCoords*sizeof(Vector2));
|
||||||
|
|
||||||
int countVertex = 0;
|
int countVertex = 0;
|
||||||
|
|
46
src/raylib.h
46
src/raylib.h
|
@ -1,6 +1,6 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib 1.1 (www.raylib.com)
|
* raylib 1.2 (www.raylib.com)
|
||||||
*
|
*
|
||||||
* A simple and easy-to-use library to learn videogames programming
|
* A simple and easy-to-use library to learn videogames programming
|
||||||
*
|
*
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
* One custom default font is loaded automatically when InitWindow()
|
* One custom default font is loaded automatically when InitWindow()
|
||||||
* If using OpenGL 3.3+ or ES2, one default shader is loaded automatically (internally defined)
|
* If using OpenGL 3.3+ or ES2, one default shader is loaded automatically (internally defined)
|
||||||
*
|
*
|
||||||
* -- LICENSE (raylib v1.1, April 2014) --
|
* -- LICENSE (raylib v1.2, September 2014) --
|
||||||
*
|
*
|
||||||
* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* 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:
|
* BSD-like license that allows static linking with closed source software:
|
||||||
|
@ -58,6 +58,15 @@
|
||||||
#ifndef RAYLIB_H
|
#ifndef RAYLIB_H
|
||||||
#define 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
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#include <android_native_app_glue.h> // Defines android_app struct
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Some basic Defines
|
// Some basic Defines
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -65,8 +74,8 @@
|
||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEG2RAD (PI / 180.0)
|
#define DEG2RAD (PI / 180.0f)
|
||||||
#define RAD2DEG (180.0 / PI)
|
#define RAD2DEG (180.0f / PI)
|
||||||
|
|
||||||
// Keyboard Function Keys
|
// Keyboard Function Keys
|
||||||
#define KEY_SPACE 32
|
#define KEY_SPACE 32
|
||||||
|
@ -234,6 +243,7 @@ typedef struct VertexData {
|
||||||
typedef struct Model {
|
typedef struct Model {
|
||||||
VertexData mesh;
|
VertexData mesh;
|
||||||
unsigned int vaoId;
|
unsigned int vaoId;
|
||||||
|
unsigned int vboId[4];
|
||||||
unsigned int textureId;
|
unsigned int textureId;
|
||||||
//Matrix transform;
|
//Matrix transform;
|
||||||
} Model;
|
} Model;
|
||||||
|
@ -256,14 +266,21 @@ extern "C" { // Prevents name mangling of functions
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Window and Graphics Device Functions (Module: core)
|
// Window and Graphics Device Functions (Module: core)
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
void InitWindow(int width, int height, const char *title); // Initialize Window and Graphics Context (OpenGL)
|
#if defined(PLATFORM_ANDROID)
|
||||||
void InitWindowEx(int width, int height, const char* title, // Initialize Window and Graphics Context (OpenGL),...
|
void InitWindow(int width, int height, struct android_app *state); // Init Android activity
|
||||||
bool resizable, const char *cursorImage); // ...define if windows-resizable and custom cursor
|
#elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
|
void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics
|
||||||
|
#endif
|
||||||
|
|
||||||
void CloseWindow(void); // Close Window and Terminate Context
|
void CloseWindow(void); // Close Window and Terminate Context
|
||||||
bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed
|
bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed
|
||||||
void ToggleFullscreen(void); // Fullscreen toggle (by default F11)
|
void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP)
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
void SetCustomCursor(const char *cursorImage); // Set a custom cursor icon/image
|
void SetCustomCursor(const char *cursorImage); // Set a custom cursor icon/image
|
||||||
void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
|
void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
|
||||||
|
#endif
|
||||||
|
int GetScreenWidth(void); // Get current screen width
|
||||||
|
int GetScreenHeight(void); // Get current screen height
|
||||||
|
|
||||||
void ClearBackground(Color color); // Sets Background Color
|
void ClearBackground(Color color); // Sets Background Color
|
||||||
void BeginDrawing(void); // Setup drawing canvas to start drawing
|
void BeginDrawing(void); // Setup drawing canvas to start drawing
|
||||||
|
@ -280,13 +297,14 @@ Color GetColor(int hexValue); // Returns a Color s
|
||||||
int GetHexValue(Color color); // Returns hexadecimal value for a Color
|
int GetHexValue(Color color); // Returns hexadecimal value for a Color
|
||||||
|
|
||||||
int GetRandomValue(int min, int max); // Returns a random value between min and max (both included)
|
int GetRandomValue(int min, int max); // Returns a random value between min and max (both included)
|
||||||
Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0 to 1.0
|
Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
|
||||||
|
|
||||||
void ShowLogo(void); // Activates raylib logo at startup
|
void ShowLogo(void); // Activates raylib logo at startup
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Input Handling Functions (Module: core)
|
// Input Handling Functions (Module: core)
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
bool IsKeyPressed(int key); // Detect if a key has been pressed once
|
bool IsKeyPressed(int key); // Detect if a key has been pressed once
|
||||||
bool IsKeyDown(int key); // Detect if a key is being pressed
|
bool IsKeyDown(int key); // Detect if a key is being pressed
|
||||||
bool IsKeyReleased(int key); // Detect if a key has been released once
|
bool IsKeyReleased(int key); // Detect if a key has been released once
|
||||||
|
@ -307,6 +325,13 @@ bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad b
|
||||||
bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed
|
bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed
|
||||||
bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once
|
bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once
|
||||||
bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed
|
bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
int GetTouchX(void); // Returns touch position X
|
||||||
|
int GetTouchY(void); // Returns touch position Y
|
||||||
|
Vector2 GetTouchPosition(void); // Returns touch position XY
|
||||||
|
#endif
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Basic Shapes Drawing Functions (Module: shapes)
|
// Basic Shapes Drawing Functions (Module: shapes)
|
||||||
|
@ -427,6 +452,7 @@ void SetSoundPitch(Sound sound, float pitch); // Set pitch for
|
||||||
void PlayMusicStream(char *fileName); // Start music playing (open stream)
|
void PlayMusicStream(char *fileName); // Start music playing (open stream)
|
||||||
void StopMusicStream(void); // Stop music playing (close stream)
|
void StopMusicStream(void); // Stop music playing (close stream)
|
||||||
void PauseMusicStream(void); // Pause music playing
|
void PauseMusicStream(void); // Pause music playing
|
||||||
|
void ResumeMusicStream(void); // Resume playing paused music
|
||||||
bool MusicIsPlaying(void); // Check if music is playing
|
bool MusicIsPlaying(void); // Check if music is playing
|
||||||
void SetMusicVolume(float volume); // Set volume for music (1.0 is max level)
|
void SetMusicVolume(float volume); // Set volume for music (1.0 is max level)
|
||||||
float GetMusicTimeLength(void); // Get current music time length (in seconds)
|
float GetMusicTimeLength(void); // Get current music time length (in seconds)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raymath
|
* raymath
|
||||||
*
|
*
|
||||||
|
@ -85,17 +85,17 @@ Vector3 VectorPerpendicular(Vector3 v)
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
|
|
||||||
float min = fabs(v.x);
|
float min = fabs(v.x);
|
||||||
Vector3 cardinalAxis = {1.0, 0.0, 0.0};
|
Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f};
|
||||||
|
|
||||||
if (fabs(v.y) < min)
|
if (fabs(v.y) < min)
|
||||||
{
|
{
|
||||||
min = fabs(v.y);
|
min = fabs(v.y);
|
||||||
cardinalAxis = (Vector3){0.0, 1.0, 0.0};
|
cardinalAxis = (Vector3){0.0f, 1.0f, 0.0f};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fabs(v.z) < min)
|
if(fabs(v.z) < min)
|
||||||
{
|
{
|
||||||
cardinalAxis = (Vector3){0.0, 0.0, 1.0};
|
cardinalAxis = (Vector3){0.0f, 0.0f, 1.0f};
|
||||||
}
|
}
|
||||||
|
|
||||||
result = VectorCrossProduct(v, cardinalAxis);
|
result = VectorCrossProduct(v, cardinalAxis);
|
||||||
|
@ -216,7 +216,7 @@ void VectorTransform(Vector3 *v, Matrix mat)
|
||||||
// Return a Vector3 init to zero
|
// Return a Vector3 init to zero
|
||||||
Vector3 VectorZero(void)
|
Vector3 VectorZero(void)
|
||||||
{
|
{
|
||||||
Vector3 zero = { 0.0, 0.0, 0.0 };
|
Vector3 zero = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
return zero;
|
return zero;
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ void MatrixNormalize(Matrix *mat)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns identity matrix
|
// Returns identity matrix
|
||||||
Matrix MatrixIdentity()
|
Matrix MatrixIdentity(void)
|
||||||
{
|
{
|
||||||
Matrix result = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
Matrix result = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
||||||
|
|
||||||
|
@ -494,6 +494,7 @@ Matrix MatrixRotate(float angleX, float angleY, float angleZ)
|
||||||
|
|
||||||
// Create rotation matrix from axis and angle
|
// Create rotation matrix from axis and angle
|
||||||
// TODO: Test this function
|
// TODO: Test this function
|
||||||
|
// NOTE: NO prototype defined!
|
||||||
Matrix MatrixFromAxisAngle(Vector3 axis, float angle)
|
Matrix MatrixFromAxisAngle(Vector3 axis, float angle)
|
||||||
{
|
{
|
||||||
Matrix result;
|
Matrix result;
|
||||||
|
@ -549,6 +550,7 @@ Matrix MatrixFromAxisAngle(Vector3 axis, float angle)
|
||||||
|
|
||||||
// Create rotation matrix from axis and angle (version 2)
|
// Create rotation matrix from axis and angle (version 2)
|
||||||
// TODO: Test this function
|
// TODO: Test this function
|
||||||
|
// NOTE: NO prototype defined!
|
||||||
Matrix MatrixFromAxisAngle2(Vector3 axis, float angle)
|
Matrix MatrixFromAxisAngle2(Vector3 axis, float angle)
|
||||||
{
|
{
|
||||||
Matrix result;
|
Matrix result;
|
||||||
|
@ -725,21 +727,24 @@ Matrix MatrixFrustum(double left, double right, double bottom, double top, doubl
|
||||||
float tb = (top - bottom);
|
float tb = (top - bottom);
|
||||||
float fn = (far - near);
|
float fn = (far - near);
|
||||||
|
|
||||||
result.m0 = (near*2) / rl;
|
result.m0 = (near*2.0f) / rl;
|
||||||
result.m1 = 0;
|
result.m1 = 0;
|
||||||
result.m2 = 0;
|
result.m2 = 0;
|
||||||
result.m3 = 0;
|
result.m3 = 0;
|
||||||
|
|
||||||
result.m4 = 0;
|
result.m4 = 0;
|
||||||
result.m5 = (near*2) / tb;
|
result.m5 = (near*2.0f) / tb;
|
||||||
result.m6 = 0;
|
result.m6 = 0;
|
||||||
result.m7 = 0;
|
result.m7 = 0;
|
||||||
|
|
||||||
result.m8 = (right + left) / rl;
|
result.m8 = (right + left) / rl;
|
||||||
result.m9 = (top + bottom) / tb;
|
result.m9 = (top + bottom) / tb;
|
||||||
result.m10 = -(far + near) / fn;
|
result.m10 = -(far + near) / fn;
|
||||||
result.m11 = -1;
|
result.m11 = -1.0f;
|
||||||
|
|
||||||
result.m12 = 0;
|
result.m12 = 0;
|
||||||
result.m13 = 0;
|
result.m13 = 0;
|
||||||
result.m14 = -(far*near*2) / fn;
|
result.m14 = -(far*near*2.0f) / fn;
|
||||||
result.m15 = 0;
|
result.m15 = 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -748,7 +753,7 @@ Matrix MatrixFrustum(double left, double right, double bottom, double top, doubl
|
||||||
// Returns perspective projection matrix
|
// Returns perspective projection matrix
|
||||||
Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
|
Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
|
||||||
{
|
{
|
||||||
double top = near*tan(fovy*PI / 360.0);
|
double top = near*tanf(fovy*PI / 360.0f);
|
||||||
double right = top*aspect;
|
double right = top*aspect;
|
||||||
|
|
||||||
return MatrixFrustum(-right, right, -top, top, near, far);
|
return MatrixFrustum(-right, right, -top, top, near, far);
|
||||||
|
@ -876,18 +881,18 @@ Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
|
||||||
|
|
||||||
float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;
|
float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;
|
||||||
|
|
||||||
if (abs(cosHalfTheta) >= 1.0) result = q1;
|
if (abs(cosHalfTheta) >= 1.0f) result = q1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float halfTheta = acos(cosHalfTheta);
|
float halfTheta = acos(cosHalfTheta);
|
||||||
float sinHalfTheta = sqrt(1.0 - cosHalfTheta*cosHalfTheta);
|
float sinHalfTheta = sqrt(1.0f - cosHalfTheta*cosHalfTheta);
|
||||||
|
|
||||||
if (abs(sinHalfTheta) < 0.001)
|
if (abs(sinHalfTheta) < 0.001f)
|
||||||
{
|
{
|
||||||
result.x = (q1.x*0.5 + q2.x*0.5);
|
result.x = (q1.x*0.5f + q2.x*0.5f);
|
||||||
result.y = (q1.y*0.5 + q2.y*0.5);
|
result.y = (q1.y*0.5f + q2.y*0.5f);
|
||||||
result.z = (q1.z*0.5 + q2.z*0.5);
|
result.z = (q1.z*0.5f + q2.z*0.5f);
|
||||||
result.w = (q1.w*0.5 + q2.w*0.5);
|
result.w = (q1.w*0.5f + q2.w*0.5f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raymath
|
* raymath
|
||||||
*
|
*
|
||||||
|
@ -39,8 +39,8 @@
|
||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEG2RAD (PI / 180.0)
|
#define DEG2RAD (PI / 180.0f)
|
||||||
#define RAD2DEG (180.0 / PI)
|
#define RAD2DEG (180.0f / PI)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
|
@ -103,7 +103,7 @@ float MatrixTrace(Matrix mat); // Returns the trace of
|
||||||
void MatrixTranspose(Matrix *mat); // Transposes provided matrix
|
void MatrixTranspose(Matrix *mat); // Transposes provided matrix
|
||||||
void MatrixInvert(Matrix *mat); // Invert provided matrix
|
void MatrixInvert(Matrix *mat); // Invert provided matrix
|
||||||
void MatrixNormalize(Matrix *mat); // Normalize provided matrix
|
void MatrixNormalize(Matrix *mat); // Normalize provided matrix
|
||||||
Matrix MatrixIdentity(); // Returns identity matrix
|
Matrix MatrixIdentity(void); // Returns identity matrix
|
||||||
Matrix MatrixAdd(Matrix left, Matrix right); // Add two matrices
|
Matrix MatrixAdd(Matrix left, Matrix right); // Add two matrices
|
||||||
Matrix MatrixSubstract(Matrix left, Matrix right); // Substract two matrices (left - right)
|
Matrix MatrixSubstract(Matrix left, Matrix right); // Substract two matrices (left - right)
|
||||||
Matrix MatrixTranslate(float x, float y, float z); // Returns translation matrix
|
Matrix MatrixTranslate(float x, float y, float z); // Returns translation matrix
|
||||||
|
|
BIN
src/resources
Normal file
BIN
src/resources
Normal file
Binary file not shown.
645
src/rlgl.c
645
src/rlgl.c
File diff suppressed because it is too large
Load diff
71
src/rlgl.h
71
src/rlgl.h
|
@ -1,11 +1,11 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* rlgl - raylib OpenGL abstraction layer
|
* rlgl - raylib OpenGL abstraction layer
|
||||||
*
|
*
|
||||||
* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
|
* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
|
||||||
* OpenGL 1.1 - Direct map rl* -> gl*
|
* OpenGL 1.1 - Direct map rl* -> gl*
|
||||||
* OpenGL 3.3+ - Vertex data is stored in VAOs, call rlglDraw() to render
|
* OpenGL 3.3+ - Vertex data is stored in VAOs, call rlglDraw() to render
|
||||||
* OpenGL ES 2 - Same behaviour as OpenGL 3.3+ (NOT TESTED)
|
* OpenGL ES 2 - Same behaviour as OpenGL 3.3+
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
|
@ -39,16 +39,49 @@
|
||||||
#include "raymath.h" // Required for data type Matrix and Matrix functions
|
#include "raymath.h" // Required for data type Matrix and Matrix functions
|
||||||
|
|
||||||
// Select desired OpenGL version
|
// Select desired OpenGL version
|
||||||
//#define USE_OPENGL_11
|
// NOTE: Those preprocessor defines are only used on rlgl module,
|
||||||
//#define USE_OPENGL_33
|
// if OpenGL version is required by any other module, it uses rlGetVersion()
|
||||||
//#define USE_OPENGL_ES2
|
|
||||||
|
// Choose opengl version here or just define it at compile time: -DGRAPHICS_API_OPENGL_33
|
||||||
|
//#define GRAPHICS_API_OPENGL_11 // Only available on PLATFORM_DESKTOP
|
||||||
|
//#define GRAPHICS_API_OPENGL_33 // Only available on PLATFORM_DESKTOP
|
||||||
|
//#define GRAPHICS_API_OPENGL_ES2 // Only available on PLATFORM_ANDROID or PLATFORM_RPI
|
||||||
|
|
||||||
|
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
||||||
|
#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
#define GRAPHICS_API_OPENGL_11
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
||||||
|
#if !defined(GRAPHICS_API_OPENGL_11) && !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_33)
|
||||||
|
#undef GRAPHICS_API_OPENGL_33
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
#undef GRAPHICS_API_OPENGL_ES2
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define MAX_LINES_BATCH 8192 // NOTE: Be careful with limits!
|
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||||
#define MAX_TRIANGLES_BATCH 4096 // NOTE: Be careful with limits!
|
// NOTE: This is the maximum amount of lines, triangles and quads per frame, be careful!
|
||||||
#define MAX_QUADS_BATCH 8192 // NOTE: Be careful with limits!
|
#define MAX_LINES_BATCH 8192
|
||||||
|
#define MAX_TRIANGLES_BATCH 4096
|
||||||
|
#define MAX_QUADS_BATCH 4096
|
||||||
|
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
// NOTE: Reduce memory sizes for embedded systems (RPI)
|
||||||
|
#define MAX_LINES_BATCH 2048 // 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
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
|
@ -59,6 +92,8 @@ typedef enum { RL_PROJECTION, RL_MODELVIEW, RL_TEXTURE } MatrixMode;
|
||||||
|
|
||||||
typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
|
typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
|
||||||
|
|
||||||
|
typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||||
|
|
||||||
#ifdef RLGL_STANDALONE
|
#ifdef RLGL_STANDALONE
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int vertexCount;
|
int vertexCount;
|
||||||
|
@ -71,6 +106,7 @@ typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
|
||||||
typedef struct Model {
|
typedef struct Model {
|
||||||
VertexData mesh;
|
VertexData mesh;
|
||||||
unsigned int vaoId;
|
unsigned int vaoId;
|
||||||
|
unsigned int vboId[4];
|
||||||
unsigned int textureId;
|
unsigned int textureId;
|
||||||
//Matrix transform;
|
//Matrix transform;
|
||||||
} Model;
|
} Model;
|
||||||
|
@ -115,28 +151,29 @@ void rlColor4f(float x, float y, float z, float w); // Define one vertex (color)
|
||||||
void rlEnableTexture(unsigned int id); // Enable texture usage
|
void rlEnableTexture(unsigned int id); // Enable texture usage
|
||||||
void rlDisableTexture(void); // Disable texture usage
|
void rlDisableTexture(void); // Disable texture usage
|
||||||
void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
|
void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
|
||||||
void rlDeleteVertexArrays(unsigned int id); // Unload vertex data from GPU memory
|
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 rlClearColor(byte r, byte g, byte b, byte a); // Clear color buffer with color
|
||||||
void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
|
void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
|
||||||
|
int rlGetVersion(void); // Returns current OpenGL version
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Functions Declaration - rlgl functionality
|
// Functions Declaration - rlgl functionality
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
|
||||||
void rlglInit(void); // Initialize rlgl (shaders, VAO, VBO...)
|
void rlglInit(void); // Initialize rlgl (shaders, VAO, VBO...)
|
||||||
void rlglClose(void); // De-init rlgl
|
void rlglClose(void); // De-init rlgl
|
||||||
void rlglDraw(void); // Draw VAOs
|
void rlglDraw(void); // Draw VAO/VBO
|
||||||
unsigned int rlglLoadModel(VertexData mesh);
|
void rlglInitGraphics(int offsetX, int offsetY, int width, int height); // Initialize Graphics (OpenGL stuff)
|
||||||
unsigned int rlglLoadCompressedTexture(unsigned char *data, int width, int height, int mipmapCount, int format);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool genMipmaps); // Load in GPU OpenGL texture
|
||||||
|
unsigned int rlglLoadCompressedTexture(unsigned char *data, int width, int height, int mipmapCount, int format);
|
||||||
|
|
||||||
|
Model rlglLoadModel(VertexData mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
||||||
void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool wires);
|
void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool wires);
|
||||||
|
|
||||||
void rlglInitGraphicsDevice(int fbWidth, int fbHeight); // Initialize Graphics Device (OpenGL stuff)
|
|
||||||
unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool genMipmaps); // Load in GPU OpenGL texture
|
|
||||||
byte *rlglReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
byte *rlglReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||||
|
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
void PrintProjectionMatrix(void); // DEBUG: Print projection matrix
|
void PrintProjectionMatrix(void); // DEBUG: Print projection matrix
|
||||||
void PrintModelviewMatrix(void); // DEBUG: Print modelview matrix
|
void PrintModelviewMatrix(void); // DEBUG: Print modelview matrix
|
||||||
#endif
|
#endif
|
||||||
|
|
20
src/shapes.c
20
src/shapes.c
|
@ -1,10 +1,10 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.shapes
|
* raylib.shapes
|
||||||
*
|
*
|
||||||
* Basic functions to draw 2d Shapes and check collisions
|
* Basic functions to draw 2d Shapes and check collisions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -31,11 +31,6 @@
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||||
|
|
||||||
// Security check in case no USE_OPENGL_* defined
|
|
||||||
#if !defined(USE_OPENGL_11) && !defined(USE_OPENGL_33) && !defined(USE_OPENGL_ES2)
|
|
||||||
#define USE_OPENGL_11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -185,7 +180,8 @@ void DrawRectangleGradient(int posX, int posY, int width, int height, Color colo
|
||||||
// Draw a color-filled rectangle (Vector version)
|
// Draw a color-filled rectangle (Vector version)
|
||||||
void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
||||||
{
|
{
|
||||||
#ifdef USE_OPENGL_11
|
if (rlGetVersion() == OPENGL_11)
|
||||||
|
{
|
||||||
rlBegin(RL_TRIANGLES);
|
rlBegin(RL_TRIANGLES);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
|
@ -197,9 +193,9 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
||||||
rlVertex2i(position.x + size.x, position.y + size.y);
|
rlVertex2i(position.x + size.x, position.y + size.y);
|
||||||
rlVertex2i(position.x + size.x, position.y);
|
rlVertex2i(position.x + size.x, position.y);
|
||||||
rlEnd();
|
rlEnd();
|
||||||
#endif
|
}
|
||||||
|
else if ((rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
{
|
||||||
// NOTE: This shape uses QUADS to avoid drawing order issues (view rlglDraw)
|
// NOTE: This shape uses QUADS to avoid drawing order issues (view rlglDraw)
|
||||||
rlEnableTexture(1); // Default white texture
|
rlEnableTexture(1); // Default white texture
|
||||||
|
|
||||||
|
@ -221,7 +217,7 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
||||||
rlEnd();
|
rlEnd();
|
||||||
|
|
||||||
rlDisableTexture();
|
rlDisableTexture();
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw rectangle outline
|
// Draw rectangle outline
|
||||||
|
|
|
@ -151,14 +151,15 @@ static stbi_uc *stbi_tga_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
||||||
static int stbi_tga_info(stbi *s, int *x, int *y, int *comp);
|
static int stbi_tga_info(stbi *s, int *x, int *y, int *comp);
|
||||||
static int stbi_psd_test(stbi *s);
|
static int stbi_psd_test(stbi *s);
|
||||||
static stbi_uc *stbi_psd_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
static stbi_uc *stbi_psd_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
||||||
static int stbi_hdr_test(stbi *s);
|
|
||||||
static float *stbi_hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
|
||||||
static int stbi_pic_test(stbi *s);
|
static int stbi_pic_test(stbi *s);
|
||||||
static stbi_uc *stbi_pic_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
static stbi_uc *stbi_pic_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
||||||
static int stbi_gif_test(stbi *s);
|
static int stbi_gif_test(stbi *s);
|
||||||
static stbi_uc *stbi_gif_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
static stbi_uc *stbi_gif_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
||||||
static int stbi_gif_info(stbi *s, int *x, int *y, int *comp);
|
static int stbi_gif_info(stbi *s, int *x, int *y, int *comp);
|
||||||
|
|
||||||
|
// RAY: Commented because not used
|
||||||
|
//static int stbi_hdr_test(stbi *s);
|
||||||
|
//static float *stbi_hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp);
|
||||||
|
|
||||||
// this is not threadsafe
|
// this is not threadsafe
|
||||||
static const char *failure_reason;
|
static const char *failure_reason;
|
||||||
|
@ -2619,7 +2620,7 @@ static int shiftsigned(int v, int shift, int bits)
|
||||||
static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
uint8 *out;
|
uint8 *out;
|
||||||
unsigned int mr=0,mg=0,mb=0,ma=0, fake_a=0;
|
unsigned int mr=0,mg=0,mb=0,ma=0; //fake_a=0;
|
||||||
stbi_uc pal[256][4];
|
stbi_uc pal[256][4];
|
||||||
int psize=0,i,j,compress=0,width;
|
int psize=0,i,j,compress=0,width;
|
||||||
int bpp, flip_vertically, pad, target, offset, hsz;
|
int bpp, flip_vertically, pad, target, offset, hsz;
|
||||||
|
@ -2668,7 +2669,7 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||||
mg = 0xffu << 8;
|
mg = 0xffu << 8;
|
||||||
mb = 0xffu << 0;
|
mb = 0xffu << 0;
|
||||||
ma = 0xffu << 24;
|
ma = 0xffu << 24;
|
||||||
fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255
|
//fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255
|
||||||
} else {
|
} else {
|
||||||
mr = 31u << 10;
|
mr = 31u << 10;
|
||||||
mg = 31u << 5;
|
mg = 31u << 5;
|
||||||
|
|
|
@ -183,7 +183,6 @@
|
||||||
// The three functions you must define are "read" (reads some bytes of data),
|
// The three functions you must define are "read" (reads some bytes of data),
|
||||||
// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end).
|
// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end).
|
||||||
|
|
||||||
|
|
||||||
#define STBI_NO_HDR // RaySan: not required by raylib
|
#define STBI_NO_HDR // RaySan: not required by raylib
|
||||||
|
|
||||||
#ifndef STBI_NO_STDIO
|
#ifndef STBI_NO_STDIO
|
||||||
|
@ -195,6 +194,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// NOTE: Added to work with raylib on Android
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#include "utils.h" // Android fopen function map
|
||||||
|
#endif
|
||||||
|
|
||||||
#define STBI_VERSION 1
|
#define STBI_VERSION 1
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -37,6 +37,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// NOTE: Added to work with raylib on Android
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#include "utils.h" // Android fopen function map
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
81
src/text.c
81
src/text.c
|
@ -1,13 +1,10 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.text
|
* raylib.text
|
||||||
*
|
*
|
||||||
* Basic functions to load SpriteFonts and draw Text
|
* Basic functions to load SpriteFonts and draw Text
|
||||||
*
|
*
|
||||||
* Uses external lib:
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
* stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -31,10 +28,9 @@
|
||||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||||
#include <string.h> // String management functions (just strlen() is used)
|
#include <string.h> // String management functions (just strlen() is used)
|
||||||
#include <stdarg.h> // Used for functions with variable number of parameters (FormatText())
|
#include <stdarg.h> // Used for functions with variable number of parameters (FormatText())
|
||||||
#include "stb_image.h" // Used to read image data (multiple formats support)
|
#include <stdio.h> // Standard input / output lib
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||||
|
|
||||||
#include "utils.h" // Required for function GetExtendion()
|
#include "utils.h" // Required for function GetExtendion()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -79,6 +75,9 @@ static int ParseImageData(Color *imgDataPixel, int imgWidth, int imgHeight, Char
|
||||||
static int GetNextPOT(int num); // Calculate next power-of-two value for a given value
|
static int GetNextPOT(int num); // Calculate next power-of-two value for a given value
|
||||||
static SpriteFont LoadRBMF(const char *fileName); // Load a rBMF font file (raylib BitMap Font)
|
static SpriteFont LoadRBMF(const char *fileName); // Load a rBMF font file (raylib BitMap Font)
|
||||||
|
|
||||||
|
extern void LoadDefaultFont(void);
|
||||||
|
extern void UnloadDefaultFont(void);
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition
|
// Module Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -188,53 +187,29 @@ extern void UnloadDefaultFont(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the default font, useful to be used with extended parameters
|
// Get the default font, useful to be used with extended parameters
|
||||||
SpriteFont GetDefaultFont(void)
|
SpriteFont GetDefaultFont()
|
||||||
{
|
{
|
||||||
return defaultFont;
|
return defaultFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a SpriteFont image into GPU memory
|
// Load a SpriteFont image into GPU memory
|
||||||
SpriteFont LoadSpriteFont(const char* fileName)
|
SpriteFont LoadSpriteFont(const char *fileName)
|
||||||
{
|
{
|
||||||
SpriteFont spriteFont;
|
SpriteFont spriteFont;
|
||||||
|
|
||||||
Image image;
|
|
||||||
|
|
||||||
// Check file extension
|
// Check file extension
|
||||||
if (strcmp(GetExtension(fileName),"rbmf") == 0) spriteFont = LoadRBMF(fileName);
|
if (strcmp(GetExtension(fileName),"rbmf") == 0) spriteFont = LoadRBMF(fileName);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Use stb_image to load image data!
|
Image image = LoadImage(fileName);
|
||||||
int imgWidth;
|
|
||||||
int imgHeight;
|
|
||||||
int imgBpp;
|
|
||||||
|
|
||||||
byte *imgData = stbi_load(fileName, &imgWidth, &imgHeight, &imgBpp, 4); // Force loading to 4 components (RGBA)
|
|
||||||
|
|
||||||
// Convert array to pixel array for working convenience
|
|
||||||
Color *imgDataPixel = (Color *)malloc(imgWidth * imgHeight * sizeof(Color));
|
|
||||||
Color *imgDataPixelPOT = NULL;
|
|
||||||
|
|
||||||
int pix = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < (imgWidth * imgHeight * 4); i += 4)
|
|
||||||
{
|
|
||||||
imgDataPixel[pix].r = imgData[i];
|
|
||||||
imgDataPixel[pix].g = imgData[i+1];
|
|
||||||
imgDataPixel[pix].b = imgData[i+2];
|
|
||||||
imgDataPixel[pix].a = imgData[i+3];
|
|
||||||
pix++;
|
|
||||||
}
|
|
||||||
|
|
||||||
stbi_image_free(imgData);
|
|
||||||
|
|
||||||
// At this point we have a pixel array with all the data...
|
// At this point we have a pixel array with all the data...
|
||||||
|
|
||||||
TraceLog(INFO, "[%s] SpriteFont image loaded: %i x %i", fileName, imgWidth, imgHeight);
|
TraceLog(INFO, "[%s] SpriteFont image loaded: %i x %i", fileName, image.width, image.height);
|
||||||
|
|
||||||
// Process bitmap Font pixel data to get measures (Character array)
|
// Process bitmap Font pixel data to get measures (Character array)
|
||||||
// spriteFont.charSet data is filled inside the function and memory is allocated!
|
// spriteFont.charSet data is filled inside the function and memory is allocated!
|
||||||
int numChars = ParseImageData(imgDataPixel, imgWidth, imgHeight, &spriteFont.charSet);
|
int numChars = ParseImageData(image.pixels, image.width, image.height, &spriteFont.charSet);
|
||||||
|
|
||||||
TraceLog(INFO, "[%s] SpriteFont data parsed correctly", fileName);
|
TraceLog(INFO, "[%s] SpriteFont data parsed correctly", fileName);
|
||||||
TraceLog(INFO, "[%s] SpriteFont num chars detected: %i", fileName, numChars);
|
TraceLog(INFO, "[%s] SpriteFont num chars detected: %i", fileName, numChars);
|
||||||
|
@ -242,13 +217,17 @@ SpriteFont LoadSpriteFont(const char* fileName)
|
||||||
spriteFont.numChars = numChars;
|
spriteFont.numChars = numChars;
|
||||||
|
|
||||||
// Convert image font to POT image before conversion to texture
|
// Convert image font to POT image before conversion to texture
|
||||||
|
// NOTE: Not required, we skip this step
|
||||||
|
/*
|
||||||
// Just add the required amount of pixels at the right and bottom sides of image...
|
// Just add the required amount of pixels at the right and bottom sides of image...
|
||||||
int potWidth = GetNextPOT(imgWidth);
|
int potWidth = GetNextPOT(image.width);
|
||||||
int potHeight = GetNextPOT(imgHeight);
|
int potHeight = GetNextPOT(image.height);
|
||||||
|
|
||||||
// Check if POT texture generation is required (if texture is not already POT)
|
// Check if POT texture generation is required (if texture is not already POT)
|
||||||
if ((potWidth != imgWidth) || (potHeight != imgHeight))
|
if ((potWidth != image.width) || (potHeight != image.height))
|
||||||
{
|
{
|
||||||
|
Color *imgDataPixelPOT = NULL;
|
||||||
|
|
||||||
// Generate POT array from NPOT data
|
// Generate POT array from NPOT data
|
||||||
imgDataPixelPOT = (Color *)malloc(potWidth * potHeight * sizeof(Color));
|
imgDataPixelPOT = (Color *)malloc(potWidth * potHeight * sizeof(Color));
|
||||||
|
|
||||||
|
@ -256,20 +235,20 @@ SpriteFont LoadSpriteFont(const char* fileName)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < potWidth; i++)
|
for (int i = 0; i < potWidth; i++)
|
||||||
{
|
{
|
||||||
if ((j < imgHeight) && (i < imgWidth)) imgDataPixelPOT[j*potWidth + i] = imgDataPixel[j*imgWidth + i];
|
if ((j < image.height) && (i < image.width)) imgDataPixelPOT[j*potWidth + i] = image.pixels[j*image.width + i];
|
||||||
else imgDataPixelPOT[j*potWidth + i] = MAGENTA;
|
else imgDataPixelPOT[j*potWidth + i] = MAGENTA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TraceLog(WARNING, "SpriteFont texture converted to POT: %ix%i", potWidth, potHeight);
|
TraceLog(WARNING, "SpriteFont texture converted to POT: %ix%i", potWidth, potHeight);
|
||||||
}
|
|
||||||
|
|
||||||
free(imgDataPixel);
|
free(image.pixels);
|
||||||
|
|
||||||
image.pixels = imgDataPixelPOT;
|
image.pixels = imgDataPixelPOT;
|
||||||
image.width = potWidth;
|
image.width = potWidth;
|
||||||
image.height = potHeight;
|
image.height = potHeight;
|
||||||
|
}
|
||||||
|
*/
|
||||||
spriteFont.texture = CreateTexture(image, false); // Convert loaded image to OpenGL texture
|
spriteFont.texture = CreateTexture(image, false); // Convert loaded image to OpenGL texture
|
||||||
UnloadImage(image);
|
UnloadImage(image);
|
||||||
}
|
}
|
||||||
|
@ -287,7 +266,7 @@ void UnloadSpriteFont(SpriteFont spriteFont)
|
||||||
// Draw text (using default font)
|
// Draw text (using default font)
|
||||||
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used
|
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used
|
||||||
// NOTE: chars spacing is proportional to fontSize
|
// NOTE: chars spacing is proportional to fontSize
|
||||||
void DrawText(const char* text, int posX, int posY, int fontSize, Color color)
|
void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
|
||||||
{
|
{
|
||||||
Vector2 position = { (float)posX, (float)posY };
|
Vector2 position = { (float)posX, (float)posY };
|
||||||
|
|
||||||
|
@ -303,7 +282,7 @@ void DrawText(const char* text, int posX, int posY, int fontSize, Color color)
|
||||||
// Draw text using SpriteFont
|
// Draw text using SpriteFont
|
||||||
// NOTE: If font size is lower than base size, base size is used
|
// NOTE: If font size is lower than base size, base size is used
|
||||||
// NOTE: chars spacing is NOT proportional to fontSize
|
// NOTE: chars spacing is NOT proportional to fontSize
|
||||||
void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, int fontSize, int spacing, Color tint)
|
void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, int fontSize, int spacing, Color tint)
|
||||||
{
|
{
|
||||||
int length = strlen(text);
|
int length = strlen(text);
|
||||||
int positionX = (int)position.x;
|
int positionX = (int)position.x;
|
||||||
|
@ -398,13 +377,15 @@ int GetFontBaseSize(SpriteFont spriteFont)
|
||||||
// NOTE: Uses default font
|
// NOTE: Uses default font
|
||||||
void DrawFPS(int posX, int posY)
|
void DrawFPS(int posX, int posY)
|
||||||
{
|
{
|
||||||
// NOTE: We are rendering fps every second for better viewing on high framerates
|
|
||||||
static float fps;
|
|
||||||
static int counter = 0;
|
|
||||||
static int refreshRate = 0;
|
|
||||||
|
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
|
|
||||||
|
// NOTE: We are rendering fps every second for better viewing on high framerates
|
||||||
|
// TODO: Not working properly on ANDROID and RPI
|
||||||
|
|
||||||
|
static float fps = 0.0f;
|
||||||
|
static int counter = 0;
|
||||||
|
static int refreshRate = 20;
|
||||||
|
|
||||||
if (counter < refreshRate)
|
if (counter < refreshRate)
|
||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
|
|
139
src/textures.c
139
src/textures.c
|
@ -1,4 +1,4 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.textures
|
* raylib.textures
|
||||||
*
|
*
|
||||||
|
@ -6,8 +6,9 @@
|
||||||
*
|
*
|
||||||
* Uses external lib:
|
* Uses external lib:
|
||||||
* stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC)
|
* stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC)
|
||||||
|
* NOTE: stb_image has been slightly modified, original library: https://github.com/nothings/stb
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -30,15 +31,12 @@
|
||||||
|
|
||||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||||
#include <string.h> // Required for strcmp(), strrchr(), strncmp()
|
#include <string.h> // Required for strcmp(), strrchr(), strncmp()
|
||||||
#include "stb_image.h" // Used to read image data (multiple formats support)
|
|
||||||
#include "utils.h" // rRES data decompression utility function
|
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||||
|
#include "utils.h" // rRES data decompression utility function
|
||||||
|
// NOTE: Includes Android fopen function map
|
||||||
|
|
||||||
// Security check in case no USE_OPENGL_* defined
|
#include "stb_image.h" // Used to read image data (multiple formats support)
|
||||||
#if !defined(USE_OPENGL_11) && !defined(USE_OPENGL_33) && !defined(USE_OPENGL_ES2)
|
|
||||||
#define USE_OPENGL_11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
|
@ -73,7 +71,8 @@ typedef struct {
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
static ImageEx LoadDDS(const char *fileName);
|
static ImageEx LoadDDS(const char *fileName); // Load DDS file
|
||||||
|
static ImageEx LoadPKM(const char *fileName); // Load PKM file
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition
|
// Module Functions Definition
|
||||||
|
@ -155,14 +154,18 @@ Image LoadImage(const char *fileName)
|
||||||
|
|
||||||
free(imageDDS.data);
|
free(imageDDS.data);
|
||||||
|
|
||||||
TraceLog(INFO, "[%s] Image loaded successfully", fileName);
|
TraceLog(INFO, "[%s] DDS Image loaded successfully (uncompressed, no mipmaps)", fileName);
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[%s] Compressed image data could not be loaded", fileName);
|
else TraceLog(WARNING, "[%s] DDS Compressed image data could not be loaded", fileName);
|
||||||
|
}
|
||||||
|
else if (strcmp(GetExtension(fileName),"pkm") == 0)
|
||||||
|
{
|
||||||
|
TraceLog(INFO, "[%s] PKM Compressed image data could not be loaded", fileName);
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[%s] Image extension not recognized, it can't be loaded", fileName);
|
else TraceLog(WARNING, "[%s] Image extension not recognized, it can't be loaded", fileName);
|
||||||
|
|
||||||
// ALTERNATIVE: We can load pixel data directly into Color struct pixels array,
|
// ALTERNATIVE: We can load pixel data directly into Color struct pixels array,
|
||||||
// to do that struct data alignment should be the right one (4 byte); it is.
|
// to do that, struct data alignment should be the right one (4 byte); it is.
|
||||||
//image.pixels = stbi_load(fileName, &imgWidth, &imgHeight, &imgBpp, 4);
|
//image.pixels = stbi_load(fileName, &imgWidth, &imgHeight, &imgBpp, 4);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
@ -302,9 +305,7 @@ Texture2D LoadTexture(const char *fileName)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(USE_OPENGL_33) || defined(USE_OPENGL_ES2)
|
|
||||||
texture.id = rlglLoadCompressedTexture(image.data, image.width, image.height, image.mipmaps, image.compFormat);
|
texture.id = rlglLoadCompressedTexture(image.data, image.width, image.height, image.mipmaps, image.compFormat);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
texture.width = image.width;
|
texture.width = image.width;
|
||||||
|
@ -315,6 +316,20 @@ Texture2D LoadTexture(const char *fileName)
|
||||||
|
|
||||||
free(image.data);
|
free(image.data);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(GetExtension(fileName),"pkm") == 0)
|
||||||
|
{
|
||||||
|
ImageEx image = LoadPKM(fileName);
|
||||||
|
|
||||||
|
texture.id = rlglLoadCompressedTexture(image.data, image.width, image.height, image.mipmaps, image.compFormat);
|
||||||
|
|
||||||
|
texture.width = image.width;
|
||||||
|
texture.height = image.height;
|
||||||
|
|
||||||
|
if (texture.id == 0) TraceLog(WARNING, "[%s] PKM texture could not be loaded", fileName);
|
||||||
|
else TraceLog(INFO, "[%s] PKM texture loaded successfully", fileName);
|
||||||
|
|
||||||
|
free(image.data);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Image image = LoadImage(fileName);
|
Image image = LoadImage(fileName);
|
||||||
|
@ -453,8 +468,6 @@ Texture2D CreateTexture(Image image, bool genMipmaps)
|
||||||
texture.width = image.width;
|
texture.width = image.width;
|
||||||
texture.height = image.height;
|
texture.height = image.height;
|
||||||
|
|
||||||
TraceLog(INFO, "[ID %i] Texture created successfully", texture.id);
|
|
||||||
|
|
||||||
free(imgData);
|
free(imgData);
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "Texture could not be created, image data is not valid");
|
else TraceLog(WARNING, "Texture could not be created, image data is not valid");
|
||||||
|
@ -582,11 +595,9 @@ ImageEx LoadDDS(const char *fileName)
|
||||||
}
|
}
|
||||||
else if ((header.ddspf.flags == 0x04) && (header.ddspf.fourCC > 0))
|
else if ((header.ddspf.flags == 0x04) && (header.ddspf.fourCC > 0))
|
||||||
{
|
{
|
||||||
#ifdef USE_OPENGL_11
|
TraceLog(WARNING, "[%s] DDS image uses compression, not supported on OpenGL 1.1", fileName);
|
||||||
TraceLog(WARNING, "[%s] DDS image uses compression, not supported by current OpenGL version", fileName);
|
|
||||||
TraceLog(WARNING, "[%s] DDS compressed files require OpenGL 3.2+ or ES 2.0", fileName);
|
TraceLog(WARNING, "[%s] DDS compressed files require OpenGL 3.2+ or ES 2.0", fileName);
|
||||||
fclose(ddsFile);
|
|
||||||
#else
|
|
||||||
int bufsize;
|
int bufsize;
|
||||||
|
|
||||||
// Calculate data size, including all mipmaps
|
// Calculate data size, including all mipmaps
|
||||||
|
@ -614,10 +625,96 @@ ImageEx LoadDDS(const char *fileName)
|
||||||
// NOTE: Image num color components not required... for now...
|
// NOTE: Image num color components not required... for now...
|
||||||
//if (fourCC == FOURCC_DXT1) image.components = 3;
|
//if (fourCC == FOURCC_DXT1) image.components = 3;
|
||||||
//else image.components = 4;
|
//else image.components = 4;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loading PKM image data (ETC1/ETC2 compression)
|
||||||
|
// NOTE: KTX is the standard Khronos Group compression format (ETC1/ETC2, mipmaps)
|
||||||
|
// PKM is a much simpler file format used mainly to contain a single ETC1/ETC2 compressed image (no mipmaps)
|
||||||
|
ImageEx LoadPKM(const char *fileName)
|
||||||
|
{
|
||||||
|
// If OpenGL ES 2.0. the following format could be supported (ETC1):
|
||||||
|
//GL_ETC1_RGB8_OES
|
||||||
|
|
||||||
|
#ifndef GL_ETC1_RGB8_OES
|
||||||
|
#define GL_ETC1_RGB8_OES 0x8D64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If OpenGL ES 3.0, the following formats are supported (ETC2/EAC):
|
||||||
|
//GL_COMPRESSED_RGB8_ETC2
|
||||||
|
//GL_COMPRESSED_RGBA8_ETC2
|
||||||
|
//GL_COMPRESSED_RG11_EAC
|
||||||
|
//...
|
||||||
|
|
||||||
|
// PKM file (ETC1) Header (16 bytes)
|
||||||
|
typedef struct {
|
||||||
|
char id[4]; // "PKM "
|
||||||
|
char version[2]; // "10"
|
||||||
|
unsigned short format; // Format = number of mipmaps = 0 (ETC1_RGB_NO_MIPMAPS)
|
||||||
|
unsigned short extWidth; // Texture width (big-endian)
|
||||||
|
unsigned short extHeight; // Texture height (big-endian)
|
||||||
|
unsigned short origWidth; // Original width (big-endian)
|
||||||
|
unsigned short origHeight; // Original height (big-endian)
|
||||||
|
} pkmHeader;
|
||||||
|
|
||||||
|
// NOTE: The extended width and height are the widths rounded up to a multiple of 4.
|
||||||
|
// NOTE: ETC is always 4bit per pixel (64 bits for each 4x4 block of pixels)
|
||||||
|
|
||||||
|
// Bytes Swap (little-endian <-> big-endian)
|
||||||
|
//unsigned short data;
|
||||||
|
//unsigned short swap = ((data & 0x00FF) << 8) | ((data & 0xFF00) >> 8);
|
||||||
|
|
||||||
|
ImageEx image;
|
||||||
|
|
||||||
|
unsigned short width;
|
||||||
|
unsigned short height;
|
||||||
|
unsigned short useless;
|
||||||
|
|
||||||
|
FILE *pkmFile = fopen(fileName, "rb");
|
||||||
|
|
||||||
|
if (pkmFile == NULL)
|
||||||
|
{
|
||||||
|
TraceLog(WARNING, "[%s] PKM File could not be opened", fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Verify the type of file
|
||||||
|
char filecode[4];
|
||||||
|
|
||||||
|
fread(filecode, 1, 4, pkmFile);
|
||||||
|
|
||||||
|
if (strncmp(filecode, "PKM ", 4) != 0)
|
||||||
|
{
|
||||||
|
TraceLog(WARNING, "[%s] PKM File does not seem to be valid", fileName);
|
||||||
|
fclose(pkmFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get the surface descriptor
|
||||||
|
fread(&useless, sizeof(unsigned short), 1, pkmFile); // Discard version
|
||||||
|
fread(&useless, sizeof(unsigned short), 1, pkmFile); // Discard format
|
||||||
|
|
||||||
|
fread(&width, sizeof(unsigned short), 1, pkmFile); // Read extended width
|
||||||
|
fread(&height, sizeof(unsigned short), 1, pkmFile); // Read extended height
|
||||||
|
|
||||||
|
int size = (width/4)*(height/4)*8; // Total data size in bytes
|
||||||
|
|
||||||
|
image.data = (unsigned char*)malloc(size * sizeof(unsigned char));
|
||||||
|
|
||||||
|
fread(image.data, 1, size, pkmFile);
|
||||||
|
|
||||||
|
fclose(pkmFile); // Close file pointer
|
||||||
|
|
||||||
|
image.width = width;
|
||||||
|
image.height = height;
|
||||||
|
image.mipmaps = 1;
|
||||||
|
image.compFormat = GL_ETC1_RGB8_OES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
130
src/utils.c
130
src/utils.c
|
@ -1,4 +1,4 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.utils
|
* raylib.utils
|
||||||
*
|
*
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
* tinfl - zlib DEFLATE algorithm decompression lib
|
* tinfl - zlib DEFLATE algorithm decompression lib
|
||||||
* stb_image_write - PNG writting functions
|
* stb_image_write - PNG writting functions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -29,20 +29,40 @@
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#include <errno.h>
|
||||||
|
#include <android/log.h>
|
||||||
|
#include <android/asset_manager.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h> // malloc(), free()
|
#include <stdlib.h> // malloc(), free()
|
||||||
#include <stdio.h> // printf(), fprintf()
|
#include <stdio.h> // printf(), fprintf()
|
||||||
#include <stdarg.h> // Used for functions with variable number of parameters (TraceLog())
|
#include <stdarg.h> // Used for functions with variable number of parameters (TraceLog())
|
||||||
//#include <string.h> // String management functions: strlen(), strrchr(), strcmp()
|
//#include <string.h> // String management functions: strlen(), strrchr(), strcmp()
|
||||||
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
#include "stb_image_write.h" // Create PNG file
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#include "stb_image_write.h" // Create PNG file
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tinfl.c"
|
#include "tinfl.c"
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Global Variables Definition
|
// Global Variables Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
static FILE *logstream = NULL;
|
#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
|
// Module Functions Definition - Utilities
|
||||||
|
@ -87,6 +107,7 @@ unsigned char *DecompressData(const unsigned char *data, unsigned long compSize,
|
||||||
return pUncomp;
|
return pUncomp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
// Creates a bitmap (BMP) file from an array of pixel data
|
// Creates a bitmap (BMP) file from an array of pixel data
|
||||||
// NOTE: This function is not explicitly available to raylib users
|
// NOTE: This function is not explicitly available to raylib users
|
||||||
void WriteBitmap(const char *fileName, unsigned char *imgData, int width, int height)
|
void WriteBitmap(const char *fileName, unsigned char *imgData, int width, int height)
|
||||||
|
@ -148,52 +169,90 @@ void TraceLog(int msgType, const char *text, ...)
|
||||||
traceDebugMsgs = 0;
|
traceDebugMsgs = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// NOTE: If trace log file not set, output redirected to stdout
|
|
||||||
if (logstream == NULL) logstream = stdout;
|
|
||||||
|
|
||||||
switch(msgType)
|
switch(msgType)
|
||||||
{
|
{
|
||||||
case INFO: fprintf(logstream, "INFO: "); break;
|
case INFO: fprintf(stdout, "INFO: "); break;
|
||||||
case ERROR: fprintf(logstream, "ERROR: "); break;
|
case ERROR: fprintf(stdout, "ERROR: "); break;
|
||||||
case WARNING: fprintf(logstream, "WARNING: "); break;
|
case WARNING: fprintf(stdout, "WARNING: "); break;
|
||||||
case DEBUG: if (traceDebugMsgs) fprintf(logstream, "DEBUG: "); break;
|
case DEBUG: if (traceDebugMsgs) fprintf(stdout, "DEBUG: "); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((msgType != DEBUG) || ((msgType == DEBUG) && (traceDebugMsgs)))
|
if ((msgType != DEBUG) || ((msgType == DEBUG) && (traceDebugMsgs)))
|
||||||
{
|
{
|
||||||
va_start(args, text);
|
va_start(args, text);
|
||||||
vfprintf(logstream, text, args);
|
vfprintf(stdout, text, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
fprintf(logstream, "\n");
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msgType == ERROR) exit(1); // If ERROR message, exit program
|
if (msgType == ERROR) exit(1); // If ERROR message, exit program
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Open a trace log file (if desired)
|
#if defined(PLATFORM_ANDROID)
|
||||||
void TraceLogOpen(const char *logFileName)
|
void TraceLog(int msgType, const char *text, ...)
|
||||||
{
|
{
|
||||||
// stdout redirected to stream file
|
static char buffer[100];
|
||||||
FILE *logstream = fopen(logFileName, "w");
|
|
||||||
|
|
||||||
if (logstream == NULL) TraceLog(WARNING, "Unable to open log file");
|
switch(msgType)
|
||||||
|
{
|
||||||
|
case INFO: strcpy(buffer, "INFO: "); break;
|
||||||
|
case ERROR: strcpy(buffer, "ERROR: "); break;
|
||||||
|
case WARNING: strcpy(buffer, "WARNING: "); break;
|
||||||
|
case DEBUG: strcpy(buffer, "DEBUG: "); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcat(buffer, text);
|
||||||
|
strcat(buffer, "\n");
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, buffer);
|
||||||
|
|
||||||
|
switch(msgType)
|
||||||
|
{
|
||||||
|
case INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
|
||||||
|
case ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break;
|
||||||
|
case WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break;
|
||||||
|
case DEBUG: __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (msgType == ERROR) exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the trace log file
|
// Initialize asset manager from android app
|
||||||
void TraceLogClose()
|
void InitAssetManager(AAssetManager *manager)
|
||||||
{
|
{
|
||||||
if (logstream != NULL) fclose(logstream);
|
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
|
||||||
|
|
||||||
// Keep track of memory allocated
|
// Keep track of memory allocated
|
||||||
// NOTE: mallocType defines the type of data allocated
|
// NOTE: mallocType defines the type of data allocated
|
||||||
|
/*
|
||||||
void RecordMalloc(int mallocType, int mallocSize, const char *msg)
|
void RecordMalloc(int mallocType, int mallocSize, const char *msg)
|
||||||
{
|
{
|
||||||
// TODO: Investigate how to record memory allocation data...
|
// TODO: Investigate how to record memory allocation data...
|
||||||
// Maybe creating my own malloc function...
|
// Maybe creating my own malloc function...
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Get the extension for a filename
|
// Get the extension for a filename
|
||||||
const char *GetExtension(const char *fileName)
|
const char *GetExtension(const char *fileName)
|
||||||
|
@ -203,3 +262,30 @@ const char *GetExtension(const char *fileName)
|
||||||
return (dot + 1);
|
return (dot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// 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(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
|
||||||
|
|
23
src/utils.h
23
src/utils.h
|
@ -1,10 +1,10 @@
|
||||||
/*********************************************************************************************
|
/**********************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib.utils
|
* raylib.utils
|
||||||
*
|
*
|
||||||
* Some utility functions: rRES files data decompression
|
* Some utility functions: rRES files data decompression
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
*
|
*
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -26,11 +26,20 @@
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#include <stdio.h> // Defines FILE struct
|
||||||
|
#include <android/asset_manager.h> // defines AAssetManager struct
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Some basic Defines
|
// Some basic Defines
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define DO_NOT_TRACE_DEBUG_MSGS // Use this define to avoid DEBUG tracing
|
#define DO_NOT_TRACE_DEBUG_MSGS // Use this define to avoid DEBUG tracing
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
#define fopen(name, mode) android_fopen(name, mode)
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -61,14 +70,18 @@ extern "C" { // Prevents name mangling of functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
unsigned char *DecompressData(const unsigned char *data, unsigned long compSize, int uncompSize);
|
unsigned char *DecompressData(const unsigned char *data, unsigned long compSize, int uncompSize);
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
void WriteBitmap(const char *fileName, unsigned char *imgData, int width, int height);
|
void WriteBitmap(const char *fileName, unsigned char *imgData, int width, int height);
|
||||||
void WritePNG(const char *fileName, unsigned char *imgData, int width, int height);
|
void WritePNG(const char *fileName, unsigned char *imgData, int width, int height);
|
||||||
|
#endif
|
||||||
|
|
||||||
void TraceLog(int msgType, const char *text, ...); // Outputs a trace log message
|
void TraceLog(int msgType, const char *text, ...); // Outputs a trace log message
|
||||||
void TraceLogOpen(const char *logFileName); // Open a trace log file (if desired)
|
const char *GetExtension(const char *fileName); // Returns extension of a filename
|
||||||
void TraceLogClose(); // Close the trace log file
|
|
||||||
|
|
||||||
const char *GetExtension(const char *fileName);
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue