aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio.c98
-rw-r--r--src/core.c100
-rw-r--r--src/models.c66
-rw-r--r--src/raylib.h26
-rw-r--r--src/rlgl.c488
-rw-r--r--src/text.c60
-rw-r--r--src/textures.c52
7 files changed, 445 insertions, 445 deletions
diff --git a/src/audio.c b/src/audio.c
index 74a54b04..22da74be 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -231,9 +231,9 @@ Wave LoadWave(const char *fileName)
else if (strcmp(GetExtension(fileName),"rres") == 0)
{
RRESData rres = LoadResource(fileName);
-
+
// NOTE: Parameters for RRES_WAVE type are: sampleCount, sampleRate, sampleSize, channels
-
+
if (rres.type == RRES_WAVE) wave = LoadWaveEx(rres.data, rres.param1, rres.param2, rres.param3, rres.param4);
else TraceLog(WARNING, "[%s] Resource file does not contain wave data", fileName);
@@ -248,18 +248,18 @@ Wave LoadWave(const char *fileName)
Wave LoadWaveEx(void *data, int sampleCount, int sampleRate, int sampleSize, int channels)
{
Wave wave;
-
+
wave.data = data;
wave.sampleCount = sampleCount;
wave.sampleRate = sampleRate;
wave.sampleSize = sampleSize;
wave.channels = channels;
-
+
// NOTE: Copy wave data to work with, user is responsible of input data to free
Wave cwave = WaveCopy(wave);
-
+
WaveFormat(&cwave, sampleRate, sampleSize, channels);
-
+
return cwave;
}
@@ -268,9 +268,9 @@ Wave LoadWaveEx(void *data, int sampleCount, int sampleRate, int sampleSize, int
Sound LoadSound(const char *fileName)
{
Wave wave = LoadWave(fileName);
-
+
Sound sound = LoadSoundFromWave(wave);
-
+
UnloadWave(wave); // Sound is loaded, we can unload wave
return sound;
@@ -354,7 +354,7 @@ void UnloadWave(Wave wave)
void UnloadSound(Sound sound)
{
alSourceStop(sound.source);
-
+
alDeleteSources(1, &sound.source);
alDeleteBuffers(1, &sound.buffer);
@@ -369,13 +369,13 @@ void UpdateSound(Sound sound, const void *data, int numSamples)
alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
alGetBufferi(sound.buffer, AL_BITS, &sampleSize); // It could also be retrieved from sound.format
alGetBufferi(sound.buffer, AL_CHANNELS, &channels); // It could also be retrieved from sound.format
-
+
TraceLog(DEBUG, "UpdateSound() : AL_FREQUENCY: %i", sampleRate);
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
-
+
alSourceStop(sound.source); // Stop sound
alSourcei(sound.source, AL_BUFFER, 0); // Unbind buffer from sound to update
//alDeleteBuffers(1, &sound.buffer); // Delete current buffer data
@@ -463,18 +463,18 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
if (wave->sampleRate != sampleRate)
{
// TODO: Resample wave data (upsampling or downsampling)
- // NOTE 1: To downsample, you have to drop samples or average them.
+ // NOTE 1: To downsample, you have to drop samples or average them.
// NOTE 2: To upsample, you have to interpolate new samples.
-
+
wave->sampleRate = sampleRate;
}
-
+
// Format sample size
// NOTE: Only supported 8 bit <--> 16 bit <--> 32 bit
if (wave->sampleSize != sampleSize)
{
void *data = malloc(wave->sampleCount*wave->channels*sampleSize/8);
-
+
for (int i = 0; i < wave->sampleCount; i++)
{
for (int j = 0; j < wave->channels; j++)
@@ -484,30 +484,30 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
if (wave->sampleSize == 16) ((unsigned char *)data)[wave->channels*i + j] = (unsigned char)(((float)(((short *)wave->data)[wave->channels*i + j])/32767.0f)*256);
else if (wave->sampleSize == 32) ((unsigned char *)data)[wave->channels*i + j] = (unsigned char)(((float *)wave->data)[wave->channels*i + j]*127.0f + 127);
}
- else if (sampleSize == 16)
+ else if (sampleSize == 16)
{
if (wave->sampleSize == 8) ((short *)data)[wave->channels*i + j] = (short)(((float)(((unsigned char *)wave->data)[wave->channels*i + j] - 127)/256.0f)*32767);
else if (wave->sampleSize == 32) ((short *)data)[wave->channels*i + j] = (short)((((float *)wave->data)[wave->channels*i + j])*32767);
}
- else if (sampleSize == 32)
+ else if (sampleSize == 32)
{
if (wave->sampleSize == 8) ((float *)data)[wave->channels*i + j] = (float)(((unsigned char *)wave->data)[wave->channels*i + j] - 127)/256.0f;
else if (wave->sampleSize == 16) ((float *)data)[wave->channels*i + j] = (float)(((short *)wave->data)[wave->channels*i + j])/32767.0f;
}
}
}
-
+
wave->sampleSize = sampleSize;
free(wave->data);
wave->data = data;
}
-
+
// Format channels (interlaced mode)
// NOTE: Only supported mono <--> stereo
if (wave->channels != channels)
{
void *data = malloc(wave->sampleCount*channels*wave->sampleSize/8);
-
+
if ((wave->channels == 1) && (channels == 2)) // mono ---> stereo (duplicate mono information)
{
for (int i = 0; i < wave->sampleCount; i++)
@@ -529,7 +529,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
else if (wave->sampleSize == 32) ((float *)data)[i] = (((float *)wave->data)[j] + ((float *)wave->data)[j + 1])/2.0f;
}
}
-
+
// TODO: Add/remove additional interlaced channels
wave->channels = channels;
@@ -563,15 +563,15 @@ Wave WaveCopy(Wave wave)
// NOTE: Security check in case of out-of-range
void WaveCrop(Wave *wave, int initSample, int finalSample)
{
- if ((initSample >= 0) && (initSample < finalSample) &&
+ if ((initSample >= 0) && (initSample < finalSample) &&
(finalSample > 0) && (finalSample < wave->sampleCount))
{
int sampleCount = finalSample - initSample;
-
+
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);
-
+
free(wave->data);
wave->data = data;
}
@@ -583,7 +583,7 @@ void WaveCrop(Wave *wave, int initSample, int finalSample)
float *GetWaveData(Wave wave)
{
float *samples = (float *)malloc(wave.sampleCount*wave.channels*sizeof(float));
-
+
for (int i = 0; i < wave.sampleCount; i++)
{
for (int j = 0; j < wave.channels; j++)
@@ -593,7 +593,7 @@ float *GetWaveData(Wave wave)
else if (wave.sampleSize == 32) samples[wave.channels*i + j] = ((float *)wave.data)[wave.channels*i + j];
}
}
-
+
return samples;
}
@@ -632,7 +632,7 @@ Music LoadMusicStream(const char *fileName)
else if (strcmp(GetExtension(fileName), "flac") == 0)
{
music->ctxFlac = drflac_open_file(fileName);
-
+
if (music->ctxFlac == NULL) TraceLog(WARNING, "[%s] FLAC audio file could not be opened", fileName);
else
{
@@ -641,7 +641,7 @@ Music LoadMusicStream(const char *fileName)
music->samplesLeft = music->totalSamples;
music->ctxType = MUSIC_AUDIO_FLAC;
music->loop = true; // We loop by default
-
+
TraceLog(DEBUG, "[%s] FLAC total samples: %i", fileName, music->totalSamples);
TraceLog(DEBUG, "[%s] FLAC sample rate: %i", fileName, music->ctxFlac->sampleRate);
TraceLog(DEBUG, "[%s] FLAC bits per sample: %i", fileName, music->ctxFlac->bitsPerSample);
@@ -728,7 +728,7 @@ void ResumeMusicStream(Music music)
void StopMusicStream(Music music)
{
alSourceStop(music->stream.source);
-
+
switch (music->ctxType)
{
case MUSIC_AUDIO_OGG: stb_vorbis_seek_start(music->ctxOgg); break;
@@ -736,7 +736,7 @@ void StopMusicStream(Music music)
case MUSIC_MODULE_MOD: jar_mod_seek_start(&music->ctxMod); break;
default: break;
}
-
+
music->samplesLeft = music->totalSamples;
}
@@ -745,14 +745,14 @@ void UpdateMusicStream(Music music)
{
ALenum state;
ALint processed = 0;
-
+
alGetSourcei(music->stream.source, AL_SOURCE_STATE, &state); // Get music stream state
alGetSourcei(music->stream.source, AL_BUFFERS_PROCESSED, &processed); // Get processed buffers
if (processed > 0)
{
bool active = true;
-
+
// NOTE: Using dynamic allocation because it could require more than 16KB
void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.channels*music->stream.sampleSize/8, 1);
@@ -764,7 +764,7 @@ void UpdateMusicStream(Music music)
{
if (music->samplesLeft >= AUDIO_BUFFER_SIZE) numSamples = AUDIO_BUFFER_SIZE;
else numSamples = music->samplesLeft;
-
+
// TODO: Really don't like ctxType thingy...
switch (music->ctxType)
{
@@ -784,7 +784,7 @@ void UpdateMusicStream(Music music)
case MUSIC_MODULE_MOD: jar_mod_fillbuffer(&music->ctxMod, pcm, numSamples, 0); break;
default: break;
}
-
+
UpdateAudioStream(music->stream, pcm, numSamples);
music->samplesLeft -= numSamples;
@@ -794,12 +794,12 @@ void UpdateMusicStream(Music music)
break;
}
}
-
+
// This error is registered when UpdateAudioStream() fails
if (alGetError() == AL_INVALID_VALUE) TraceLog(WARNING, "OpenAL: Error buffering data...");
// Reset audio stream for looping
- if (!active)
+ if (!active)
{
StopMusicStream(music); // Stop music (and reset)
if (music->loop) PlayMusicStream(music); // Play again
@@ -810,7 +810,7 @@ void UpdateMusicStream(Music music)
// just make sure to play again on window restore
if (state != AL_PLAYING) PlayMusicStream(music);
}
-
+
free(pcm);
}
}
@@ -866,7 +866,7 @@ AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, un
stream.sampleRate = sampleRate;
stream.sampleSize = sampleSize;
-
+
// Only mono and stereo channels are supported, more channels require AL_EXT_MCFORMATS extension
if ((channels > 0) && (channels < 3)) stream.channels = channels;
else
@@ -910,12 +910,12 @@ AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, un
// Initialize buffer with zeros by default
// NOTE: Using dynamic allocation because it requires more than 16KB
void *pcm = calloc(AUDIO_BUFFER_SIZE*stream.sampleSize/8*stream.channels, 1);
-
+
for (int i = 0; i < MAX_STREAM_BUFFERS; i++)
{
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*stream.sampleSize/8*stream.channels, stream.sampleRate);
}
-
+
free(pcm);
alSourceQueueBuffers(stream.source, MAX_STREAM_BUFFERS, stream.buffers);
@@ -1095,7 +1095,7 @@ static Wave LoadWAV(const char *fileName)
wave.sampleRate = wavFormat.sampleRate;
wave.sampleSize = wavFormat.bitsPerSample;
wave.channels = wavFormat.numChannels;
-
+
// NOTE: Only support 8 bit, 16 bit and 32 bit sample sizes
if ((wave.sampleSize != 8) && (wave.sampleSize != 16) && (wave.sampleSize != 32))
{
@@ -1104,16 +1104,16 @@ static Wave LoadWAV(const char *fileName)
}
// NOTE: Only support up to 2 channels (mono, stereo)
- if (wave.channels > 2)
+ if (wave.channels > 2)
{
WaveFormat(&wave, wave.sampleRate, wave.sampleSize, 2);
TraceLog(WARNING, "[%s] WAV channels number (%i) not supported, converted to 2 channels", fileName, wave.channels);
}
-
+
// NOTE: subChunkSize comes in bytes, we need to translate it to number of samples
wave.sampleCount = (wavData.subChunkSize/(wave.sampleSize/8))/wave.channels;
- TraceLog(INFO, "[%s] WAV file loaded successfully (%i Hz, %i bit, %s)", fileName, wave.sampleRate, wave.sampleSize, (wave.channels == 1) ? "Mono" : "Stereo");
+ TraceLog(INFO, "[%s] WAV file loaded successfully (%i Hz, %i bit, %s)", fileName, wave.sampleRate, wave.sampleSize, (wave.channels == 1) ? "Mono" : "Stereo");
}
}
}
@@ -1145,7 +1145,7 @@ static Wave LoadOGG(const char *fileName)
wave.sampleSize = 16; // 16 bit per sample (short)
wave.channels = info.channels;
wave.sampleCount = (int)stb_vorbis_stream_length_in_samples(oggFile);
-
+
float totalSeconds = stb_vorbis_stream_length_in_seconds(oggFile);
if (totalSeconds > 10) TraceLog(WARNING, "[%s] Ogg audio lenght is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds);
@@ -1173,16 +1173,16 @@ static Wave LoadFLAC(const char *fileName)
// Decode an entire FLAC file in one go
uint64_t totalSampleCount;
wave.data = drflac_open_and_decode_file_s16(fileName, &wave.channels, &wave.sampleRate, &totalSampleCount);
-
+
wave.sampleCount = (int)totalSampleCount/wave.channels;
wave.sampleSize = 16;
-
+
// NOTE: Only support up to 2 channels (mono, stereo)
if (wave.channels > 2) TraceLog(WARNING, "[%s] FLAC channels number (%i) not supported", fileName, wave.channels);
if (wave.data == NULL) TraceLog(WARNING, "[%s] FLAC data could not be loaded", fileName);
else TraceLog(INFO, "[%s] FLAC file loaded successfully (%i Hz, %i bit, %s)", fileName, wave.sampleRate, wave.sampleSize, (wave.channels == 1) ? "Mono" : "Stereo");
-
+
return wave;
}
diff --git a/src/core.c b/src/core.c
index 8b97314d..ea363fce 100644
--- a/src/core.c
+++ b/src/core.c
@@ -9,7 +9,7 @@
* External libs:
* GLFW3 - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX)
* raymath - 3D math functionality (Vector3, Matrix, Quaternion)
-* camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person)
+* 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:
@@ -103,7 +103,7 @@
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
#include <linux/input.h> // Linux: Keycodes constants definition (KEY_A, ...)
#include <linux/joystick.h> // Linux: Joystick support library
-
+
#include "bcm_host.h" // Raspberry Pi VideoCore IV access functions
#include "EGL/egl.h" // Khronos EGL library - Native platform display device control functions
@@ -488,9 +488,9 @@ void CloseWindow(void)
// Wait for mouse and gamepad threads to finish before closing
// NOTE: Those threads should already have finished at this point
// because they are controlled by windowShouldClose variable
-
+
windowShouldClose = true; // Added to force threads to exit when the close window is called
-
+
pthread_join(mouseThreadId, NULL);
pthread_join(touchThreadId, NULL);
pthread_join(gamepadThreadId, NULL);
@@ -649,14 +649,14 @@ void EndDrawing(void)
frameTime = updateTime + drawTime;
// Wait for some milliseconds...
- if (frameTime < targetTime)
+ if (frameTime < targetTime)
{
Wait((int)((targetTime - frameTime)*1000));
-
+
currentTime = GetTime();
double extraTime = currentTime - previousTime;
previousTime = currentTime;
-
+
frameTime = updateTime + drawTime + extraTime;
}
}
@@ -1147,7 +1147,7 @@ bool IsKeyDown(int key)
bool IsKeyReleased(int key)
{
bool released = false;
-
+
if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true;
else released = false;
@@ -1182,7 +1182,7 @@ void SetExitKey(int key)
bool IsGamepadAvailable(int gamepad)
{
bool result = false;
-
+
#if !defined(PLATFORM_ANDROID)
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad]) result = true;
#endif
@@ -1196,7 +1196,7 @@ bool IsGamepadName(int gamepad, const char *name)
bool result = false;
#if !defined(PLATFORM_ANDROID)
- const char *gamepadName = NULL;
+ const char *gamepadName = NULL;
if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad);
if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0);
@@ -1235,7 +1235,7 @@ int GetGamepadAxisCount(int gamepad)
float GetGamepadAxisMovement(int gamepad, int axis)
{
float value = 0;
-
+
#if !defined(PLATFORM_ANDROID)
if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (axis < MAX_GAMEPAD_AXIS)) value = gamepadAxisState[gamepad][axis];
#endif
@@ -1249,8 +1249,8 @@ bool IsGamepadButtonPressed(int gamepad, int button)
bool pressed = false;
#if !defined(PLATFORM_ANDROID)
- if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
- (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
(currentGamepadState[gamepad][button] == 1)) pressed = true;
#endif
@@ -1274,10 +1274,10 @@ bool IsGamepadButtonDown(int gamepad, int button)
bool IsGamepadButtonReleased(int gamepad, int button)
{
bool released = false;
-
+
#if !defined(PLATFORM_ANDROID)
- if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
- (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) &&
(currentGamepadState[gamepad][button] == 0)) released = true;
#endif
@@ -1290,7 +1290,7 @@ bool IsGamepadButtonUp(int gamepad, int button)
bool result = false;
#if !defined(PLATFORM_ANDROID)
- if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
+ if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
(currentGamepadState[gamepad][button] == 0)) result = true;
#endif
@@ -1503,7 +1503,7 @@ static void InitGraphicsDevice(int width, int height)
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
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
//glfwWindowHint(GLFW_DEPTH_BITS, 16); // Depthbuffer bits (24 by default)
@@ -1941,7 +1941,7 @@ static double GetTime(void)
// Wait for some milliseconds (stop program execution)
static void Wait(int ms)
{
-#if defined _WIN32
+#if defined _WIN32
Sleep(ms);
#elif defined __linux || defined(PLATFORM_WEB)
struct timespec req = { 0 };
@@ -1949,7 +1949,7 @@ static void Wait(int ms)
ms -= (sec*1000);
req.tv_sec=sec;
req.tv_nsec=ms*1000000L;
-
+
// NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated.
while (nanosleep(&req,&req) == -1) continue;
//#elif defined __APPLE__
@@ -1999,10 +1999,10 @@ static void PollInputEvents(void)
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is just called on an event, not every frame
UpdateGestures();
-
+
// Reset last key pressed registered
lastKeyPressed = -1;
-
+
#if !defined(PLATFORM_RPI)
// Reset last gamepad button/axis registered state
lastGamepadButtonPressed = -1;
@@ -2018,7 +2018,7 @@ static void PollInputEvents(void)
mousePosition.x = (float)mouseX;
mousePosition.y = (float)mouseY;
-
+
// Keyboard input polling (automatically managed by GLFW3 through callback)
// Register previous keys states
@@ -2039,7 +2039,7 @@ static void PollInputEvents(void)
if (glfwJoystickPresent(i)) gamepadReady[i] = true;
else gamepadReady[i] = false;
}
-
+
// Register gamepads buttons events
for (int i = 0; i < MAX_GAMEPADS; i++)
{
@@ -2047,14 +2047,14 @@ static void PollInputEvents(void)
{
// Register previous gamepad states
for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k];
-
+
// Get current gamepad state
// NOTE: There is no callback available, so we get it manually
const unsigned char *buttons;
int buttonsCount;
buttons = glfwGetJoystickButtons(i, &buttonsCount);
-
+
for (int k = 0; (buttons != NULL) && (k < buttonsCount) && (buttonsCount < MAX_GAMEPAD_BUTTONS); k++)
{
if (buttons[k] == GLFW_PRESS)
@@ -2064,18 +2064,18 @@ static void PollInputEvents(void)
}
else currentGamepadState[i][k] = 0;
}
-
+
// Get current axis state
const float *axes;
int axisCount = 0;
axes = glfwGetJoystickAxes(i, &axisCount);
-
+
for (int k = 0; (axes != NULL) && (k < axisCount) && (k < MAX_GAMEPAD_AXIS); k++)
{
gamepadAxisState[i][k] = axes[k];
}
-
+
gamepadAxisCount = axisCount;
}
}
@@ -2088,16 +2088,16 @@ static void PollInputEvents(void)
#if defined(PLATFORM_WEB)
// Get number of gamepads connected
int numGamepads = emscripten_get_num_gamepads();
-
+
for (int i = 0; (i < numGamepads) && (i < MAX_GAMEPADS); i++)
{
// Register previous gamepad button states
for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k];
-
+
EmscriptenGamepadEvent gamepadState;
-
+
int result = emscripten_get_gamepad_status(i, &gamepadState);
-
+
if (result == EMSCRIPTEN_RESULT_SUCCESS)
{
// Register buttons data for every connected gamepad
@@ -2109,16 +2109,16 @@ static void PollInputEvents(void)
lastGamepadButtonPressed = j;
}
else currentGamepadState[i][j] = 0;
-
+
//printf("Gamepad %d, button %d: Digital: %d, Analog: %g\n", gamepadState.index, j, gamepadState.digitalButton[j], gamepadState.analogButton[j]);
}
-
+
// Register axis data for every connected gamepad
for (int j = 0; (j < gamepadState.numAxes) && (j < MAX_GAMEPAD_AXIS); j++)
{
gamepadAxisState[i][j] = gamepadState.axis[j];
}
-
+
gamepadAxisCount = gamepadState.numAxes;
}
}
@@ -2665,16 +2665,16 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
{
/*
printf("%s: timeStamp: %g, connected: %d, index: %ld, numAxes: %d, numButtons: %d, id: \"%s\", mapping: \"%s\"\n",
- eventType != 0 ? emscripten_event_type_to_string(eventType) : "Gamepad state",
+ eventType != 0 ? emscripten_event_type_to_string(eventType) : "Gamepad state",
gamepadEvent->timestamp, gamepadEvent->connected, gamepadEvent->index, gamepadEvent->numAxes, gamepadEvent->numButtons, gamepadEvent->id, gamepadEvent->mapping);
-
+
for(int i = 0; i < gamepadEvent->numAxes; ++i) printf("Axis %d: %g\n", i, gamepadEvent->axis[i]);
for(int i = 0; i < gamepadEvent->numButtons; ++i) printf("Button %d: Digital: %d, Analog: %g\n", i, gamepadEvent->digitalButton[i], gamepadEvent->analogButton[i]);
*/
-
+
if ((gamepadEvent->connected) && (gamepadEvent->index < MAX_GAMEPADS)) gamepadReady[gamepadEvent->index] = true;
else gamepadReady[gamepadEvent->index] = false;
-
+
// TODO: Test gamepadEvent->index
return 0;
@@ -2935,7 +2935,7 @@ static void InitTouch(void)
}
// Touch reading thread.
-// This reads from a Virtual Input Event /dev/input/event4 which is
+// This reads from a Virtual Input Event /dev/input/event4 which is
// created by the ts_uinput daemon. This takes, filters and scales
// raw input from the Touchscreen (which appears in /dev/input/event3)
// based on the Calibration data referenced by tslib.
@@ -2949,7 +2949,7 @@ static void *TouchThread(void *arg)
if (read(touchStream, &ev, sizeof(ev)) == (int)sizeof(ev))
{
// if pressure > 0 then simulate left mouse button click
- if (ev.type == EV_ABS && ev.code == 24 && ev.value == 0 && currentMouseState[0] == 1)
+ if (ev.type == EV_ABS && ev.code == 24 && ev.value == 0 && currentMouseState[0] == 1)
{
currentMouseState[0] = 0;
gestureEvent.touchAction = TOUCH_UP;
@@ -2963,10 +2963,10 @@ static void *TouchThread(void *arg)
gestureEvent.position[1].x /= (float)GetScreenWidth();
gestureEvent.position[1].y /= (float)GetScreenHeight();
ProcessGestureEvent(gestureEvent);
- }
- if (ev.type == EV_ABS && ev.code == 24 && ev.value > 0 && currentMouseState[0] == 0)
+ }
+ if (ev.type == EV_ABS && ev.code == 24 && ev.value > 0 && currentMouseState[0] == 0)
{
- currentMouseState[0] = 1;
+ currentMouseState[0] = 1;
gestureEvent.touchAction = TOUCH_DOWN;
gestureEvent.pointCount = 1;
gestureEvent.pointerId[0] = 0;
@@ -2978,9 +2978,9 @@ static void *TouchThread(void *arg)
gestureEvent.position[1].x /= (float)GetScreenWidth();
gestureEvent.position[1].y /= (float)GetScreenHeight();
ProcessGestureEvent(gestureEvent);
- }
+ }
// x & y values supplied by event4 have been scaled & de-jittered using tslib calibration data
- if (ev.type == EV_ABS && ev.code == 0)
+ if (ev.type == EV_ABS && ev.code == 0)
{
mousePosition.x = ev.value;
if (mousePosition.x < 0) mousePosition.x = 0;
@@ -2997,7 +2997,7 @@ static void *TouchThread(void *arg)
gestureEvent.position[1].y /= (float)GetScreenHeight();
ProcessGestureEvent(gestureEvent);
}
- if (ev.type == EV_ABS && ev.code == 1)
+ if (ev.type == EV_ABS && ev.code == 1)
{
mousePosition.y = ev.value;
if (mousePosition.y < 0) mousePosition.y = 0;
@@ -3014,7 +3014,7 @@ static void *TouchThread(void *arg)
gestureEvent.position[1].y /= (float)GetScreenHeight();
ProcessGestureEvent(gestureEvent);
}
-
+
}
}
return NULL;
@@ -3084,7 +3084,7 @@ static void *GamepadThread(void *arg)
{
// 1 - button pressed, 0 - button released
currentGamepadState[i][gamepadEvent.number] = (int)gamepadEvent.value;
-
+
if ((int)gamepadEvent.value == 1) lastGamepadButtonPressed = gamepadEvent.number;
else lastGamepadButtonPressed = -1;
}
diff --git a/src/models.c b/src/models.c
index 23c2e6fd..43821691 100644
--- a/src/models.c
+++ b/src/models.c
@@ -584,7 +584,7 @@ Mesh LoadMesh(const char *fileName)
if (mesh.vertexCount == 0) TraceLog(WARNING, "Mesh could not be loaded");
else rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh)
-
+
// TODO: Initialize default mesh data in case loading fails, maybe a cube?
return mesh;
@@ -607,7 +607,7 @@ Mesh LoadMeshEx(int numVertex, float *vData, float *vtData, float *vnData, Color
mesh.indices = NULL;
rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh)
-
+
return mesh;
}
@@ -668,7 +668,7 @@ Model LoadCubicmap(Image cubicmap)
return model;
}
-
+
// Unload mesh from memory (RAM and/or VRAM)
void UnloadMesh(Mesh *mesh)
{
@@ -1438,34 +1438,34 @@ RayHitInfo GetCollisionRayMesh(Ray ray, Mesh *mesh)
int triangleCount = mesh->vertexCount/3;
// Test against all triangles in mesh
- for (int i = 0; i < triangleCount; i++)
+ for (int i = 0; i < triangleCount; i++)
{
Vector3 a, b, c;
Vector3 *vertdata = (Vector3 *)mesh->vertices;
-
- if (mesh->indices)
+
+ if (mesh->indices)
{
a = vertdata[mesh->indices[i*3 + 0]];
b = vertdata[mesh->indices[i*3 + 1]];
- c = vertdata[mesh->indices[i*3 + 2]];
- }
- else
- {
+ c = vertdata[mesh->indices[i*3 + 2]];
+ }
+ else
+ {
a = vertdata[i*3 + 0];
b = vertdata[i*3 + 1];
c = vertdata[i*3 + 2];
}
RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, a, b, c);
-
- if (triHitInfo.hit)
+
+ if (triHitInfo.hit)
{
// Save the closest hit triangle
if ((!result.hit) || (result.distance > triHitInfo.distance)) result = triHitInfo;
}
}
- return result;
+ return result;
}
// Get collision info between ray and triangle
@@ -1478,44 +1478,44 @@ RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
Vector3 p, q, tv;
float det, invDet, u, v, t;
RayHitInfo result = {0};
-
+
// Find vectors for two edges sharing V1
edge1 = VectorSubtract(p2, p1);
edge2 = VectorSubtract(p3, p1);
-
+
// Begin calculating determinant - also used to calculate u parameter
p = VectorCrossProduct(ray.direction, edge2);
-
+
// If determinant is near zero, ray lies in plane of triangle or ray is parallel to plane of triangle
det = VectorDotProduct(edge1, p);
-
+
// Avoid culling!
if ((det > -EPSILON) && (det < EPSILON)) return result;
-
+
invDet = 1.0f/det;
-
+
// Calculate distance from V1 to ray origin
tv = VectorSubtract(ray.position, p1);
-
+
// Calculate u parameter and test bound
u = VectorDotProduct(tv, p)*invDet;
-
+
// The intersection lies outside of the triangle
if ((u < 0.0f) || (u > 1.0f)) return result;
-
+
// Prepare to test v parameter
q = VectorCrossProduct(tv, edge1);
-
+
// Calculate V parameter and test bound
v = VectorDotProduct(ray.direction, q)*invDet;
-
+
// The intersection lies outside of the triangle
if ((v < 0.0f) || ((u + v) > 1.0f)) return result;
-
+
t = VectorDotProduct(edge2, q)*invDet;
-
- if (t > EPSILON)
- {
+
+ if (t > EPSILON)
+ {
// Ray hit, get hit point and normal
result.hit = true;
result.distance = t;
@@ -1523,10 +1523,10 @@ RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
result.hitNormal = VectorCrossProduct(edge1, edge2);
VectorNormalize(&result.hitNormal);
Vector3 rayDir = ray.direction;
- VectorScale(&rayDir, t);
+ VectorScale(&rayDir, t);
result.hitPosition = VectorAdd(ray.position, rayDir);
}
-
+
return result;
}
@@ -1540,8 +1540,8 @@ RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight)
if (fabsf(ray.direction.y) > EPSILON)
{
float t = (ray.position.y - groundHeight)/-ray.direction.y;
-
- if (t >= 0.0)
+
+ if (t >= 0.0)
{
Vector3 rayDir = ray.direction;
VectorScale(&rayDir, t);
@@ -1551,7 +1551,7 @@ RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight)
result.hitPosition = VectorAdd(ray.position, rayDir);
}
}
-
+
return result;
}
diff --git a/src/raylib.h b/src/raylib.h
index 97130253..c1c9ebae 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -593,21 +593,21 @@ typedef enum {
// rRES data returned when reading a resource, it contains all required data for user (24 byte)
typedef struct {
unsigned int type; // Resource type (4 byte)
-
+
unsigned int param1; // Resouce parameter 1 (4 byte)
unsigned int param2; // Resouce parameter 2 (4 byte)
unsigned int param3; // Resouce parameter 3 (4 byte)
unsigned int param4; // Resouce parameter 4 (4 byte)
-
+
void *data; // Resource data pointer (4 byte)
} RRESData;
-typedef enum {
- RRES_RAW = 0,
- RRES_IMAGE,
- RRES_WAVE,
- RRES_VERTEX,
- RRES_TEXT
+typedef enum {
+ RRES_RAW = 0,
+ RRES_IMAGE,
+ RRES_WAVE,
+ RRES_VERTEX,
+ RRES_TEXT
} RRESDataType;
#ifdef __cplusplus
@@ -800,7 +800,7 @@ RLAPI Image ImageText(const char *text, int fontSize, Color color);
RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font)
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination)
-RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text,
+RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text,
float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination)
RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
@@ -876,15 +876,15 @@ RLAPI Material LoadDefaultMaterial(void);
RLAPI void UnloadMaterial(Material material); // Unload material from GPU memory (VRAM)
RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
-RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis,
+RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis,
float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
-RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis,
+RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis,
float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
-RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec,
+RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec,
Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
RLAPI BoundingBox CalculateBoundingBox(Mesh mesh); // Calculate mesh bounding box limits
@@ -892,7 +892,7 @@ RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB
RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes
RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere
RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere
-RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius,
+RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius,
Vector3 *collisionPoint); // Detect collision between ray and sphere, returns collision point
RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box
RLAPI RayHitInfo GetCollisionRayMesh(Ray ray, Mesh *mesh); // Get collision info between ray and mesh
diff --git a/src/rlgl.c b/src/rlgl.c
index 8ec867eb..6c4e5927 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -2,10 +2,10 @@
*
* rlgl - raylib OpenGL abstraction layer
*
-* 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).
+* rlgl allows usage of OpenGL 1.1 style functions (rlVertex) that are internally mapped to
+* selected OpenGL version (1.1, 2.1, 3.3 Core, ES 2.0).
*
-* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal
+* When chosing an OpenGL version greater than OpenGL 1.1, rlgl stores vertex data on internal
* VBO buffers (and VAOs if available). It requires calling 3 functions:
* rlglInit() - Initialize internal buffers and auxiliar resources
* rlglDraw() - Process internal buffers and send required draw calls
@@ -57,7 +57,7 @@
#endif
#if defined(GRAPHICS_API_OPENGL_11)
- #ifdef __APPLE__
+ #ifdef __APPLE__
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
#else
#include <GL/gl.h> // OpenGL 1.1 library
@@ -69,7 +69,7 @@
#endif
#if defined(GRAPHICS_API_OPENGL_33)
- #ifdef __APPLE__
+ #ifdef __APPLE__
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
#else
#define GLAD_IMPLEMENTATION
@@ -168,7 +168,7 @@
#if defined(GRAPHICS_API_OPENGL_ES2)
#define glClearDepth glClearDepthf
- #define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
+ #define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
#define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER
#endif
@@ -695,7 +695,7 @@ void rlEnd(void)
} break;
default: break;
}
-
+
// NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
// as well as depth buffer bit-depth (16bit or 24bit or 32bit)
// Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
@@ -880,7 +880,7 @@ void rlDisableTexture(void)
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
#else
- // NOTE: If quads batch limit is reached,
+ // NOTE: If quads batch limit is reached,
// we force a draw call and next batch starts
if (quads.vCounter/4 >= MAX_QUADS_BATCH) rlglDraw();
#endif
@@ -982,7 +982,7 @@ void rlDeleteRenderTextures(RenderTexture2D target)
if (target.id != 0) glDeleteFramebuffers(1, &target.id);
if (target.texture.id != 0) glDeleteTextures(1, &target.texture.id);
if (target.depth.id != 0) glDeleteTextures(1, &target.depth.id);
-
+
TraceLog(INFO, "[FBO ID %i] Unloaded render texture data from VRAM (GPU)", target.id);
#endif
}
@@ -999,7 +999,7 @@ void rlDeleteShader(unsigned int id)
void rlDeleteVertexArrays(unsigned int id)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
- if (vaoSupported)
+ if (vaoSupported)
{
if (id != 0) glDeleteVertexArrays(1, &id);
TraceLog(INFO, "[VAO ID %i] Unloaded model data from VRAM (GPU)", id);
@@ -1061,7 +1061,7 @@ void rlglInit(int width, int height)
{
// Check OpenGL information and capabilities
//------------------------------------------------------------------------------
-
+
// Print current OpenGL and GLSL version
TraceLog(INFO, "GPU: Vendor: %s", glGetString(GL_VENDOR));
TraceLog(INFO, "GPU: Renderer: %s", glGetString(GL_RENDERER));
@@ -1072,14 +1072,14 @@ void rlglInit(int width, int height)
//int maxTexSize;
//glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
//TraceLog(INFO, "GL_MAX_TEXTURE_SIZE: %i", maxTexSize);
-
+
//GL_MAX_TEXTURE_IMAGE_UNITS
//GL_MAX_VIEWPORT_DIMS
//int numAuxBuffers;
//glGetIntegerv(GL_AUX_BUFFERS, &numAuxBuffers);
//TraceLog(INFO, "GL_AUX_BUFFERS: %i", numAuxBuffers);
-
+
//GLint numComp = 0;
//GLint format[32] = { 0 };
//glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numComp);
@@ -1087,7 +1087,7 @@ void rlglInit(int width, int height)
//for (int i = 0; i < numComp; i++) TraceLog(INFO, "Supported compressed format: 0x%x", format[i]);
// NOTE: We don't need that much data on screen... right now...
-
+
#if defined(GRAPHICS_API_OPENGL_11)
//TraceLog(INFO, "OpenGL 1.1 (or driver default) profile initialized");
#endif
@@ -1095,7 +1095,7 @@ void rlglInit(int width, int height)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Get supported extensions list
GLint numExt = 0;
-
+
#if defined(GRAPHICS_API_OPENGL_33)
// NOTE: On OpenGL 3.3 VAO and NPOT are supported by default
@@ -1105,18 +1105,18 @@ void rlglInit(int width, int height)
// We get a list of available extensions and we check for some of them (compressed textures)
// NOTE: We don't need to check again supported extensions but we do (GLAD already dealt with that)
glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);
-
+
#ifdef _MSC_VER
const char **extList = malloc(sizeof(const char *)*numExt);
#else
const char *extList[numExt];
#endif
-
+
for (int i = 0; i < numExt; i++) extList[i] = (char *)glGetStringi(GL_EXTENSIONS, i);
-
+
#elif defined(GRAPHICS_API_OPENGL_ES2)
char *extensions = (char *)glGetString(GL_EXTENSIONS); // One big const string
-
+
// NOTE: We have to duplicate string because glGetString() returns a const value
// If not duplicated, it fails in some systems (Raspberry Pi)
// Equivalent to function: char *strdup(const char *str)
@@ -1125,12 +1125,12 @@ void rlglInit(int width, int height)
void *newstr = malloc(len);
if (newstr == NULL) extensionsDup = NULL;
extensionsDup = (char *)memcpy(newstr, extensions, len);
-
+
// NOTE: String could be splitted using strtok() function (string.h)
// NOTE: strtok() modifies the received string, it can not be const
-
+
char *extList[512]; // Allocate 512 strings pointers (2 KB)
-
+
extList[numExt] = strtok(extensionsDup, " ");
while (extList[numExt] != NULL)
@@ -1138,9 +1138,9 @@ void rlglInit(int width, int height)
numExt++;
extList[numExt] = strtok(NULL, " ");
}
-
+
free(extensionsDup); // Duplicated string must be deallocated
-
+
numExt -= 1;
#endif
@@ -1158,25 +1158,25 @@ void rlglInit(int width, int height)
if (strcmp(extList[i], (const char *)"GL_OES_vertex_array_object") == 0)
{
vaoSupported = true;
-
- // The extension is supported by our hardware and driver, try to get related functions pointers
+
+ // The extension is supported by our hardware and driver, try to get related functions pointers
// NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
//glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted
}
-
+
// Check NPOT textures support
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
if (strcmp(extList[i], (const char *)"GL_OES_texture_npot") == 0) npotSupported = true;
#endif
-
+
// DDS texture compression support
if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
(strcmp(extList[i], (const char *)"GL_WEBGL_compressed_texture_s3tc") == 0) ||
- (strcmp(extList[i], (const char *)"GL_WEBKIT_WEBGL_compressed_texture_s3tc") == 0)) texCompDXTSupported = true;
-
+ (strcmp(extList[i], (const char *)"GL_WEBKIT_WEBGL_compressed_texture_s3tc") == 0)) texCompDXTSupported = true;
+
// ETC1 texture compression support
if ((strcmp(extList[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) ||
(strcmp(extList[i], (const char *)"GL_WEBGL_compressed_texture_etc1") == 0)) texCompETC1Supported = true;
@@ -1189,26 +1189,26 @@ void rlglInit(int width, int height)
// ASTC texture compression support
if (strcmp(extList[i], (const char *)"GL_KHR_texture_compression_astc_hdr") == 0) texCompASTCSupported = true;
-
+
// Anisotropic texture filter support
if (strcmp(extList[i], (const char *)"GL_EXT_texture_filter_anisotropic") == 0)
{
texAnisotropicFilterSupported = true;
- glGetFloatv(0x84FF, &maxAnisotropicLevel); // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
+ glGetFloatv(0x84FF, &maxAnisotropicLevel); // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
}
-
+
// Clamp mirror wrap mode supported
if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texClampMirrorSupported = true;
}
-
+
#ifdef _MSC_VER
free(extList);
#endif
-
+
#if defined(GRAPHICS_API_OPENGL_ES2)
if (vaoSupported) TraceLog(INFO, "[EXTENSION] VAO extension detected, VAO functions initialized successfully");
else TraceLog(WARNING, "[EXTENSION] VAO extension not found, VAO usage not supported");
-
+
if (npotSupported) TraceLog(INFO, "[EXTENSION] NPOT textures extension detected, full NPOT textures supported");
else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, limited NPOT support (no-mipmaps, no-repeat)");
#endif
@@ -1218,13 +1218,13 @@ void rlglInit(int width, int height)
if (texCompETC2Supported) TraceLog(INFO, "[EXTENSION] ETC2/EAC compressed textures supported");
if (texCompPVRTSupported) TraceLog(INFO, "[EXTENSION] PVRT compressed textures supported");
if (texCompASTCSupported) TraceLog(INFO, "[EXTENSION] ASTC compressed textures supported");
-
+
if (texAnisotropicFilterSupported) TraceLog(INFO, "[EXTENSION] Anisotropic textures filtering supported (max: %.0fX)", maxAnisotropicLevel);
if (texClampMirrorSupported) TraceLog(INFO, "[EXTENSION] Clamp mirror wrap texture mode supported");
// Initialize buffers, default shaders and default textures
//----------------------------------------------------------
-
+
// Init default white texture
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
@@ -1238,7 +1238,7 @@ void rlglInit(int width, int height)
currentShader = defaultShader;
// Init default vertex arrays buffers (lines, triangles, quads)
- LoadDefaultBuffers();
+ LoadDefaultBuffers();
// Init temp vertex buffer, used when transformation required (translate, rotate, scale)
tempBuffer = (Vector3 *)malloc(sizeof(Vector3)*TEMP_VERTEX_BUFFER_SIZE);
@@ -1257,7 +1257,7 @@ void rlglInit(int width, int height)
drawsCounter = 1;
draws[drawsCounter - 1].textureId = whiteTexture;
currentDrawMode = RL_TRIANGLES; // Set default draw mode
-
+
// Init internal matrix stack (emulating OpenGL 1.1)
for (int i = 0; i < MATRIX_STACK_SIZE; i++) stack[i] = MatrixIdentity();
@@ -1286,7 +1286,7 @@ void rlglInit(int width, int height)
#if defined(GRAPHICS_API_OPENGL_11)
// Init state: Color hints (deprecated in OpenGL 3.0+)
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Improve quality of color and texture coordinate interpolation
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Improve quality of color and texture coordinate interpolation
glShadeModel(GL_SMOOTH); // Smooth shading between vertex (vertex colors interpolation)
#endif
@@ -1294,7 +1294,7 @@ void rlglInit(int width, int height)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set clear color (black)
glClearDepth(1.0f); // Set clear depth value (default)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers (depth buffer required for 3D)
-
+
// Store screen size into global variables
screenWidth = width;
screenHeight = height;
@@ -1308,7 +1308,7 @@ void rlglClose(void)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
UnloadDefaultShader();
UnloadDefaultBuffers();
-
+
// Delete default white texture
glDeleteTextures(1, &whiteTexture);
TraceLog(INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture);
@@ -1326,7 +1326,7 @@ void rlglDraw(void)
// NOTE: Default buffers upload and draw
UpdateDefaultBuffers();
-
+
if (vrEnabled && vrRendering) DrawDefaultBuffers(2);
else DrawDefaultBuffers(1);
#endif
@@ -1342,7 +1342,7 @@ void rlglLoadExtensions(void *loader)
if (!gladLoadGLLoader((GLADloadproc)loader)) TraceLog(WARNING, "GLAD: Cannot load OpenGL extensions");
else TraceLog(INFO, "GLAD: OpenGL extensions loaded successfully");
#endif
-
+
#if defined(GRAPHICS_API_OPENGL_21)
#ifndef __APPLE__
if (GLAD_GL_VERSION_2_1) TraceLog(INFO, "OpenGL 2.1 profile supported");
@@ -1363,17 +1363,17 @@ void rlglLoadExtensions(void *loader)
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view)
{
Vector3 result = { 0.0f, 0.0f, 0.0f };
-
+
// Calculate unproject matrix (multiply projection matrix and view matrix) and invert it
Matrix matProjView = MatrixMultiply(proj, view);
MatrixInvert(&matProjView);
-
+
// Create quaternion from source point
Quaternion quat = { source.x, source.y, source.z, 1.0f };
-
+
// Multiply quat point by unproject matrix
QuaternionTransform(&quat, matProjView);
-
+
// Normalized world points in vectors
result.x = quat.x/quat.w;
result.y = quat.y/quat.w;
@@ -1388,41 +1388,41 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding
GLuint id = 0;
-
+
// Check texture format support by OpenGL 1.1 (compressed textures not supported)
-#if defined(GRAPHICS_API_OPENGL_11)
+#if defined(GRAPHICS_API_OPENGL_11)
if (textureFormat >= 8)
{
TraceLog(WARNING, "OpenGL 1.1 does not support GPU compressed texture formats");
return id;
}
#endif
-
+
if ((!texCompDXTSupported) && ((textureFormat == COMPRESSED_DXT1_RGB) || (textureFormat == COMPRESSED_DXT1_RGBA) ||
(textureFormat == COMPRESSED_DXT3_RGBA) || (textureFormat == COMPRESSED_DXT5_RGBA)))
{
TraceLog(WARNING, "DXT compressed texture format not supported");
return id;
}
-#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
if ((!texCompETC1Supported) && (textureFormat == COMPRESSED_ETC1_RGB))
{
TraceLog(WARNING, "ETC1 compressed texture format not supported");
return id;
}
-
+
if ((!texCompETC2Supported) && ((textureFormat == COMPRESSED_ETC2_RGB) || (textureFormat == COMPRESSED_ETC2_EAC_RGBA)))
{
TraceLog(WARNING, "ETC2 compressed texture format not supported");
return id;
}
-
+
if ((!texCompPVRTSupported) && ((textureFormat == COMPRESSED_PVRT_RGB) || (textureFormat == COMPRESSED_PVRT_RGBA)))
{
TraceLog(WARNING, "PVRT compressed texture format not supported");
return id;
}
-
+
if ((!texCompASTCSupported) && ((textureFormat == COMPRESSED_ASTC_4x4_RGBA) || (textureFormat == COMPRESSED_ASTC_8x8_RGBA)))
{
TraceLog(WARNING, "ASTC compressed texture format not supported");
@@ -1450,24 +1450,24 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
// GL_RGBA4 GL_RGBA GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_4_4_4_4
// GL_RGBA8 GL_RGBA GL_UNSIGNED_BYTE
// GL_RGB8 GL_RGB GL_UNSIGNED_BYTE
-
+
switch (textureFormat)
{
case UNCOMPRESSED_GRAYSCALE:
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, (unsigned char *)data);
-
+
// With swizzleMask we define how a one channel texture will be mapped to RGBA
// Required GL >= 3.3 or EXT_texture_swizzle/ARB_texture_swizzle
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
-
+
TraceLog(INFO, "[TEX ID %i] Grayscale texture loaded and swizzled", id);
} break;
case UNCOMPRESSED_GRAY_ALPHA:
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, (unsigned char *)data);
-
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
} break;
@@ -1541,7 +1541,7 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
// Magnification and minification filters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Alternative: GL_LINEAR
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Alternative: GL_LINEAR
-
+
#if defined(GRAPHICS_API_OPENGL_33)
if (mipmapCount > 1)
{
@@ -1551,7 +1551,7 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
#endif
// At this point we have the texture loaded in GPU and texture parameters configured
-
+
// NOTE: If mipmaps were not in data, they are not generated automatically
// Unbind current texture
@@ -1567,15 +1567,15 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
RenderTexture2D rlglLoadRenderTexture(int width, int height)
{
RenderTexture2D target;
-
+
target.id = 0;
-
+
target.texture.id = 0;
target.texture.width = width;
target.texture.height = height;
target.texture.format = UNCOMPRESSED_R8G8B8A8;
target.texture.mipmaps = 1;
-
+
target.depth.id = 0;
target.depth.width = width;
target.depth.height = height;
@@ -1592,13 +1592,13 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
-
+
#if defined(GRAPHICS_API_OPENGL_33)
#define USE_DEPTH_TEXTURE
#else
#define USE_DEPTH_RENDERBUFFER
#endif
-
+
#if defined(USE_DEPTH_RENDERBUFFER)
// Create the renderbuffer that will serve as the depth attachment for the framebuffer.
glGenRenderbuffers(1, &target.depth.id);
@@ -1634,7 +1634,7 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height)
if (status != GL_FRAMEBUFFER_COMPLETE)
{
TraceLog(WARNING, "Framebuffer object could not be created...");
-
+
switch (status)
{
case GL_FRAMEBUFFER_UNSUPPORTED: TraceLog(WARNING, "Framebuffer is unsupported"); break;
@@ -1645,17 +1645,17 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height)
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: TraceLog(WARNING, "Framebuffer incomplete missing attachment"); break;
default: break;
}
-
+
glDeleteTextures(1, &target.texture.id);
glDeleteTextures(1, &target.depth.id);
glDeleteFramebuffers(1, &target.id);
}
else TraceLog(INFO, "[FBO ID %i] Framebuffer object created successfully", target.id);
-
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
- return target;
+ return target;
}
// Update already loaded texture in GPU with new data
@@ -1695,11 +1695,11 @@ void rlglUpdateTexture(unsigned int id, int width, int height, int format, const
void rlglGenerateMipmaps(Texture2D *texture)
{
glBindTexture(GL_TEXTURE_2D, texture->id);
-
+
// Check if texture is power-of-two (POT)
bool texIsPOT = false;
-
- if (((texture->width > 0) && ((texture->width & (texture->width - 1)) == 0)) &&
+
+ if (((texture->width > 0) && ((texture->width & (texture->width - 1)) == 0)) &&
((texture->height > 0) && ((texture->height & (texture->height - 1)) == 0))) texIsPOT = true;
if ((texIsPOT) || (npotSupported))
@@ -1707,7 +1707,7 @@ void rlglGenerateMipmaps(Texture2D *texture)
#if defined(GRAPHICS_API_OPENGL_11)
// Compute required mipmaps
void *data = rlglReadTexturePixels(*texture);
-
+
// NOTE: data size is reallocated to fit mipmaps data
// NOTE: CPU mipmap generation only supports RGBA 32bit data
int mipmapCount = GenerateMipmaps(data, texture->width, texture->height);
@@ -1729,12 +1729,12 @@ void rlglGenerateMipmaps(Texture2D *texture)
mipWidth /= 2;
mipHeight /= 2;
}
-
+
TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture->id);
-
+
// NOTE: Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
free(data);
-
+
texture->mipmaps = mipmapCount + 1;
#endif
@@ -1745,10 +1745,10 @@ void rlglGenerateMipmaps(Texture2D *texture)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps
-
+
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
-
+
texture->mipmaps = 1 + (int)floor(log(MAX(texture->width, texture->height))/log(2));
#endif
}
@@ -1768,7 +1768,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
mesh->vboId[4] = 0; // Vertex tangents VBO
mesh->vboId[5] = 0; // Vertex texcoords2 VBO
mesh->vboId[6] = 0; // Vertex indices VBO
-
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
int drawHint = GL_STATIC_DRAW;
if (dynamic) drawHint = GL_DYNAMIC_DRAW;
@@ -1783,8 +1783,8 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
glBindVertexArray(vaoId);
}
- // NOTE: Attributes must be uploaded considering default locations points
-
+ // NOTE: Attributes must be uploaded considering default locations points
+
// Enable vertex attributes: position (shader-location = 0)
glGenBuffers(1, &vboId[0]);
glBindBuffer(GL_ARRAY_BUFFER, vboId[0]);
@@ -1814,7 +1814,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
glVertexAttrib3f(2, 1.0f, 1.0f, 1.0f);
glDisableVertexAttribArray(2);
}
-
+
// Default color vertex attribute (shader-location = 3)
if (mesh->colors != NULL)
{
@@ -1830,7 +1830,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f);
glDisableVertexAttribArray(3);
}
-
+
// Default tangent vertex attribute (shader-location = 4)
if (mesh->tangents != NULL)
{
@@ -1846,7 +1846,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
glVertexAttrib3f(4, 0.0f, 0.0f, 0.0f);
glDisableVertexAttribArray(4);
}
-
+
// Default texcoord2 vertex attribute (shader-location = 5)
if (mesh->texcoords2 != NULL)
{
@@ -1862,7 +1862,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
glVertexAttrib2f(5, 0.0f, 0.0f);
glDisableVertexAttribArray(5);
}
-
+
if (mesh->indices != NULL)
{
glGenBuffers(1, &vboId[6]);
@@ -1900,7 +1900,7 @@ void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Activate mesh VAO
if (vaoSupported) glBindVertexArray(mesh.vaoId);
-
+
switch (buffer)
{
case 0: // Update vertices (vertex position)
@@ -1908,28 +1908,28 @@ void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*numVertex, mesh.vertices, GL_DYNAMIC_DRAW);
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*numVertex, mesh.vertices);
-
+
} break;
case 1: // Update texcoords (vertex texture coordinates)
{
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[1]);
if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*numVertex, mesh.texcoords, GL_DYNAMIC_DRAW);
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*numVertex, mesh.texcoords);
-
+
} break;
case 2: // Update normals (vertex normals)
{
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[2]);
if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*numVertex, mesh.normals, GL_DYNAMIC_DRAW);
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*numVertex, mesh.normals);
-
+
} break;
case 3: // Update colors (vertex colors)
{
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[3]);
if (numVertex >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*numVertex, mesh.colors, GL_DYNAMIC_DRAW);
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*numVertex, mesh.colors);
-
+
} break;
case 4: // Update tangents (vertex tangents)
{
@@ -1945,7 +1945,7 @@ void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
} break;
default: break;
}
-
+
// Unbind the current VAO
if (vaoSupported) glBindVertexArray(0);
@@ -1973,11 +1973,11 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
glTexCoordPointer(2, GL_FLOAT, 0, mesh.texcoords); // Pointer to texture coords array
if (mesh.normals != NULL) glNormalPointer(GL_FLOAT, 0, mesh.normals); // Pointer to normals array
if (mesh.colors != NULL) glColorPointer(4, GL_UNSIGNED_BYTE, 0, mesh.colors); // Pointer to colors array
-
+
rlPushMatrix();
rlMultMatrixf(MatrixToFloat(transform));
rlColor4ub(material.colDiffuse.r, material.colDiffuse.g, material.colDiffuse.b, material.colDiffuse.a);
-
+
if (mesh.indices != NULL) glDrawElements(GL_TRIANGLES, mesh.triangleCount*3, GL_UNSIGNED_SHORT, mesh.indices);
else glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);
rlPopMatrix();
@@ -1996,13 +1996,13 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
if (vrEnabled) eyesCount = 2;
glUseProgram(material.shader.id);
-
+
// Upload to shader material.colDiffuse
glUniform4f(material.shader.colDiffuseLoc, (float)material.colDiffuse.r/255, (float)material.colDiffuse.g/255, (float)material.colDiffuse.b/255, (float)material.colDiffuse.a/255);
-
+
// Upload to shader material.colAmbient (if available)
if (material.shader.colAmbientLoc != -1) glUniform4f(material.shader.colAmbientLoc, (float)material.colAmbient.r/255, (float)material.colAmbient.g/255, (float)material.colAmbient.b/255, (float)material.colAmbient.a/255);
-
+
// Upload to shader material.colSpecular (if available)
if (material.shader.colSpecularLoc != -1) glUniform4f(material.shader.colSpecularLoc, (float)material.colSpecular.r/255, (float)material.colSpecular.g/255, (float)material.colSpecular.b/255, (float)material.colSpecular.a/255);
@@ -2010,7 +2010,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
// That's because Begin3dMode() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
Matrix matView = modelview; // View matrix (camera)
Matrix matProjection = projection; // Projection matrix (perspective)
-
+
// Calculate model-view matrix combining matModel and matView
Matrix matModelView = MatrixMultiply(transform, matView); // Transform to camera-space coordinates
@@ -2026,7 +2026,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
Matrix transInvTransform = transform;
MatrixTranspose(&transInvTransform);
MatrixInvert(&transInvTransform);
-
+
// Send model transformations matrix to shader
glUniformMatrix4fv(modelMatrixLoc, 1, false, MatrixToFloat(transInvTransform));
}
@@ -2039,7 +2039,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
// Check if glossiness is located in shader and upload value
int glossinessLoc = glGetUniformLocation(material.shader.id, "glossiness");
if (glossinessLoc != -1) glUniform1f(glossinessLoc, material.glossiness);
- }
+ }
// Set shader textures (diffuse, normal, specular)
glActiveTexture(GL_TEXTURE0);
@@ -2050,22 +2050,22 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
{
// Upload to shader specular map flag
glUniform1i(glGetUniformLocation(material.shader.id, "useNormal"), 1);
-
+
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, material.texNormal.id);
glUniform1i(material.shader.mapTexture1Loc, 1); // Normal texture fits in active texture unit 1
}
-
+
if ((material.texSpecular.id != 0) && (material.shader.mapTexture2Loc != -1))
{
// Upload to shader specular map flag
glUniform1i(glGetUniformLocation(material.shader.id, "useSpecular"), 1);
-
+
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, material.texSpecular.id);
glUniform1i(material.shader.mapTexture2Loc, 2); // Specular texture fits in active texture unit 2
}
-
+
if (vaoSupported)
{
glBindVertexArray(mesh.vaoId);
@@ -2089,7 +2089,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
glVertexAttribPointer(material.shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.normalLoc);
}
-
+
// Bind mesh VBO data: vertex colors (shader-location = 3, if available)
if (material.shader.colorLoc != -1)
{
@@ -2107,7 +2107,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
glDisableVertexAttribArray(material.shader.colorLoc);
}
}
-
+
// Bind mesh VBO data: vertex tangents (shader-location = 4, if available)
if (material.shader.tangentLoc != -1)
{
@@ -2115,7 +2115,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
glVertexAttribPointer(material.shader.tangentLoc, 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.tangentLoc);
}
-
+
// Bind mesh VBO data: vertex texcoords2 (shader-location = 5, if available)
if (material.shader.texcoord2Loc != -1)
{
@@ -2123,7 +2123,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
glVertexAttribPointer(material.shader.texcoord2Loc, 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(material.shader.texcoord2Loc);
}
-
+
if (mesh.indices != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quads.vboId[3]);
}
@@ -2142,13 +2142,13 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
if (mesh.indices != NULL) glDrawElements(GL_TRIANGLES, mesh.triangleCount*3, GL_UNSIGNED_SHORT, 0); // Indexed vertices draw
else glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);
}
-
+
if (material.texNormal.id != 0)
{
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
}
-
+
if (material.texSpecular.id != 0)
{
glActiveTexture(GL_TEXTURE2);
@@ -2166,7 +2166,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
}
glUseProgram(0); // Unbind shader program
-
+
// Restore projection/modelview matrices
projection = matProjection;
modelview = matView;
@@ -2212,7 +2212,7 @@ unsigned char *rlglReadScreenPixels(int width, int height)
{
// Flip line
imgData[((height - 1) - y)*width*4 + x] = screenData[(y*width*4) + x];
-
+
// Set alpha component value to 255 (no trasparent image retrieval)
// NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
if (((x + 1)%4) == 0) imgData[((height - 1) - y)*width*4 + x] = 255;
@@ -2230,10 +2230,10 @@ unsigned char *rlglReadScreenPixels(int width, int height)
void *rlglReadTexturePixels(Texture2D texture)
{
void *pixels = NULL;
-
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
glBindTexture(GL_TEXTURE_2D, texture.id);
-
+
// NOTE: Using texture.id, we can retrieve some texture info (but not on OpenGL ES 2.0)
/*
int width, height, format;
@@ -2242,11 +2242,11 @@ void *rlglReadTexturePixels(Texture2D texture)
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
// Other texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
*/
-
+
int glFormat = 0, glType = 0;
unsigned int size = texture.width*texture.height;
-
+
// NOTE: GL_LUMINANCE and GL_LUMINANCE_ALPHA are removed since OpenGL 3.1
// Must be replaced by GL_RED and GL_RG on Core OpenGL 3.3
@@ -2255,8 +2255,8 @@ void *rlglReadTexturePixels(Texture2D texture)
#if defined(GRAPHICS_API_OPENGL_11)
case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_LUMINANCE; glType = GL_UNSIGNED_BYTE; break; // 8 bit per pixel (no alpha)
case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_LUMINANCE_ALPHA; glType = GL_UNSIGNED_BYTE; break; // 16 bpp (2 channels)
-#elif defined(GRAPHICS_API_OPENGL_33)
- case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_RED; glType = GL_UNSIGNED_BYTE; break;
+#elif defined(GRAPHICS_API_OPENGL_33)
+ case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_RED; glType = GL_UNSIGNED_BYTE; break;
case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_RG; glType = GL_UNSIGNED_BYTE; break;
#endif
case UNCOMPRESSED_R5G6B5: pixels = (unsigned short *)malloc(size); glFormat = GL_RGB; glType = GL_UNSIGNED_SHORT_5_6_5; break; // 16 bpp
@@ -2266,15 +2266,15 @@ void *rlglReadTexturePixels(Texture2D texture)
case UNCOMPRESSED_R8G8B8A8: pixels = (unsigned char *)malloc(size*4); glFormat = GL_RGBA; glType = GL_UNSIGNED_BYTE; break; // 32 bpp
default: TraceLog(WARNING, "Texture data retrieval, format not suported"); break;
}
-
+
// NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding.
- // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
- // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
+ // Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
+ // GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
// GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels);
-
+
glBindTexture(GL_TEXTURE_2D, 0);
#endif
@@ -2285,7 +2285,7 @@ void *rlglReadTexturePixels(Texture2D texture)
// NOTE: Two possible Options:
// 1 - Bind texture to color fbo attachment and glReadPixels()
// 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
-
+
#define GET_TEXTURE_FBO_OPTION_1 // It works
#if defined(GET_TEXTURE_FBO_OPTION_1)
@@ -2295,48 +2295,48 @@ void *rlglReadTexturePixels(Texture2D texture)
// Attach our texture to FBO -> Texture must be RGB
// NOTE: Previoust attached texture is automatically detached
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id, 0);
-
+
pixels = (unsigned char *)malloc(texture.width*texture.height*4*sizeof(unsigned char));
-
+
// NOTE: Despite FBO color texture is RGB, we read data as RGBA... reading as RGB doesn't work... o__O
glReadPixels(0, 0, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-
+
// Re-attach internal FBO color texture before deleting it
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo.texture.id, 0);
-
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
+
#elif defined(GET_TEXTURE_FBO_OPTION_2)
// Render texture to fbo
glBindFramebuffer(GL_FRAMEBUFFER, fbo.id);
-
+
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width, height);
//glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
- rlOrtho(0.0, width, height, 0.0, 0.0, 1.0);
+ rlOrtho(0.0, width, height, 0.0, 0.0, 1.0);
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
//glDisable(GL_TEXTURE_2D);
//glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
-
+
Model quad;
//quad.mesh = GenMeshQuad(width, height);
quad.transform = MatrixIdentity();
quad.shader = defaultShader;
-
+
DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE);
-
+
pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char));
-
+
glReadPixels(0, 0, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// Bind framebuffer 0, which means render to back buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
+
UnloadModel(quad);
#endif // GET_TEXTURE_FBO_OPTION
@@ -2361,7 +2361,7 @@ void rlglRecordDraw(void)
draws[drawsCounter].projection = projection;
draws[drawsCounter].modelview = modelview;
draws[drawsCounter].vertexCount = currentState.vertexCount;
-
+
drawsCounter++;
#endif
}
@@ -2376,13 +2376,13 @@ void rlglRecordDraw(void)
Texture2D GetDefaultTexture(void)
{
Texture2D texture;
-
+
texture.id = whiteTexture;
texture.width = 1;
texture.height = 1;
texture.mipmaps = 1;
texture.format = UNCOMPRESSED_R8G8B8A8;
-
+
return texture;
}
@@ -2429,24 +2429,24 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
// Shaders loading from external text file
char *vShaderStr = LoadText(vsFileName);
char *fShaderStr = LoadText(fsFileName);
-
+
if ((vShaderStr != NULL) && (fShaderStr != NULL))
{
shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
// After shader loading, we try to load default location names
if (shader.id != 0) LoadDefaultShaderLocations(&shader);
-
+
// Shader strings must be freed
free(vShaderStr);
free(fShaderStr);
}
-
+
if (shader.id == 0)
{
TraceLog(WARNING, "Custom shader could not be loaded");
shader = defaultShader;
- }
+ }
#endif
return shader;
@@ -2497,9 +2497,9 @@ Shader GetDefaultShader(void)
int GetShaderLocation(Shader shader, const char *uniformName)
{
int location = -1;
-#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
+#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
location = glGetUniformLocation(shader.id, uniformName);
-
+
if (location == -1) TraceLog(DEBUG, "[SHDR ID %i] Shader location for %s could not be found", shader.id, uniformName);
#endif
return location;
@@ -2516,7 +2516,7 @@ void SetShaderValue(Shader shader, int uniformLoc, float *value, int size)
else if (size == 3) glUniform3fv(uniformLoc, 1, value); // Shader uniform type: vec3
else if (size == 4) glUniform4fv(uniformLoc, 1, value); // Shader uniform type: vec4
else TraceLog(WARNING, "Shader value float array size not supported");
-
+
//glUseProgram(0); // Avoid reseting current shader program, in case other uniforms are set
#endif
}
@@ -2532,7 +2532,7 @@ void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size)
else if (size == 3) glUniform3iv(uniformLoc, 1, value); // Shader uniform type: ivec3
else if (size == 4) glUniform4iv(uniformLoc, 1, value); // Shader uniform type: ivec4
else TraceLog(WARNING, "Shader value int array size not supported");
-
+
//glUseProgram(0);
#endif
}
@@ -2544,7 +2544,7 @@ void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
glUseProgram(shader.id);
glUniformMatrix4fv(uniformLoc, 1, false, MatrixToFloat(mat));
-
+
//glUseProgram(0);
#endif
}
@@ -2572,7 +2572,7 @@ void BeginBlendMode(int mode)
if ((blendMode != mode) && (mode < 3))
{
rlglDraw();
-
+
switch (mode)
{
case BLEND_ALPHA: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break;
@@ -2580,7 +2580,7 @@ void BeginBlendMode(int mode)
case BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); break;
default: break;
}
-
+
blendMode = mode;
}
}
@@ -2646,9 +2646,9 @@ void InitVrDevice(int vrDevice)
{
// Oculus Rift CV1 parameters
// NOTE: CV1 represents a complete HMD redesign compared to previous versions,
- // new Fresnel-hybrid-asymmetric lenses have been added and, consequently,
- // previous parameters (DK2) and distortion shader (DK2) doesn't work any more.
- // I just defined a set of parameters for simulator that approximate to CV1 stereo rendering
+ // new Fresnel-hybrid-asymmetric lenses have been added and, consequently,
+ // previous parameters (DK2) and distortion shader (DK2) doesn't work any more.
+ // I just defined a set of parameters for simulator that approximate to CV1 stereo rendering
// but result is not the same obtained with Oculus PC SDK.
hmd.hResolution = 2160; // HMD horizontal resolution in pixels
hmd.vResolution = 1200; // HMD vertical resolution in pixels
@@ -2667,17 +2667,17 @@ void InitVrDevice(int vrDevice)
hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2
hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3
}
-
+
// Initialize framebuffer and textures for stereo rendering
// NOTE: screen size should match HMD aspect ratio
vrConfig.stereoFbo = rlglLoadRenderTexture(screenWidth, screenHeight);
-
+
// Load distortion shader (initialized by default with Oculus Rift CV1 parameters)
vrConfig.distortionShader.id = LoadShaderProgram(vDistortionShaderStr, fDistortionShaderStr);
if (vrConfig.distortionShader.id != 0) LoadDefaultShaderLocations(&vrConfig.distortionShader);
SetStereoConfig(hmd);
-
+
vrSimulator = true;
vrEnabled = true;
}
@@ -2722,9 +2722,9 @@ void ToggleVrMode(void)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
if (vrDeviceReady || vrSimulator) vrEnabled = !vrEnabled;
else vrEnabled = false;
-
+
if (!vrEnabled)
- {
+ {
// Reset viewport and default projection-modelview matrices
rlViewport(0, 0, screenWidth, screenHeight);
projection = MatrixOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f);
@@ -2759,15 +2759,15 @@ void BeginVrDrawing(void)
rlEnableRenderTexture(vrConfig.stereoFbo.id);
}
- // NOTE: If your application is configured to treat the texture as a linear format (e.g. GL_RGBA)
+ // NOTE: If your application is configured to treat the texture as a linear format (e.g. GL_RGBA)
// and performs linear-to-gamma conversion in GLSL or does not care about gamma-correction, then:
// - Require OculusBuffer format to be OVR_FORMAT_R8G8B8A8_UNORM_SRGB
// - Do NOT enable GL_FRAMEBUFFER_SRGB
//glEnable(GL_FRAMEBUFFER_SRGB);
-
+
//glViewport(0, 0, buffer.width, buffer.height); // Useful if rendering to separate framebuffers (every eye)
rlClearScreenBuffers(); // Clear current framebuffer(s)
-
+
vrRendering = true;
#endif
}
@@ -2786,12 +2786,12 @@ void EndVrDrawing(void)
{
// Unbind current framebuffer
rlDisableRenderTexture();
-
+
rlClearScreenBuffers(); // Clear current framebuffer
// Set viewport to default framebuffer size (screen size)
rlViewport(0, 0, screenWidth, screenHeight);
-
+
// Let rlgl reconfigure internal matrices
rlMatrixMode(RL_PROJECTION); // Enable internal projection matrix
rlLoadIdentity(); // Reset internal projection matrix
@@ -2799,7 +2799,7 @@ void EndVrDrawing(void)
rlMatrixMode(RL_MODELVIEW); // Enable internal modelview matrix
rlLoadIdentity(); // Reset internal modelview matrix
- // Draw RenderTexture (stereoFbo) using distortion shader
+ // Draw RenderTexture (stereoFbo) using distortion shader
currentShader = vrConfig.distortionShader;
rlEnableTexture(vrConfig.stereoFbo.texture.id);
@@ -2836,7 +2836,7 @@ void EndVrDrawing(void)
}
rlDisableDepthTest();
-
+
vrRendering = false;
#endif
}
@@ -2867,7 +2867,7 @@ static void LoadCompressedTexture(unsigned char *data, int width, int height, in
for (int level = 0; level < mipmapCount && (width || height); level++)
{
unsigned int size = 0;
-
+
size = ((width + 3)/4)*((height + 3)/4)*blockSize;
glCompressedTexImage2D(GL_TEXTURE_2D, level, compressedFormat, width, height, 0, size, data + offset);
@@ -2923,7 +2923,7 @@ static unsigned int LoadShaderProgram(const char *vShaderStr, const char *fShade
glGetShaderInfoLog(vertexShader, maxLength, &length, log);
TraceLog(INFO, "%s", log);
-
+
#ifdef _MSC_VER
free(log);
#endif
@@ -2962,7 +2962,7 @@ static unsigned int LoadShaderProgram(const char *vShaderStr, const char *fShade
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
-
+
// NOTE: Default attribute shader locations must be binded before linking
glBindAttribLocation(program, 0, DEFAULT_ATTRIB_POSITION_NAME);
glBindAttribLocation(program, 1, DEFAULT_ATTRIB_TEXCOORD_NAME);
@@ -2970,11 +2970,11 @@ static unsigned int LoadShaderProgram(const char *vShaderStr, const char *fShade
glBindAttribLocation(program, 3, DEFAULT_ATTRIB_COLOR_NAME);
glBindAttribLocation(program, 4, DEFAULT_ATTRIB_TANGENT_NAME);
glBindAttribLocation(program, 5, DEFAULT_ATTRIB_TEXCOORD2_NAME);
-
+
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
-
+
glLinkProgram(program);
-
+
// NOTE: All uniform variables are intitialised to 0 when a program links
glGetProgramiv(program, GL_LINK_STATUS, &success);
@@ -2996,7 +2996,7 @@ static unsigned int LoadShaderProgram(const char *vShaderStr, const char *fShade
glGetProgramInfoLog(program, maxLength, &length, log);
TraceLog(INFO, "%s", log);
-
+
#ifdef _MSC_VER
free(log);
#endif
@@ -3099,7 +3099,7 @@ static void LoadDefaultShaderLocations(Shader *shader)
// vertex color location = 3
// vertex tangent location = 4
// vertex texcoord2 location = 5
-
+
// Get handles to GLSL input attibute locations
shader->vertexLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_POSITION_NAME);
shader->texcoordLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD_NAME);
@@ -3115,15 +3115,15 @@ static void LoadDefaultShaderLocations(Shader *shader)
shader->colDiffuseLoc = glGetUniformLocation(shader->id, "colDiffuse");
shader->colAmbientLoc = glGetUniformLocation(shader->id, "colAmbient");
shader->colSpecularLoc = glGetUniformLocation(shader->id, "colSpecular");
-
+
shader->mapTexture0Loc = glGetUniformLocation(shader->id, "texture0");
shader->mapTexture1Loc = glGetUniformLocation(shader->id, "texture1");
shader->mapTexture2Loc = glGetUniformLocation(shader->id, "texture2");
-
+
// TODO: Try to find all expected/recognized shader locations (predefined names, must be documented)
}
-// Unload default shader
+// Unload default shader
static void UnloadDefaultShader(void)
{
glUseProgram(0);
@@ -3140,7 +3140,7 @@ static void LoadDefaultBuffers(void)
{
// [CPU] Allocate and initialize float array buffers to store vertex data (lines, triangles, quads)
//--------------------------------------------------------------------------------------------
-
+
// Lines - Initialize arrays (vertex position and color data)
lines.vertices = (float *)malloc(sizeof(float)*3*2*MAX_LINES_BATCH); // 3 float by vertex, 2 vertex by line
lines.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*2*MAX_LINES_BATCH); // 4 float by color, 2 colors by line
@@ -3202,11 +3202,11 @@ static void LoadDefaultBuffers(void)
TraceLog(INFO, "[CPU] Default buffers initialized successfully (lines, triangles, quads)");
//--------------------------------------------------------------------------------------------
-
+
// [GPU] Upload vertex data and initialize VAOs/VBOs (lines, triangles, quads)
// NOTE: Default buffers are linked to use currentShader (defaultShader)
//--------------------------------------------------------------------------------------------
-
+
// Upload and link lines vertex buffers
if (vaoSupported)
{
@@ -3215,7 +3215,7 @@ static void LoadDefaultBuffers(void)
glBindVertexArray(lines.vaoId);
}
- // Lines - Vertex buffers binding and attributes enable
+ // Lines - Vertex buffers binding and attributes enable
// Vertex position buffer (shader-location = 0)
glGenBuffers(2, &lines.vboId[0]);
glBindBuffer(GL_ARRAY_BUFFER, lines.vboId[0]);
@@ -3241,7 +3241,7 @@ static void LoadDefaultBuffers(void)
glBindVertexArray(triangles.vaoId);
}
- // Triangles - Vertex buffers binding and attributes enable
+ // Triangles - Vertex buffers binding and attributes enable
// Vertex position buffer (shader-location = 0)
glGenBuffers(1, &triangles.vboId[0]);
glBindBuffer(GL_ARRAY_BUFFER, triangles.vboId[0]);
@@ -3267,7 +3267,7 @@ static void LoadDefaultBuffers(void)
glBindVertexArray(quads.vaoId);
}
- // Quads - Vertex buffers binding and attributes enable
+ // Quads - Vertex buffers binding and attributes enable
// Vertex position buffer (shader-location = 0)
glGenBuffers(1, &quads.vboId[0]);
glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[0]);
@@ -3383,7 +3383,7 @@ static void DrawDefaultBuffers(int eyesCount)
{
Matrix matProjection = projection;
Matrix matModelView = modelview;
-
+
for (int eye = 0; eye < eyesCount; eye++)
{
if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView);
@@ -3392,17 +3392,17 @@ static void DrawDefaultBuffers(int eyesCount)
if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
{
glUseProgram(currentShader.id);
-
+
// Create modelview-projection matrix
Matrix matMVP = MatrixMultiply(modelview, projection);
glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP));
glUniform4f(currentShader.colDiffuseLoc, 1.0f, 1.0f, 1.0f, 1.0f);
glUniform1i(currentShader.mapTexture0Loc, 0);
-
+
// NOTE: Additional map textures not considered for default buffers drawing
}
-
+
// Draw lines buffers
if (lines.vCounter > 0)
{
@@ -3486,7 +3486,7 @@ static void DrawDefaultBuffers(int eyesCount)
glBindBuffer(GL_ARRAY_BUFFER, quads.vboId[2]);
glVertexAttribPointer(currentShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
glEnableVertexAttribArray(currentShader.colorLoc);
-
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quads.vboId[3]);
}
@@ -3526,7 +3526,7 @@ static void DrawDefaultBuffers(int eyesCount)
glUseProgram(0); // Unbind shader program
}
-
+
// Reset draws counter
drawsCounter = 1;
draws[0].textureId = whiteTexture;
@@ -3540,10 +3540,10 @@ static void DrawDefaultBuffers(int eyesCount)
quads.vCounter = 0;
quads.tcCounter = 0;
quads.cCounter = 0;
-
+
// Reset depth for next draw
currentDepth = -1.0f;
-
+
// Restore projection/modelview matrices
projection = matProjection;
modelview = matModelView;
@@ -3604,34 +3604,34 @@ static void SetStereoConfig(VrDeviceInfo hmd)
float rightLensCenter[2] = { 0.75f - lensShift, 0.5f };
float leftScreenCenter[2] = { 0.25f, 0.5f };
float rightScreenCenter[2] = { 0.75f, 0.5f };
-
+
// Compute distortion scale parameters
// NOTE: To get lens max radius, lensShift must be normalized to [-1..1]
float lensRadius = fabsf(-1.0f - 4.0f*lensShift);
float lensRadiusSq = lensRadius*lensRadius;
- float distortionScale = hmd.distortionK[0] +
- hmd.distortionK[1]*lensRadiusSq +
- hmd.distortionK[2]*lensRadiusSq*lensRadiusSq +
+ float distortionScale = hmd.distortionK[0] +
+ hmd.distortionK[1]*lensRadiusSq +
+ hmd.distortionK[2]*lensRadiusSq*lensRadiusSq +
hmd.distortionK[3]*lensRadiusSq*lensRadiusSq*lensRadiusSq;
-
+
TraceLog(DEBUG, "VR: Distortion Scale: %f", distortionScale);
-
+
float normScreenWidth = 0.5f;
float normScreenHeight = 1.0f;
float scaleIn[2] = { 2.0f/normScreenWidth, 2.0f/normScreenHeight/aspect };
float scale[2] = { normScreenWidth*0.5f/distortionScale, normScreenHeight*0.5f*aspect/distortionScale };
-
+
TraceLog(DEBUG, "VR: Distortion Shader: LeftLensCenter = { %f, %f }", leftLensCenter[0], leftLensCenter[1]);
TraceLog(DEBUG, "VR: Distortion Shader: RightLensCenter = { %f, %f }", rightLensCenter[0], rightLensCenter[1]);
TraceLog(DEBUG, "VR: Distortion Shader: Scale = { %f, %f }", scale[0], scale[1]);
TraceLog(DEBUG, "VR: Distortion Shader: ScaleIn = { %f, %f }", scaleIn[0], scaleIn[1]);
-
+
// Update distortion shader with lens and distortion-scale parameters
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftLensCenter"), leftLensCenter, 2);
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightLensCenter"), rightLensCenter, 2);
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftScreenCenter"), leftScreenCenter, 2);
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightScreenCenter"), rightScreenCenter, 2);
-
+
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scale"), scale, 2);
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scaleIn"), scaleIn, 2);
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "hmdWarpParam"), hmd.distortionK, 4);
@@ -3641,24 +3641,24 @@ static void SetStereoConfig(VrDeviceInfo hmd)
// ...but with lens distortion it is increased (see Oculus SDK Documentation)
//float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance)*RAD2DEG; // Really need distortionScale?
float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance)*RAD2DEG;
-
+
// Compute camera projection matrices
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
Matrix proj = MatrixPerspective(fovy, aspect, 0.01, 1000.0);
vrConfig.eyesProjection[0] = MatrixMultiply(proj, MatrixTranslate(projOffset, 0.0f, 0.0f));
vrConfig.eyesProjection[1] = MatrixMultiply(proj, MatrixTranslate(-projOffset, 0.0f, 0.0f));
-
+
// NOTE: Projection matrices must be transposed due to raymath convention
MatrixTranspose(&vrConfig.eyesProjection[0]);
MatrixTranspose(&vrConfig.eyesProjection[1]);
-
+
// Compute camera transformation matrices
- // NOTE: Camera movement might seem more natural if we model the head.
- // Our axis of rotation is the base of our head, so we might want to add
+ // NOTE: Camera movement might seem more natural if we model the head.
+ // Our axis of rotation is the base of our head, so we might want to add
// some y (base of head to eye level) and -z (center of head to eye protrusion) to the camera positions.
vrConfig.eyesViewOffset[0] = MatrixTranslate(-hmd.interpupillaryDistance*0.5f, 0.075f, 0.045f);
vrConfig.eyesViewOffset[1] = MatrixTranslate(hmd.interpupillaryDistance*0.5f, 0.075f, 0.045f);
-
+
// Compute eyes Viewports
//vrConfig.eyesViewport[0] = (Rectangle){ 0, 0, hmd.hResolution/2, hmd.vResolution };
//vrConfig.eyesViewport[1] = (Rectangle){ hmd.hResolution/2, 0, hmd.hResolution/2, hmd.vResolution };
@@ -3675,17 +3675,17 @@ static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView)
#if defined(RLGL_OCULUS_SUPPORT)
if (vrDeviceReady)
{
- rlViewport(layer.eyeLayer.Viewport[eye].Pos.x, layer.eyeLayer.Viewport[eye].Pos.y,
+ rlViewport(layer.eyeLayer.Viewport[eye].Pos.x, layer.eyeLayer.Viewport[eye].Pos.y,
layer.eyeLayer.Viewport[eye].Size.w, layer.eyeLayer.Viewport[eye].Size.h);
- Quaternion eyeRenderPose = (Quaternion){ layer.eyeLayer.RenderPose[eye].Orientation.x,
- layer.eyeLayer.RenderPose[eye].Orientation.y,
- layer.eyeLayer.RenderPose[eye].Orientation.z,
+ Quaternion eyeRenderPose = (Quaternion){ layer.eyeLayer.RenderPose[eye].Orientation.x,
+ layer.eyeLayer.RenderPose[eye].Orientation.y,
+ layer.eyeLayer.RenderPose[eye].Orientation.z,
layer.eyeLayer.RenderPose[eye].Orientation.w };
QuaternionInvert(&eyeRenderPose);
Matrix eyeOrientation = QuaternionToMatrix(eyeRenderPose);
- Matrix eyeTranslation = MatrixTranslate(-layer.eyeLayer.RenderPose[eye].Position.x,
- -layer.eyeLayer.RenderPose[eye].Position.y,
+ Matrix eyeTranslation = MatrixTranslate(-layer.eyeLayer.RenderPose[eye].Position.x,
+ -layer.eyeLayer.RenderPose[eye].Position.y,
-layer.eyeLayer.RenderPose[eye].Position.z);
Matrix eyeView = MatrixMultiply(eyeTranslation, eyeOrientation); // Matrix containing eye-head movement
@@ -3701,7 +3701,7 @@ static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView)
// Apply view offset to modelview matrix
eyeModelView = MatrixMultiply(matModelView, vrConfig.eyesViewOffset[eye]);
-
+
eyeProjection = vrConfig.eyesProjection[eye];
}
@@ -3845,7 +3845,7 @@ OCULUSAPI bool InitOculusDevice(void)
bool oculusReady = false;
ovrResult result = ovr_Initialize(NULL);
-
+
if (OVR_FAILURE(result)) TraceLog(WARNING, "OVR: Could not initialize Oculus device");
else
{
@@ -3865,24 +3865,24 @@ OCULUSAPI bool InitOculusDevice(void)
TraceLog(INFO, "OVR: Product Type: %i", hmdDesc.Type);
//TraceLog(INFO, "OVR: Serial Number: %s", hmdDesc.SerialNumber);
TraceLog(INFO, "OVR: Resolution: %ix%i", hmdDesc.Resolution.w, hmdDesc.Resolution.h);
-
+
// NOTE: Oculus mirror is set to defined screenWidth and screenHeight...
// ...ideally, it should be (hmdDesc.Resolution.w/2, hmdDesc.Resolution.h/2)
-
+
// Initialize Oculus Buffers
- layer = InitOculusLayer(session);
+ layer = InitOculusLayer(session);
buffer = LoadOculusBuffer(session, layer.width, layer.height);
mirror = LoadOculusMirror(session, hmdDesc.Resolution.w/2, hmdDesc.Resolution.h/2); // NOTE: hardcoded...
layer.eyeLayer.ColorTexture[0] = buffer.textureChain; //SetOculusLayerTexture(eyeLayer, buffer.textureChain);
-
+
// Recenter OVR tracking origin
ovr_RecenterTrackingOrigin(session);
-
+
oculusReady = true;
vrEnabled = true;
}
}
-
+
return oculusReady;
}
@@ -3903,18 +3903,18 @@ OCULUSAPI void UpdateOculusTracking(Camera *camera)
ovrPosef eyePoses[2];
ovr_GetEyePoses(session, frameIndex, ovrTrue, layer.viewScaleDesc.HmdToEyeOffset, eyePoses, &layer.eyeLayer.SensorSampleTime);
-
+
layer.eyeLayer.RenderPose[0] = eyePoses[0];
layer.eyeLayer.RenderPose[1] = eyePoses[1];
-
+
// TODO: Update external camera with eyePoses data (position, orientation)
// NOTE: We can simplify to simple camera if we consider IPD and HMD device configuration again later
// it will be useful for the user to draw, lets say, billboards oriented to camera
-
+
// Get session status information
ovrSessionStatus sessionStatus;
ovr_GetSessionStatus(session, &sessionStatus);
-
+
if (sessionStatus.ShouldQuit) TraceLog(WARNING, "OVR: Session should quit...");
if (sessionStatus.ShouldRecenter) ovr_RecenterTrackingOrigin(session);
//if (sessionStatus.HmdPresent) // HMD is present.
@@ -3928,7 +3928,7 @@ OCULUSAPI void BeginOculusDrawing(void)
{
GLuint currentTexId;
int currentIndex;
-
+
ovr_GetTextureSwapChainCurrentIndex(session, buffer.textureChain, &currentIndex);
ovr_GetTextureSwapChainBufferGL(session, buffer.textureChain, currentIndex, &currentTexId);
@@ -3943,9 +3943,9 @@ OCULUSAPI void EndOculusDrawing(void)
// Unbind current framebuffer (Oculus buffer)
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-
+
ovr_CommitTextureSwapChain(session, buffer.textureChain);
-
+
ovrLayerHeader *layers = &layer.eyeLayer.Header;
ovr_SubmitFrame(session, frameIndex, &layer.viewScaleDesc, &layers, 1);
@@ -3959,7 +3959,7 @@ static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height)
OculusBuffer buffer;
buffer.width = width;
buffer.height = height;
-
+
// Create OVR texture chain
ovrTextureSwapChainDesc desc = {};
desc.Type = ovrTexture_2D;
@@ -3972,12 +3972,12 @@ static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height)
desc.StaticImage = ovrFalse;
ovrResult result = ovr_CreateTextureSwapChainGL(session, &desc, &buffer.textureChain);
-
+
if (!OVR_SUCCESS(result)) TraceLog(WARNING, "OVR: Failed to create swap textures buffer");
int textureCount = 0;
ovr_GetTextureSwapChainLength(session, buffer.textureChain, &textureCount);
-
+
if (!OVR_SUCCESS(result) || !textureCount) TraceLog(WARNING, "OVR: Unable to count swap chain textures");
for (int i = 0; i < textureCount; ++i)
@@ -3990,9 +3990,9 @@ static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
-
+
glBindTexture(GL_TEXTURE_2D, 0);
-
+
/*
// Setup framebuffer object (using depth texture)
glGenFramebuffers(1, &buffer.fboId);
@@ -4004,7 +4004,7 @@ static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, buffer.width, buffer.height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
*/
-
+
// Setup framebuffer object (using depth renderbuffer)
glGenFramebuffers(1, &buffer.fboId);
glGenRenderbuffers(1, &buffer.depthId);
@@ -4037,13 +4037,13 @@ static OculusMirror LoadOculusMirror(ovrSession session, int width, int height)
OculusMirror mirror;
mirror.width = width;
mirror.height = height;
-
+
ovrMirrorTextureDesc mirrorDesc;
memset(&mirrorDesc, 0, sizeof(mirrorDesc));
mirrorDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
mirrorDesc.Width = mirror.width;
mirrorDesc.Height = mirror.height;
-
+
if (!OVR_SUCCESS(ovr_CreateMirrorTextureGL(session, &mirrorDesc, &mirror.texture))) TraceLog(WARNING, "Could not create mirror texture");
glGenFramebuffers(1, &mirror.fboId);
@@ -4062,9 +4062,9 @@ static void UnloadOculusMirror(ovrSession session, OculusMirror mirror)
static void BlitOculusMirror(ovrSession session, OculusMirror mirror)
{
GLuint mirrorTextureId;
-
+
ovr_GetMirrorTextureBufferGL(session, mirror.texture, &mirrorTextureId);
-
+
glBindFramebuffer(GL_READ_FRAMEBUFFER, mirror.fboId);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mirrorTextureId, 0);
#if defined(GRAPHICS_API_OPENGL_33)
@@ -4078,7 +4078,7 @@ static void BlitOculusMirror(ovrSession session, OculusMirror mirror)
static OculusLayer InitOculusLayer(ovrSession session)
{
OculusLayer layer = { 0 };
-
+
layer.viewScaleDesc.HmdSpaceToWorldScaleInMeters = 1.0f;
memset(&layer.eyeLayer, 0, sizeof(ovrLayerEyeFov));
@@ -4086,7 +4086,7 @@ static OculusLayer InitOculusLayer(ovrSession session)
layer.eyeLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft;
ovrEyeRenderDesc eyeRenderDescs[2];
-
+
for (int eye = 0; eye < 2; eye++)
{
eyeRenderDescs[eye] = ovr_GetRenderDesc(session, eye, hmdDesc.DefaultEyeFov[eye]);
@@ -4095,7 +4095,7 @@ static OculusLayer InitOculusLayer(ovrSession session)
layer.viewScaleDesc.HmdToEyeOffset[eye] = eyeRenderDescs[eye].HmdToEyeOffset;
layer.eyeLayer.Fov[eye] = eyeRenderDescs[eye].Fov;
-
+
ovrSizei eyeSize = ovr_GetFovTextureSize(session, eye, layer.eyeLayer.Fov[eye], 1.0f);
layer.eyeLayer.Viewport[eye].Size = eyeSize;
layer.eyeLayer.Viewport[eye].Pos.x = layer.width;
@@ -4104,7 +4104,7 @@ static OculusLayer InitOculusLayer(ovrSession session)
layer.height = eyeSize.h; //std::max(renderTargetSize.y, (uint32_t)eyeSize.h);
layer.width += eyeSize.w;
}
-
+
return layer;
}
@@ -4112,7 +4112,7 @@ static OculusLayer InitOculusLayer(ovrSession session)
static Matrix FromOvrMatrix(ovrMatrix4f ovrmat)
{
Matrix rmat;
-
+
rmat.m0 = ovrmat.M[0][0];
rmat.m1 = ovrmat.M[1][0];
rmat.m2 = ovrmat.M[2][0];
@@ -4129,9 +4129,9 @@ static Matrix FromOvrMatrix(ovrMatrix4f ovrmat)
rmat.m13 = ovrmat.M[1][3];
rmat.m14 = ovrmat.M[2][3];
rmat.m15 = ovrmat.M[3][3];
-
+
MatrixTranspose(&rmat);
-
+
return rmat;
}
#endif
@@ -4162,7 +4162,7 @@ void TraceLog(int msgType, const char *text, ...)
}
// Converts Matrix to float array
-// NOTE: Returned vector is a transposed version of the Matrix struct,
+// NOTE: Returned vector is a transposed version of the Matrix struct,
// it should be this way because, despite raymath use OpenGL column-major convention,
// Matrix struct memory alignment and variables naming are not coherent
float *MatrixToFloat(Matrix mat)
diff --git a/src/text.c b/src/text.c
index 4e163668..e3d22fbd 100644
--- a/src/text.c
+++ b/src/text.c
@@ -286,17 +286,17 @@ SpriteFont LoadSpriteFont(const char *fileName)
SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int numChars, int *fontChars)
{
SpriteFont spriteFont = { 0 };
-
- if (strcmp(GetExtension(fileName),"ttf") == 0)
+
+ if (strcmp(GetExtension(fileName),"ttf") == 0)
{
if ((fontChars == NULL) || (numChars == 0))
{
int totalChars = 95; // Default charset [32..126]
-
+
int *defaultFontChars = (int *)malloc(totalChars*sizeof(int));
-
+
for (int i = 0; i < totalChars; i++) defaultFontChars[i] = i + 32; // Default first character: SPACE[32]
-
+
spriteFont = LoadTTF(fileName, fontSize, totalChars, defaultFontChars);
}
else spriteFont = LoadTTF(fileName, fontSize, numChars, fontChars);
@@ -353,10 +353,10 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, float
int textOffsetX = 0; // Offset between characters
int textOffsetY = 0; // Required for line break!
float scaleFactor;
-
+
unsigned char letter; // Current character
int index; // Index position in sprite font
-
+
scaleFactor = fontSize/spriteFont.size;
// NOTE: Some ugly hacks are made to support Latin-1 Extended characters directly
@@ -388,10 +388,10 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, float
}
else index = GetCharIndex(spriteFont, (int)text[i]);
- DrawTexturePro(spriteFont.texture, spriteFont.charRecs[index],
+ DrawTexturePro(spriteFont.texture, spriteFont.charRecs[index],
(Rectangle){ position.x + textOffsetX + spriteFont.charOffsets[index].x*scaleFactor,
position.y + textOffsetY + spriteFont.charOffsets[index].y*scaleFactor,
- spriteFont.charRecs[index].width*scaleFactor,
+ spriteFont.charRecs[index].width*scaleFactor,
spriteFont.charRecs[index].height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, tint);
if (spriteFont.charAdvanceX[index] == 0) textOffsetX += (int)(spriteFont.charRecs[index].width*scaleFactor + spacing);
@@ -476,7 +476,7 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, i
if (text[i] != '\n')
{
int index = GetCharIndex(spriteFont, (int)text[i]);
-
+
if (spriteFont.charAdvanceX[index] != 0) textWidth += spriteFont.charAdvanceX[index];
else textWidth += (spriteFont.charRecs[index].width + spriteFont.charOffsets[index].x);
}
@@ -517,7 +517,7 @@ static int GetCharIndex(SpriteFont font, int letter)
#define UNORDERED_CHARSET
#if defined(UNORDERED_CHARSET)
int index = 0;
-
+
for (int i = 0; i < font.numChars; i++)
{
if (font.charValues[i] == letter)
@@ -526,7 +526,7 @@ static int GetCharIndex(SpriteFont font, int letter)
break;
}
}
-
+
return index;
#else
return (letter - 32);
@@ -607,14 +607,14 @@ static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
}
TraceLog(DEBUG, "SpriteFont data parsed correctly from image");
-
- // NOTE: We need to remove key color borders from image to avoid weird
+
+ // NOTE: We need to remove key color borders from image to avoid weird
// artifacts on texture scaling when using FILTER_BILINEAR or FILTER_TRILINEAR
for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK;
// Create a new image with the processed color data (key color replaced by BLANK)
Image fontClear = LoadImageEx(pixels, image.width, image.height);
-
+
free(pixels); // Free pixels array memory
// Create spritefont with all data parsed from image
@@ -622,7 +622,7 @@ static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
spriteFont.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture
spriteFont.numChars = index;
-
+
UnloadImage(fontClear); // Unload processed image once converted to texture
// We got tempCharValues and tempCharsRecs populated with chars data
@@ -643,7 +643,7 @@ static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
}
spriteFont.size = spriteFont.charRecs[0].height;
-
+
TraceLog(INFO, "Image file loaded correctly as SpriteFont");
return spriteFont;
@@ -853,13 +853,13 @@ static SpriteFont LoadBMFont(const char *fileName)
strncat(texPath, texFileName, strlen(texFileName));
TraceLog(DEBUG, "[%s] Font texture loading path: %s", fileName, texPath);
-
+
Image imFont = LoadImage(texPath);
-
- if (imFont.format == UNCOMPRESSED_GRAYSCALE)
+
+ if (imFont.format == UNCOMPRESSED_GRAYSCALE)
{
Image imCopy = ImageCopy(imFont);
-
+
for (int i = 0; i < imCopy.width*imCopy.height; i++) ((unsigned char *)imCopy.data)[i] = 0xff; // WHITE pixel
ImageAlphaMask(&imCopy, imFont);
@@ -867,7 +867,7 @@ static SpriteFont LoadBMFont(const char *fileName)
UnloadImage(imCopy);
}
else font.texture = LoadTextureFromImage(imFont);
-
+
font.size = fontSize;
font.numChars = numChars;
font.charValues = (int *)malloc(numChars*sizeof(int));
@@ -876,7 +876,7 @@ static SpriteFont LoadBMFont(const char *fileName)
font.charAdvanceX = (int *)malloc(numChars*sizeof(int));
UnloadImage(imFont);
-
+
free(texPath);
int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX;
@@ -913,11 +913,11 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int numChars, int
// 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...
-
+
// Calculate next power-of-two value
float guessSize = ceilf((float)fontSize*3/4)*ceilf(sqrtf((float)numChars));
int textureSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT
-
+
TraceLog(INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize);
unsigned char *ttfBuffer = (unsigned char *)malloc(1 << 25);
@@ -935,7 +935,7 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int numChars, int
}
fread(ttfBuffer, 1, 1 << 25, ttfFile);
-
+
if (fontChars[0] != 32) TraceLog(WARNING, "TTF spritefont loading: first character is not SPACE(32) character");
// NOTE: Using stb_truetype crappy packing method, no guarante the font fits the image...
@@ -945,7 +945,7 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int numChars, int
//if (result > 0) TraceLog(INFO, "TTF spritefont loading: first unused row of generated bitmap: %i", result);
if (result < 0) TraceLog(WARNING, "TTF spritefont loading: Not all the characters fit in the font");
-
+
free(ttfBuffer);
// Convert image data from grayscale to to UNCOMPRESSED_GRAY_ALPHA
@@ -966,11 +966,11 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int numChars, int
image.mipmaps = 1;
image.format = UNCOMPRESSED_GRAY_ALPHA;
image.data = dataGrayAlpha;
-
+
font.texture = LoadTextureFromImage(image);
-
+
//SavePNG("generated_ttf_image.png", (unsigned char *)image.data, image.width, image.height, 2);
-
+
UnloadImage(image); // Unloads dataGrayAlpha
font.size = fontSize;
diff --git a/src/textures.c b/src/textures.c
index 3fa250c2..9d865aa1 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -144,9 +144,9 @@ Image LoadImage(const char *fileName)
else if (strcmp(GetExtension(fileName),"rres") == 0)
{
RRESData rres = LoadResource(fileName);
-
+
// NOTE: Parameters for RRES_IMAGE type are: width, height, format, mipmaps
-
+
if (rres.type == RRES_IMAGE) image = LoadImagePro(rres.data, rres.param1, rres.param2, rres.param3);
else TraceLog(WARNING, "[%s] Resource file does not contain image data", fileName);
@@ -197,9 +197,9 @@ Image LoadImagePro(void *data, int width, int height, int format)
srcImage.height = height;
srcImage.mipmaps = 1;
srcImage.format = format;
-
+
Image dstImage = ImageCopy(srcImage);
-
+
return dstImage;
}
@@ -244,7 +244,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
if (bytes < size)
{
TraceLog(WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName);
-
+
if (image.data != NULL) free(image.data);
}
else
@@ -615,12 +615,12 @@ void ImageAlphaMask(Image *image, Image alphaMask)
// Force mask to be Grayscale
Image mask = ImageCopy(alphaMask);
if (mask.format != UNCOMPRESSED_GRAYSCALE) ImageFormat(&mask, UNCOMPRESSED_GRAYSCALE);
-
+
// In case image is only grayscale, we just add alpha channel
if (image->format == UNCOMPRESSED_GRAYSCALE)
{
ImageFormat(image, UNCOMPRESSED_GRAY_ALPHA);
-
+
// Apply alpha mask to alpha channel
for (int i = 0, k = 1; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2)
{
@@ -955,7 +955,7 @@ void ImageResizeNN(Image *image,int newWidth,int newHeight)
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec)
{
bool cropRequired = false;
-
+
// Security checks to avoid size and rectangle issues (out of bounds)
// Check that srcRec is inside src image
if (srcRec.x < 0) srcRec.x = 0;
@@ -973,15 +973,15 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec)
TraceLog(WARNING, "Source rectangle height out of bounds, rescaled height: %i", srcRec.height);
cropRequired = true;
}
-
+
Image srcCopy = ImageCopy(src); // Make a copy of source image to work with it
ImageCrop(&srcCopy, srcRec); // Crop source image to desired source rectangle
-
+
// Check that dstRec is inside dst image
// TODO: Allow negative position within destination with cropping
if (dstRec.x < 0) dstRec.x = 0;
if (dstRec.y < 0) dstRec.y = 0;
-
+
// Scale source image in case destination rec size is different than source rec size
if ((dstRec.width != srcRec.width) || (dstRec.height != srcRec.height))
{
@@ -1001,20 +1001,20 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec)
TraceLog(WARNING, "Destination rectangle height out of bounds, rescaled height: %i", dstRec.height);
cropRequired = true;
}
-
+
if (cropRequired)
{
// Crop destination rectangle if out of bounds
Rectangle crop = { 0, 0, dstRec.width, dstRec.height };
ImageCrop(&srcCopy, crop);
}
-
+
// Get image data as Color pixels array to work with it
Color *dstPixels = GetImageData(*dst);
Color *srcPixels = GetImageData(srcCopy);
UnloadImage(srcCopy); // Source copy not required any more...
-
+
Color srcCol, dstCol;
// Blit pixels, copy source image into destination
@@ -1026,13 +1026,13 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec)
// Alpha blending implementation
dstCol = dstPixels[j*dst->width + i];
srcCol = srcPixels[(j - dstRec.y)*dstRec.width + (i - dstRec.x)];
-
+
dstCol.r = ((srcCol.a*(srcCol.r - dstCol.r)) >> 8) + dstCol.r;
dstCol.g = ((srcCol.a*(srcCol.g - dstCol.g)) >> 8) + dstCol.g;
dstCol.b = ((srcCol.a*(srcCol.b - dstCol.b)) >> 8) + dstCol.b;
-
+
dstPixels[j*dst->width + i] = dstCol;
-
+
// TODO: Support other blending options
}
}
@@ -1369,7 +1369,7 @@ void SetTextureFilter(Texture2D texture, int filterMode)
{
// RL_FILTER_MIP_NEAREST - tex filter: POINT, mipmaps filter: POINT (sharp switching between mipmaps)
rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_MIP_NEAREST);
-
+
// RL_FILTER_NEAREST - tex filter: POINT (no filter), no mipmaps
rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_NEAREST);
}
@@ -1387,7 +1387,7 @@ void SetTextureFilter(Texture2D texture, int filterMode)
// RL_FILTER_LINEAR_MIP_NEAREST - tex filter: BILINEAR, mipmaps filter: POINT (sharp switching between mipmaps)
// Alternative: RL_FILTER_NEAREST_MIP_LINEAR - tex filter: POINT, mipmaps filter: BILINEAR (smooth transition between mipmaps)
rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_LINEAR_MIP_NEAREST);
-
+
// RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR);
}
@@ -1404,14 +1404,14 @@ void SetTextureFilter(Texture2D texture, int filterMode)
{
// RL_FILTER_MIP_LINEAR - tex filter: BILINEAR, mipmaps filter: BILINEAR (smooth transition between mipmaps)
rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_MIP_LINEAR);
-
+
// RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR);
}
else
{
TraceLog(WARNING, "[TEX ID %i] No mipmaps available for TRILINEAR texture filtering", texture.id);
-
+
// RL_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
rlTextureParameters(texture.id, RL_TEXTURE_MIN_FILTER, RL_FILTER_LINEAR);
rlTextureParameters(texture.id, RL_TEXTURE_MAG_FILTER, RL_FILTER_LINEAR);
@@ -2007,19 +2007,19 @@ static Image LoadPVR(const char *fileName)
image.mipmaps = pvrHeader.numMipmaps;
// Check data format
- if (((pvrHeader.channels[0] == 'l') && (pvrHeader.channels[1] == 0)) && (pvrHeader.channelDepth[0] == 8))
+ if (((pvrHeader.channels[0] == 'l') && (pvrHeader.channels[1] == 0)) && (pvrHeader.channelDepth[0] == 8))
image.format = UNCOMPRESSED_GRAYSCALE;
- else if (((pvrHeader.channels[0] == 'l') && (pvrHeader.channels[1] == 'a')) && ((pvrHeader.channelDepth[0] == 8) && (pvrHeader.channelDepth[1] == 8)))
+ else if (((pvrHeader.channels[0] == 'l') && (pvrHeader.channels[1] == 'a')) && ((pvrHeader.channelDepth[0] == 8) && (pvrHeader.channelDepth[1] == 8)))
image.format = UNCOMPRESSED_GRAY_ALPHA;
else if ((pvrHeader.channels[0] == 'r') && (pvrHeader.channels[1] == 'g') && (pvrHeader.channels[2] == 'b'))
{
if (pvrHeader.channels[3] == 'a')
{
- if ((pvrHeader.channelDepth[0] == 5) && (pvrHeader.channelDepth[1] == 5) && (pvrHeader.channelDepth[2] == 5) && (pvrHeader.channelDepth[3] == 1))
+ if ((pvrHeader.channelDepth[0] == 5) && (pvrHeader.channelDepth[1] == 5) && (pvrHeader.channelDepth[2] == 5) && (pvrHeader.channelDepth[3] == 1))
image.format = UNCOMPRESSED_R5G5B5A1;
- else if ((pvrHeader.channelDepth[0] == 4) && (pvrHeader.channelDepth[1] == 4) && (pvrHeader.channelDepth[2] == 4) && (pvrHeader.channelDepth[3] == 4))
+ else if ((pvrHeader.channelDepth[0] == 4) && (pvrHeader.channelDepth[1] == 4) && (pvrHeader.channelDepth[2] == 4) && (pvrHeader.channelDepth[3] == 4))
image.format = UNCOMPRESSED_R4G4B4A4;
- else if ((pvrHeader.channelDepth[0] == 8) && (pvrHeader.channelDepth[1] == 8) && (pvrHeader.channelDepth[2] == 8) && (pvrHeader.channelDepth[3] == 8))
+ else if ((pvrHeader.channelDepth[0] == 8) && (pvrHeader.channelDepth[1] == 8) && (pvrHeader.channelDepth[2] == 8) && (pvrHeader.channelDepth[3] == 8))
image.format = UNCOMPRESSED_R8G8B8A8;
}
else if (pvrHeader.channels[3] == 0)