diff options
| author | Ray <[email protected]> | 2017-05-12 14:01:39 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-12 14:01:39 +0200 |
| commit | 1ed3d3285f1c1f6a01e0588ec46a177c84b864f5 (patch) | |
| tree | 4af033e377a27636d20cb165bc53c72d692ccb09 /src | |
| parent | 0ca874c710aace697c5a383f41fc81abf34e2e06 (diff) | |
| parent | 42ad00b7c280e2242e3338a4acd85815c1707701 (diff) | |
| download | raylib-1ed3d3285f1c1f6a01e0588ec46a177c84b864f5.tar.gz raylib-1ed3d3285f1c1f6a01e0588ec46a177c84b864f5.zip | |
Merge pull request #285 from raysan5/develop
Integrate develop branch
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 14 | ||||
| -rw-r--r-- | src/android/jni/include/AL/oalMacOSX_OALExtensions.h | 161 | ||||
| -rw-r--r-- | src/android/jni/include/AL/oalStaticBufferExtension.h | 0 | ||||
| -rw-r--r-- | src/audio.c | 26 | ||||
| -rw-r--r-- | src/core.c | 341 | ||||
| -rw-r--r-- | src/models.c | 10 | ||||
| -rw-r--r-- | src/physac.h | 11 | ||||
| -rw-r--r-- | src/raylib.h | 59 | ||||
| -rw-r--r-- | src/rlgl.c | 3 | ||||
| -rw-r--r-- | src/textures.c | 6 |
10 files changed, 267 insertions, 364 deletions
diff --git a/src/Makefile b/src/Makefile index f2e09988..e9de5623 100644 --- a/src/Makefile +++ b/src/Makefile @@ -101,7 +101,7 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID) # Android standalone toolchain path # NOTE: This path is also used if toolchain generation #ANDROID_TOOLCHAIN = $(CURDIR)/toolchain - ANDROID_TOOLCHAIN = C:/raylib/android-standalone-toolchain + ANDROID_TOOLCHAIN = C:/raylib/android-toolchain # Android architecture: ARM or ARM64 ANDROID_ARCH ?= ARM @@ -230,8 +230,13 @@ endif # external required libraries (stb and others) INCLUDES = -I. -Iexternal + # OpenAL Soft library -INCLUDES += -Iexternal/openal_soft/include +ifeq ($(PLATFORM),PLATFORM_ANDROID) + INCLUDES += -Iandroid/jni/include/AL +else + INCLUDES += -Iexternal/openal_soft/include +endif # define any directories containing required header files ifeq ($(PLATFORM),PLATFORM_DESKTOP) @@ -325,12 +330,12 @@ else endif ifeq ($(PLATFORM),PLATFORM_ANDROID) $(CC) -shared -o $(OUTPUT_PATH)/libraylib.so $(OBJS) - @echo "raylib shared library (libraylib.so) generated!" + @echo "raylib shared library generated (libraylib.so)!" endif else # compile raylib static library. $(AR) rcs $(OUTPUT_PATH)/libraylib.a $(OBJS) - @echo "libraylib.a generated (static library)!" + @echo "raylib static library generated (libraylib.a)!" ifeq ($(SHARED_OPENAL),NO) @echo "expected OpenAL Soft static library linking" else @@ -377,7 +382,6 @@ external/stb_vorbis.o: external/stb_vorbis.c external/stb_vorbis.h utils.o : utils.c utils.h $(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG) - # It installs generated and needed files to compile projects using raylib. # The installation works manually. # TODO: add other platforms. diff --git a/src/android/jni/include/AL/oalMacOSX_OALExtensions.h b/src/android/jni/include/AL/oalMacOSX_OALExtensions.h deleted file mode 100644 index c3db3054..00000000 --- a/src/android/jni/include/AL/oalMacOSX_OALExtensions.h +++ /dev/null @@ -1,161 +0,0 @@ -/********************************************************************************************************************************** -* -* OpenAL cross platform audio library -* Copyright (c) 2004-2006, Apple Computer, Inc. All rights reserved. -* Copyright (c) 2007-2008, Apple Inc. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following -* conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided with the distribution. -* 3. Neither the name of Apple Inc. ("Apple") nor the names of its contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -**********************************************************************************************************************************/ - -#ifndef __OAL_MAC_OSX_OAL_EXTENSIONS_H__ -#define __OAL_MAC_OSX_OAL_EXTENSIONS_H__ - -#include <OpenAL/al.h> - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ALC_EXT_MAC_OSX - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -// Retrieve functions via alGetProcAddress() by passing in strings: alcMacOSXMixerOutputRate or alcMacOSXGetMixerOutputRate - -// Setting the Mixer Output Rate effectively sets the samnple rate at which the mixer -typedef ALvoid (*alcMacOSXRenderingQualityProcPtr) (ALint value); -typedef ALvoid (*alMacOSXRenderChannelCountProcPtr) (ALint value); -typedef ALvoid (*alcMacOSXMixerMaxiumumBussesProcPtr) (ALint value); -typedef ALvoid (*alcMacOSXMixerOutputRateProcPtr) (ALdouble value); - -typedef ALint (*alcMacOSXGetRenderingQualityProcPtr) (); -typedef ALint (*alMacOSXGetRenderChannelCountProcPtr) (); -typedef ALint (*alcMacOSXGetMixerMaxiumumBussesProcPtr) (); -typedef ALdouble (*alcMacOSXGetMixerOutputRateProcPtr) (); - -/* Render Quality. Used with alcMacOSXRenderingQuality() */ - - #define ALC_MAC_OSX_SPATIAL_RENDERING_QUALITY_HIGH 'rqhi' - #define ALC_MAC_OSX_SPATIAL_RENDERING_QUALITY_LOW 'rdlo' - - // High Quality Spatial Algorithm suitable only for headphone use - #define ALC_IPHONE_SPATIAL_RENDERING_QUALITY_HEADPHONES 'hdph' - -/* - Render Channels. Used with alMacOSXRenderChannelCount() - Allows a user to force OpenAL to render to stereo, regardless of the audio hardware being used -*/ - #define ALC_MAC_OSX_RENDER_CHANNEL_COUNT_STEREO 'rcst' - -/* GameKit extension */ - - #define AL_GAMEKIT 'gksr' - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - AL_EXT_SOURCE_NOTIFICATIONS - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* - Source Notifications - - Eliminates the need for continuous polling for source state by providing a - mechanism for the application to receive source state change notifications. - Upon receiving a notification, the application can retrieve the actual state - corresponding to the notification ID for which the notification was sent. - */ - -#define AL_QUEUE_HAS_LOOPED 0x9000 - -/* - Notification Proc: ALSourceNotificationProc - - sid - source id - notificationID - id of state that has changed - userData - user data provided to alSourceAddNotification() - */ - -typedef ALvoid (*alSourceNotificationProc)(ALuint sid, ALuint notificationID, ALvoid* userData); - -/* - API: alSourceAddNotification - - sid - source id - notificationID - id of state for which caller wants to be notified of a change - notifyProc - notification proc - userData - ptr to applications user data, will be returned in the notification proc - - Returns AL_NO_ERROR if request is successful. - - Valid IDs: - AL_SOURCE_STATE - AL_BUFFERS_PROCESSED - AL_QUEUE_HAS_LOOPED - notification sent when a looping source has looped to it's start point - */ -typedef ALenum (*alSourceAddNotificationProcPtr) (ALuint sid, ALuint notificationID, alSourceNotificationProc notifyProc, ALvoid* userData); - -/* - API: alSourceRemoveStateNotification - - sid - source id - notificationID - id of state for which caller wants to remove an existing notification - notifyProc - notification proc - userData - ptr to applications user data, will be returned in the notification proc - */ -typedef ALvoid (*alSourceRemoveNotificationProcPtr) (ALuint sid, ALuint notificationID, alSourceNotificationProc notifyProc, ALvoid* userData); - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ALC_EXT_ASA : Apple Spatial Audio Extension - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* - Used with the ASA API calls: alcASAGetSource(), alcASASetSource(), alcASAGetListener(), alcASASetListener() -*/ - -typedef ALenum (*alcASAGetSourceProcPtr) (ALuint property, ALuint source, ALvoid *data, ALuint* dataSize); -typedef ALenum (*alcASASetSourceProcPtr) (ALuint property, ALuint source, ALvoid *data, ALuint dataSize); -typedef ALenum (*alcASAGetListenerProcPtr) (ALuint property, ALvoid *data, ALuint* dataSize); -typedef ALenum (*alcASASetListenerProcPtr) (ALuint property, ALvoid *data, ALuint dataSize); - - /* listener properties */ - #define ALC_ASA_REVERB_ON 'rvon' // type ALuint - #define ALC_ASA_REVERB_GLOBAL_LEVEL 'rvgl' // type ALfloat -40.0 db - 40.0 db - - #define ALC_ASA_REVERB_ROOM_TYPE 'rvrt' // type ALint - - /* reverb room type presets for the ALC_ASA_REVERB_ROOM_TYPE property */ - #define ALC_ASA_REVERB_ROOM_TYPE_SmallRoom 0 - #define ALC_ASA_REVERB_ROOM_TYPE_MediumRoom 1 - #define ALC_ASA_REVERB_ROOM_TYPE_LargeRoom 2 - #define ALC_ASA_REVERB_ROOM_TYPE_MediumHall 3 - #define ALC_ASA_REVERB_ROOM_TYPE_LargeHall 4 - #define ALC_ASA_REVERB_ROOM_TYPE_Plate 5 - #define ALC_ASA_REVERB_ROOM_TYPE_MediumChamber 6 - #define ALC_ASA_REVERB_ROOM_TYPE_LargeChamber 7 - #define ALC_ASA_REVERB_ROOM_TYPE_Cathedral 8 - #define ALC_ASA_REVERB_ROOM_TYPE_LargeRoom2 9 - #define ALC_ASA_REVERB_ROOM_TYPE_MediumHall2 10 - #define ALC_ASA_REVERB_ROOM_TYPE_MediumHall3 11 - #define ALC_ASA_REVERB_ROOM_TYPE_LargeHall2 12 - - #define ALC_ASA_REVERB_EQ_GAIN 'rveg' // type ALfloat - #define ALC_ASA_REVERB_EQ_BANDWITH 'rveb' // type ALfloat - #define ALC_ASA_REVERB_EQ_FREQ 'rvef' // type ALfloat - - /* source properties */ - #define ALC_ASA_REVERB_SEND_LEVEL 'rvsl' // type ALfloat 0.0 (dry) - 1.0 (wet) (0-100% dry/wet mix, 0.0 default) - #define ALC_ASA_OCCLUSION 'occl' // type ALfloat -100.0 db (most occlusion) - 0.0 db (no occlusion, 0.0 default) - #define ALC_ASA_OBSTRUCTION 'obst' // type ALfloat -100.0 db (most obstruction) - 0.0 db (no obstruction, 0.0 default) - -#endif // __OAL_MAC_OSX_OAL_EXTENSIONS_H__ diff --git a/src/android/jni/include/AL/oalStaticBufferExtension.h b/src/android/jni/include/AL/oalStaticBufferExtension.h deleted file mode 100644 index e69de29b..00000000 --- a/src/android/jni/include/AL/oalStaticBufferExtension.h +++ /dev/null diff --git a/src/audio.c b/src/audio.c index 39befbbc..3005586f 100644 --- a/src/audio.c +++ b/src/audio.c @@ -801,20 +801,26 @@ void ResumeMusicStream(Music music) } // Stop music playing (close stream) +// TODO: To clear a buffer, make sure they have been already processed! void StopMusicStream(Music music) { alSourceStop(music->stream.source); + /* // Clear stream buffers + // WARNING: Queued buffers must have been processed before unqueueing and reloaded with data!!! void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, 1); - + for (int i = 0; i < MAX_STREAM_BUFFERS; i++) { - UpdateAudioStream(music->stream, pcm, AUDIO_BUFFER_SIZE); - //alBufferData(music->stream.buffers[i], music->stream.format, pcm, AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, music->stream.sampleRate); + + + //UpdateAudioStream(music->stream, pcm, AUDIO_BUFFER_SIZE); // Update one buffer at a time + alBufferData(music->stream.buffers[i], music->stream.format, pcm, AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, music->stream.sampleRate); } free(pcm); + */ // Restart music context switch (music->ctxType) @@ -896,9 +902,9 @@ void UpdateMusicStream(Music music) break; } } - - // This error is registered when UpdateAudioStream() fails - if (alGetError() == AL_INVALID_VALUE) TraceLog(WARNING, "OpenAL: Error buffering data..."); + + // Free allocated pcm data + free(pcm); // Reset audio stream for looping if (!active) @@ -918,8 +924,6 @@ void UpdateMusicStream(Music music) // just make sure to play again on window restore if (state != AL_PLAYING) PlayMusicStream(music); } - - free(pcm); } } @@ -1066,7 +1070,8 @@ void CloseAudioStream(AudioStream stream) } // Update audio stream buffers with data -// NOTE: Only updates one buffer per call +// NOTE 1: Only updates one buffer of the stream source: unqueue -> update -> queue +// NOTE 2: To unqueue a buffer it needs to be processed: IsAudioBufferProcessed() void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount) { ALuint buffer = 0; @@ -1075,9 +1080,10 @@ void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount) // Check if any buffer was available for unqueue if (alGetError() != AL_INVALID_VALUE) { - alBufferData(buffer, stream.format, data, samplesCount*stream.channels*stream.sampleSize/8, stream.sampleRate); + alBufferData(buffer, stream.format, data, samplesCount*stream.sampleSize/8*stream.channels, stream.sampleRate); alSourceQueueBuffers(stream.source, 1, &buffer); } + else TraceLog(WARNING, "[AUD ID %i] Audio buffer not available for unqueuing", stream.source); } // Check if any audio stream buffers requires refill @@ -108,6 +108,16 @@ #include <string.h> // Required for: strrchr(), strcmp() //#include <errno.h> // Macros for reporting and retrieving error conditions through error codes +#ifdef _WIN32 + #include <direct.h> // Required for: _getch(), _chdir() + #define GETCWD _getcwd // NOTE: MSDN recommends not to use getcwd(), chdir() + #define CHDIR _chdir +#else + #include "unistd.h" // Required for: getch(), chdir() (POSIX) + #define GETCWD getcwd + #define CHDIR chdir +#endif + #if defined(__linux__) || defined(PLATFORM_WEB) #include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX #elif defined(__APPLE__) @@ -259,6 +269,7 @@ static Matrix downscaleView; // Matrix to downscale view (in case static const char *windowTitle; // Window text title... static bool cursorOnScreen = false; // Tracks if cursor is inside client area static bool cursorHidden = false; // Track if cursor is hidden +static int screenshotCounter = 0; // Screenshots counter // Register mouse states static char previousMouseState[3] = { 0 }; // Registers previous mouse button state @@ -380,7 +391,7 @@ static void *GamepadThread(void *arg); // Mouse reading thread // Module Functions Definition - Window and OpenGL Context Functions //---------------------------------------------------------------------------------- #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -// Initialize Window and Graphics Context (OpenGL) +// Initialize window and OpenGL context void InitWindow(int width, int height, const char *title) { TraceLog(INFO, "Initializing raylib (v1.7.0)"); @@ -443,7 +454,7 @@ void InitWindow(int width, int height, const char *title) #endif #if defined(PLATFORM_ANDROID) -// Android activity initialization +// Initialize Android activity void InitWindow(int width, int height, void *state) { TraceLog(INFO, "Initializing raylib (v1.7.0)"); @@ -506,7 +517,7 @@ void InitWindow(int width, int height, void *state) } #endif -// Close Window and Terminate Context +// Close window and unload OpenGL context void CloseWindow(void) { #if defined(SUPPORT_DEFAULT_FONT) @@ -562,7 +573,7 @@ void CloseWindow(void) TraceLog(INFO, "Window closed successfully"); } -// Detect if KEY_ESCAPE pressed or Close icon pressed +// Check if KEY_ESCAPE pressed or Close icon pressed bool WindowShouldClose(void) { #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) @@ -577,7 +588,7 @@ bool WindowShouldClose(void) #endif } -// Detect if window has been minimized (or lost focus) +// Check if window has been minimized (or lost focus) bool IsWindowMinimized(void) { #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) @@ -587,7 +598,7 @@ bool IsWindowMinimized(void) #endif } -// Fullscreen toggle (only PLATFORM_DESKTOP) +// Toggle fullscreen mode (only PLATFORM_DESKTOP) void ToggleFullscreen(void) { #if defined(PLATFORM_DESKTOP) @@ -646,7 +657,7 @@ void SetWindowMonitor(int monitor) #endif } -// Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) +// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) void SetWindowMinSize(int width, int height) { #if defined(PLATFORM_DESKTOP) @@ -681,7 +692,7 @@ void ShowCursor() cursorHidden = false; } -// Hide mouse cursor +// Hides mouse cursor void HideCursor() { #if defined(PLATFORM_DESKTOP) @@ -701,13 +712,13 @@ void HideCursor() cursorHidden = true; } -// Check if mouse cursor is hidden +// Check if cursor is not visible bool IsCursorHidden() { return cursorHidden; } -// Enable mouse cursor +// Enables cursor (unlock cursor) void EnableCursor() { #if defined(PLATFORM_DESKTOP) @@ -719,7 +730,7 @@ void EnableCursor() cursorHidden = false; } -// Disable mouse cursor +// Disables cursor (lock cursor) void DisableCursor() { #if defined(PLATFORM_DESKTOP) @@ -732,14 +743,14 @@ void DisableCursor() } #endif // !defined(PLATFORM_ANDROID) -// Sets Background Color +// Set background color (framebuffer clear color) void ClearBackground(Color color) { // Clear full framebuffer (not only render area) to color rlClearColor(color.r, color.g, color.b, color.a); } -// Setup drawing canvas to start drawing +// Setup canvas (framebuffer) to start drawing void BeginDrawing(void) { currentTime = GetTime(); // Number of elapsed seconds since InitTimer() was called @@ -754,7 +765,7 @@ void BeginDrawing(void) // NOTE: Not required with OpenGL 3.3+ } -// End canvas drawing and Swap Buffers (Double Buffering) +// End canvas drawing and swap buffers (double buffering) void EndDrawing(void) { rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) @@ -782,7 +793,7 @@ void EndDrawing(void) } } -// Initialize 2D mode with custom camera +// Initialize 2D mode with custom camera (2D) void Begin2dMode(Camera2D camera) { rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) @@ -800,7 +811,7 @@ void Begin2dMode(Camera2D camera) rlMultMatrixf(MatrixToFloat(matTransform)); } -// Ends 2D mode custom camera usage +// Ends 2D mode with custom camera void End2dMode(void) { rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) @@ -808,7 +819,7 @@ void End2dMode(void) rlLoadIdentity(); // Reset current matrix (MODELVIEW) } -// Initializes 3D mode for drawing (Camera setup) +// Initializes 3D mode with custom camera (3D) void Begin3dMode(Camera camera) { rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) @@ -897,7 +908,107 @@ void EndTextureMode(void) rlLoadIdentity(); // Reset current matrix (MODELVIEW) } -// Set target FPS for the game +// Returns a ray trace from mouse position +Ray GetMouseRay(Vector2 mousePosition, Camera camera) +{ + Ray ray; + + // Calculate normalized device coordinates + // NOTE: y value is negative + float x = (2.0f*mousePosition.x)/(float)GetScreenWidth() - 1.0f; + float y = 1.0f - (2.0f*mousePosition.y)/(float)GetScreenHeight(); + float z = 1.0f; + + // Store values in a vector + Vector3 deviceCoords = { x, y, z }; + + TraceLog(DEBUG, "Device coordinates: (%f, %f, %f)", deviceCoords.x, deviceCoords.y, deviceCoords.z); + + // Calculate projection matrix (from perspective instead of frustum) + Matrix matProj = MatrixPerspective(camera.fovy, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0); + + // Calculate view matrix from camera look at + Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); + + // Do I need to transpose it? It seems that yes... + // NOTE: matrix order may be incorrect... In OpenGL to get world position from + // camera view it just needs to get inverted, but here we need to transpose it too. + // For example, if you get view matrix, transpose and inverted and you transform it + // to a vector, you will get its 3d world position coordinates (camera.position). + // If you don't transpose, final position will be wrong. + MatrixTranspose(&matView); + +//#define USE_RLGL_UNPROJECT +#if defined(USE_RLGL_UNPROJECT) // OPTION 1: Use rlglUnproject() + + Vector3 nearPoint = rlglUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView); + Vector3 farPoint = rlglUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView); + +#else // OPTION 2: Compute unprojection directly here + + // Calculate unproject matrix (multiply projection matrix and view matrix) and invert it + Matrix matProjView = MatrixMultiply(matProj, matView); + MatrixInvert(&matProjView); + + // Calculate far and near points + Quaternion qNear = { deviceCoords.x, deviceCoords.y, 0.0f, 1.0f }; + Quaternion qFar = { deviceCoords.x, deviceCoords.y, 1.0f, 1.0f }; + + // Multiply points by unproject matrix + QuaternionTransform(&qNear, matProjView); + QuaternionTransform(&qFar, matProjView); + + // Calculate normalized world points in vectors + Vector3 nearPoint = { qNear.x/qNear.w, qNear.y/qNear.w, qNear.z/qNear.w}; + Vector3 farPoint = { qFar.x/qFar.w, qFar.y/qFar.w, qFar.z/qFar.w}; +#endif + + // Calculate normalized direction vector + Vector3 direction = VectorSubtract(farPoint, nearPoint); + VectorNormalize(&direction); + + // Apply calculated vectors to ray + ray.position = camera.position; + ray.direction = direction; + + return ray; +} + +// Returns the screen space position from a 3d world space position +Vector2 GetWorldToScreen(Vector3 position, Camera camera) +{ + // Calculate projection matrix (from perspective instead of frustum + Matrix matProj = MatrixPerspective(camera.fovy, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0); + + // Calculate view matrix from camera look at (and transpose it) + Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); + MatrixTranspose(&matView); + + // Convert world position vector to quaternion + Quaternion worldPos = { position.x, position.y, position.z, 1.0f }; + + // Transform world position to view + QuaternionTransform(&worldPos, matView); + + // Transform result to projection (clip space position) + QuaternionTransform(&worldPos, matProj); + + // Calculate normalized device coordinates (inverted y) + Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w }; + + // Calculate 2d screen position vector + Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() }; + + return screenPosition; +} + +// Get transform matrix for camera +Matrix GetCameraMatrix(Camera camera) +{ + return MatrixLookAt(camera.position, camera.target, camera.up); +} + +// Set target FPS (maximum) void SetTargetFPS(int fps) { if (fps < 1) targetTime = 0.0; @@ -912,7 +1023,7 @@ int GetFPS(void) return (int)(1.0f/GetFrameTime()); } -// Returns time in seconds for one frame +// Returns time in seconds for last frame drawn float GetFrameTime(void) { // NOTE: We round value to milliseconds @@ -944,7 +1055,6 @@ float *VectorToFloat(Vector3 vec) return buffer; } -// Converts Matrix to float array // 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 @@ -1004,7 +1114,7 @@ int GetRandomValue(int min, int max) return (rand()%(abs(max-min)+1) + min); } -// Fades color by a percentadge +// Color fade-in or fade-out, alpha goes from 0.0f to 1.0f Color Fade(Color color, float alpha) { if (alpha < 0.0f) alpha = 0.0f; @@ -1015,13 +1125,13 @@ Color Fade(Color color, float alpha) return (Color){color.r, color.g, color.b, (unsigned char)colorAlpha}; } -// Activates raylib logo at startup +// Activate raylib logo at startup (can be done with flags) void ShowLogo(void) { showLogo = true; } -// Enable some window/system configurations +// Setup window configuration flags (view FLAGS) void SetConfigFlags(char flags) { configFlags = flags; @@ -1030,25 +1140,17 @@ void SetConfigFlags(char flags) if (configFlags & FLAG_FULLSCREEN_MODE) fullscreen = true; } -// Takes a screenshot and saves it in the same folder as executable -void TakeScreenshot(void) +// NOTE TraceLog() function is located in [utils.h] + +// Takes a screenshot of current screen (saved a .png) +void TakeScreenshot(const char *fileName) { #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) - static int shotNum = 0; // Screenshot number, increments every screenshot take during program execution - char buffer[20]; // Buffer to store file name - unsigned char *imgData = rlglReadScreenPixels(renderWidth, renderHeight); - - sprintf(buffer, "screenshot%03i.png", shotNum); - - // Save image as PNG - SavePNG(buffer, imgData, renderWidth, renderHeight, 4); - + SavePNG(fileName, imgData, renderWidth, renderHeight, 4); // Save image as PNG free(imgData); - shotNum++; - - TraceLog(INFO, "[%s] Screenshot taken #03i", buffer, shotNum); + TraceLog(INFO, "Screenshot taken: %s", fileName); #endif } @@ -1066,15 +1168,46 @@ bool IsFileExtension(const char *fileName, const char *ext) return result; } +// Get directory for a given fileName (with path) +const char *GetDirectoryPath(const char *fileName) +{ + char *lastSlash = NULL; + static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256 + memset(filePath, 0, 256); + + lastSlash = strrchr(fileName, '\\'); + strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1)); + filePath[strlen(fileName) - strlen(lastSlash)] = '\0'; + + return filePath; +} + +// Get current working directory +const char *GetWorkingDirectory(void) +{ + static char currentDir[256]; // MAX_DIRECTORY_PATH_SIZE = 256 + memset(currentDir, 0, 256); + + GETCWD(currentDir, 256 - 1); + + return currentDir; +} + +// Change working directory, returns true if success +bool ChangeDirectory(const char *dir) +{ + return (CHDIR(dir) == 0); +} + #if defined(PLATFORM_DESKTOP) -// Check if a file have been dropped into window +// Check if a file has been dropped into window bool IsFileDropped(void) { if (dropFilesCount > 0) return true; else return false; } -// Retrieve dropped files into window +// Get dropped files names char **GetDroppedFiles(int *count) { *count = dropFilesCount; @@ -1095,7 +1228,7 @@ void ClearDroppedFiles(void) } #endif -// Storage save integer value (to defined position) +// Save integer value to storage file (to defined position) // NOTE: Storage positions is directly related to file memory layout (4 bytes each integer) void StorageSaveValue(int position, int value) { @@ -1135,7 +1268,7 @@ void StorageSaveValue(int position, int value) } } -// Storage load integer value (from defined position) +// Load integer value from storage file (from defined position) // NOTE: If requested position could not be found, value 0 is returned int StorageLoadValue(int position) { @@ -1174,106 +1307,6 @@ int StorageLoadValue(int position) return value; } -// Returns a ray trace from mouse position -Ray GetMouseRay(Vector2 mousePosition, Camera camera) -{ - Ray ray; - - // Calculate normalized device coordinates - // NOTE: y value is negative - float x = (2.0f*mousePosition.x)/(float)GetScreenWidth() - 1.0f; - float y = 1.0f - (2.0f*mousePosition.y)/(float)GetScreenHeight(); - float z = 1.0f; - - // Store values in a vector - Vector3 deviceCoords = { x, y, z }; - - TraceLog(DEBUG, "Device coordinates: (%f, %f, %f)", deviceCoords.x, deviceCoords.y, deviceCoords.z); - - // Calculate projection matrix (from perspective instead of frustum) - Matrix matProj = MatrixPerspective(camera.fovy, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0); - - // Calculate view matrix from camera look at - Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); - - // Do I need to transpose it? It seems that yes... - // NOTE: matrix order may be incorrect... In OpenGL to get world position from - // camera view it just needs to get inverted, but here we need to transpose it too. - // For example, if you get view matrix, transpose and inverted and you transform it - // to a vector, you will get its 3d world position coordinates (camera.position). - // If you don't transpose, final position will be wrong. - MatrixTranspose(&matView); - -//#define USE_RLGL_UNPROJECT -#if defined(USE_RLGL_UNPROJECT) // OPTION 1: Use rlglUnproject() - - Vector3 nearPoint = rlglUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView); - Vector3 farPoint = rlglUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView); - -#else // OPTION 2: Compute unprojection directly here - - // Calculate unproject matrix (multiply projection matrix and view matrix) and invert it - Matrix matProjView = MatrixMultiply(matProj, matView); - MatrixInvert(&matProjView); - - // Calculate far and near points - Quaternion qNear = { deviceCoords.x, deviceCoords.y, 0.0f, 1.0f }; - Quaternion qFar = { deviceCoords.x, deviceCoords.y, 1.0f, 1.0f }; - - // Multiply points by unproject matrix - QuaternionTransform(&qNear, matProjView); - QuaternionTransform(&qFar, matProjView); - - // Calculate normalized world points in vectors - Vector3 nearPoint = { qNear.x/qNear.w, qNear.y/qNear.w, qNear.z/qNear.w}; - Vector3 farPoint = { qFar.x/qFar.w, qFar.y/qFar.w, qFar.z/qFar.w}; -#endif - - // Calculate normalized direction vector - Vector3 direction = VectorSubtract(farPoint, nearPoint); - VectorNormalize(&direction); - - // Apply calculated vectors to ray - ray.position = camera.position; - ray.direction = direction; - - return ray; -} - -// Returns the screen space position from a 3d world space position -Vector2 GetWorldToScreen(Vector3 position, Camera camera) -{ - // Calculate projection matrix (from perspective instead of frustum - Matrix matProj = MatrixPerspective(camera.fovy, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0); - - // Calculate view matrix from camera look at (and transpose it) - Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); - MatrixTranspose(&matView); - - // Convert world position vector to quaternion - Quaternion worldPos = { position.x, position.y, position.z, 1.0f }; - - // Transform world position to view - QuaternionTransform(&worldPos, matView); - - // Transform result to projection (clip space position) - QuaternionTransform(&worldPos, matProj); - - // Calculate normalized device coordinates (inverted y) - Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w }; - - // Calculate 2d screen position vector - Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() }; - - return screenPosition; -} - -// Get transform matrix for camera -Matrix GetCameraMatrix(Camera camera) -{ - return MatrixLookAt(camera.position, camera.target, camera.up); -} - //---------------------------------------------------------------------------------- // Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions //---------------------------------------------------------------------------------- @@ -1559,7 +1592,7 @@ int GetMouseWheelMove(void) #endif } -// Returns touch position X +// Returns touch position X for touch point 0 (relative to screen size) int GetTouchX(void) { #if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) @@ -1569,7 +1602,7 @@ int GetTouchX(void) #endif } -// Returns touch position Y +// Returns touch position Y for touch point 0 (relative to screen size) int GetTouchY(void) { #if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) @@ -1579,7 +1612,7 @@ int GetTouchY(void) #endif } -// Returns touch position XY +// Returns touch position XY for a touch point index (relative to screen size) // TODO: Touch position should be scaled depending on display size and render size Vector2 GetTouchPosition(int index) { @@ -1836,8 +1869,8 @@ static void InitGraphicsDevice(int width, int height) EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5) EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6) EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5) - //EGL_ALPHA_SIZE, 8, // ALPHA bit depth - //EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB, // Request transparent framebuffer + //EGL_ALPHA_SIZE, 8, // ALPHA bit depth (required for transparent framebuffer) + //EGL_TRANSPARENT_TYPE, EGL_NONE, // Request transparent framebuffer (EGL_TRANSPARENT_RGB does not work on RPI) EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!) //EGL_STENCIL_SIZE, 8, // Stencil buffer size EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA @@ -1912,7 +1945,7 @@ static void InitGraphicsDevice(int width, int height) VC_DISPMANX_ALPHA_T alpha; alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS; - alpha.opacity = 255; + alpha.opacity = 255; // Set transparency level for framebuffer, requires EGLAttrib: EGL_TRANSPARENT_TYPE alpha.mask = 0; dispmanDisplay = vc_dispmanx_display_open(0); // LCD @@ -2362,7 +2395,11 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i // NOTE: Before closing window, while loop must be left! } #if defined(PLATFORM_DESKTOP) - else if (key == GLFW_KEY_F12 && action == GLFW_PRESS) TakeScreenshot(); + else if (key == GLFW_KEY_F12 && action == GLFW_PRESS) + { + TakeScreenshot(FormatText("screenshot%03i.png", screenshotCounter)); + screenshotCounter++; + } #endif else { @@ -3002,8 +3039,12 @@ static void ProcessKeyboard(void) // Check exit key (same functionality as GLFW3 KeyCallback()) if (currentKeyState[exitKey] == 1) windowShouldClose = true; - // Check screen capture key - if (currentKeyState[301] == 1) TakeScreenshot(); // raylib key: KEY_F12 (GLFW_KEY_F12) + // Check screen capture key (raylib key: KEY_F12) + if (currentKeyState[301] == 1) + { + TakeScreenshot(FormatText("screenshot%03i.png", screenshotCounter)); + screenshotCounter++; + } } // Restore default keyboard input diff --git a/src/models.c b/src/models.c index 2459edf1..0a692f5c 100644 --- a/src/models.c +++ b/src/models.c @@ -1541,11 +1541,11 @@ RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3) result.hit = true; result.distance = t; result.hit = true; - result.hitNormal = VectorCrossProduct(edge1, edge2); - VectorNormalize(&result.hitNormal); + result.normal = VectorCrossProduct(edge1, edge2); + VectorNormalize(&result.normal); Vector3 rayDir = ray.direction; VectorScale(&rayDir, t); - result.hitPosition = VectorAdd(ray.position, rayDir); + result.position = VectorAdd(ray.position, rayDir); } return result; @@ -1568,8 +1568,8 @@ RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight) VectorScale(&rayDir, t); result.hit = true; result.distance = t; - result.hitNormal = (Vector3){ 0.0, 1.0, 0.0 }; - result.hitPosition = VectorAdd(ray.position, rayDir); + result.normal = (Vector3){ 0.0, 1.0, 0.0 }; + result.position = VectorAdd(ray.position, rayDir); } } diff --git a/src/physac.h b/src/physac.h index cec3afc9..b71f2877 100644 --- a/src/physac.h +++ b/src/physac.h @@ -274,13 +274,13 @@ PHYSACDEF void ClosePhysics(void); // Global Variables Definition //---------------------------------------------------------------------------------- #if !defined(PHYSAC_NO_THREADS) - static pthread_t physicsThreadId; // Physics thread id +static pthread_t physicsThreadId; // Physics thread id #endif static unsigned int usedMemory = 0; // Total allocated dynamic memory static bool physicsThreadEnabled = false; // Physics thread enabled state static double currentTime = 0; // Current time in milliseconds #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux__) || defined(PLATFORM_WEB) - static double baseTime = 0; // Android and RPI platforms base time +static double baseTime = 0; // Android and RPI platforms base time #endif static double startTime = 0; // Start time in milliseconds static double deltaTime = 0; // Delta time used for physics steps @@ -316,10 +316,12 @@ static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, Physics static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB); // Calculates clipping based on a normal and two faces static bool BiasGreaterThan(float valueA, float valueB); // Check if values are between bias range static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3); // Returns the barycenter of a triangle given by 3 points + static void InitTimer(void); // Initializes hi-resolution timer static double GetCurrentTime(void); // Get current time in milliseconds static int GetRandomNumber(int min, int max); // Returns a random number between min and max (both included) +// Math functions static void MathClamp(double *value, double min, double max); // Clamp a value in a range static Vector2 MathCross(float value, Vector2 vector); // Returns the cross product of a vector and a value static float MathCrossVector2(Vector2 v1, Vector2 v2); // Returns the cross product of two vectors @@ -327,8 +329,10 @@ static float MathLenSqr(Vector2 vector); static float MathDot(Vector2 v1, Vector2 v2); // Returns the dot product of two vectors static inline float DistSqr(Vector2 v1, Vector2 v2); // Returns the square root of distance between two vectors static void MathNormalize(Vector2 *vector); // Returns the normalized values of a vector +#if defined(PHYSAC_STANDALONE) static Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Returns the sum of two given vectors static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Returns the subtract of two given vectors +#endif static Mat2 Mat2Radians(float radians); // Creates a matrix 2x2 from a given radians value static void Mat2Set(Mat2 *matrix, float radians); // Set values from radians to a created matrix 2x2 @@ -1978,6 +1982,7 @@ static void MathNormalize(Vector2 *vector) vector->y *= ilength; } +#if defined(PHYSAC_STANDALONE) // Returns the sum of two given vectors static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2) { @@ -1988,7 +1993,7 @@ static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2) static inline Vector2 Vector2Subtract(Vector2 v1, Vector2 v2) { return (Vector2){ v1.x - v2.x, v1.y - v2.y }; -} +#endif // Creates a matrix 2x2 from a given radians value static inline Mat2 Mat2Radians(float radians) diff --git a/src/raylib.h b/src/raylib.h index 4038215e..a3276d8e 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -479,8 +479,8 @@ typedef struct Ray { typedef struct RayHitInfo { bool hit; // Did the ray hit something? float distance; // Distance to nearest hit - Vector3 hitPosition; // Position of nearest hit - Vector3 hitNormal; // Surface normal of hit + Vector3 position; // Position of nearest hit + Vector3 normal; // Surface normal of hit } RayHitInfo; // Wave type, defines audio wave data @@ -656,15 +656,15 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) +RLAPI void InitWindow(int width, int height, void *state); // Initialize Android activity #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics +RLAPI void InitWindow(int width, int height, const char *title); // Initialize window and OpenGL context #endif -RLAPI void CloseWindow(void); // Close Window and Terminate Context -RLAPI bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed -RLAPI bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus) -RLAPI void ToggleFullscreen(void); // Fullscreen toggle (only PLATFORM_DESKTOP) +RLAPI void CloseWindow(void); // Close window and unload OpenGL context +RLAPI bool WindowShouldClose(void); // Check if KEY_ESCAPE pressed or Close icon pressed +RLAPI bool IsWindowMinimized(void); // Check if window has been minimized (or lost focus) +RLAPI void ToggleFullscreen(void); // Toggle fullscreen mode (only PLATFORM_DESKTOP) RLAPI void SetWindowIcon(Image image); // Set icon for window (only PLATFORM_DESKTOP) RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP) RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode) @@ -675,29 +675,29 @@ RLAPI int GetScreenHeight(void); // Get current #if !defined(PLATFORM_ANDROID) RLAPI void ShowCursor(void); // Shows cursor RLAPI void HideCursor(void); // Hides cursor -RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible -RLAPI void EnableCursor(void); // Enables cursor -RLAPI void DisableCursor(void); // Disables cursor +RLAPI bool IsCursorHidden(void); // Check if cursor is not visible +RLAPI void EnableCursor(void); // Enables cursor (unlock cursor) +RLAPI void DisableCursor(void); // Disables cursor (lock cursor) #endif -RLAPI void ClearBackground(Color color); // Sets Background Color -RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing -RLAPI void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering) +RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color) +RLAPI void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing +RLAPI void EndDrawing(void); // End canvas drawing and swap buffers (double buffering) -RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera -RLAPI void End2dMode(void); // Ends 2D mode custom camera usage -RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup) +RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera (2D) +RLAPI void End2dMode(void); // Ends 2D mode with custom camera +RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode with custom camera (3D) RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing RLAPI void EndTextureMode(void); // Ends drawing to render texture RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position -RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position +RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position for a 3d world space position RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix) RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) RLAPI int GetFPS(void); // Returns current FPS -RLAPI float GetFrameTime(void); // Returns time in seconds for one frame +RLAPI float GetFrameTime(void); // Returns time in seconds for last frame drawn RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color @@ -708,18 +708,21 @@ RLAPI float *MatrixToFloat(Matrix mat); // Converts Ma RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f -RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags) -RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags +RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags) +RLAPI void SetConfigFlags(char flags); // Setup window configuration flags (view FLAGS) RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (INFO, WARNING, ERROR, DEBUG) -RLAPI void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable -RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension +RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (saved a .png) -RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window -RLAPI char **GetDroppedFiles(int *count); // Retrieve dropped files into window +RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension +RLAPI const char *GetDirectoryPath(const char *fileName); // Get directory for a given fileName (with path) +RLAPI const char *GetWorkingDirectory(void); // Get current working directory +RLAPI bool ChangeDirectory(const char *dir); // Change working directory, returns true if success +RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window +RLAPI char **GetDroppedFiles(int *count); // Get dropped files names RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer -RLAPI void StorageSaveValue(int position, int value); // Storage save integer value (to defined position) -RLAPI int StorageLoadValue(int position); // Storage load integer value (from defined position) +RLAPI void StorageSaveValue(int position, int value); // Save integer value to storage file (to defined position) +RLAPI int StorageLoadValue(int position); // Load integer value from storage file (from defined position) //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) @@ -877,7 +880,7 @@ RLAPI void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font RLAPI Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont -RLAPI void DrawFPS(int posX, int posY); // Shows current FPS on top-left corner +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string @@ -1052,6 +1052,7 @@ void rlglInit(int width, int height) // NOTE: On OpenGL 3.3 VAO and NPOT are supported by default vaoSupported = true; texNPOTSupported = true; + texFloatSupported = true; // We get a list of available extensions and we check for some of them (compressed textures) // NOTE: We don't need to check again supported extensions but we do (GLAD already dealt with that) @@ -1425,7 +1426,7 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int format, int case UNCOMPRESSED_R5G5B5A1: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break; case UNCOMPRESSED_R4G4B4A4: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break; case UNCOMPRESSED_R8G8B8A8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break; - case UNCOMPRESSED_R32G32B32: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, (float *)data); break; + case UNCOMPRESSED_R32G32B32: if (texFloatSupported) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, (float *)data); break; case COMPRESSED_DXT1_RGB: if (texCompDXTSupported) LoadCompressedTexture((unsigned char *)data, width, height, mipmapCount, GL_COMPRESSED_RGB_S3TC_DXT1_EXT); break; case COMPRESSED_DXT1_RGBA: if (texCompDXTSupported) LoadCompressedTexture((unsigned char *)data, width, height, mipmapCount, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT); break; case COMPRESSED_DXT3_RGBA: if (texCompDXTSupported) LoadCompressedTexture((unsigned char *)data, width, height, mipmapCount, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT); break; diff --git a/src/textures.c b/src/textures.c index 115c8fff..81d36ef8 100644 --- a/src/textures.c +++ b/src/textures.c @@ -213,8 +213,12 @@ Image LoadImage(const char *fileName) FILE *imFile = fopen(fileName, "rb"); + stbi_set_flip_vertically_on_load(true); + // Load 32 bit per channel floats data image.data = stbi_loadf_from_file(imFile, &image.width, &image.height, &imgBpp, 0); + + stbi_set_flip_vertically_on_load(false); fclose(imFile); @@ -381,7 +385,7 @@ Texture2D LoadTextureFromImage(Image image) texture.mipmaps = image.mipmaps; texture.format = image.format; - TraceLog(INFO, "[TEX %i] Parameters: %ix%i, %i mips, format %i", texture.id, texture.width, texture.height, texture.mipmaps, texture.format); + TraceLog(DEBUG, "[TEX ID %i] Parameters: %ix%i, %i mips, format %i", texture.id, texture.width, texture.height, texture.mipmaps, texture.format); return texture; } |
