diff options
| -rw-r--r-- | src/core.c | 71 | ||||
| -rw-r--r-- | src/models.c | 6 | ||||
| -rw-r--r-- | src/raylib.h | 17 | ||||
| -rw-r--r-- | src/rlgl.h | 7 |
4 files changed, 70 insertions, 31 deletions
@@ -739,6 +739,15 @@ bool IsWindowMinimized(void) #endif } +// Check if window is currently hidden +bool IsWindowHidden(void) +{ +#if defined(PLATFORM_DESKTOP) + return (glfwGetWindowAttrib(window, GLFW_VISIBLE) == GL_FALSE); +#endif + return false; +} + // Toggle fullscreen mode (only PLATFORM_DESKTOP) void ToggleFullscreen(void) { @@ -827,7 +836,7 @@ void SetWindowSize(int width, int height) } // Show the window -void ShowWindow() +void ShowWindow(void) { #if defined(PLATFORM_DESKTOP) glfwShowWindow(window); @@ -835,22 +844,13 @@ void ShowWindow() } // Hide the window -void HideWindow() +void HideWindow(void) { #if defined(PLATFORM_DESKTOP) glfwHideWindow(window); #endif } -// Check if window is currently hidden -bool IsWindowHidden() -{ -#if defined(PLATFORM_DESKTOP) - return glfwGetWindowAttrib(window, GLFW_VISIBLE) == GL_FALSE; -#endif - return false; -} - // Get current screen width int GetScreenWidth(void) { @@ -982,7 +982,7 @@ const char *GetMonitorName(int monitor) } // Show mouse cursor -void ShowCursor() +void ShowCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); @@ -991,7 +991,7 @@ void ShowCursor() } // Hides mouse cursor -void HideCursor() +void HideCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); @@ -1000,13 +1000,13 @@ void HideCursor() } // Check if cursor is not visible -bool IsCursorHidden() +bool IsCursorHidden(void) { return cursorHidden; } // Enables cursor (unlock cursor) -void EnableCursor() +void EnableCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); @@ -1018,7 +1018,7 @@ void EnableCursor() } // Disables cursor (lock cursor) -void DisableCursor() +void DisableCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); @@ -1445,6 +1445,41 @@ Vector3 ColorToHSV(Color color) return hsv; } +// Returns a Color from HSV values +// Implementation reference: https://en.wikipedia.org/wiki/HSL_and_HSV#Alternative_HSV_conversion +// NOTE: Color->HSV->Color conversion will not yield exactly the same color due to rounding errors +Color ColorFromHSV(Vector3 hsv) +{ + Color color = { 0, 0, 0, 255 }; + float h = hsv.x, s = hsv.y, v = hsv.z; + + // Red channel + float k = fmod((5.0f + h/60.0f), 6); + float t = 4.0f - k; + k = (t < k) ? t : k; + k = (k < 1) ? k : 1; + k = (k > 0) ? k : 0; + color.r = (v - v*s*k)*255; + + // Green channel + k = fmod((3.0f + h/60.0f), 6); + t = 4.0f - k; + k = (t < k) ? t : k; + k = (k < 1) ? k : 1; + k = (k > 0) ? k : 0; + color.g = (v - v*s*k)*255; + + // Blue channel + k = fmod((1.0f + h/60.0f), 6); + t = 4.0f - k; + k = (t < k) ? t : k; + k = (k < 1) ? k : 1; + k = (k > 0) ? k : 0; + color.b = (v - v*s*k)*255; + + return color; +} + // Returns a Color struct from hexadecimal value Color GetColor(int hexValue) { @@ -2282,13 +2317,13 @@ static bool InitGraphicsDevice(int width, int height) //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers // Check some Window creation flags - if (configFlags & FLAG_WINDOW_HIDDEN) glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // Visible window + if (configFlags & FLAG_WINDOW_HIDDEN) glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // Visible window else glfwWindowHint(GLFW_VISIBLE, GL_TRUE); // Window initially hidden if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window else glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Avoid window being resizable - if (configFlags & FLAG_WINDOW_UNDECORATED) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window + if (configFlags & FLAG_WINDOW_UNDECORATED) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window // FLAG_WINDOW_TRANSPARENT not supported on HTML5 and not included in any released GLFW version yet #if defined(GLFW_TRANSPARENT_FRAMEBUFFER) diff --git a/src/models.c b/src/models.c index 4efde340..39e8781e 100644 --- a/src/models.c +++ b/src/models.c @@ -115,6 +115,8 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) // Draw a circle in 3D world space void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color) { + if (rlCheckBufferLimit(2*36)) rlglDraw(); + rlPushMatrix(); rlTranslatef(center.x, center.y, center.z); rlRotatef(rotationAngle, rotationAxis.x, rotationAxis.y, rotationAxis.z); @@ -138,6 +140,8 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c float x = 0.0f; float y = 0.0f; float z = 0.0f; + + if (rlCheckBufferLimit(36)) rlglDraw(); rlPushMatrix(); // NOTE: Transformation is applied in inverse order (scale -> rotate -> translate) @@ -217,6 +221,8 @@ void DrawCubeWires(Vector3 position, float width, float height, float length, Co float x = 0.0f; float y = 0.0f; float z = 0.0f; + + if (rlCheckBufferLimit(36)) rlglDraw(); rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); diff --git a/src/raylib.h b/src/raylib.h index b554d10d..3f484193 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -415,9 +415,9 @@ typedef enum { FLAG_WINDOW_RESIZABLE = 4, // Set to allow resizable window FLAG_WINDOW_UNDECORATED = 8, // Set to disable window decoration (frame and buttons) FLAG_WINDOW_TRANSPARENT = 16, // Set to allow transparent window - FLAG_WINDOW_HIDDEN = 32, // Set to create the window initially hidden - FLAG_MSAA_4X_HINT = 64, // Set to try enabling MSAA 4X - FLAG_VSYNC_HINT = 128 // Set to try enabling V-Sync on GPU + FLAG_WINDOW_HIDDEN = 128, // Set to create the window initially hidden + FLAG_MSAA_4X_HINT = 32, // Set to try enabling MSAA 4X + FLAG_VSYNC_HINT = 64 // Set to try enabling V-Sync on GPU } ConfigFlag; // Trace log type @@ -834,23 +834,23 @@ extern "C" { // Prevents name mangling of functions // Window-related functions RLAPI void InitWindow(int width, int height, const char *title); // Initialize window and OpenGL context +RLAPI bool WindowShouldClose(void); // Check if KEY_ESCAPE pressed or Close icon pressed RLAPI void CloseWindow(void); // Close window and unload OpenGL context RLAPI bool IsWindowReady(void); // Check if window has been initialized successfully -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 bool IsWindowHidden(void); // Check if window is currently hidden RLAPI void ToggleFullscreen(void); // Toggle fullscreen mode (only PLATFORM_DESKTOP) +RLAPI void ShowWindow(void); // Show the window +RLAPI void HideWindow(void); // Hide the window RLAPI void SetWindowIcon(Image image); // Set icon for window (only PLATFORM_DESKTOP) RLAPI void SetWindowTitle(const char *title); // Set title for window (only PLATFORM_DESKTOP) RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP) RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode) RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) RLAPI void SetWindowSize(int width, int height); // Set window dimensions -RLAPI void ShowWindow(); // Show the window -RLAPI void HideWindow(); // Hide the window -RLAPI bool IsWindowHidden(); // Check if window is currently hidden +RLAPI void *GetWindowHandle(void); // Get native window handle RLAPI int GetScreenWidth(void); // Get current screen width RLAPI int GetScreenHeight(void); // Get current screen height -RLAPI void *GetWindowHandle(void); // Get native window handle RLAPI int GetMonitorCount(void); // Get number of connected monitors RLAPI int GetMonitorWidth(int monitor); // Get primary monitor width RLAPI int GetMonitorHeight(int monitor); // Get primary monitor height @@ -891,6 +891,7 @@ RLAPI double GetTime(void); // Returns ela RLAPI int ColorToInt(Color color); // Returns hexadecimal value for a Color RLAPI Vector4 ColorNormalize(Color color); // Returns color normalized as float [0..1] RLAPI Vector3 ColorToHSV(Color color); // Returns HSV values for a Color +RLAPI Color ColorFromHSV(Vector3 hsv); // Returns a Color from HSV values RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f @@ -2619,7 +2619,8 @@ unsigned char *rlReadScreenPixels(int width, int height) { unsigned char *screenData = (unsigned char *)calloc(width*height*4, sizeof(unsigned char)); - // NOTE: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer + // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer + // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly! glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, screenData); // Flip image vertically! @@ -2631,10 +2632,6 @@ unsigned char *rlReadScreenPixels(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; } } |
