commit
bb7b9adb37
@ -13,7 +13,7 @@ The following help is highly appreciated:
|
||||
- Testers of current features and multiple systems - Can you find some bug on raylib?
|
||||
|
||||
If you can not help on any of the above points but you still want to contribute in some way... please, consider helping
|
||||
with a small [donation](http://www.raylib.com/helpme.htm) or contributing with [raylib patreon](https://www.patreon.com/raysan5). It will really motivate to continue improving this project (and pay some bills… or some coffee).
|
||||
with a small [donation](http://www.raylib.com/helpme.html) or contributing with [raylib patreon](https://www.patreon.com/raysan5). It will really motivate to continue improving this project (and pay some bills… or some coffee).
|
||||
|
||||
raylib philosophy
|
||||
------------------
|
||||
|
@ -9,7 +9,7 @@ raylib is highly inspired by Borland BGI graphics lib and by XNA framework.
|
||||
|
||||
NOTE for ADVENTURERS: raylib is a programming library to learn videogames programming;
|
||||
no fancy interface, no visual helpers, no auto-debugging... just coding in the most
|
||||
pure spartan-programmers way. Are you ready to learn? Jump to [code examples!](http://www.raylib.com/examples.htm)
|
||||
pure spartan-programmers way. Are you ready to learn? Jump to [code examples!](http://www.raylib.com/examples.html)
|
||||
|
||||
history
|
||||
-------
|
||||
@ -247,7 +247,7 @@ contact
|
||||
|
||||
If you are using raylib and you enjoy it, please, [let me know][raysan5].
|
||||
|
||||
If you feel you can help, then, [helpme!](http://www.raylib.com/helpme.htm)
|
||||
If you feel you can help, then, [helpme!](http://www.raylib.com/helpme.html)
|
||||
|
||||
acknowledgements
|
||||
---------------
|
||||
|
@ -117,7 +117,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<a id="logo" href="index.htm"></a>
|
||||
<a id="logo" href="index.html"></a>
|
||||
|
||||
<div class="spinner" id='spinner'></div>
|
||||
<div class="emscripten" id="status">Downloading...</div>
|
||||
|
@ -147,13 +147,13 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
||||
LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl
|
||||
# on XWindow could require also below libraries, just uncomment
|
||||
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
else
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# libraries for OS X 10.9 desktop compiling
|
||||
# requires the following packages:
|
||||
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
||||
LIBS = -lraylib -lglfw3 -framework OpenGL -framework OpenAl -framework Cocoa
|
||||
LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAL -framework Cocoa
|
||||
else
|
||||
# libraries for Windows desktop compiling
|
||||
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
|
||||
@ -497,6 +497,13 @@ audio_module_playing: audio_module_playing.c
|
||||
audio_raw_stream: audio_raw_stream.c
|
||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||
|
||||
# Linux Fix to timespect from
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
CFLAGS += -D_POSIX_C_SOURCE=199309L
|
||||
endif
|
||||
endif
|
||||
|
||||
# compile [physac] example - physics demo
|
||||
physics_demo: physics_demo.c
|
||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||
|
111
src/audio.c
111
src/audio.c
@ -3,33 +3,51 @@
|
||||
* raylib.audio
|
||||
*
|
||||
* This module provides basic functionality to work with audio:
|
||||
* Manage audio device (init/close)
|
||||
* Load and Unload audio files (WAV, OGG, FLAC, XM, MOD)
|
||||
* Play/Stop/Pause/Resume loaded audio
|
||||
* Manage mixing channels
|
||||
* Manage raw audio context
|
||||
* Manage audio device (init/close)
|
||||
* Load and Unload audio files (WAV, OGG, FLAC, XM, MOD)
|
||||
* Play/Stop/Pause/Resume loaded audio
|
||||
* Manage mixing channels
|
||||
* Manage raw audio context
|
||||
*
|
||||
* External libs:
|
||||
* NOTES:
|
||||
*
|
||||
* Only up to two channels supported: MONO and STEREO (for additional channels, use AL_EXT_MCFORMATS)
|
||||
* Only the following sample sizes supported: 8bit PCM, 16bit PCM, 32-bit float PCM (using AL_EXT_FLOAT32)
|
||||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define AUDIO_STANDALONE
|
||||
* If defined, the module can be used as standalone library (independently of raylib).
|
||||
* Required types and functions are defined in the same module.
|
||||
*
|
||||
* #define SUPPORT_FILEFORMAT_WAV / SUPPORT_LOAD_WAV / ENABLE_LOAD_WAV
|
||||
* #define SUPPORT_FILEFORMAT_OGG
|
||||
* #define SUPPORT_FILEFORMAT_XM
|
||||
* #define SUPPORT_FILEFORMAT_MOD
|
||||
* #define SUPPORT_FILEFORMAT_FLAC
|
||||
* Selected desired fileformats to be supported for loading. Some of those formats are
|
||||
* supported by default, to remove support, just comment unrequired #define in this module
|
||||
*
|
||||
* #define SUPPORT_RAW_AUDIO_BUFFERS
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html)
|
||||
* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||
* jar_xm - XM module file loading
|
||||
* jar_mod - MOD audio file loading
|
||||
* dr_flac - FLAC audio file loading
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* AUDIO_STANDALONE - Use this module as standalone library (independently of raylib)
|
||||
*
|
||||
* Some design decisions:
|
||||
* Support only up to two channels: MONO and STEREO (for additional channels, AL_EXT_MCFORMATS)
|
||||
* Support only the following sample sizes: 8bit PCM, 16bit PCM, 32-bit float PCM (using AL_EXT_FLOAT32)
|
||||
* CONTRIBUTORS:
|
||||
*
|
||||
* Many thanks to Joshua Reisenauer (github: @kd7tck) for the following additions:
|
||||
* XM audio module support (jar_xm)
|
||||
* MOD audio module support (jar_mod)
|
||||
* Mixing channels support
|
||||
* Raw audio context support
|
||||
* XM audio module support (jar_xm)
|
||||
* MOD audio module support (jar_mod)
|
||||
* Mixing channels support
|
||||
* Raw audio context support
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
@ -59,9 +77,14 @@
|
||||
#include "utils.h" // Required for: fopen() Android mapping, TraceLog()
|
||||
#endif
|
||||
|
||||
#include "AL/al.h" // OpenAL basic header
|
||||
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||
//#include "AL/alext.h" // OpenAL extensions header, required for AL_EXT_FLOAT32 and AL_EXT_MCFORMATS
|
||||
#ifdef __APPLE__
|
||||
#include "OpenAL/al.h" // OpenAL basic header
|
||||
#include "OpenAL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||
#else
|
||||
#include "AL/al.h" // OpenAL basic header
|
||||
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||
//#include "AL/alext.h" // OpenAL extensions header, required for AL_EXT_FLOAT32 and AL_EXT_MCFORMATS
|
||||
#endif
|
||||
|
||||
// OpenAL extension: AL_EXT_FLOAT32 - Support for 32bit float samples
|
||||
// OpenAL extension: AL_EXT_MCFORMATS - Support for multi-channel formats (Quad, 5.1, 6.1, 7.1)
|
||||
@ -241,11 +264,11 @@ Wave LoadWave(const char *fileName)
|
||||
else if (strcmp(GetExtension(fileName), "flac") == 0) wave = LoadFLAC(fileName);
|
||||
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
||||
{
|
||||
RRESData rres = LoadResource(fileName);
|
||||
RRES rres = LoadResource(fileName, 0);
|
||||
|
||||
// NOTE: Parameters for RRES_WAVE type are: sampleCount, sampleRate, sampleSize, channels
|
||||
// NOTE: Parameters for RRES_TYPE_WAVE are: sampleCount, sampleRate, sampleSize, channels
|
||||
|
||||
if (rres.type == RRES_WAVE) wave = LoadWaveEx(rres.data, rres.param1, rres.param2, rres.param3, rres.param4);
|
||||
if (rres[0].type == RRES_TYPE_WAVE) wave = LoadWaveEx(rres[0].data, rres[0].param1, rres[0].param2, rres[0].param3, rres[0].param4);
|
||||
else TraceLog(WARNING, "[%s] Resource file does not contain wave data", fileName);
|
||||
|
||||
UnloadResource(rres);
|
||||
@ -374,7 +397,7 @@ void UnloadSound(Sound sound)
|
||||
|
||||
// Update sound buffer with new data
|
||||
// NOTE: data must match sound.format
|
||||
void UpdateSound(Sound sound, const void *data, int numSamples)
|
||||
void UpdateSound(Sound sound, const void *data, int samplesCount)
|
||||
{
|
||||
ALint sampleRate, sampleSize, channels;
|
||||
alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
|
||||
@ -385,7 +408,7 @@ void UpdateSound(Sound sound, const void *data, int numSamples)
|
||||
TraceLog(DEBUG, "UpdateSound() : AL_BITS: %i", sampleSize);
|
||||
TraceLog(DEBUG, "UpdateSound() : AL_CHANNELS: %i", channels);
|
||||
|
||||
unsigned int dataSize = numSamples*channels*sampleSize/8; // Size of data in bytes
|
||||
unsigned int dataSize = samplesCount*channels*sampleSize/8; // Size of data in bytes
|
||||
|
||||
alSourceStop(sound.source); // Stop sound
|
||||
alSourcei(sound.source, AL_BUFFER, 0); // Unbind buffer from sound to update
|
||||
@ -581,7 +604,7 @@ void WaveCrop(Wave *wave, int initSample, int finalSample)
|
||||
|
||||
void *data = malloc(sampleCount*wave->channels*wave->sampleSize/8);
|
||||
|
||||
memcpy(data, wave->data + (initSample*wave->channels*wave->sampleSize/8), sampleCount*wave->channels*wave->sampleSize/8);
|
||||
memcpy(data, (unsigned char*)wave->data + (initSample*wave->channels*wave->sampleSize/8), sampleCount*wave->channels*wave->sampleSize/8);
|
||||
|
||||
free(wave->data);
|
||||
wave->data = data;
|
||||
@ -740,6 +763,17 @@ void StopMusicStream(Music music)
|
||||
{
|
||||
alSourceStop(music->stream.source);
|
||||
|
||||
// Clear stream buffers
|
||||
void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, 1);
|
||||
|
||||
for (int i = 0; i < MAX_STREAM_BUFFERS; i++)
|
||||
{
|
||||
alBufferData(music->stream.buffers[i], music->stream.format, pcm, AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, music->stream.sampleRate);
|
||||
}
|
||||
|
||||
free(pcm);
|
||||
|
||||
// Restart music context
|
||||
switch (music->ctxType)
|
||||
{
|
||||
case MUSIC_AUDIO_OGG: stb_vorbis_seek_start(music->ctxOgg); break;
|
||||
@ -752,6 +786,7 @@ void StopMusicStream(Music music)
|
||||
}
|
||||
|
||||
// Update (re-fill) music buffers if data already processed
|
||||
// TODO: Make sure buffers are ready for update... check music state
|
||||
void UpdateMusicStream(Music music)
|
||||
{
|
||||
ALenum state;
|
||||
@ -768,13 +803,13 @@ void UpdateMusicStream(Music music)
|
||||
void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.channels*music->stream.sampleSize/8, 1);
|
||||
|
||||
int numBuffersToProcess = processed;
|
||||
int numSamples = 0; // Total size of data steamed in L+R samples for xm floats,
|
||||
// individual L or R for ogg shorts
|
||||
int samplesCount = 0; // Total size of data steamed in L+R samples for xm floats,
|
||||
//individual L or R for ogg shorts
|
||||
|
||||
for (int i = 0; i < numBuffersToProcess; i++)
|
||||
{
|
||||
if (music->samplesLeft >= AUDIO_BUFFER_SIZE) numSamples = AUDIO_BUFFER_SIZE;
|
||||
else numSamples = music->samplesLeft;
|
||||
if (music->samplesLeft >= AUDIO_BUFFER_SIZE) samplesCount = AUDIO_BUFFER_SIZE;
|
||||
else samplesCount = music->samplesLeft;
|
||||
|
||||
// TODO: Really don't like ctxType thingy...
|
||||
switch (music->ctxType)
|
||||
@ -782,22 +817,22 @@ void UpdateMusicStream(Music music)
|
||||
case MUSIC_AUDIO_OGG:
|
||||
{
|
||||
// NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!)
|
||||
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, numSamples*music->stream.channels);
|
||||
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels);
|
||||
|
||||
} break;
|
||||
case MUSIC_AUDIO_FLAC:
|
||||
{
|
||||
// NOTE: Returns the number of samples to process
|
||||
unsigned int numSamplesFlac = (unsigned int)drflac_read_s16(music->ctxFlac, numSamples*music->stream.channels, (short *)pcm);
|
||||
unsigned int numSamplesFlac = (unsigned int)drflac_read_s16(music->ctxFlac, samplesCount*music->stream.channels, (short *)pcm);
|
||||
|
||||
} break;
|
||||
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, numSamples); break;
|
||||
case MUSIC_MODULE_MOD: jar_mod_fillbuffer(&music->ctxMod, pcm, numSamples, 0); break;
|
||||
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
||||
case MUSIC_MODULE_MOD: jar_mod_fillbuffer(&music->ctxMod, pcm, samplesCount, 0); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
UpdateAudioStream(music->stream, pcm, numSamples);
|
||||
music->samplesLeft -= numSamples;
|
||||
UpdateAudioStream(music->stream, pcm, samplesCount);
|
||||
music->samplesLeft -= samplesCount;
|
||||
|
||||
if (music->samplesLeft <= 0)
|
||||
{
|
||||
@ -976,7 +1011,7 @@ void CloseAudioStream(AudioStream stream)
|
||||
|
||||
// Update audio stream buffers with data
|
||||
// NOTE: Only updates one buffer per call
|
||||
void UpdateAudioStream(AudioStream stream, const void *data, int numSamples)
|
||||
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
|
||||
{
|
||||
ALuint buffer = 0;
|
||||
alSourceUnqueueBuffers(stream.source, 1, &buffer);
|
||||
@ -984,7 +1019,7 @@ void UpdateAudioStream(AudioStream stream, const void *data, int numSamples)
|
||||
// Check if any buffer was available for unqueue
|
||||
if (alGetError() != AL_INVALID_VALUE)
|
||||
{
|
||||
alBufferData(buffer, stream.format, data, numSamples*stream.channels*stream.sampleSize/8, stream.sampleRate);
|
||||
alBufferData(buffer, stream.format, data, samplesCount*stream.channels*stream.sampleSize/8, stream.sampleRate);
|
||||
alSourceQueueBuffers(stream.source, 1, &buffer);
|
||||
}
|
||||
}
|
||||
@ -1113,7 +1148,7 @@ static Wave LoadWAV(const char *fileName)
|
||||
wave.data = malloc(wavData.subChunkSize);
|
||||
|
||||
// Read in the sound data into the soundData variable
|
||||
fread(wave.data, 1, wavData.subChunkSize, wavFile);
|
||||
fread(wave.data, wavData.subChunkSize, 1, wavFile);
|
||||
|
||||
// Store wave parameters
|
||||
wave.sampleRate = wavFormat.sampleRate;
|
||||
|
@ -9,7 +9,7 @@
|
||||
* Manage mixing channels
|
||||
* Manage raw audio context
|
||||
*
|
||||
* External libs:
|
||||
* DEPENDENCIES:
|
||||
* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html)
|
||||
* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||
* jar_xm - XM module file loading
|
||||
@ -23,6 +23,8 @@
|
||||
* Raw audio context support
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
@ -115,7 +117,7 @@ Wave LoadWave(const char *fileName); // Load wave dat
|
||||
Wave LoadWaveEx(void *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from raw array data
|
||||
Sound LoadSound(const char *fileName); // Load sound from file
|
||||
Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
|
||||
void UpdateSound(Sound sound, const void *data, int numSamples);// Update sound buffer with new data
|
||||
void UpdateSound(Sound sound, const void *data, int samplesCount); // Update sound buffer with new data
|
||||
void UnloadWave(Wave wave); // Unload wave data
|
||||
void UnloadSound(Sound sound); // Unload sound
|
||||
void PlaySound(Sound sound); // Play a sound
|
||||
@ -146,7 +148,7 @@ float GetMusicTimePlayed(Music music); // Get current m
|
||||
AudioStream InitAudioStream(unsigned int sampleRate,
|
||||
unsigned int sampleSize,
|
||||
unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
||||
void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data
|
||||
void UpdateAudioStream(AudioStream stream, void *data, int samplesCount); // Update audio stream buffers with data
|
||||
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
|
||||
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
|
||||
void PlayAudioStream(AudioStream stream); // Play audio stream
|
||||
|
14
src/camera.h
14
src/camera.h
@ -2,6 +2,10 @@
|
||||
*
|
||||
* raylib Camera System - Camera Modes Setup and Control Functions
|
||||
*
|
||||
* NOTE: Memory footprint of this library is aproximately 52 bytes (global variables)
|
||||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define CAMERA_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
@ -11,10 +15,14 @@
|
||||
* If defined, the library can be used as standalone as a camera system but some
|
||||
* functions must be redefined to manage inputs accordingly.
|
||||
*
|
||||
* NOTE: Memory footprint of this library is aproximately 52 bytes (global variables)
|
||||
* CONTRIBUTORS:
|
||||
* Marc Palau: Initial implementation (2014)
|
||||
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||
*
|
||||
* Initial design by Marc Palau (2014)
|
||||
* Reviewed by Ramon Santamaria (2015-2016)
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2015-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
|
107
src/core.c
107
src/core.c
@ -1,27 +1,46 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.core
|
||||
*
|
||||
* Basic functions to manage windows, OpenGL context and input on multiple platforms
|
||||
* raylib.core - Basic functions to manage windows, OpenGL context and input on multiple platforms
|
||||
*
|
||||
* The following platforms are supported: Windows, Linux, Mac (OSX), Android, Raspberry Pi, HTML5, Oculus Rift CV1
|
||||
*
|
||||
* External libs:
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define PLATFORM_DESKTOP
|
||||
* Windowing and input system configured for desktop platforms: Windows, Linux, OSX (managed by GLFW3 library)
|
||||
* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for mirror rendering - View [rlgl] module to enable it
|
||||
*
|
||||
* #define PLATFORM_ANDROID
|
||||
* Windowing and input system configured for Android device, app activity managed internally in this module.
|
||||
* NOTE: OpenGL ES 2.0 is required and graphic device is managed by EGL
|
||||
*
|
||||
* #define PLATFORM_RPI
|
||||
* Windowing and input system configured for Raspberry Pi (tested on Raspbian), graphic device is managed by EGL
|
||||
* and inputs are processed is raw mode, reading from /dev/input/
|
||||
*
|
||||
* #define PLATFORM_WEB
|
||||
* Windowing and input system configured for HTML5 (run on browser), code converted from C to asm.js
|
||||
* using emscripten compiler. OpenGL ES 2.0 required for direct translation to WebGL equivalent code.
|
||||
*
|
||||
* #define LOAD_DEFAULT_FONT (defined by default)
|
||||
* Default font is loaded on window initialization to be available for the user to render simple text.
|
||||
* NOTE: If enabled, uses external module functions to load default raylib font (module: text)
|
||||
*
|
||||
* #define INCLUDE_CAMERA_SYSTEM / SUPPORT_CAMERA_SYSTEM
|
||||
*
|
||||
* #define INCLUDE_GESTURES_SYSTEM / SUPPORT_GESTURES_SYSTEM
|
||||
*
|
||||
* #define SUPPORT_MOUSE_GESTURES
|
||||
* Mouse gestures are directly mapped like touches and processed by gestures system.
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* GLFW3 - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX)
|
||||
* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
|
||||
* camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person)
|
||||
* gestures - Gestures system for touch-ready devices (or simulated from mouse inputs)
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* PLATFORM_DESKTOP - Windows, Linux, Mac (OSX)
|
||||
* PLATFORM_ANDROID - Android (only OpenGL ES 2.0 devices), graphic device is managed by EGL and input system by Android activity.
|
||||
* PLATFORM_RPI - Rapsberry Pi (tested on Raspbian), graphic device is managed by EGL and input system is coded in raw mode.
|
||||
* PLATFORM_WEB - HTML5 (using emscripten compiler)
|
||||
*
|
||||
* RL_LOAD_DEFAULT_FONT - Use external module functions to load default raylib font (module: text)
|
||||
*
|
||||
* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for render mirror - View [rlgl] module to enable it
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
@ -140,7 +159,7 @@
|
||||
#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
|
||||
#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
|
||||
|
||||
#define RL_LOAD_DEFAULT_FONT // Load default font on window initialization (module: text)
|
||||
#define LOAD_DEFAULT_FONT // Load default font on window initialization (module: text)
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -256,7 +275,7 @@ static bool showLogo = false; // Track if showing logo at init is
|
||||
//----------------------------------------------------------------------------------
|
||||
// Other Modules Functions Declaration (required by core)
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||
#if defined(LOAD_DEFAULT_FONT)
|
||||
extern void LoadDefaultFont(void); // [Module: text] Loads default font on InitWindow()
|
||||
extern void UnloadDefaultFont(void); // [Module: text] Unloads default font from GPU memory
|
||||
#endif
|
||||
@ -338,7 +357,7 @@ void InitWindow(int width, int height, const char *title)
|
||||
// Init graphics device (display device and OpenGL context)
|
||||
InitGraphicsDevice(width, height);
|
||||
|
||||
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||
#if defined(LOAD_DEFAULT_FONT)
|
||||
// Load default font
|
||||
// NOTE: External function (defined in module: text)
|
||||
LoadDefaultFont();
|
||||
@ -450,7 +469,7 @@ void InitWindow(int width, int height, void *state)
|
||||
// Close Window and Terminate Context
|
||||
void CloseWindow(void)
|
||||
{
|
||||
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||
#if defined(LOAD_DEFAULT_FONT)
|
||||
UnloadDefaultFont();
|
||||
#endif
|
||||
|
||||
@ -559,6 +578,26 @@ void SetWindowIcon(Image image)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set window position on screen (windowed mode)
|
||||
void SetWindowPosition(int x, int y)
|
||||
{
|
||||
glfwSetWindowPos(window, x, y);
|
||||
}
|
||||
|
||||
// Set monitor for the current window (fullscreen mode)
|
||||
void SetWindowMonitor(int monitor)
|
||||
{
|
||||
int monitorCount;
|
||||
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||
|
||||
if ((monitor >= 0) && (monitor < monitorCount))
|
||||
{
|
||||
glfwSetWindowMonitor(window, monitors[monitor], 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
|
||||
TraceLog(INFO, "Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));
|
||||
}
|
||||
else TraceLog(WARNING, "Selected monitor not found");
|
||||
}
|
||||
|
||||
// Get current screen width
|
||||
int GetScreenWidth(void)
|
||||
{
|
||||
@ -1025,14 +1064,14 @@ int StorageLoadValue(int position)
|
||||
{
|
||||
// Get file size
|
||||
fseek(storageFile, 0, SEEK_END);
|
||||
int fileSize = ftell(storageFile); // Size in bytes
|
||||
int fileSize = ftell(storageFile); // Size in bytes
|
||||
rewind(storageFile);
|
||||
|
||||
if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
|
||||
else
|
||||
{
|
||||
fseek(storageFile, (position*4), SEEK_SET);
|
||||
fread(&value, 1, 4, storageFile);
|
||||
fread(&value, 4, 1, storageFile); // Read 1 element of 4 bytes size
|
||||
}
|
||||
|
||||
fclose(storageFile);
|
||||
@ -1517,13 +1556,23 @@ static void InitGraphicsDevice(int width, int height)
|
||||
|
||||
glfwDefaultWindowHints(); // Set default windows hints
|
||||
|
||||
if (configFlags & FLAG_RESIZABLE_WINDOW)
|
||||
{
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window
|
||||
}
|
||||
// Check some Window creation flags
|
||||
if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window
|
||||
else glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Avoid window being resizable
|
||||
|
||||
//glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Border and buttons on Window
|
||||
if (configFlags & FLAG_WINDOW_DECORATED) glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Border and buttons on Window
|
||||
|
||||
if (configFlags & FLAG_WINDOW_TRANSPARENT)
|
||||
{
|
||||
// TODO: Enable transparent window (not ready yet on GLFW 3.2)
|
||||
}
|
||||
|
||||
if (configFlags & FLAG_MSAA_4X_HINT)
|
||||
{
|
||||
glfwWindowHint(GLFW_SAMPLES, 4); // Enables multisampling x4 (MSAA), default is 0
|
||||
TraceLog(INFO, "Trying to enable MSAA x4");
|
||||
}
|
||||
|
||||
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
||||
//glfwWindowHint(GLFW_DEPTH_BITS, 16); // Depthbuffer bits (24 by default)
|
||||
//glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window
|
||||
@ -1532,13 +1581,7 @@ static void InitGraphicsDevice(int width, int height)
|
||||
|
||||
// NOTE: When asking for an OpenGL context version, most drivers provide highest supported version
|
||||
// with forward compatibility to older OpenGL versions.
|
||||
// For example, if using OpenGL 1.1, driver can provide a 3.3 context fordward compatible.
|
||||
|
||||
if (configFlags & FLAG_MSAA_4X_HINT)
|
||||
{
|
||||
glfwWindowHint(GLFW_SAMPLES, 4); // Enables multisampling x4 (MSAA), default is 0
|
||||
TraceLog(INFO, "Trying to enable MSAA x4");
|
||||
}
|
||||
// For example, if using OpenGL 1.1, driver can provide a 4.3 context forward compatible.
|
||||
|
||||
// Check selection OpenGL version
|
||||
if (rlGetVersion() == OPENGL_21)
|
||||
@ -2410,7 +2453,7 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||
// Init graphics device (display device and OpenGL context)
|
||||
InitGraphicsDevice(screenWidth, screenHeight);
|
||||
|
||||
#if defined(RL_LOAD_DEFAULT_FONT)
|
||||
#if defined(LOAD_DEFAULT_FONT)
|
||||
// Load default font
|
||||
// NOTE: External function (defined in module: text)
|
||||
LoadDefaultFont();
|
||||
|
3
src/external/jar_mod.h
vendored
3
src/external/jar_mod.h
vendored
@ -83,8 +83,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
//#include <stdbool.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -2,6 +2,10 @@
|
||||
*
|
||||
* raylib Gestures System - Gestures Processing based on input gesture events (touch/mouse)
|
||||
*
|
||||
* NOTE: Memory footprint of this library is aproximately 128 bytes (global variables)
|
||||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define GESTURES_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
@ -11,11 +15,16 @@
|
||||
* If defined, the library can be used as standalone to process gesture events with
|
||||
* no external dependencies.
|
||||
*
|
||||
* NOTE: Memory footprint of this library is aproximately 128 bytes
|
||||
* CONTRIBUTORS:
|
||||
* Marc Palau: Initial implementation (2014)
|
||||
* Albert Martos: Complete redesign and testing (2015)
|
||||
* Ian Eito: Complete redesign and testing (2015)
|
||||
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||
*
|
||||
* Initial design by Marc Palau (2014)
|
||||
* Redesigned by Albert Martos and Ian Eito (2015)
|
||||
* Reviewed by Ramon Santamaria (2015-2016)
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
|
13
src/models.c
13
src/models.c
@ -1,14 +1,15 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.models
|
||||
* raylib.models - Basic functions to draw 3d shapes and 3d models
|
||||
*
|
||||
* Basic functions to draw 3d shapes and load/draw 3d models (.OBJ)
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* External libs:
|
||||
* rlgl - raylib OpenGL abstraction layer
|
||||
* #define SUPPORT_FILEFORMAT_OBJ / SUPPORT_LOAD_OBJ
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* ...
|
||||
* #define SUPPORT_FILEFORMAT_MTL
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
|
15
src/physac.h
15
src/physac.h
@ -1,11 +1,13 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Physac - 2D Physics library for videogames
|
||||
* Physac v1.0 - 2D Physics library for videogames
|
||||
*
|
||||
* Description: Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop
|
||||
* to simluate physics. A physics step contains the following phases: get collision information, apply dynamics,
|
||||
* collision solving and position correction. It uses a very simple struct for physic bodies with a position vector
|
||||
* to be used in any 3D rendering API.
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop
|
||||
* to simluate physics. A physics step contains the following phases: get collision information,
|
||||
* apply dynamics, collision solving and position correction. It uses a very simple struct for physic
|
||||
* bodies with a position vector to be used in any 3D rendering API.
|
||||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
@ -37,7 +39,8 @@
|
||||
* Otherwise it will include stdlib.h and use the C standard library malloc()/free() function.
|
||||
*
|
||||
* VERY THANKS TO:
|
||||
* - Ramón Santamaria (@raysan5)
|
||||
* Ramón Santamaria (@raysan5)
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
|
73
src/raylib.h
73
src/raylib.h
@ -1,10 +1,10 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib 1.7.0 (www.raylib.com)
|
||||
* raylib v1.7.0 (www.raylib.com)
|
||||
*
|
||||
* A simple and easy-to-use library to learn videogames programming
|
||||
*
|
||||
* Features:
|
||||
* FEATURES:
|
||||
* Library written in plain C code (C99)
|
||||
* Uses PascalCase/camelCase notation
|
||||
* Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0)
|
||||
@ -20,7 +20,13 @@
|
||||
* Minimal external dependencies (GLFW3, OpenGL, OpenAL)
|
||||
* Complete binding for Lua [rlua]
|
||||
*
|
||||
* External libs:
|
||||
* NOTES:
|
||||
* 32bit Colors - All defined color are always RGBA (struct Color is 4 byte)
|
||||
* One custom default font could be loaded automatically when InitWindow() [core]
|
||||
* If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads
|
||||
* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined)
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* GLFW3 (www.glfw.org) for window/context management and input [core]
|
||||
* GLAD for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl]
|
||||
* stb_image (Sean Barret) for images loading (JPEG, PNG, BMP, TGA) [textures]
|
||||
@ -33,13 +39,8 @@
|
||||
* OpenAL Soft for audio device/context management [audio]
|
||||
* tinfl for data decompression (DEFLATE algorithm) [utils]
|
||||
*
|
||||
* Some design decisions:
|
||||
* 32bit Colors - All defined color are always RGBA (struct Color is 4 byte)
|
||||
* One custom default font could be loaded automatically when InitWindow() [core]
|
||||
* If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads
|
||||
* If using OpenGL 3.3 or ES2, two default shaders could be loaded automatically (internally defined)
|
||||
*
|
||||
* -- LICENSE --
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||
* BSD-like license that allows static linking with closed source software:
|
||||
@ -97,13 +98,14 @@
|
||||
#define RAD2DEG (180.0f/PI)
|
||||
|
||||
// raylib Config Flags
|
||||
#define FLAG_FULLSCREEN_MODE 1
|
||||
#define FLAG_RESIZABLE_WINDOW 2
|
||||
#define FLAG_SHOW_LOGO 4
|
||||
#define FLAG_SHOW_MOUSE_CURSOR 8
|
||||
#define FLAG_CENTERED_MODE 16
|
||||
#define FLAG_MSAA_4X_HINT 32
|
||||
#define FLAG_VSYNC_HINT 64
|
||||
#define FLAG_SHOW_LOGO 1
|
||||
#define FLAG_SHOW_MOUSE_CURSOR 2
|
||||
#define FLAG_FULLSCREEN_MODE 4
|
||||
#define FLAG_WINDOW_RESIZABLE 8
|
||||
#define FLAG_WINDOW_DECORATED 16
|
||||
#define FLAG_WINDOW_TRANSPARENT 32
|
||||
#define FLAG_MSAA_4X_HINT 64
|
||||
#define FLAG_VSYNC_HINT 128
|
||||
|
||||
// Keyboard Function Keys
|
||||
#define KEY_SPACE 32
|
||||
@ -296,13 +298,9 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifndef __cplusplus
|
||||
// Boolean type
|
||||
#ifndef __APPLE__
|
||||
#if !defined(_STDBOOL_H)
|
||||
typedef enum { false, true } bool;
|
||||
#define _STDBOOL_H
|
||||
#endif
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#if !defined(_STDBOOL_H)
|
||||
typedef enum { false, true } bool;
|
||||
#define _STDBOOL_H
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -596,8 +594,9 @@ typedef enum {
|
||||
HMD_FOVE_VR,
|
||||
} VrDevice;
|
||||
|
||||
// rRES data returned when reading a resource, it contains all required data for user (24 byte)
|
||||
typedef struct {
|
||||
// rRES data returned when reading a resource,
|
||||
// it contains all required data for user (24 byte)
|
||||
typedef struct RRESData {
|
||||
unsigned int type; // Resource type (4 byte)
|
||||
|
||||
unsigned int param1; // Resouce parameter 1 (4 byte)
|
||||
@ -608,14 +607,21 @@ typedef struct {
|
||||
void *data; // Resource data pointer (4 byte)
|
||||
} RRESData;
|
||||
|
||||
// RRESData type
|
||||
typedef enum {
|
||||
RRES_RAW = 0,
|
||||
RRES_IMAGE,
|
||||
RRES_WAVE,
|
||||
RRES_VERTEX,
|
||||
RRES_TEXT
|
||||
RRES_TYPE_RAW = 0,
|
||||
RRES_TYPE_IMAGE,
|
||||
RRES_TYPE_WAVE,
|
||||
RRES_TYPE_VERTEX,
|
||||
RRES_TYPE_TEXT,
|
||||
RRES_TYPE_FONT_IMAGE,
|
||||
RRES_TYPE_FONT_CHARDATA, // CharInfo data array
|
||||
RRES_TYPE_DIRECTORY
|
||||
} RRESDataType;
|
||||
|
||||
// RRES type (pointer to RRESData array)
|
||||
typedef struct RRESData *RRES;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
@ -639,6 +645,8 @@ RLAPI bool WindowShouldClose(void); // Detect if K
|
||||
RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus)
|
||||
RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP)
|
||||
RLAPI void SetWindowIcon(Image image); // Set icon for window (only PLATFORM_DESKTOP)
|
||||
RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP)
|
||||
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode)
|
||||
RLAPI int GetScreenWidth(void); // Get current screen width
|
||||
RLAPI int GetScreenHeight(void); // Get current screen height
|
||||
|
||||
@ -762,6 +770,7 @@ RLAPI void DrawCircleV(Vector2 center, float radius, Color color);
|
||||
RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline
|
||||
RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle
|
||||
RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle
|
||||
RLAPI void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color); // Draw a color-filled rectangle with pro parameters
|
||||
RLAPI void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2); // Draw a gradient-filled rectangle
|
||||
RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version)
|
||||
RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline
|
||||
@ -953,7 +962,7 @@ RLAPI Wave LoadWave(const char *fileName); // Load wa
|
||||
RLAPI Wave LoadWaveEx(void *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from raw array data
|
||||
RLAPI Sound LoadSound(const char *fileName); // Load sound from file
|
||||
RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
|
||||
RLAPI void UpdateSound(Sound sound, const void *data, int numSamples);// Update sound buffer with new data
|
||||
RLAPI void UpdateSound(Sound sound, const void *data, int samplesCount);// Update sound buffer with new data
|
||||
RLAPI void UnloadWave(Wave wave); // Unload wave data
|
||||
RLAPI void UnloadSound(Sound sound); // Unload sound
|
||||
RLAPI void PlaySound(Sound sound); // Play a sound
|
||||
@ -984,7 +993,7 @@ RLAPI float GetMusicTimePlayed(Music music); // Get cur
|
||||
RLAPI AudioStream InitAudioStream(unsigned int sampleRate,
|
||||
unsigned int sampleSize,
|
||||
unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
||||
RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int numSamples); // Update audio stream buffers with data
|
||||
RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
|
||||
RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
|
||||
RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
|
||||
RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream
|
||||
|
@ -1,23 +1,24 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raymath (header only file)
|
||||
* raymath v1.0 - Some useful functions to work with Vector3, Matrix and Quaternions
|
||||
*
|
||||
* Some useful functions to work with Vector3, Matrix and Quaternions
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* You must:
|
||||
* #define RAYMATH_IMPLEMENTATION
|
||||
* before you include this file in *only one* C or C++ file to create the implementation.
|
||||
* #define RAYMATH_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* Example:
|
||||
* #define RAYMATH_IMPLEMENTATION
|
||||
* #include "raymath.h"
|
||||
* #define RAYMATH_EXTERN_INLINE
|
||||
* Inlines all functions code, so it runs faster. This requires lots of memory on system.
|
||||
*
|
||||
* You can also use:
|
||||
* #define RAYMATH_EXTERN_INLINE // Inlines all functions code, so it runs faster.
|
||||
* // This requires lots of memory on system.
|
||||
* #define RAYMATH_STANDALONE // Not dependent on raylib.h structs: Vector3, Matrix.
|
||||
* #define RAYMATH_STANDALONE
|
||||
* Avoid raylib.h header inclusion in this file.
|
||||
* Vector3 and Matrix data types are defined internally in raymath module.
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
|
46
src/rlgl.c
46
src/rlgl.c
@ -2,6 +2,8 @@
|
||||
*
|
||||
* rlgl - raylib OpenGL abstraction layer
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* rlgl allows usage of OpenGL 1.1 style functions (rlVertex) that are internally mapped to
|
||||
* selected OpenGL version (1.1, 2.1, 3.3 Core, ES 2.0).
|
||||
*
|
||||
@ -11,20 +13,44 @@
|
||||
* rlglDraw() - Process internal buffers and send required draw calls
|
||||
* rlglClose() - De-initialize internal buffers data and other auxiliar resources
|
||||
*
|
||||
* External libs:
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define GRAPHICS_API_OPENGL_11
|
||||
* Use OpenGL 1.1 backend
|
||||
*
|
||||
* #define GRAPHICS_API_OPENGL_21
|
||||
* Use OpenGL 2.1 backend
|
||||
*
|
||||
* #define GRAPHICS_API_OPENGL_33
|
||||
* Use OpenGL 3.3 Core profile backend
|
||||
*
|
||||
* #define GRAPHICS_API_OPENGL_ES2
|
||||
* Use OpenGL ES 2.0 backend
|
||||
*
|
||||
* #define RLGL_STANDALONE
|
||||
* Use rlgl as standalone library (no raylib dependency)
|
||||
*
|
||||
* #define RLGL_NO_DISTORTION_SHADER
|
||||
* Avoid stereo rendering distortion sahder (shader_distortion.h) inclusion
|
||||
*
|
||||
* #define SUPPORT_SHADER_DEFAULT / ENABLE_SHADER_DEFAULT
|
||||
*
|
||||
* #define SUPPORT_SHADER_DISTORTION
|
||||
*
|
||||
*
|
||||
* #define SUPPORT_OCULUS_RIFT_CV1 / RLGL_OCULUS_SUPPORT
|
||||
* Enable Oculus Rift CV1 functionality
|
||||
*
|
||||
* #define SUPPORT_STEREO_RENDERING
|
||||
*
|
||||
* #define RLGL_NO_DEFAULT_SHADER
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
|
||||
* GLAD - OpenGL extensions loading (OpenGL 3.3 Core only)
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* GRAPHICS_API_OPENGL_11 - Use OpenGL 1.1 backend
|
||||
* GRAPHICS_API_OPENGL_21 - Use OpenGL 2.1 backend
|
||||
* GRAPHICS_API_OPENGL_33 - Use OpenGL 3.3 Core profile backend
|
||||
* GRAPHICS_API_OPENGL_ES2 - Use OpenGL ES 2.0 backend
|
||||
*
|
||||
* RLGL_STANDALONE - Use rlgl as standalone library (no raylib dependency)
|
||||
* RLGL_NO_DISTORTION_SHADER - Avoid stereo rendering distortion sahder (shader_distortion.h) inclusion
|
||||
* RLGL_OCULUS_SUPPORT - Enable Oculus Rift CV1 functionality
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
|
127
src/rres.h
127
src/rres.h
@ -4,14 +4,18 @@
|
||||
*
|
||||
* Basic functions to load/save rRES resource files
|
||||
*
|
||||
* External libs:
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define RREM_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* tinfl - DEFLATE decompression functions
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
*
|
||||
* #define RREM_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2016-2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
@ -62,7 +66,7 @@
|
||||
#if defined(RRES_STANDALONE)
|
||||
// rRES data returned when reading a resource, it contains all required data for user (24 byte)
|
||||
// NOTE: Using void *data pointer, so we can load to image.data, wave.data, mesh.*, (unsigned char *)
|
||||
typedef struct {
|
||||
typedef struct RRESData {
|
||||
unsigned int type; // Resource type (4 byte)
|
||||
|
||||
unsigned int param1; // Resouce parameter 1 (4 byte)
|
||||
@ -73,6 +77,7 @@
|
||||
void *data; // Resource data pointer (4 byte)
|
||||
} RRESData;
|
||||
|
||||
// RRESData type
|
||||
typedef enum {
|
||||
RRES_TYPE_RAW = 0,
|
||||
RRES_TYPE_IMAGE,
|
||||
@ -80,9 +85,12 @@
|
||||
RRES_TYPE_VERTEX,
|
||||
RRES_TYPE_TEXT,
|
||||
RRES_TYPE_FONT_IMAGE,
|
||||
RRES_TYPE_FONT_DATA, // Character { int value, recX, recY, recWidth, recHeight, offsetX, offsetY, xAdvance }
|
||||
RRES_TYPE_FONT_CHARDATA, // Character { int value, recX, recY, recWidth, recHeight, offsetX, offsetY, xAdvance }
|
||||
RRES_TYPE_DIRECTORY
|
||||
} RRESDataType;
|
||||
|
||||
// RRES type (pointer to RRESData array)
|
||||
typedef struct RRESData *RRES;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -93,9 +101,9 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
RRESDEF RRESData LoadResource(const char *rresFileName);
|
||||
RRESDEF RRESData LoadResourceById(const char *rresFileName, int rresId);
|
||||
RRESDEF void UnloadResource(RRESData rres);
|
||||
//RRESDEF RRESData LoadResourceData(const char *rresFileName, int rresId, int part);
|
||||
RRESDEF RRES LoadResource(const char *fileName, int rresId);
|
||||
RRESDEF void UnloadResource(RRES rres);
|
||||
|
||||
#endif // RRES_H
|
||||
|
||||
@ -235,23 +243,11 @@ static void *DecompressData(const unsigned char *data, unsigned long compSize, i
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Load resource from file (only one)
|
||||
// NOTE: Returns uncompressed data with parameters, only first resource found
|
||||
RRESDEF RRESData LoadResource(const char *fileName)
|
||||
{
|
||||
// Force loading first resource available
|
||||
RRESData rres = { 0 };
|
||||
|
||||
rres = LoadResourceById(fileName, 0);
|
||||
|
||||
return rres;
|
||||
}
|
||||
|
||||
// Load resource from file by id
|
||||
// Load resource from file by id (could be multiple parts)
|
||||
// NOTE: Returns uncompressed data with parameters, search resource by id
|
||||
RRESDEF RRESData LoadResourceById(const char *fileName, int rresId)
|
||||
RRESDEF RRES LoadResource(const char *fileName, int rresId)
|
||||
{
|
||||
RRESData rres = { 0 };
|
||||
RRES rres = { 0 };
|
||||
|
||||
RRESFileHeader fileHeader;
|
||||
RRESInfoHeader infoHeader;
|
||||
@ -281,32 +277,41 @@ RRESDEF RRESData LoadResourceById(const char *fileName, int rresId)
|
||||
// Read resource info and parameters
|
||||
fread(&infoHeader, sizeof(RRESInfoHeader), 1, rresFile);
|
||||
|
||||
rres = (RRES)malloc(sizeof(RRESData)*infoHeader.partsCount);
|
||||
|
||||
if (infoHeader.id == rresId)
|
||||
{
|
||||
// Register data type and parameters
|
||||
rres.type = infoHeader.dataType;
|
||||
rres.param1 = infoHeader.param1;
|
||||
rres.param2 = infoHeader.param2;
|
||||
rres.param3 = infoHeader.param3;
|
||||
rres.param4 = infoHeader.param4;
|
||||
|
||||
// Read resource data block
|
||||
void *data = RRES_MALLOC(infoHeader.dataSize);
|
||||
fread(data, infoHeader.dataSize, 1, rresFile);
|
||||
|
||||
if (infoHeader.compType == RRES_COMP_DEFLATE)
|
||||
// Load all required resources parts
|
||||
for (int k = 0; k < infoHeader.partsCount; k++)
|
||||
{
|
||||
void *uncompData = DecompressData(data, infoHeader.dataSize, infoHeader.uncompSize);
|
||||
// TODO: Verify again that rresId is the same in every part
|
||||
|
||||
rres.data = uncompData;
|
||||
// Register data type and parameters
|
||||
rres[k].type = infoHeader.dataType;
|
||||
rres[k].param1 = infoHeader.param1;
|
||||
rres[k].param2 = infoHeader.param2;
|
||||
rres[k].param3 = infoHeader.param3;
|
||||
rres[k].param4 = infoHeader.param4;
|
||||
|
||||
RRES_FREE(data);
|
||||
// Read resource data block
|
||||
void *data = RRES_MALLOC(infoHeader.dataSize);
|
||||
fread(data, infoHeader.dataSize, 1, rresFile);
|
||||
|
||||
if (infoHeader.compType == RRES_COMP_DEFLATE)
|
||||
{
|
||||
void *uncompData = DecompressData(data, infoHeader.dataSize, infoHeader.uncompSize);
|
||||
|
||||
rres[k].data = uncompData;
|
||||
|
||||
RRES_FREE(data);
|
||||
}
|
||||
else rres[k].data = data;
|
||||
|
||||
if (rres[k].data != NULL) TraceLog(INFO, "[%s][ID %i] Resource data loaded successfully", fileName, (int)infoHeader.id);
|
||||
|
||||
// Read next part
|
||||
fread(&infoHeader, sizeof(RRESInfoHeader), 1, rresFile);
|
||||
}
|
||||
else rres.data = data;
|
||||
|
||||
if (rres.data != NULL) TraceLog(INFO, "[%s][ID %i] Resource data loaded successfully", fileName, (int)infoHeader.id);
|
||||
|
||||
if (rresId == 0) break; // Break for loop, do not check next resource
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -315,7 +320,7 @@ RRESDEF RRESData LoadResourceById(const char *fileName, int rresId)
|
||||
}
|
||||
}
|
||||
|
||||
if (rres.data == NULL) TraceLog(WARNING, "[%s][ID %i] Requested resource could not be found", fileName, (int)rresId);
|
||||
if (rres[0].data == NULL) TraceLog(WARNING, "[%s][ID %i] Requested resource could not be found", fileName, (int)rresId);
|
||||
}
|
||||
|
||||
fclose(rresFile);
|
||||
@ -324,9 +329,9 @@ RRESDEF RRESData LoadResourceById(const char *fileName, int rresId)
|
||||
return rres;
|
||||
}
|
||||
|
||||
RRESDEF void UnloadResource(RRESData rres)
|
||||
RRESDEF void UnloadResource(RRES rres)
|
||||
{
|
||||
if (rres.data != NULL) free(rres.data);
|
||||
if (rres[0].data != NULL) free(rres[0].data);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -372,7 +377,6 @@ static void *DecompressData(const unsigned char *data, unsigned long compSize, i
|
||||
return uncompData;
|
||||
}
|
||||
|
||||
|
||||
// Some required functions for rres standalone module version
|
||||
#if defined(RRES_STANDALONE)
|
||||
// Outputs a trace log message (INFO, ERROR, WARNING)
|
||||
@ -417,22 +421,19 @@ Mesh LoadMeshEx(rres.param1, rres.data, rres.data + offset, rres.data + offset*2
|
||||
Shader LoadShader(const char *vsText, int vsLength);
|
||||
Shader LoadShaderV(rres.data, rres.param1);
|
||||
|
||||
// Parameters information depending on resource type (IMAGE, WAVE, MESH, TEXT)
|
||||
// Parameters information depending on resource type
|
||||
|
||||
// Image data params
|
||||
int imgWidth, imgHeight;
|
||||
char colorFormat, mipmaps;
|
||||
// RRES_TYPE_IMAGE params: imgWidth, imgHeight, format, mipmaps;
|
||||
// RRES_TYPE_WAVE params: sampleCount, sampleRate, sampleSize, channels;
|
||||
// RRES_TYPE_FONT_IMAGE params: imgWidth, imgHeight, format, mipmaps;
|
||||
// RRES_TYPE_FONT_DATA params: charsCount, baseSize
|
||||
// RRES_TYPE_VERTEX params: vertexCount, vertexType, vertexFormat // Use masks instead?
|
||||
// RRES_TYPE_TEXT params: charsCount, cultureCode
|
||||
// RRES_TYPE_DIRECTORY params: fileCount, directoryCount
|
||||
|
||||
// Wave data params
|
||||
int sampleCount,
|
||||
short sampleRate, bps;
|
||||
char channels, reserved;
|
||||
// SpriteFont = RRES_TYPE_FONT_IMAGE chunk + RRES_TYPE_FONT_DATA chunk
|
||||
// Mesh = multiple RRES_TYPE_VERTEX chunks
|
||||
|
||||
// Mesh data params
|
||||
int vertexCount, reserved;
|
||||
short vertexTypesMask, vertexFormatsMask;
|
||||
Ref: RIFF file-format: http://www.johnloomis.org/cpe102/asgn/asgn1/riff.html
|
||||
|
||||
// Text data params
|
||||
int charsCount;
|
||||
int cultureCode;
|
||||
*/
|
38
src/shapes.c
38
src/shapes.c
@ -1,14 +1,17 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.shapes
|
||||
* raylib.shapes - Basic functions to draw 2d Shapes and check collisions
|
||||
*
|
||||
* Basic functions to draw 2d Shapes and check collisions
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* External libs:
|
||||
* rlgl - raylib OpenGL abstraction layer
|
||||
* #define SUPPORT_QUADS_ONLY
|
||||
* Draw shapes using only QUADS, vertex are accumulated in QUADS arrays (like textures)
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* ...
|
||||
* #define SUPPORT_TRIANGLES_ONLY
|
||||
* Draw shapes using only TRIANGLES, vertex are accumulated in TRIANGLES arrays
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
@ -190,6 +193,29 @@ void DrawRectangleRec(Rectangle rec, Color color)
|
||||
DrawRectangle(rec.x, rec.y, rec.width, rec.height, color);
|
||||
}
|
||||
|
||||
void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color)
|
||||
{
|
||||
rlEnableTexture(GetDefaultTexture().id);
|
||||
|
||||
rlPushMatrix();
|
||||
rlTranslatef((float)rec.x, (float)rec.y, 0);
|
||||
rlRotatef(rotation, 0, 0, 1);
|
||||
rlTranslatef(-origin.x, -origin.y, 0);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
|
||||
|
||||
rlVertex2f(0.0f, 0.0f);
|
||||
rlVertex2f(0.0f, (float)rec.height);
|
||||
rlVertex2f((float)rec.width, (float)rec.height);
|
||||
rlVertex2f((float)rec.width, 0.0f);
|
||||
rlEnd();
|
||||
rlPopMatrix();
|
||||
|
||||
rlDisableTexture();
|
||||
}
|
||||
|
||||
// Draw a gradient-filled rectangle
|
||||
// NOTE: Gradient goes from bottom (color1) to top (color2)
|
||||
void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2)
|
||||
|
43
src/text.c
43
src/text.c
@ -1,14 +1,22 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.text
|
||||
* raylib.text - Basic functions to load SpriteFonts and draw Text
|
||||
*
|
||||
* Basic functions to load SpriteFonts and draw Text
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* External libs:
|
||||
* #define SUPPORT_FILEFORMAT_FNT
|
||||
* #define SUPPORT_FILEFORMAT_TTF / INCLUDE_STB_TRUETYPE
|
||||
* #define SUPPORT_FILEFORMAT_IMAGE_FONT
|
||||
* Selected desired fileformats to be supported for loading. Some of those formats are
|
||||
* supported by default, to remove support, just comment unrequired #define in this module
|
||||
*
|
||||
* #define INCLUDE_DEFAULT_FONT / SUPPORT_DEFAULT_FONT
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* stb_truetype - Load TTF file and rasterize characters data
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* ...
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
@ -262,30 +270,28 @@ SpriteFont LoadSpriteFont(const char *fileName)
|
||||
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
||||
{
|
||||
// TODO: Read multiple resource blocks from file (RRES_FONT_IMAGE, RRES_FONT_CHARDATA)
|
||||
RRESData rres = LoadResource(fileName);
|
||||
RRES rres = LoadResource(fileName, 0);
|
||||
|
||||
// Load sprite font texture
|
||||
/*
|
||||
if (rres.type == RRES_FONT_IMAGE)
|
||||
if (rres[0].type == RRES_TYPE_FONT_IMAGE)
|
||||
{
|
||||
// NOTE: Parameters for RRES_FONT_IMAGE type are: width, height, format, mipmaps
|
||||
Image image = LoadImagePro(rres.data, rres.param1, rres.param2, rres.param3);
|
||||
Image image = LoadImagePro(rres[0].data, rres[0].param1, rres[0].param2, rres[0].param3);
|
||||
spriteFont.texture = LoadTextureFromImage(image);
|
||||
UnloadImage(image);
|
||||
}
|
||||
|
||||
// Load sprite characters data
|
||||
if (rres.type == RRES_FONT_CHARDATA)
|
||||
if (rres[1].type == RRES_TYPE_FONT_CHARDATA)
|
||||
{
|
||||
// NOTE: Parameters for RRES_FONT_CHARDATA type are: fontSize, charsCount
|
||||
spriteFont.baseSize = rres.param1;
|
||||
spriteFont.charsCount = rres.param2;
|
||||
spriteFont.chars = rres.data;
|
||||
spriteFont.baseSize = rres[1].param1;
|
||||
spriteFont.charsCount = rres[1].param2;
|
||||
spriteFont.chars = rres[1].data;
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Do not free rres.data memory (chars info data!)
|
||||
UnloadResource(rres);
|
||||
//UnloadResource(rres[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -928,6 +934,8 @@ static SpriteFont LoadBMFont(const char *fileName)
|
||||
// TODO: Review texture packing method and generation (use oversampling)
|
||||
static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars)
|
||||
{
|
||||
#define MAX_TTF_SIZE 16 // Maximum ttf file size in MB
|
||||
|
||||
// NOTE: Font texture size is predicted (being as much conservative as possible)
|
||||
// Predictive method consist of supposing same number of chars by line-column (sqrtf)
|
||||
// and a maximum character width of 3/4 of fontSize... it worked ok with all my tests...
|
||||
@ -938,7 +946,7 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||
|
||||
TraceLog(INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize);
|
||||
|
||||
unsigned char *ttfBuffer = (unsigned char *)malloc(1 << 25);
|
||||
unsigned char *ttfBuffer = (unsigned char *)malloc(MAX_TTF_SIZE*1024*1024);
|
||||
unsigned char *dataBitmap = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)); // One channel bitmap returned!
|
||||
stbtt_bakedchar *charData = (stbtt_bakedchar *)malloc(sizeof(stbtt_bakedchar)*charsCount);
|
||||
|
||||
@ -952,7 +960,8 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||
return font;
|
||||
}
|
||||
|
||||
fread(ttfBuffer, 1, 1 << 25, ttfFile);
|
||||
// NOTE: We try reading up to 16 MB of elements of 1 byte
|
||||
fread(ttfBuffer, 1, MAX_TTF_SIZE*1024*1024, ttfFile);
|
||||
|
||||
if (fontChars[0] != 32) TraceLog(WARNING, "TTF spritefont loading: first character is not SPACE(32) character");
|
||||
|
||||
|
@ -1,16 +1,35 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.textures
|
||||
* raylib.textures - Basic functions to load and draw Textures (2d)
|
||||
*
|
||||
* Basic functions to load and draw Textures (2d)
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* External libs:
|
||||
* #define SUPPORT_STB_IMAGE / INCLUDE_STB_IMAGE
|
||||
*
|
||||
* #define SUPPORT_FILEFORMAT_BMP / SUPPORT_LOAD_BMP
|
||||
* #define SUPPORT_FILEFORMAT_PNG / SUPPORT_LOAD_PNG
|
||||
* #define SUPPORT_FILEFORMAT_TGA
|
||||
* #define SUPPORT_FILEFORMAT_JPG / ENABLE_LOAD_JPG
|
||||
* #define SUPPORT_FILEFORMAT_GIF
|
||||
* #define SUPPORT_FILEFORMAT_HDR
|
||||
* #define SUPPORT_FILEFORMAT_DDS / ENABLE_LOAD_DDS
|
||||
* #define SUPPORT_FILEFORMAT_PKM
|
||||
* #define SUPPORT_FILEFORMAT_KTX
|
||||
* #define SUPPORT_FILEFORMAT_PVR
|
||||
* #define SUPPORT_FILEFORMAT_ASTC
|
||||
* Selected desired fileformats to be supported for loading. Some of those formats are
|
||||
* supported by default, to remove support, just comment unrequired #define in this module
|
||||
*
|
||||
* #define SUPPORT_IMAGE_RESIZE / INCLUDE_STB_IMAGE_RESIZE
|
||||
* #define SUPPORT_IMAGE_MANIPULATION
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* stb_image - Multiple image formats loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC)
|
||||
* NOTE: stb_image has been slightly modified to support Android platform.
|
||||
* stb_image_resize - Multiple image resize algorythms
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* ...
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
@ -143,11 +162,11 @@ Image LoadImage(const char *fileName)
|
||||
else if (strcmp(GetExtension(fileName),"astc") == 0) image = LoadASTC(fileName);
|
||||
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
||||
{
|
||||
RRESData rres = LoadResource(fileName);
|
||||
RRES rres = LoadResource(fileName, 0);
|
||||
|
||||
// NOTE: Parameters for RRES_IMAGE type are: width, height, format, mipmaps
|
||||
// NOTE: Parameters for RRES_TYPE_IMAGE are: width, height, format, mipmaps
|
||||
|
||||
if (rres.type == RRES_IMAGE) image = LoadImagePro(rres.data, rres.param1, rres.param2, rres.param3);
|
||||
if (rres[0].type == RRES_TYPE_IMAGE) image = LoadImagePro(rres[0].data, rres[0].param1, rres[0].param2, rres[0].param3);
|
||||
else TraceLog(WARNING, "[%s] Resource file does not contain image data", fileName);
|
||||
|
||||
UnloadResource(rres);
|
||||
@ -238,7 +257,9 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
|
||||
default: TraceLog(WARNING, "Image format not suported"); break;
|
||||
}
|
||||
|
||||
int bytes = fread(image.data, size, 1, rawFile);
|
||||
// NOTE: fread() returns num read elements instead of bytes,
|
||||
// to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element)
|
||||
int bytes = fread(image.data, 1, size, rawFile);
|
||||
|
||||
// Check if data has been read successfully
|
||||
if (bytes < size)
|
||||
@ -1591,7 +1612,7 @@ static Image LoadDDS(const char *fileName)
|
||||
// Verify the type of file
|
||||
char filecode[4];
|
||||
|
||||
fread(filecode, 1, 4, ddsFile);
|
||||
fread(filecode, 4, 1, ddsFile);
|
||||
|
||||
if (strncmp(filecode, "DDS ", 4) != 0)
|
||||
{
|
||||
@ -1690,17 +1711,17 @@ static Image LoadDDS(const char *fileName)
|
||||
}
|
||||
else if (((ddsHeader.ddspf.flags == 0x04) || (ddsHeader.ddspf.flags == 0x05)) && (ddsHeader.ddspf.fourCC > 0)) // Compressed
|
||||
{
|
||||
int bufsize;
|
||||
int size; // DDS image data size
|
||||
|
||||
// Calculate data size, including all mipmaps
|
||||
if (ddsHeader.mipmapCount > 1) bufsize = ddsHeader.pitchOrLinearSize*2;
|
||||
else bufsize = ddsHeader.pitchOrLinearSize;
|
||||
if (ddsHeader.mipmapCount > 1) size = ddsHeader.pitchOrLinearSize*2;
|
||||
else size = ddsHeader.pitchOrLinearSize;
|
||||
|
||||
TraceLog(DEBUG, "Pitch or linear size: %i", ddsHeader.pitchOrLinearSize);
|
||||
|
||||
image.data = (unsigned char*)malloc(bufsize*sizeof(unsigned char));
|
||||
image.data = (unsigned char*)malloc(size*sizeof(unsigned char));
|
||||
|
||||
fread(image.data, 1, bufsize, ddsFile);
|
||||
fread(image.data, size, 1, ddsFile);
|
||||
|
||||
image.mipmaps = ddsHeader.mipmapCount;
|
||||
|
||||
@ -1803,7 +1824,7 @@ static Image LoadPKM(const char *fileName)
|
||||
|
||||
image.data = (unsigned char*)malloc(size*sizeof(unsigned char));
|
||||
|
||||
fread(image.data, 1, size, pkmFile);
|
||||
fread(image.data, size, 1, pkmFile);
|
||||
|
||||
if (pkmHeader.format == 0) image.format = COMPRESSED_ETC1_RGB;
|
||||
else if (pkmHeader.format == 1) image.format = COMPRESSED_ETC2_RGB;
|
||||
@ -1888,7 +1909,7 @@ static Image LoadKTX(const char *fileName)
|
||||
|
||||
if (ktxHeader.keyValueDataSize > 0)
|
||||
{
|
||||
for (int i = 0; i < ktxHeader.keyValueDataSize; i++) fread(&unused, 1, 1, ktxFile);
|
||||
for (int i = 0; i < ktxHeader.keyValueDataSize; i++) fread(&unused, sizeof(unsigned char), 1, ktxFile);
|
||||
}
|
||||
|
||||
int dataSize;
|
||||
@ -1896,7 +1917,7 @@ static Image LoadKTX(const char *fileName)
|
||||
|
||||
image.data = (unsigned char*)malloc(dataSize*sizeof(unsigned char));
|
||||
|
||||
fread(image.data, 1, dataSize, ktxFile);
|
||||
fread(image.data, dataSize, 1, ktxFile);
|
||||
|
||||
if (ktxHeader.glInternalFormat == 0x8D64) image.format = COMPRESSED_ETC1_RGB;
|
||||
else if (ktxHeader.glInternalFormat == 0x9274) image.format = COMPRESSED_ETC2_RGB;
|
||||
|
19
src/utils.c
19
src/utils.c
@ -1,16 +1,23 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.utils
|
||||
* raylib.utils - Some common utility functions
|
||||
*
|
||||
* Some utility functions
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* External libs:
|
||||
* tinfl - zlib DEFLATE algorithm decompression
|
||||
* #define SUPPORT_SAVE_PNG
|
||||
* Enable saving PNG fileformat
|
||||
* NOTE: Requires stb_image_write library
|
||||
*
|
||||
* #define SUPPORT_SAVE_BMP
|
||||
*
|
||||
* #define DO_NOT_TRACE_DEBUG_MSGS
|
||||
* Avoid showing DEBUG TraceLog() messages
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* stb_image_write - PNG writting functions
|
||||
*
|
||||
* Module Configuration Flags:
|
||||
* DO_NOT_TRACE_DEBUG_MSGS - Avoid showing DEBUG TraceLog() messages
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user