From 2536bea379387e525e3107ee07355292ee87a566 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 1 Jun 2018 00:53:40 +0200 Subject: Added: ImageResizeCanvas() -WIP- Added note idea on ImageFormat() for future redesign (to support 16bit-32bit pixel-formats) --- src/raylib.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/raylib.h') diff --git a/src/raylib.h b/src/raylib.h index e83650e6..2659d70d 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -912,8 +912,9 @@ RLAPI void ImageAlphaClear(Image *image, Color color, float threshold); RLAPI void ImageAlphaCrop(Image *image, float threshold); // Crop image depending on alpha value RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm) +RLAPI void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int anchor, Color color); // Resize canvas, using anchor point and color filling RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) -- cgit v1.2.3 From b1b4a11bdb450c415ae54eded7f868af19a7fb5d Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 2 Jun 2018 13:05:23 +0200 Subject: Corrected issue with function definition --- release/include/raylib.h | 5 +++-- release/libs/win32/tcc/libraylib.a | Bin 1463102 -> 1463584 bytes src/raylib.h | 2 +- src/textures.c | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index e83650e6..dad08ba2 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -912,8 +912,9 @@ RLAPI void ImageAlphaClear(Image *image, Color color, float threshold); RLAPI void ImageAlphaCrop(Image *image, float threshold); // Crop image depending on alpha value RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle -RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) -RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) +RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (bilinear filtering) +RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm) +RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color color); // Resize canvas and fill with color RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) diff --git a/release/libs/win32/tcc/libraylib.a b/release/libs/win32/tcc/libraylib.a index 94114ac0..0d1d4549 100644 Binary files a/release/libs/win32/tcc/libraylib.a and b/release/libs/win32/tcc/libraylib.a differ diff --git a/src/raylib.h b/src/raylib.h index 2659d70d..dad08ba2 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -914,7 +914,7 @@ RLAPI void ImageAlphaPremultiply(Image *image); RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (bilinear filtering) RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm) -RLAPI void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int anchor, Color color); // Resize canvas, using anchor point and color filling +RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color color); // Resize canvas and fill with color RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) diff --git a/src/textures.c b/src/textures.c index c4e77458..3a62ac14 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1118,7 +1118,6 @@ void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int offsetX, in { // TODO: ImageCrop(), define proper cropping rectangle } - } // Generate all mipmap levels for a provided image -- cgit v1.2.3 From 9688c677de8b56a78175c87f8a18af7c6bcc9d1f Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 2 Jun 2018 18:26:57 +0200 Subject: Review window creation hints --- release/include/raylib.h | 2 +- release/libs/win32/mingw32/libraylib.a | Bin 1101816 -> 1102432 bytes src/core.c | 37 +++++++++++++++------------------ src/raylib.h | 2 +- 4 files changed, 19 insertions(+), 22 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index dad08ba2..a3fa1311 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -92,7 +92,7 @@ #define FLAG_SHOW_LOGO 1 // Set to show raylib logo at startup #define FLAG_FULLSCREEN_MODE 2 // Set to run program in fullscreen #define FLAG_WINDOW_RESIZABLE 4 // Set to allow resizable window -#define FLAG_WINDOW_DECORATED 8 // Set to show window decoration (frame and buttons) +#define FLAG_WINDOW_UNDECORATED 8 // Set to disable window decoration (frame and buttons) #define FLAG_WINDOW_TRANSPARENT 16 // Set to allow transparent window #define FLAG_MSAA_4X_HINT 32 // Set to try enabling MSAA 4X #define FLAG_VSYNC_HINT 64 // Set to try enabling V-Sync on GPU diff --git a/release/libs/win32/mingw32/libraylib.a b/release/libs/win32/mingw32/libraylib.a index 940dc353..45b4f336 100644 Binary files a/release/libs/win32/mingw32/libraylib.a and b/release/libs/win32/mingw32/libraylib.a differ diff --git a/src/core.c b/src/core.c index 5cd9bfd4..1f9159f9 100644 --- a/src/core.c +++ b/src/core.c @@ -1884,31 +1884,28 @@ static bool InitGraphicsDevice(int width, int height) displayHeight = screenHeight; #endif // defined(PLATFORM_WEB) - glfwDefaultWindowHints(); // Set default windows hints + glfwDefaultWindowHints(); // Set default windows hints: + //glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits + //glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits + //glfwWindowHint(GLFW_BLUE_BITS, 8); // Framebuffer blue color component bits + //glfwWindowHint(GLFW_ALPHA_BITS, 8); // Framebuffer alpha color component bits + //glfwWindowHint(GLFW_DEPTH_BITS, 24); // Depthbuffer bits + //glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window + //glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); // OpenGL API to use. Alternative: GLFW_OPENGL_ES_API + //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers // Check some Window creation flags - if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window + 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_DECORATED) glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Border and buttons on Window + if (configFlags & FLAG_WINDOW_UNDECORATED) glfwWindowHint(GLFW_DECORATED, GL_FALSE); // Border and buttons on Window + else glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Decorated window - if (configFlags & FLAG_WINDOW_TRANSPARENT) - { - // TODO: Enable transparent window (not ready yet on GLFW 3.2) - } + if (configFlags & FLAG_WINDOW_TRANSPARENT) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); // Transparent framebuffer + else glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); // Opaque framebuffer - if (configFlags & FLAG_MSAA_4X_HINT) - { - glfwWindowHint(GLFW_SAMPLES, 4); // Enables multisampling x4 (MSAA), default is 0 - TraceLog(LOG_INFO, "Trying to enable MSAA x4"); - } + if (configFlags & FLAG_MSAA_4X_HINT) glfwWindowHint(GLFW_SAMPLES, 4); // Tries to enable multisampling x4 (MSAA), default is 0 - //glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits - //glfwWindowHint(GLFW_DEPTH_BITS, 16); // Depthbuffer bits (24 by default) - //glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window - //glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); // Default OpenGL API to use. Alternative: GLFW_OPENGL_ES_API - //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers - // NOTE: When asking for an OpenGL context version, most drivers provide highest supported version // with forward compatibility to older OpenGL versions. // For example, if using OpenGL 1.1, driver can provide a 4.3 context forward compatible. @@ -1926,11 +1923,11 @@ static bool InitGraphicsDevice(int width, int height) glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above! // Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE #if defined(__APPLE__) - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires fordward compatibility #else glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above! #endif - //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); + //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); // Request OpenGL DEBUG context } if (fullscreen) diff --git a/src/raylib.h b/src/raylib.h index dad08ba2..a3fa1311 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -92,7 +92,7 @@ #define FLAG_SHOW_LOGO 1 // Set to show raylib logo at startup #define FLAG_FULLSCREEN_MODE 2 // Set to run program in fullscreen #define FLAG_WINDOW_RESIZABLE 4 // Set to allow resizable window -#define FLAG_WINDOW_DECORATED 8 // Set to show window decoration (frame and buttons) +#define FLAG_WINDOW_UNDECORATED 8 // Set to disable window decoration (frame and buttons) #define FLAG_WINDOW_TRANSPARENT 16 // Set to allow transparent window #define FLAG_MSAA_4X_HINT 32 // Set to try enabling MSAA 4X #define FLAG_VSYNC_HINT 64 // Set to try enabling V-Sync on GPU -- cgit v1.2.3 From 0e6458cfee398e572340db461ef6beb85253a4c5 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 3 Jun 2018 21:05:01 +0200 Subject: Added ImageRotate*() functions --- release/include/raylib.h | 2 ++ release/libs/win32/tcc/libraylib.a | Bin 1463584 -> 1465002 bytes src/raylib.h | 2 ++ src/textures.c | 56 +++++++++++++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 2 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index a3fa1311..86ad5408 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -925,6 +925,8 @@ RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fon RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float 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 +RLAPI void ImageRotateCW(Image *image); // Rotate image clockwise 90deg +RLAPI void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint RLAPI void ImageColorInvert(Image *image); // Modify image color: invert RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale diff --git a/release/libs/win32/tcc/libraylib.a b/release/libs/win32/tcc/libraylib.a index 0d1d4549..1aa76249 100644 Binary files a/release/libs/win32/tcc/libraylib.a and b/release/libs/win32/tcc/libraylib.a differ diff --git a/src/raylib.h b/src/raylib.h index a3fa1311..86ad5408 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -925,6 +925,8 @@ RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fon RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float 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 +RLAPI void ImageRotateCW(Image *image); // Rotate image clockwise 90deg +RLAPI void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint RLAPI void ImageColorInvert(Image *image); // Modify image color: invert RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale diff --git a/src/textures.c b/src/textures.c index 3a62ac14..0b9f907e 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1539,7 +1539,7 @@ void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, void ImageFlipVertical(Image *image) { Color *srcPixels = GetImageData(*image); - Color *dstPixels = (Color *)malloc(sizeof(Color)*image->width*image->height); + Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); for (int y = 0; y < image->height; y++) { @@ -1563,7 +1563,7 @@ void ImageFlipVertical(Image *image) void ImageFlipHorizontal(Image *image) { Color *srcPixels = GetImageData(*image); - Color *dstPixels = (Color *)malloc(sizeof(Color)*image->width*image->height); + Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); for (int y = 0; y < image->height; y++) { @@ -1583,6 +1583,58 @@ void ImageFlipHorizontal(Image *image) image->data = processed.data; } +// Rotate image clockwise 90deg +void ImageRotateCW(Image *image) +{ + Color *srcPixels = GetImageData(*image); + Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); + + for (int y = 0; y < image->height; y++) + { + for (int x = 0; x < image->width; x++) + { + rotPixels[x*image->height + (image->height - y - 1)] = srcPixels[y*image->width + x]; + } + } + + Image processed = LoadImageEx(rotPixels, image->height, image->width); + ImageFormat(&processed, image->format); + UnloadImage(*image); + + free(srcPixels); + free(rotPixels); + + image->data = processed.data; + image->width = processed.width; + image->height = processed.height; +} + +// Rotate image counter-clockwise 90deg +void ImageRotateCCW(Image *image) +{ + Color *srcPixels = GetImageData(*image); + Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); + + for (int y = 0; y < image->height; y++) + { + for (int x = 0; x < image->width; x++) + { + rotPixels[x*image->height + y] = srcPixels[y*image->width + (image->width - x - 1)]; + } + } + + Image processed = LoadImageEx(rotPixels, image->height, image->width); + ImageFormat(&processed, image->format); + UnloadImage(*image); + + free(srcPixels); + free(rotPixels); + + image->data = processed.data; + image->width = processed.width; + image->height = processed.height; +} + // Modify image color: tint void ImageColorTint(Image *image, Color color) { -- cgit v1.2.3 From 59fd2614916249ad5a229f032cb92f34692ca29b Mon Sep 17 00:00:00 2001 From: Ray San Date: Tue, 12 Jun 2018 13:13:09 +0200 Subject: Added function: GetImageDataNormalized() Reviewed: GetImageData() Reviewed: ImageFormat() --- release/include/raylib.h | 1 + src/raylib.h | 1 + src/textures.c | 199 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 169 insertions(+), 32 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index 86ad5408..e0cfaa6d 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -899,6 +899,7 @@ RLAPI void UnloadImage(Image image); RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory (VRAM) RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM) RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Vector4 *GetImageDataNormalized(Image image); // Get pixel data from image as Vector4 array (float normalized) RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture) RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data diff --git a/src/raylib.h b/src/raylib.h index 86ad5408..e0cfaa6d 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -899,6 +899,7 @@ RLAPI void UnloadImage(Image image); RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory (VRAM) RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM) RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array +RLAPI Vector4 *GetImageDataNormalized(Image image); // Get pixel data from image as Vector4 array (float normalized) RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture) RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data diff --git a/src/textures.c b/src/textures.c index fe408481..5c2196e2 100644 --- a/src/textures.c +++ b/src/textures.c @@ -405,7 +405,6 @@ void UnloadRenderTexture(RenderTexture2D target) } // Get pixel data from image in the form of Color struct array -// TODO: Support float pixel data retrieval Color *GetImageData(Image image) { Color *pixels = (Color *)malloc(image.width*image.height*sizeof(Color)); @@ -479,6 +478,34 @@ Color *GetImageData(Image image) k += 3; } break; + case UNCOMPRESSED_R32: + { + TraceLog(LOG_WARNING, "32bit pixel format converted to 8bit per channel"); break; + + pixels[i].r = (unsigned char)(((float *)image.data)[k]*255.0f); + pixels[i].g = 0; + pixels[i].b = 0; + pixels[i].a = 255; + + } break; + case UNCOMPRESSED_R32G32B32: + { + pixels[i].r = (unsigned char)(((float *)image.data)[k]*255.0f); + pixels[i].g = (unsigned char)(((float *)image.data)[k + 1]*255.0f); + pixels[i].b = (unsigned char)(((float *)image.data)[k + 2]*255.0f); + pixels[i].a = 255; + + k += 3; + } + case UNCOMPRESSED_R32G32B32A32: + { + pixels[i].r = (unsigned char)(((float *)image.data)[k]*255.0f); + pixels[i].g = (unsigned char)(((float *)image.data)[k]*255.0f); + pixels[i].b = (unsigned char)(((float *)image.data)[k]*255.0f); + pixels[i].a = (unsigned char)(((float *)image.data)[k]*255.0f); + + k += 4; + } default: TraceLog(LOG_WARNING, "Format not supported for pixel data retrieval"); break; } } @@ -486,6 +513,113 @@ Color *GetImageData(Image image) return pixels; } +// Get pixel data from image as Vector4 array (float normalized) +Vector4 *GetImageDataNormalized(Image image) +{ + Vector4 *pixels = (Vector4 *)malloc(image.width*image.height*sizeof(Vector4)); + + for (int i = 0, k = 0; i < image.width*image.height; i++) + { + switch (image.format) + { + case UNCOMPRESSED_GRAYSCALE: + { + pixels[i].x = (float)((unsigned char *)image.data)[i]/255.0f; + pixels[i].y = (float)((unsigned char *)image.data)[i]/255.0f; + pixels[i].z = (float)((unsigned char *)image.data)[i]/255.0f; + pixels[i].w = 1.0f; + + } break; + case UNCOMPRESSED_GRAY_ALPHA: + { + pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f; + pixels[i].y = (float)((unsigned char *)image.data)[k]/255.0f; + pixels[i].z = (float)((unsigned char *)image.data)[k]/255.0f; + pixels[i].w = (float)((unsigned char *)image.data)[k + 1]/255.0f; + + k += 2; + } break; + case UNCOMPRESSED_R5G5B5A1: + { + unsigned short pixel = ((unsigned short *)image.data)[i]; + + pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31); + pixels[i].y = (float)((pixel & 0b0000011111000000) >> 6)*(1.0f/31); + pixels[i].z = (float)((pixel & 0b0000000000111110) >> 1)*(1.0f/31); + pixels[i].w = ((pixel & 0b0000000000000001) == 0) ? 0.0f : 1.0f; + + } break; + case UNCOMPRESSED_R5G6B5: + { + unsigned short pixel = ((unsigned short *)image.data)[i]; + + pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31); + pixels[i].y = (float)((pixel & 0b0000011111100000) >> 5)*(1.0f/63); + pixels[i].z = (float)(pixel & 0b0000000000011111)*(1.0f/31); + pixels[i].w = 1.0f; + + } break; + case UNCOMPRESSED_R4G4B4A4: + { + unsigned short pixel = ((unsigned short *)image.data)[i]; + + pixels[i].x = (float)((pixel & 0b1111000000000000) >> 12)*(1.0f/15); + pixels[i].y = (float)((pixel & 0b0000111100000000) >> 8)*(1.0f/15); + pixels[i].z = (float)((pixel & 0b0000000011110000) >> 4)*(1.0f/15); + pixels[i].w = (float)(pixel & 0b0000000000001111)*(1.0f/15); + + } break; + case UNCOMPRESSED_R8G8B8A8: + { + pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f; + pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f; + pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f; + pixels[i].w = (float)((unsigned char *)image.data)[k + 3]/255.0f; + + k += 4; + } break; + case UNCOMPRESSED_R8G8B8: + { + pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f; + pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f; + pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f; + pixels[i].w = 1.0f; + + k += 3; + } break; + case UNCOMPRESSED_R32: + { + pixels[i].x = ((float *)image.data)[k]; + pixels[i].y = 0.0f; + pixels[i].z = 0.0f; + pixels[i].w = 1.0f; + + } break; + case UNCOMPRESSED_R32G32B32: + { + pixels[i].x = ((float *)image.data)[k]; + pixels[i].y = ((float *)image.data)[k + 1]; + pixels[i].z = ((float *)image.data)[k + 2]; + pixels[i].w = 1.0f; + + k += 3; + } + case UNCOMPRESSED_R32G32B32A32: + { + pixels[i].x = ((float *)image.data)[k]; + pixels[i].y = ((float *)image.data)[k + 1]; + pixels[i].z = ((float *)image.data)[k + 2]; + pixels[i].w = ((float *)image.data)[k + 3]; + + k += 4; + } + default: TraceLog(LOG_WARNING, "Format not supported for pixel data retrieval"); break; + } + } + + return pixels; +} + // Get pixel data size in bytes (image or texture) // NOTE: Size depends on pixel format int GetPixelDataSize(int width, int height, int format) @@ -663,8 +797,7 @@ void ImageFormat(Image *image, int newFormat) { if ((image->format < COMPRESSED_DXT1_RGB) && (newFormat < COMPRESSED_DXT1_RGB)) { - Color *pixels = GetImageData(*image); - //Vector4 *pixels = GetImageDataNormalized(*image); // TODO: Support 8->32bit channels + Vector4 *pixels = GetImageDataNormalized(*image); // Supports 8 to 32 bit per channel free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end... image->data = NULL; @@ -680,7 +813,7 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - ((unsigned char *)image->data)[i] = (unsigned char)((float)pixels[i].r*0.299f + (float)pixels[i].g*0.587f + (float)pixels[i].b*0.114f); + ((unsigned char *)image->data)[i] = (unsigned char)((pixels[i].x*0.299f + pixels[i].y*0.587f + pixels[i].z*0.114f)*255.0f); } } break; @@ -690,8 +823,8 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height*2; i += 2, k++) { - ((unsigned char *)image->data)[i] = (unsigned char)((float)pixels[k].r*0.299f + (float)pixels[k].g*0.587f + (float)pixels[k].b*0.114f); - ((unsigned char *)image->data)[i + 1] = pixels[k].a; + ((unsigned char *)image->data)[i] = (unsigned char)((pixels[k].x*0.299f + (float)pixels[k].y*0.587f + (float)pixels[k].z*0.114f)*255.0f); + ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[k].w*255.0f); } } break; @@ -705,9 +838,9 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - r = (unsigned char)(round((float)pixels[i].r*31.0f/255)); - g = (unsigned char)(round((float)pixels[i].g*63.0f/255)); - b = (unsigned char)(round((float)pixels[i].b*31.0f/255)); + r = (unsigned char)(round(pixels[i].x*31.0f)); + g = (unsigned char)(round(pixels[i].y*63.0f)); + b = (unsigned char)(round(pixels[i].z*31.0f)); ((unsigned short *)image->data)[i] = (unsigned short)r << 11 | (unsigned short)g << 5 | (unsigned short)b; } @@ -719,9 +852,9 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++) { - ((unsigned char *)image->data)[i] = pixels[k].r; - ((unsigned char *)image->data)[i + 1] = pixels[k].g; - ((unsigned char *)image->data)[i + 2] = pixels[k].b; + ((unsigned char *)image->data)[i] = (unsigned char)(pixels[k].x*255.0f); + ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[k].y*255.0f); + ((unsigned char *)image->data)[i + 2] = (unsigned char)(pixels[k].z*255.0f); } } break; case UNCOMPRESSED_R5G5B5A1: @@ -737,10 +870,10 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - r = (unsigned char)(round((float)pixels[i].r*31.0f/255)); - g = (unsigned char)(round((float)pixels[i].g*31.0f/255)); - b = (unsigned char)(round((float)pixels[i].b*31.0f/255)); - a = (pixels[i].a > ALPHA_THRESHOLD) ? 1 : 0; + r = (unsigned char)(round(pixels[i].x*31.0f)); + g = (unsigned char)(round(pixels[i].y*31.0f)); + b = (unsigned char)(round(pixels[i].z*31.0f)); + a = (pixels[i].w > ((float)ALPHA_THRESHOLD/255.0f)) ? 1 : 0; ((unsigned short *)image->data)[i] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a; } @@ -757,10 +890,10 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - r = (unsigned char)(round((float)pixels[i].r*15.0f/255)); - g = (unsigned char)(round((float)pixels[i].g*15.0f/255)); - b = (unsigned char)(round((float)pixels[i].b*15.0f/255)); - a = (unsigned char)(round((float)pixels[i].a*15.0f/255)); + r = (unsigned char)(round(pixels[i].x*15.0f)); + g = (unsigned char)(round(pixels[i].y*15.0f)); + b = (unsigned char)(round(pixels[i].z*15.0f)); + a = (unsigned char)(round(pixels[i].w*15.0f)); ((unsigned short *)image->data)[i] = (unsigned short)r << 12 | (unsigned short)g << 8 | (unsigned short)b << 4 | (unsigned short)a; } @@ -772,19 +905,21 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++) { - ((unsigned char *)image->data)[i] = pixels[k].r; - ((unsigned char *)image->data)[i + 1] = pixels[k].g; - ((unsigned char *)image->data)[i + 2] = pixels[k].b; - ((unsigned char *)image->data)[i + 3] = pixels[k].a; + ((unsigned char *)image->data)[i] = (unsigned char)(pixels[k].x*255.0f); + ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[k].y*255.0f); + ((unsigned char *)image->data)[i + 2] = (unsigned char)(pixels[k].z*255.0f); + ((unsigned char *)image->data)[i + 3] = (unsigned char)(pixels[k].w*255.0f); } } break; case UNCOMPRESSED_R32: { + // WARNING: Image is converted to GRAYSCALE eqeuivalent 32bit + image->data = (float *)malloc(image->width*image->height*sizeof(float)); for (int i = 0; i < image->width*image->height; i++) { - ((float *)image->data)[i] = (float)((float)pixels[i].r*0.299f/255.0f + (float)pixels[i].g*0.587f/255.0f + (float)pixels[i].b*0.114f/255.0f); + ((float *)image->data)[i] = (float)(pixels[i].x*0.299f + pixels[i].y*0.587f + pixels[i].z*0.114f); } } break; case UNCOMPRESSED_R32G32B32: @@ -793,9 +928,9 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++) { - ((float *)image->data)[i] = (float)pixels[k].r/255.0f; - ((float *)image->data)[i + 1] = (float)pixels[k].g/255.0f; - ((float *)image->data)[i + 2] = (float)pixels[k].b/255.0f; + ((float *)image->data)[i] = pixels[k].x; + ((float *)image->data)[i + 1] = pixels[k].y; + ((float *)image->data)[i + 2] = pixels[k].z; } } break; case UNCOMPRESSED_R32G32B32A32: @@ -804,10 +939,10 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++) { - ((float *)image->data)[i] = (float)pixels[k].r/255.0f; - ((float *)image->data)[i + 1] = (float)pixels[k].g/255.0f; - ((float *)image->data)[i + 2] = (float)pixels[k].b/255.0f; - ((float *)image->data)[i + 3] = (float)pixels[k].a/255.0f; + ((float *)image->data)[i] = pixels[k].x; + ((float *)image->data)[i + 1] = pixels[k].y; + ((float *)image->data)[i + 2] = pixels[k].z; + ((float *)image->data)[i + 3] = pixels[k].w; } } break; default: break; -- cgit v1.2.3 From 75ba5aca551d2b16fa75ba31e616b009ac5dde6a Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 20 Jun 2018 00:52:14 +0200 Subject: Improved font generation and SDF Added: data to CharInfo struct Added: LoadFontData() Added: GenImageFontAtlas() Removed: LoadFontEx() Removed: LoadTTF() [internal] Some code tweaks --- release/include/raylib.h | 27 +-- release/libs/win32/mingw32/libraylib.a | Bin 1103438 -> 1116752 bytes src/raylib.h | 27 +-- src/text.c | 356 ++++++++++++++++++++------------- src/textures.c | 4 +- 5 files changed, 243 insertions(+), 171 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index e0cfaa6d..49434d52 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -389,6 +389,7 @@ typedef struct CharInfo { int offsetX; // Character offset X when drawing int offsetY; // Character offset Y when drawing int advanceX; // Character advance position X + unsigned char *data; // Character pixel data (grayscale) } CharInfo; // Font type, includes texture and charSet array data @@ -955,29 +956,29 @@ RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters - //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ // Font loading/unloading functions -RLAPI Font GetDefaultFont(void); // Get the default Font -RLAPI Font LoadFont(const char *fileName); // Load Font from file into GPU memory (VRAM) -RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load Font from file with extended parameters -RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) +RLAPI Font GetDefaultFont(void); // Get the default Font +RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) +RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use +RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int packing); // Generate image font atlas using chars info +RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) // Text drawing functions -RLAPI void DrawFPS(int posX, int posY); // Shows current FPS -RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -RLAPI void DrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using Font and additional parameters +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters // Text misc. functions -RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font -RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font -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 -RLAPI int GetGlyphIndex(Font font, int character); // Returns index position for a unicode character on sprite font +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font +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 +RLAPI int GetGlyphIndex(Font font, int character); // Get index position for a unicode character on sprite font //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) diff --git a/release/libs/win32/mingw32/libraylib.a b/release/libs/win32/mingw32/libraylib.a index 2701869a..3425c71a 100644 Binary files a/release/libs/win32/mingw32/libraylib.a and b/release/libs/win32/mingw32/libraylib.a differ diff --git a/src/raylib.h b/src/raylib.h index e0cfaa6d..49434d52 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -389,6 +389,7 @@ typedef struct CharInfo { int offsetX; // Character offset X when drawing int offsetY; // Character offset Y when drawing int advanceX; // Character advance position X + unsigned char *data; // Character pixel data (grayscale) } CharInfo; // Font type, includes texture and charSet array data @@ -955,29 +956,29 @@ RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters - //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ // Font loading/unloading functions -RLAPI Font GetDefaultFont(void); // Get the default Font -RLAPI Font LoadFont(const char *fileName); // Load Font from file into GPU memory (VRAM) -RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load Font from file with extended parameters -RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) +RLAPI Font GetDefaultFont(void); // Get the default Font +RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) +RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use +RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int packing); // Generate image font atlas using chars info +RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) // Text drawing functions -RLAPI void DrawFPS(int posX, int posY); // Shows current FPS -RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -RLAPI void DrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using Font and additional parameters +RLAPI void DrawFPS(int posX, int posY); // Shows current FPS +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters // Text misc. functions -RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font -RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font -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 -RLAPI int GetGlyphIndex(Font font, int character); // Returns index position for a unicode character on sprite font +RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font +RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font +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 +RLAPI int GetGlyphIndex(Font font, int character); // Get index position for a unicode character on sprite font //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) diff --git a/src/text.c b/src/text.c index 9755ff8b..3c3ff751 100644 --- a/src/text.c +++ b/src/text.c @@ -47,16 +47,14 @@ #include "utils.h" // Required for: fopen() Android mapping #if defined(SUPPORT_FILEFORMAT_TTF) - // Following libs are used on LoadTTF() - #define STBTT_STATIC // Define stb_truetype functions static to this module + #define STB_RECT_PACK_IMPLEMENTATION + #include "external/stb_rect_pack.h" // Required for: ttf font rectangles packaging + + #define STBTT_STATIC #define STB_TRUETYPE_IMPLEMENTATION - #include "external/stb_truetype.h" // Required for: stbtt_BakeFontBitmap() + #include "external/stb_truetype.h" // Required for: ttf font data reading #endif -// Rectangle packing functions (not used at the moment) -//#define STB_RECT_PACK_IMPLEMENTATION -//#include "stb_rect_pack.h" - //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- @@ -89,7 +87,7 @@ static Font LoadImageFont(Image image, Color key, int firstChar); // Load a Imag static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file) #endif #if defined(SUPPORT_FILEFORMAT_TTF) -static Font LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load spritefont from TTF data +//static Font LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load spritefont from TTF data #endif #if defined(SUPPORT_DEFAULT_FONT) @@ -276,68 +274,244 @@ Font LoadFont(const char *fileName) // Default hardcoded values for ttf file loading #define DEFAULT_TTF_FONTSIZE 32 // Font first character (32 - space) #define DEFAULT_TTF_NUMCHARS 95 // ASCII 32..126 is 95 glyphs - #define DEFAULT_FIRST_CHAR 32 // Expected first char for image spritefont + #define DEFAULT_FIRST_CHAR 32 // Expected first char for image sprite font - Font spriteFont = { 0 }; + Font font = { 0 }; #if defined(SUPPORT_FILEFORMAT_TTF) - if (IsFileExtension(fileName, ".ttf")) spriteFont = LoadFontEx(fileName, DEFAULT_TTF_FONTSIZE, 0, NULL); + if (IsFileExtension(fileName, ".ttf")) + { + font.baseSize = DEFAULT_TTF_FONTSIZE; + font.charsCount = DEFAULT_TTF_NUMCHARS; + font.chars = LoadFontData(fileName, font.baseSize, NULL, font.charsCount, false); + Image atlas = GenImageFontAtlas(font.chars, font.charsCount, font.baseSize, 0); + font.texture = LoadTextureFromImage(atlas); + UnloadImage(atlas); + } else #endif #if defined(SUPPORT_FILEFORMAT_FNT) - if (IsFileExtension(fileName, ".fnt")) spriteFont = LoadBMFont(fileName); + if (IsFileExtension(fileName, ".fnt")) font = LoadBMFont(fileName); else #endif { Image image = LoadImage(fileName); - if (image.data != NULL) spriteFont = LoadImageFont(image, MAGENTA, DEFAULT_FIRST_CHAR); + if (image.data != NULL) font = LoadImageFont(image, MAGENTA, DEFAULT_FIRST_CHAR); UnloadImage(image); } - if (spriteFont.texture.id == 0) + if (font.texture.id == 0) { TraceLog(LOG_WARNING, "[%s] Font could not be loaded, using default font", fileName); - spriteFont = GetDefaultFont(); + font = GetDefaultFont(); } - else SetTextureFilter(spriteFont.texture, FILTER_POINT); // By default we set point filter (best performance) + else SetTextureFilter(font.texture, FILTER_POINT); // By default we set point filter (best performance) - return spriteFont; + return font; } -// Load Font from TTF font file with generation parameters -// NOTE: You can pass an array with desired characters, those characters should be available in the font -// if array is NULL, default char set is selected 32..126 -Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars) +// Load font data for further use +// NOTE: Requires TTF font and can generate SDF data +CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf) { - Font spriteFont = { 0 }; - int totalChars = 95; // Default charset [32..126] - bool fontCharsLoaded = false; + // NOTE: Using some SDF generation default values, + // trades off precision with ability to handle *smaller* sizes + #define SDF_CHAR_PADDING 4 + #define SDF_ON_EDGE_VALUE 128 + #define SDF_PIXEL_DIST_SCALE 64.0f + + CharInfo *chars = (CharInfo *)malloc(charsCount*sizeof(CharInfo)); + + // Load font data (including pixel data) from TTF file + // NOTE: Loaded information should be enough to generate font image atlas, + // using any packaging method + FILE *fontFile = fopen(fileName, "rb"); // Load font file + + fseek(fontFile, 0, SEEK_END); + long size = ftell(fontFile); // Get file size + fseek(fontFile, 0, SEEK_SET); // Reset file pointer + + unsigned char *fontBuffer = (unsigned char *)malloc(size); + + fread(fontBuffer, size, 1, fontFile); + fclose(fontFile); + + // Init font for data reading + stbtt_fontinfo fontInfo; + if (!stbtt_InitFont(&fontInfo, fontBuffer, 0)) TraceLog(LOG_WARNING, "Failed to init font!"); -#if defined(SUPPORT_FILEFORMAT_TTF) - if (IsFileExtension(fileName, ".ttf")) + // Calculate font scale factor + float scaleFactor = stbtt_ScaleForPixelHeight(&fontInfo, fontSize); + + // Calculate font basic metrics + // NOTE: ascent is equivalent to font baseline + int ascent, descent, lineGap; + stbtt_GetFontVMetrics(&fontInfo, &ascent, &descent, &lineGap); + ascent *= scaleFactor; + descent *= scaleFactor; + + // Fill fontChars in case not provided externally + // NOTE: By default we fill charsCount consecutevely, starting at 32 (Space) + int genFontChars = false; + if (fontChars == NULL) genFontChars = true; + if (genFontChars) + { + fontChars = (int *)malloc(charsCount*sizeof(int)); + for (int i = 0; i < charsCount; i++) fontChars[i] = i + 32; + } + + // NOTE: Using simple packaging, one char after another + for (int i = 0; i < charsCount; i++) + { + int chw = 0, chh = 0; // Character width and height (on generation) + int ch = fontChars[i]; // Character value to get info for + chars[i].value = ch; + + // Render a unicode codepoint to a bitmap + // stbtt_GetCodepointBitmap() -- allocates and returns a bitmap + // stbtt_GetCodepointBitmapBox() -- how big the bitmap must be + // stbtt_MakeCodepointBitmap() -- renders into bitmap you provide + + if (!sdf) chars[i].data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); + else if (ch != 32) chars[i].data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, SDF_CHAR_PADDING, SDF_ON_EDGE_VALUE, SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); + + chars[i].rec.width = (float)chw; + chars[i].rec.height = (float)chh; + chars[i].offsetY += ascent; + + // Get bounding box for character (may be offset to account for chars that dip above or below the line) + int chX1, chY1, chX2, chY2; + stbtt_GetCodepointBitmapBox(&fontInfo, ch, scaleFactor, scaleFactor, &chX1, &chY1, &chX2, &chY2); + + TraceLog(LOG_DEBUG, "Character box measures: %i, %i, %i, %i", chX1, chY1, chX2 - chX1, chY2 - chY1); + TraceLog(LOG_DEBUG, "Character offsetY: %i", ascent + chY1); + + stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL); + chars[i].advanceX *= scaleFactor; + } + + free(fontBuffer); + if (genFontChars) free(fontChars); + + return chars; +} + +// Generate image font atlas using chars info +// NOTE: Packing method: 0-Default, 1-Skyline +Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packing) +{ + Image atlas = { 0 }; + + int padding = 10; + + // Calculate atlas texture size based on fontSize + // 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... + //float guessSize = ceilf((float)fontSize*3/4)*ceilf(sqrtf((float)charsCount)); + //int textureSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT + + // TODO: TEXTURE SIZE NOT GOOD ENOUGH! -> Calculate chars area -> guess texture size? + float requiredArea = 0; + for (int i = 0; i < charsCount; i++) requiredArea += ((chars[i].rec.width + 2*padding)*(chars[i].rec.height + 2*padding)); + float guessSize = sqrtf(requiredArea)*1.25f; + int textureSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT + + atlas.width = textureSize; // Atlas bitmap width + atlas.height = textureSize; // Atlas bitmap height + atlas.data = (unsigned char *)calloc(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp) + atlas.format = UNCOMPRESSED_GRAYSCALE; + atlas.mipmaps = 1; + + if (packing == 0) // Use basic packing algorythm { - if (charsCount != 0) totalChars = charsCount; + int offsetX = padding; + int offsetY = padding; - if (fontChars == NULL) + // NOTE: Using simple packaging, one char after another + for (int i = 0; i < charsCount; i++) { - fontChars = (int *)malloc(totalChars*sizeof(int)); - for (int i = 0; i < totalChars; i++) fontChars[i] = i + 32; // Default first character: SPACE[32] - fontCharsLoaded = true; + // Copy pixel data from fc.data to atlas + for (int y = 0; y < (int)chars[i].rec.height; y++) + { + for (int x = 0; x < (int)chars[i].rec.width; x++) + { + ((unsigned char *)atlas.data)[(offsetY + y)*atlas.width + (offsetX + x)] = chars[i].data[y*(int)chars[i].rec.width + x]; + } + } + + chars[i].rec.x = offsetX; + chars[i].rec.y = offsetY; + + // Move atlas position X for next character drawing + offsetX += ((int)chars[i].advanceX + 2*padding); + + if (offsetX >= (atlas.width - (int)chars[i].rec.width - padding)) + { + offsetX = padding; + offsetY += (fontSize + 2*padding); + + if (offsetY > (atlas.height - fontSize - padding)) break; + } } + } + else if (packing == 1) // Use Skyline rect packing algorythm + { + stbrp_context *context = (stbrp_context *)malloc(sizeof(*context)); + stbrp_node *nodes = (stbrp_node *)malloc(charsCount*sizeof(*nodes)); + + stbrp_init_target(context, atlas.width, atlas.height, nodes, charsCount); + stbrp_rect *rects = (stbrp_rect *)malloc(charsCount*sizeof(stbrp_rect)); - spriteFont = LoadTTF(fileName, fontSize, totalChars, fontChars); + // Fill rectangles for packaging + for (int i = 0; i < charsCount; i++) + { + rects[i].id = i; + rects[i].w = (int)chars[i].rec.width + 2*padding; + rects[i].h = (int)chars[i].rec.height + 2*padding; + } + + // Package rectangles into atlas + stbrp_pack_rects(context, rects, charsCount); - if (fontCharsLoaded) free(fontChars); + for (int i = 0; i < charsCount; i++) + { + chars[i].rec.x = rects[i].x + padding; + chars[i].rec.y = rects[i].y + padding; + + if (rects[i].was_packed) + { + // Copy pixel data from fc.data to atlas + for (int y = 0; y < (int)chars[i].rec.height; y++) + { + for (int x = 0; x < (int)chars[i].rec.width; x++) + { + ((unsigned char *)atlas.data)[(rects[i].y + padding + y)*atlas.width + (rects[i].x + padding + x)] = chars[i].data[y*(int)chars[i].rec.width + x]; + } + } + } + else TraceLog(LOG_WARNING, "Character could not be packed: %i", i); + } + + free(nodes); + free(context); } -#endif + + // Convert image data from GRAYSCALE to GRAY_ALPHA + //ImageAlphaMask(&atlas, atlas); // WARNING: Not working in this case, requires manual operation + unsigned char *dataGrayAlpha = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)*2); // Two channels - if (spriteFont.texture.id == 0) + for (int i = 0, k = 0; i < atlas.width*atlas.height; i++, k += 2) { - TraceLog(LOG_WARNING, "[%s] Font could not be generated, using default font", fileName); - spriteFont = GetDefaultFont(); + dataGrayAlpha[k] = 255; + dataGrayAlpha[k + 1] = ((unsigned char *)atlas.data)[i]; } - return spriteFont; + free(atlas.data); + atlas.data = dataGrayAlpha; + atlas.format = UNCOMPRESSED_GRAY_ALPHA; + + return atlas; } // Unload Font from GPU memory (VRAM) @@ -811,108 +985,4 @@ static Font LoadBMFont(const char *fileName) return font; } -#endif - -#if defined(SUPPORT_FILEFORMAT_TTF) -// Generate a sprite font from TTF file data (font size required) -// TODO: Review texture packing method and generation (use oversampling) -static Font LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars) -{ - #define MAX_TTF_SIZE 16 // Maximum ttf file size in MB - - // NOTE: Font texture size is predicted (being as much conservative as possible) - // Predictive method consist of supposing same number of chars by line-column (sqrtf) - // and a maximum character width of 3/4 of fontSize... it worked ok with all my tests... - - // Calculate next power-of-two value - float guessSize = ceilf((float)fontSize*3/4)*ceilf(sqrtf((float)charsCount)); - int textureSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT - - TraceLog(LOG_INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize); - - unsigned char *ttfBuffer = (unsigned char *)malloc(MAX_TTF_SIZE*1024*1024); - unsigned char *dataBitmap = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)); // One channel bitmap returned! - stbtt_bakedchar *charData = (stbtt_bakedchar *)malloc(sizeof(stbtt_bakedchar)*charsCount); - - Font font = { 0 }; - - FILE *ttfFile = fopen(fileName, "rb"); - - if (ttfFile == NULL) - { - TraceLog(LOG_WARNING, "[%s] TTF file could not be opened", fileName); - return font; - } - - // NOTE: We try reading up to 16 MB of elements of 1 byte - fread(ttfBuffer, 1, MAX_TTF_SIZE*1024*1024, ttfFile); - - // Find font baseline (vertical origin of the font) - // NOTE: This value is required because y-offset depends on it! - stbtt_fontinfo fontInfo; - int ascent, baseline; - float scale; - - stbtt_InitFont(&fontInfo, ttfBuffer, 0); - scale = stbtt_ScaleForPixelHeight(&fontInfo, fontSize); - stbtt_GetFontVMetrics(&fontInfo, &ascent, 0, 0); - baseline = (int)(ascent*scale); - - if (fontChars[0] != 32) TraceLog(LOG_WARNING, "TTF spritefont loading: first character is not SPACE(32) character"); - - // NOTE: Using stb_truetype crappy packing method, no guarantee the font fits the image... - // TODO: Replace this function by a proper packing method and support random chars order, - // we already receive a list (fontChars) with the ordered expected characters - int result = stbtt_BakeFontBitmap(ttfBuffer, 0, fontSize, dataBitmap, textureSize, textureSize, fontChars[0], charsCount, charData); - - //if (result > 0) TraceLog(LOG_INFO, "TTF spritefont loading: first unused row of generated bitmap: %i", result); - if (result < 0) TraceLog(LOG_WARNING, "TTF spritefont loading: Not all the characters fit in the font"); - - free(ttfBuffer); - - // Convert image data from grayscale to to UNCOMPRESSED_GRAY_ALPHA - unsigned char *dataGrayAlpha = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)*2); // Two channels - - for (int i = 0, k = 0; i < textureSize*textureSize; i++, k += 2) - { - dataGrayAlpha[k] = 0xff; - dataGrayAlpha[k + 1] = dataBitmap[i]; - } - - free(dataBitmap); - - // Sprite font generation from TTF extracted data - Image image; - image.width = textureSize; - image.height = textureSize; - image.mipmaps = 1; - image.format = UNCOMPRESSED_GRAY_ALPHA; - image.data = dataGrayAlpha; - font.texture = LoadTextureFromImage(image); // Load image into texture - UnloadImage(image); // Unloads image data (dataGrayAlpha) - - - // Fill font characters info data - font.baseSize = fontSize; - font.charsCount = charsCount; - font.chars = (CharInfo *)malloc(font.charsCount*sizeof(CharInfo)); - - for (int i = 0; i < font.charsCount; i++) - { - font.chars[i].value = fontChars[i]; - - font.chars[i].rec.x = (int)charData[i].x0; - font.chars[i].rec.y = (int)charData[i].y0; - font.chars[i].rec.width = (int)charData[i].x1 - (int)charData[i].x0; - font.chars[i].rec.height = (int)charData[i].y1 - (int)charData[i].y0; - - font.chars[i].offsetX = charData[i].xoff; - font.chars[i].offsetY = baseline + charData[i].yoff; - font.chars[i].advanceX = (int)charData[i].xadvance; - } - - free(charData); - - return font; -} -#endif +#endif \ No newline at end of file diff --git a/src/textures.c b/src/textures.c index eeaf7ffd..29316a7a 100644 --- a/src/textures.c +++ b/src/textures.c @@ -828,9 +828,9 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_GRAY_ALPHA: { - image->data = (unsigned char *)malloc(image->width*image->height*2*sizeof(unsigned char)); + image->data = (unsigned char *)malloc(image->width*image->height*2*sizeof(unsigned char)); - for (int i = 0; i < image->width*image->height*2; i += 2, k++) + for (int i = 0; i < image->width*image->height*2; i += 2, k++) { ((unsigned char *)image->data)[i] = (unsigned char)((pixels[k].x*0.299f + (float)pixels[k].y*0.587f + (float)pixels[k].z*0.114f)*255.0f); ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[k].w*255.0f); -- cgit v1.2.3 From 0e135118fd0edd3ef613cb28cb573d12916dca98 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Jun 2018 00:18:13 +0200 Subject: Improved GenImageFontAtlas() --- release/include/raylib.h | 2 +- release/libs/win32/mingw32/libraylib.a | Bin 1116752 -> 1116822 bytes src/raylib.h | 2 +- src/text.c | 22 +++++++--------------- 4 files changed, 9 insertions(+), 17 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index 49434d52..9a6e117f 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -965,7 +965,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest RLAPI Font GetDefaultFont(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use -RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int packing); // Generate image font atlas using chars info +RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int padding, int packMethod); // Generate image font atlas using chars info RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) // Text drawing functions diff --git a/release/libs/win32/mingw32/libraylib.a b/release/libs/win32/mingw32/libraylib.a index 3425c71a..0bf3c421 100644 Binary files a/release/libs/win32/mingw32/libraylib.a and b/release/libs/win32/mingw32/libraylib.a differ diff --git a/src/raylib.h b/src/raylib.h index 49434d52..9a6e117f 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -965,7 +965,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest RLAPI Font GetDefaultFont(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use -RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int packing); // Generate image font atlas using chars info +RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int padding, int packMethod); // Generate image font atlas using chars info RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) // Text drawing functions diff --git a/src/text.c b/src/text.c index 3c3ff751..5e02a471 100644 --- a/src/text.c +++ b/src/text.c @@ -284,7 +284,7 @@ Font LoadFont(const char *fileName) font.baseSize = DEFAULT_TTF_FONTSIZE; font.charsCount = DEFAULT_TTF_NUMCHARS; font.chars = LoadFontData(fileName, font.baseSize, NULL, font.charsCount, false); - Image atlas = GenImageFontAtlas(font.chars, font.charsCount, font.baseSize, 0); + Image atlas = GenImageFontAtlas(font.chars, font.charsCount, font.baseSize, 4, 0); font.texture = LoadTextureFromImage(atlas); UnloadImage(atlas); } @@ -398,20 +398,12 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c // Generate image font atlas using chars info // NOTE: Packing method: 0-Default, 1-Skyline -Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packing) +Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int padding, int packMethod) { Image atlas = { 0 }; - int padding = 10; - - // Calculate atlas texture size based on fontSize - // 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... - //float guessSize = ceilf((float)fontSize*3/4)*ceilf(sqrtf((float)charsCount)); - //int textureSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT - - // TODO: TEXTURE SIZE NOT GOOD ENOUGH! -> Calculate chars area -> guess texture size? + // Calculate texture size based on required pixel area + // NOTE: Texture is forced to be squared and POT float requiredArea = 0; for (int i = 0; i < charsCount; i++) requiredArea += ((chars[i].rec.width + 2*padding)*(chars[i].rec.height + 2*padding)); float guessSize = sqrtf(requiredArea)*1.25f; @@ -423,7 +415,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packi atlas.format = UNCOMPRESSED_GRAYSCALE; atlas.mipmaps = 1; - if (packing == 0) // Use basic packing algorythm + if (packMethod == 0) // Use basic packing algorythm { int offsetX = padding; int offsetY = padding; @@ -455,7 +447,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packi } } } - else if (packing == 1) // Use Skyline rect packing algorythm + else if (packMethod == 1) // Use Skyline rect packing algorythm (stb_pack_rect) { stbrp_context *context = (stbrp_context *)malloc(sizeof(*context)); stbrp_node *nodes = (stbrp_node *)malloc(charsCount*sizeof(*nodes)); @@ -498,7 +490,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packi } // Convert image data from GRAYSCALE to GRAY_ALPHA - //ImageAlphaMask(&atlas, atlas); // WARNING: Not working in this case, requires manual operation + // WARNING: ImageAlphaMask(&atlas, atlas) does not work in this case, requires manual operation unsigned char *dataGrayAlpha = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)*2); // Two channels for (int i = 0, k = 0; i < atlas.width*atlas.height; i++, k += 2) -- cgit v1.2.3 From 59ebe1b7c322232f38c98afa7d5df8fade9bc6f5 Mon Sep 17 00:00:00 2001 From: "maficccc@gmail.com" Date: Sat, 23 Jun 2018 00:33:48 +0200 Subject: Added support OpenBSD, NetBSD, DragonFly --- README.md | 2 +- examples/Makefile | 27 ++++++++++++++++++--------- games/Makefile | 25 +++++++++++++++++-------- games/drturtle/Makefile | 25 +++++++++++++++++-------- games/just_do/Makefile | 23 ++++++++++++++++------- games/koala_seasons/Makefile | 25 +++++++++++++++++-------- games/light_my_ritual/Makefile | 25 +++++++++++++++++-------- games/skully_escape/Makefile | 25 +++++++++++++++++-------- games/transmission/Makefile | 25 +++++++++++++++++-------- games/wave_collector/Makefile | 23 ++++++++++++++++------- release/include/raylib.h | 2 +- src/Makefile | 25 +++++++++++++++++-------- src/core.c | 6 +++--- src/raylib.h | 2 +- templates/advance_game/Makefile | 21 +++++++++++++++------ templates/simple_game/Makefile | 25 +++++++++++++++++-------- templates/standard_game/Makefile | 25 +++++++++++++++++-------- 17 files changed, 224 insertions(+), 107 deletions(-) (limited to 'src/raylib.h') diff --git a/README.md b/README.md index da604004..ebe410f5 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ features * Shaders support, including Model shaders and Postprocessing shaders * Powerful math module for Vector, Matrix and Quaternion operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) * Audio loading and playing with streaming support (WAV, OGG, FLAC, XM, MOD) - * Multiple platforms support: Windows, Linux, FreeBSD, MacOS, UWP, Android, Raspberry Pi, HTML5. + * Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. * VR stereo rendering with configurable HMD device parameters * NO external dependencies, all required libraries included with raylib * Complete bindings to LUA ([raylib-lua](https://github.com/raysan5/raylib-lua)) and Go ([raylib-go](https://github.com/gen2brain/raylib-go)) diff --git a/examples/Makefile b/examples/Makefile index 2e9d458f..2e42fb05 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -76,7 +76,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -129,8 +138,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -163,8 +172,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -254,7 +263,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI) INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads endif ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) # Consider -L$(RAYLIB_H_INSTALL_PATH) INCLUDE_PATHS += -I/usr/local/include endif @@ -270,7 +279,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) # Consider -L$(RAYLIB_INSTALL_PATH) LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -316,8 +325,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm # On XWindow requires also below libraries diff --git a/games/Makefile b/games/Makefile index 9d83f8f5..01c0bbe3 100644 --- a/games/Makefile +++ b/games/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,8 +246,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/drturtle/Makefile b/games/drturtle/Makefile index e30a53a3..d200a929 100644 --- a/games/drturtle/Makefile +++ b/games/drturtle/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,8 +246,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/just_do/Makefile b/games/just_do/Makefile index 217e6622..9877b7d5 100644 --- a/games/just_do/Makefile +++ b/games/just_do/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,7 +246,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) # Libraries for FreeBSD desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/koala_seasons/Makefile b/games/koala_seasons/Makefile index 89d53463..d88177fe 100644 --- a/games/koala_seasons/Makefile +++ b/games/koala_seasons/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,8 +246,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/light_my_ritual/Makefile b/games/light_my_ritual/Makefile index b89b861e..1eb69d7d 100644 --- a/games/light_my_ritual/Makefile +++ b/games/light_my_ritual/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,8 +246,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/skully_escape/Makefile b/games/skully_escape/Makefile index 61789787..924aad3d 100644 --- a/games/skully_escape/Makefile +++ b/games/skully_escape/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,8 +246,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/transmission/Makefile b/games/transmission/Makefile index ef9b06e4..34e50864 100644 --- a/games/transmission/Makefile +++ b/games/transmission/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,8 +246,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/games/wave_collector/Makefile b/games/wave_collector/Makefile index dfa219c3..d7ef1a35 100644 --- a/games/wave_collector/Makefile +++ b/games/wave_collector/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -237,7 +246,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) # Libraries for FreeBSD desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/release/include/raylib.h b/release/include/raylib.h index 9a6e117f..5542db71 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -13,7 +13,7 @@ * - Shaders support, including Model shaders and Postprocessing shaders * - Powerful math module for Vector, Matrix and Quaternion operations: [raymath] * - Audio loading and playing with streaming support (WAV, OGG, FLAC, XM, MOD) -* - Multiple platforms support: Windows, Linux, FreeBSD, MacOS, UWP, Android, Raspberry Pi, HTML5. +* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. * - VR stereo rendering with configurable HMD device parameters * - NO external dependencies, all required libraries included with raylib * - Complete bindings to LUA (raylib-lua) and Go (raylib-go) diff --git a/src/Makefile b/src/Makefile index c05e74bb..6f71874f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,7 @@ # PLATFORM_DESKTOP: Windows (Win32, Win64) # PLATFORM_DESKTOP: Linux (32 and 64 bit) # PLATFORM_DESKTOP: OSX/macOS -# PLATFORM_DESKTOP: FreeBSD +# PLATFORM_DESKTOP: FreeBSD, OpenBSD, NetBSD, DragonFly # PLATFORM_ANDROID: Android (ARM, ARM64) # PLATFORM_RPI: Raspberry Pi (Raspbian) # PLATFORM_WEB: HTML5 (Chrome, Firefox) @@ -111,7 +111,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -185,8 +194,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -231,8 +240,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) CC = clang GLFW_CFLAGS = -x objective-c endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -346,7 +355,7 @@ endif INCLUDE_PATHS = -I. -Iexternal -Iexternal/glfw/include ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib -L$(RAYLIB_RELEASE_PATH) endif @@ -459,7 +468,7 @@ else cd $(RAYLIB_RELEASE_PATH) && ln -fs libraylib.$(RAYLIB_VERSION).dylib libraylib.$(RAYLIB_API_VERSION).dylib cd $(RAYLIB_RELEASE_PATH) && ln -fs libraylib.$(RAYLIB_VERSION).dylib libraylib.dylib endif - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) # WARNING: you should type "gmake clean" before doing this target $(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.$(RAYLIB_VERSION).so $(OBJS) -Wl,-soname,libraylib.$(RAYLIB_API_VERSION).so -lGL -lpthread @echo "raylib shared library generated (libraylib.$(RAYLIB_VERSION).so)!" diff --git a/src/core.c b/src/core.c index 3dbe4199..b00f8c44 100644 --- a/src/core.c +++ b/src/core.c @@ -5,7 +5,7 @@ * PLATFORMS SUPPORTED: * - PLATFORM_DESKTOP: Windows (Win32, Win64) * - PLATFORM_DESKTOP: Linux (X11 desktop mode) -* - PLATFORM_DESKTOP: FreeBSD (X11 desktop) +* - PLATFORM_DESKTOP: FreeBSD, OpenBSD, NetBSD, DragonFly (X11 desktop) * - PLATFORM_DESKTOP: OSX/macOS * - PLATFORM_ANDROID: Android 4.0 (ARM, ARM64) * - PLATFORM_RPI: Raspberry Pi 0,1,2,3 (Raspbian) @@ -15,7 +15,7 @@ * CONFIGURATION: * * #define PLATFORM_DESKTOP -* Windowing and input system configured for desktop platforms: Windows, Linux, OSX, FreeBSD +* Windowing and input system configured for desktop platforms: Windows, Linux, OSX, FreeBSD, OpenBSD, NetBSD, DragonFly * NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for mirror rendering - View [rlgl] module to enable it * * #define PLATFORM_ANDROID @@ -57,7 +57,7 @@ * Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback() * * DEPENDENCIES: -* rglfw - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX. FreeBSD) +* rglfw - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX. FreeBSD, OpenBSD, NetBSD, DragonFly) * raymath - 3D math functionality (Vector2, Vector3, Matrix, Quaternion) * camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person) * gestures - Gestures system for touch-ready devices (or simulated from mouse inputs) diff --git a/src/raylib.h b/src/raylib.h index 9a6e117f..5542db71 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -13,7 +13,7 @@ * - Shaders support, including Model shaders and Postprocessing shaders * - Powerful math module for Vector, Matrix and Quaternion operations: [raymath] * - Audio loading and playing with streaming support (WAV, OGG, FLAC, XM, MOD) -* - Multiple platforms support: Windows, Linux, FreeBSD, MacOS, UWP, Android, Raspberry Pi, HTML5. +* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. * - VR stereo rendering with configurable HMD device parameters * - NO external dependencies, all required libraries included with raylib * - Complete bindings to LUA (raylib-lua) and Go (raylib-go) diff --git a/templates/advance_game/Makefile b/templates/advance_game/Makefile index 29818041..a2d41193 100644 --- a/templates/advance_game/Makefile +++ b/templates/advance_game/Makefile @@ -58,8 +58,17 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(UNAMEOS),Linux) PLATFORM_OS=LINUX endif - ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + ifeq ($(UNAMEOS),FreeBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif diff --git a/templates/simple_game/Makefile b/templates/simple_game/Makefile index feab47ba..9e768f5f 100644 --- a/templates/simple_game/Makefile +++ b/templates/simple_game/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -240,8 +249,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm diff --git a/templates/standard_game/Makefile b/templates/standard_game/Makefile index 55fabde5..2e19e17c 100644 --- a/templates/standard_game/Makefile +++ b/templates/standard_game/Makefile @@ -59,7 +59,16 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) PLATFORM_OS=LINUX endif ifeq ($(UNAMEOS),FreeBSD) - PLATFORM_OS=FREEBSD + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD endif ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -97,8 +106,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),OSX) RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx endif - ifeq ($(PLATFORM_OS),FREEBSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/freebsd + ifeq ($(PLATFORM_OS),BSD) + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd endif endif ifeq ($(PLATFORM),PLATFORM_RPI) @@ -117,8 +126,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # OSX default compiler CC = clang endif - ifeq ($(PLATFORM_OS),FREEBSD) - # FreeBSD default compiler + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler CC = clang endif endif @@ -200,7 +209,7 @@ endif LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),FREEBSD) + ifeq ($(PLATFORM_OS),BSD) INCLUDE_PATHS += -I/usr/local/include LDFLAGS += -L. -Lsrc -L/usr/local/lib endif @@ -240,8 +249,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: Required packages: libopenal-dev libegl1-mesa-dev LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa endif - ifeq ($(PLATFORM_OS),FREEBSD) - # Libraries for FreeBSD desktop compiling + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling # NOTE: Required packages: mesa-libs LDLIBS = -lraylib -lGL -lpthread -lm -- cgit v1.2.3 From dbfd8d713f10008b9e80940cc8825a0300c47325 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 26 Jun 2018 01:36:13 +0200 Subject: Reviewed comments section --- src/raylib.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/raylib.h') diff --git a/src/raylib.h b/src/raylib.h index 5542db71..eeadbbb7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -3,6 +3,8 @@ * raylib - A simple and easy-to-use library to learn videogames programming (www.raylib.com) * * FEATURES: +* - NO external dependencies, all required libraries included with raylib +* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. * - Written in plain C code (C99) in PascalCase/camelCase notation * - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2 - choose at compile) * - Unique OpenGL abstraction layer (usable as standalone module): [rlgl] @@ -12,10 +14,8 @@ * - Flexible Materials system, supporting classic maps and PBR maps * - Shaders support, including Model shaders and Postprocessing shaders * - Powerful math module for Vector, Matrix and Quaternion operations: [raymath] -* - Audio loading and playing with streaming support (WAV, OGG, FLAC, XM, MOD) -* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. +* - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD) * - VR stereo rendering with configurable HMD device parameters -* - NO external dependencies, all required libraries included with raylib * - Complete bindings to LUA (raylib-lua) and Go (raylib-go) * * NOTES: @@ -33,14 +33,15 @@ * stb_image_resize (Sean Barret) for image resizing algorythms [textures] * stb_image_write (Sean Barret) for image writting (PNG) [utils] * stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_rect_pack (Sean Barret) for rectangles packing [text] * stb_vorbis (Sean Barret) for OGG audio loading [audio] * stb_perlin (Sean Barret) for Perlin noise image generation [textures] * par_shapes (Philip Rideout) for parametric 3d shapes generation [models] * jar_xm (Joshua Reisenauer) for XM audio module loading [audio] * jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] * dr_flac (David Reid) for FLAC audio file loading [audio] +* dr_mp3 (David Reid) for MP3 audio file loading [audio] * rgif (Charlie Tangora, Ramon Santamaria) for GIF recording [core] -* tinfl for data decompression (DEFLATE algorithm) [rres] * * * LICENSE: zlib/libpng -- cgit v1.2.3 From afe81d94cebd0f803327743c867a38b1dceffe76 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 30 Jun 2018 19:58:44 +0200 Subject: Re-added: LoadFontEx() --- examples/textures/textures_image_text.c | 2 +- src/raylib.h | 1 + src/text.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/raylib.h') diff --git a/examples/textures/textures_image_text.c b/examples/textures/textures_image_text.c index 0a939b8d..78d25c14 100644 --- a/examples/textures/textures_image_text.c +++ b/examples/textures/textures_image_text.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); // TTF Font loading with custom generation parameters - Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0); + Font font = LoadFontEx("resources/KAISG.ttf", 64, 95, 0); Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) diff --git a/src/raylib.h b/src/raylib.h index eeadbbb7..924d1299 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -965,6 +965,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest // Font loading/unloading functions RLAPI Font GetDefaultFont(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) +RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int padding, int packMethod); // Generate image font atlas using chars info RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) diff --git a/src/text.c b/src/text.c index 5e02a471..c895540b 100644 --- a/src/text.c +++ b/src/text.c @@ -310,6 +310,23 @@ Font LoadFont(const char *fileName) return font; } +// Load Font from TTF font file with generation parameters +// NOTE: You can pass an array with desired characters, those characters should be available in the font +// if array is NULL, default char set is selected 32..126 +Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars) +{ + Font font = { 0 }; + + font.baseSize = fontSize; + font.charsCount = (charsCount > 0) ? charsCount : 95; + font.chars = LoadFontData(fileName, font.baseSize, fontChars, font.charsCount, false); + Image atlas = GenImageFontAtlas(font.chars, font.charsCount, font.baseSize, 0, 0); + font.texture = LoadTextureFromImage(atlas); + UnloadImage(atlas); + + return font; +} + // Load font data for further use // NOTE: Requires TTF font and can generate SDF data CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf) -- cgit v1.2.3 From d0166c9d45dc964a96528de6b272315219a83def Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 30 Jun 2018 21:56:26 +0200 Subject: Spacing tweaks --- src/raylib.h | 26 ++++---- src/rlgl.c | 194 +++++++++++++++++++++++++++++------------------------------ src/rlgl.h | 58 +++++++++--------- 3 files changed, 139 insertions(+), 139 deletions(-) (limited to 'src/raylib.h') diff --git a/src/raylib.h b/src/raylib.h index 924d1299..de78b8c3 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -541,12 +541,12 @@ typedef struct VrDeviceInfo { // Enumerators Definition //---------------------------------------------------------------------------------- // Trace log type -typedef enum { +typedef enum { LOG_INFO = 1, - LOG_WARNING = 2, - LOG_ERROR = 4, - LOG_DEBUG = 8, - LOG_OTHER = 16 + LOG_WARNING = 2, + LOG_ERROR = 4, + LOG_DEBUG = 8, + LOG_OTHER = 16 } LogType; // Shader location point type @@ -638,16 +638,16 @@ typedef enum { } TextureFilterMode; // Texture parameters: wrap mode -typedef enum { - WRAP_REPEAT = 0, - WRAP_CLAMP, - WRAP_MIRROR +typedef enum { + WRAP_REPEAT = 0, + WRAP_CLAMP, + WRAP_MIRROR } TextureWrapMode; // Color blending modes (pre-defined) -typedef enum { - BLEND_ALPHA = 0, - BLEND_ADDITIVE, +typedef enum { + BLEND_ALPHA = 0, + BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -1020,7 +1020,7 @@ RLAPI void ExportMesh(const char *fileName, Mesh mesh); // Mesh manipulation functions RLAPI BoundingBox MeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits -RLAPI void MeshTangents(Mesh *mesh); // Compute mesh tangents +RLAPI void MeshTangents(Mesh *mesh); // Compute mesh tangents RLAPI void MeshBinormals(Mesh *mesh); // Compute mesh binormals // Mesh generation functions diff --git a/src/rlgl.c b/src/rlgl.c index 87613b36..c806d35d 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -2,8 +2,8 @@ * * rlgl - raylib OpenGL abstraction layer * -* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to -* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...). +* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to +* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...). * * 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: @@ -657,7 +657,7 @@ void rlEnd(void) // as well as depth buffer bit-depth (16bit or 24bit or 32bit) // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) currentDepth += (1.0f/20000.0f); - + // Verify internal buffers limits // NOTE: This check is combined with usage of rlCheckBufferLimit() if ((lines.vCounter/2 >= MAX_LINES_BATCH - 2) || @@ -829,7 +829,7 @@ void rlEnableTexture(unsigned int id) if (draws[drawsCounter - 1].textureId != id) { if (draws[drawsCounter - 1].vertexCount > 0) drawsCounter++; - + if (drawsCounter >= MAX_DRAWS_BY_TEXTURE) { rlglDraw(); @@ -1126,7 +1126,7 @@ void rlglInit(int width, int height) // 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) texNPOTSupported = true; - + // Check texture float support if (strcmp(extList[i], (const char *)"GL_OES_texture_float") == 0) texFloatSupported = true; #endif @@ -1158,7 +1158,7 @@ void rlglInit(int width, int height) // Clamp mirror wrap mode supported if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texClampMirrorSupported = true; - + // Debug marker support if(strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; } @@ -1271,9 +1271,9 @@ void rlglClose(void) { #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) UnloadShaderDefault(); // Unload default shader - UnloadBuffersDefault(); // Unload default buffers (lines, triangles, quads) + UnloadBuffersDefault(); // Unload default buffers (lines, triangles, quads) glDeleteTextures(1, &whiteTexture); // Unload default texture - + TraceLog(LOG_INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture); free(draws); @@ -1438,30 +1438,30 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi #endif glBindTexture(GL_TEXTURE_2D, id); - + int mipWidth = width; int mipHeight = height; int mipOffset = 0; // Mipmap data offset - + TraceLog(LOG_DEBUG, "Load texture from data memory address: 0x%x", data); - + // Load the different mipmap levels for (int i = 0; i < mipmapCount; i++) { unsigned int mipSize = GetPixelDataSize(mipWidth, mipHeight, format); - + int glInternalFormat, glFormat, glType; GetGlFormats(format, &glInternalFormat, &glFormat, &glType); - + TraceLog(LOG_DEBUG, "Load mipmap level %i (%i x %i), size: %i, offset: %i", i, mipWidth, mipHeight, mipSize, mipOffset); - + if (glInternalFormat != -1) { if (format < COMPRESSED_DXT1_RGB) glTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, glFormat, glType, (unsigned char *)data + mipOffset); - #if !defined(GRAPHICS_API_OPENGL_11) + #if !defined(GRAPHICS_API_OPENGL_11) else glCompressedTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, mipSize, (unsigned char *)data + mipOffset); #endif - + #if defined(GRAPHICS_API_OPENGL_33) if (format == UNCOMPRESSED_GRAYSCALE) { @@ -1479,11 +1479,11 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi } #endif } - + mipWidth /= 2; mipHeight /= 2; mipOffset += mipSize; - + // Security check for NPOT textures if (mipWidth < 1) mipWidth = 1; if (mipHeight < 1) mipHeight = 1; @@ -1539,7 +1539,7 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data) { glBindTexture(GL_TEXTURE_2D, id); - + int glInternalFormat, glFormat, glType; GetGlFormats(format, &glInternalFormat, &glFormat, &glType); @@ -1671,7 +1671,7 @@ void rlGenerateMipmaps(Texture2D *texture) { // Retrieve texture data from VRAM void *data = rlReadTexturePixels(*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); @@ -1696,7 +1696,7 @@ void rlGenerateMipmaps(Texture2D *texture) texture->mipmaps = mipmapCount + 1; free(data); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data - + TraceLog(LOG_WARNING, "[TEX ID %i] Mipmaps [%i] generated manually on CPU side", texture->id, texture->mipmaps); } else TraceLog(LOG_WARNING, "[TEX ID %i] Mipmaps could not be generated for texture format", texture->id); @@ -1943,27 +1943,27 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Bind shader program - glUseProgram(material.shader.id); + glUseProgram(material.shader.id); // Matrices and other values required by shader //----------------------------------------------------- // Calculate and send to shader model matrix (used by PBR shader) if (material.shader.locs[LOC_MATRIX_MODEL] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_MODEL], transform); - + // Upload to shader material.colDiffuse if (material.shader.locs[LOC_COLOR_DIFFUSE] != -1) - glUniform4f(material.shader.locs[LOC_COLOR_DIFFUSE], (float)material.maps[MAP_DIFFUSE].color.r/255.0f, - (float)material.maps[MAP_DIFFUSE].color.g/255.0f, - (float)material.maps[MAP_DIFFUSE].color.b/255.0f, + glUniform4f(material.shader.locs[LOC_COLOR_DIFFUSE], (float)material.maps[MAP_DIFFUSE].color.r/255.0f, + (float)material.maps[MAP_DIFFUSE].color.g/255.0f, + (float)material.maps[MAP_DIFFUSE].color.b/255.0f, (float)material.maps[MAP_DIFFUSE].color.a/255.0f); // Upload to shader material.colSpecular (if available) - if (material.shader.locs[LOC_COLOR_SPECULAR] != -1) - glUniform4f(material.shader.locs[LOC_COLOR_SPECULAR], (float)material.maps[MAP_SPECULAR].color.r/255.0f, - (float)material.maps[MAP_SPECULAR].color.g/255.0f, - (float)material.maps[MAP_SPECULAR].color.b/255.0f, + if (material.shader.locs[LOC_COLOR_SPECULAR] != -1) + glUniform4f(material.shader.locs[LOC_COLOR_SPECULAR], (float)material.maps[MAP_SPECULAR].color.r/255.0f, + (float)material.maps[MAP_SPECULAR].color.g/255.0f, + (float)material.maps[MAP_SPECULAR].color.b/255.0f, (float)material.maps[MAP_SPECULAR].color.a/255.0f); - + if (material.shader.locs[LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_VIEW], modelview); if (material.shader.locs[LOC_MATRIX_PROJECTION] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[LOC_MATRIX_PROJECTION], projection); @@ -2054,7 +2054,7 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform) #if defined(SUPPORT_VR_SIMULATOR) if (vrStereoRender) eyesCount = 2; #endif - + for (int eye = 0; eye < eyesCount; eye++) { if (eyesCount == 1) modelview = matModelView; @@ -2072,7 +2072,7 @@ void rlDrawMesh(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); } - + // Unbind all binded texture maps for (int i = 0; i < MAX_MATERIAL_MAPS; i++) { @@ -2168,7 +2168,7 @@ void *rlReadTexturePixels(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 */ - + // 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.) @@ -2178,7 +2178,7 @@ void *rlReadTexturePixels(Texture2D texture) int glInternalFormat, glFormat, glType; GetGlFormats(texture.format, &glInternalFormat, &glFormat, &glType); unsigned int size = GetPixelDataSize(texture.width, texture.height, texture.format); - + if ((glInternalFormat != -1) && (texture.format < COMPRESSED_DXT1_RGB)) { pixels = (unsigned char *)malloc(size); @@ -2224,7 +2224,7 @@ void *rlReadTexturePixels(Texture2D texture) //glDisable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); //glDisable(GL_BLEND); - + glViewport(0, 0, texture.width, texture.height); rlOrtho(0.0, texture.width, texture.height, 0.0, 0.0, 1.0); @@ -2234,17 +2234,17 @@ void *rlReadTexturePixels(Texture2D texture) GenDrawQuad(); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); - + pixels = (unsigned char *)malloc(texture.width*texture.height*4*sizeof(unsigned char)); glReadPixels(0, 0, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Bind framebuffer 0, which means render to back buffer glBindFramebuffer(GL_FRAMEBUFFER, 0); - + // Reset viewport dimensions to default glViewport(0, 0, screenWidth, screenHeight); - + #endif // GET_TEXTURE_FBO_OPTION // Clean up temporal fbo @@ -2349,9 +2349,9 @@ Shader LoadShader(const char *vsFileName, const char *fsFileName) if (vsFileName != NULL) vShaderStr = LoadText(vsFileName); if (fsFileName != NULL) fShaderStr = LoadText(fsFileName); - + shader = LoadShaderCode(vShaderStr, fShaderStr); - + if (vShaderStr != NULL) free(vShaderStr); if (fShaderStr != NULL) free(fShaderStr); @@ -2366,16 +2366,16 @@ Shader LoadShaderCode(char *vsCode, char *fsCode) // NOTE: All locations must be reseted to -1 (no location) for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1; - + #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) unsigned int vertexShaderId = defaultVShaderId; unsigned int fragmentShaderId = defaultFShaderId; - + if (vsCode != NULL) vertexShaderId = CompileShader(vsCode, GL_VERTEX_SHADER); if (fsCode != NULL) fragmentShaderId = CompileShader(fsCode, GL_FRAGMENT_SHADER); - + if ((vertexShaderId == defaultVShaderId) && (fragmentShaderId == defaultFShaderId)) shader = defaultShader; - else + else { shader.id = LoadShaderProgram(vertexShaderId, fragmentShaderId); @@ -2387,17 +2387,17 @@ Shader LoadShaderCode(char *vsCode, char *fsCode) TraceLog(LOG_WARNING, "Custom shader could not be loaded"); shader = defaultShader; } - + // After shader loading, we TRY to set default location names if (shader.id > 0) SetShaderDefaultLocations(&shader); } - + // Get available shader uniforms // NOTE: This information is useful for debug... int uniformCount = -1; - + glGetProgramiv(shader.id, GL_ACTIVE_UNIFORMS, &uniformCount); - + for(int i = 0; i < uniformCount; i++) { int namelen = -1; @@ -2407,16 +2407,16 @@ Shader LoadShaderCode(char *vsCode, char *fsCode) // Get the name of the uniforms glGetActiveUniform(shader.id, i,sizeof(name) - 1, &namelen, &num, &type, name); - + name[namelen] = 0; // Get the location of the named uniform GLuint location = glGetUniformLocation(shader.id, name); - + TraceLog(LOG_DEBUG, "[SHDR ID %i] Active uniform [%s] set at location: %i", shader.id, name, location); } #endif - + return shader; } @@ -2524,7 +2524,7 @@ void SetMatrixModelview(Matrix view) } // Return internal modelview matrix -Matrix GetMatrixModelview() +Matrix GetMatrixModelview() { Matrix matrix = MatrixIdentity(); #if defined(GRAPHICS_API_OPENGL_11) @@ -2541,16 +2541,16 @@ Matrix GetMatrixModelview() Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) { Texture2D cubemap = { 0 }; -#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2) +#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2) // NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader // Other locations should be setup externally in shader before calling the function - + // Set up depth face culling and cubemap seamless glDisable(GL_CULL_FACE); #if defined(GRAPHICS_API_OPENGL_33) glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // Flag not supported on OpenGL ES 2.0 #endif - + // Setup framebuffer unsigned int fbo, rbo; @@ -2565,7 +2565,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) // NOTE: faces are stored with 16 bit floating point values glGenTextures(1, &cubemap.id); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id); - for (unsigned int i = 0; i < 6; i++) + for (unsigned int i = 0; i < 6; i++) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -2607,7 +2607,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) // Unbind framebuffer and textures glBindFramebuffer(GL_FRAMEBUFFER, 0); - + // Reset viewport dimensions to default glViewport(0, 0, screenWidth, screenHeight); //glEnable(GL_CULL_FACE); @@ -2623,11 +2623,11 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) { Texture2D irradiance = { 0 }; - + #if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2) // NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader // Other locations should be setup externally in shader before calling the function - + // Setup framebuffer unsigned int fbo, rbo; glGenFramebuffers(1, &fbo); @@ -2636,18 +2636,18 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo); - + // Create an irradiance cubemap, and re-scale capture FBO to irradiance scale glGenTextures(1, &irradiance.id); glBindTexture(GL_TEXTURE_CUBE_MAP, irradiance.id); - for (unsigned int i = 0; i < 6; i++) + for (unsigned int i = 0; i < 6; i++) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - + // Create projection (transposed) and different views for each face Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0); //MatrixTranspose(&fboProjection); @@ -2680,7 +2680,7 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) // Unbind framebuffer and textures glBindFramebuffer(GL_FRAMEBUFFER, 0); - + // Reset viewport dimensions to default glViewport(0, 0, screenWidth, screenHeight); @@ -2695,13 +2695,13 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) { Texture2D prefilter = { 0 }; - + #if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2) // NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader // Other locations should be setup externally in shader before calling the function // TODO: Locations should be taken out of this function... too shader dependant... int roughnessLoc = GetShaderLocation(shader, "roughness"); - + // Setup framebuffer unsigned int fbo, rbo; glGenFramebuffers(1, &fbo); @@ -2710,11 +2710,11 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo); - + // Create a prefiltered HDR environment map glGenTextures(1, &prefilter.id); glBindTexture(GL_TEXTURE_CUBE_MAP, prefilter.id); - for (unsigned int i = 0; i < 6; i++) + for (unsigned int i = 0; i < 6; i++) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -2724,7 +2724,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) // Generate mipmaps for the prefiltered HDR texture glGenerateMipmap(GL_TEXTURE_CUBE_MAP); - + // Create projection (transposed) and different views for each face Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0); //MatrixTranspose(&fboProjection); @@ -2744,7 +2744,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) SetShaderValueMatrix(shader, shader.locs[LOC_MATRIX_PROJECTION], fboProjection); glBindFramebuffer(GL_FRAMEBUFFER, fbo); - + #define MAX_MIPMAP_LEVELS 5 // Max number of prefilter texture mipmaps for (unsigned int mip = 0; mip < MAX_MIPMAP_LEVELS; mip++) @@ -2752,7 +2752,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) // Resize framebuffer according to mip-level size. unsigned int mipWidth = size*powf(0.5f, mip); unsigned int mipHeight = size*powf(0.5f, mip); - + glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mipWidth, mipHeight); glViewport(0, 0, mipWidth, mipHeight); @@ -2771,7 +2771,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) // Unbind framebuffer and textures glBindFramebuffer(GL_FRAMEBUFFER, 0); - + // Reset viewport dimensions to default glViewport(0, 0, screenWidth, screenHeight); @@ -2804,7 +2804,7 @@ Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size) glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, brdf.id, 0); - + glViewport(0, 0, size, size); glUseProgram(shader.id); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -2812,10 +2812,10 @@ Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size) // Unbind framebuffer and textures glBindFramebuffer(GL_FRAMEBUFFER, 0); - + // Reset viewport dimensions to default glViewport(0, 0, screenWidth, screenHeight); - + brdf.width = size; brdf.height = size; #endif @@ -2853,7 +2853,7 @@ void EndBlendMode(void) VrDeviceInfo GetVrDeviceInfo(int vrDeviceType) { VrDeviceInfo hmd = { 0 }; // Current VR device info - + switch (vrDeviceType) { case HMD_DEFAULT_DEVICE: @@ -2881,7 +2881,7 @@ VrDeviceInfo GetVrDeviceInfo(int vrDeviceType) hmd.chromaAbCorrection[1] = -0.004f; // HMD chromatic aberration correction parameter 1 hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2 hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3 - + TraceLog(LOG_INFO, "Initializing VR Simulator (Oculus Rift CV1)"); } break; case HMD_OCULUS_RIFT_DK2: @@ -2903,9 +2903,9 @@ VrDeviceInfo GetVrDeviceInfo(int vrDeviceType) hmd.chromaAbCorrection[1] = -0.004f; // HMD chromatic aberration correction parameter 1 hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2 hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3 - + TraceLog(LOG_INFO, "Initializing VR Simulator (Oculus Rift DK2)"); - } break; + } break; case HMD_OCULUS_GO: { // TODO: Provide device display and lens parameters @@ -2920,7 +2920,7 @@ VrDeviceInfo GetVrDeviceInfo(int vrDeviceType) } default: break; } - + return hmd; } @@ -2932,12 +2932,12 @@ void InitVrSimulator(VrDeviceInfo info) // Initialize framebuffer and textures for stereo rendering // NOTE: Screen size should match HMD aspect ratio vrConfig.stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight); - + #if defined(SUPPORT_DISTORTION_SHADER) // Load distortion shader unsigned int vertexShaderId = CompileShader(distortionVShaderStr, GL_VERTEX_SHADER); unsigned int fragmentShaderId = CompileShader(distortionFShaderStr, GL_FRAGMENT_SHADER); - + vrConfig.distortionShader.id = LoadShaderProgram(vertexShaderId, fragmentShaderId); if (vrConfig.distortionShader.id > 0) SetShaderDefaultLocations(&vrConfig.distortionShader); #endif @@ -2997,7 +2997,7 @@ void ToggleVrMode(void) if (!vrSimulatorReady) { vrStereoRender = false; - + // Reset viewport and default projection-modelview matrices rlViewport(0, 0, screenWidth, screenHeight); projection = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); @@ -3031,7 +3031,7 @@ void BeginVrDrawing(void) //glViewport(0, 0, buffer.width, buffer.height); // Useful if rendering to separate framebuffers (every eye) rlClearScreenBuffers(); // Clear current framebuffer(s) - + vrStereoRender = true; } #endif @@ -3044,7 +3044,7 @@ void EndVrDrawing(void) if (vrSimulatorReady) { vrStereoRender = false; // Disable stereo render - + rlDisableRenderTexture(); // Unbind current framebuffer rlClearScreenBuffers(); // Clear current framebuffer @@ -3096,7 +3096,7 @@ void EndVrDrawing(void) // Update and draw render texture fbo with distortion to backbuffer UpdateBuffersDefault(); DrawBuffersDefault(); - + // Restore defaultShader currentShader = defaultShader; @@ -3104,7 +3104,7 @@ void EndVrDrawing(void) rlViewport(0, 0, screenWidth, screenHeight); projection = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); modelview = MatrixIdentity(); - + rlDisableDepthTest(); } #endif @@ -3216,7 +3216,7 @@ static unsigned int LoadShaderProgram(unsigned int vShaderId, unsigned int fShad static Shader LoadShaderDefault(void) { Shader shader = { 0 }; - + // NOTE: All locations must be reseted to -1 (no location) for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1; @@ -3282,10 +3282,10 @@ static Shader LoadShaderDefault(void) // NOTE: Compiled vertex/fragment shaders are kept for re-use defaultVShaderId = CompileShader(defaultVShaderStr, GL_VERTEX_SHADER); // Compile default vertex shader defaultFShaderId = CompileShader(defaultFShaderStr, GL_FRAGMENT_SHADER); // Compile default fragment shader - + shader.id = LoadShaderProgram(defaultVShaderId, defaultFShaderId); - if (shader.id > 0) + if (shader.id > 0) { TraceLog(LOG_INFO, "[SHDR ID %i] Default shader loaded successfully", shader.id); @@ -3298,7 +3298,7 @@ static Shader LoadShaderDefault(void) shader.locs[LOC_MATRIX_MVP] = glGetUniformLocation(shader.id, "mvp"); shader.locs[LOC_COLOR_DIFFUSE] = glGetUniformLocation(shader.id, "colDiffuse"); shader.locs[LOC_MAP_DIFFUSE] = glGetUniformLocation(shader.id, "texture0"); - + // NOTE: We could also use below function but in case DEFAULT_ATTRIB_* points are // changed for external custom shaders, we just use direct bindings above //SetShaderDefaultLocations(&shader); @@ -3349,7 +3349,7 @@ static void UnloadShaderDefault(void) glDetachShader(defaultShader.id, defaultFShaderId); glDeleteShader(defaultVShaderId); glDeleteShader(defaultFShaderId); - + glDeleteProgram(defaultShader.id); } @@ -3601,7 +3601,7 @@ static void DrawBuffersDefault(void) { Matrix matProjection = projection; Matrix matModelView = modelview; - + int eyesCount = 1; #if defined(SUPPORT_VR_SIMULATOR) if (vrStereoRender) eyesCount = 2; @@ -3825,7 +3825,7 @@ static void GenDrawQuad(void) { unsigned int quadVAO = 0; unsigned int quadVBO = 0; - + float vertices[] = { // Positions // Texture Coords -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, @@ -3853,7 +3853,7 @@ static void GenDrawQuad(void) glBindVertexArray(quadVAO); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); - + glDeleteBuffers(1, &quadVBO); glDeleteVertexArrays(1, &quadVAO); } @@ -3926,7 +3926,7 @@ static void GenDrawCube(void) glBindVertexArray(cubeVAO); glDrawArrays(GL_TRIANGLES, 0, 36); glBindVertexArray(0); - + glDeleteBuffers(1, &cubeVBO); glDeleteVertexArrays(1, &cubeVAO); } @@ -4031,7 +4031,7 @@ static void GetGlFormats(int format, int *glInternalFormat, int *glFormat, int * *glInternalFormat = -1; *glFormat = -1; *glType = -1; - + switch (format) { #if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_21) || defined(GRAPHICS_API_OPENGL_ES2) diff --git a/src/rlgl.h b/src/rlgl.h index 18eff380..0a66a8f0 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -2,10 +2,10 @@ * * rlgl - raylib OpenGL abstraction layer * -* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to -* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...). +* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to +* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...). * -* 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 @@ -18,7 +18,7 @@ * #define GRAPHICS_API_OPENGL_33 * #define GRAPHICS_API_OPENGL_ES2 * Use selected OpenGL graphics backend, should be supported by platform -* Those preprocessor defines are only used on rlgl module, if OpenGL version is +* Those preprocessor defines are only used on rlgl module, if OpenGL version is * required by any other module, use rlGetVersion() tocheck it * * #define RLGL_STANDALONE @@ -124,7 +124,7 @@ #define RL_WRAP_CLAMP_MIRROR 0x8742 // GL_MIRROR_CLAMP_EXT // Matrix modes (equivalent to OpenGL) -#define RL_MODELVIEW 0x1700 // GL_MODELVIEW +#define RL_MODELVIEW 0x1700 // GL_MODELVIEW #define RL_PROJECTION 0x1701 // GL_PROJECTION #define RL_TEXTURE 0x1702 // GL_TEXTURE @@ -153,7 +153,7 @@ typedef unsigned char byte; unsigned char b; unsigned char a; } Color; - + // Rectangle type typedef struct Rectangle { int x; @@ -161,7 +161,7 @@ typedef unsigned char byte; int width; int height; } Rectangle; - + // Texture2D type // NOTE: Data stored in GPU memory typedef struct Texture2D { @@ -194,11 +194,11 @@ typedef unsigned char byte; unsigned int vaoId; // OpenGL Vertex Array Object id unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data) } Mesh; - + // Shader and material limits #define MAX_SHADER_LOCATIONS 32 #define MAX_MATERIAL_MAPS 12 - + // Shader type (generic) typedef struct Shader { unsigned int id; // Shader program id @@ -226,7 +226,7 @@ typedef unsigned char byte; Vector3 up; // Camera up vector (rotation over its axis) float fovy; // Camera field-of-view apperture in Y (degrees) } Camera; - + // Head-Mounted-Display device parameters typedef struct VrDeviceInfo { int hResolution; // HMD horizontal resolution in pixels @@ -240,16 +240,16 @@ typedef unsigned char byte; float lensDistortionValues[4]; // HMD lens distortion constant parameters float chromaAbCorrection[4]; // HMD chromatic aberration correction parameters } VrDeviceInfo; - + // TraceLog message types - typedef enum { - LOG_INFO = 0, - LOG_ERROR, - LOG_WARNING, - LOG_DEBUG, - LOG_OTHER + typedef enum { + LOG_INFO = 0, + LOG_ERROR, + LOG_WARNING, + LOG_DEBUG, + LOG_OTHER } TraceLogType; - + // Texture formats (support depends on OpenGL version) typedef enum { UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha) @@ -278,7 +278,7 @@ typedef unsigned char byte; // Texture parameters: filter mode // NOTE 1: Filtering considers mipmaps if available in the texture // NOTE 2: Filter is accordingly set for minification and magnification - typedef enum { + typedef enum { FILTER_POINT = 0, // No filter, just pixel aproximation FILTER_BILINEAR, // Linear filtering FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) @@ -286,19 +286,19 @@ typedef unsigned char byte; FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x } TextureFilterMode; - + // Texture parameters: wrap mode - typedef enum { - WRAP_REPEAT = 0, - WRAP_CLAMP, - WRAP_MIRROR + typedef enum { + WRAP_REPEAT = 0, + WRAP_CLAMP, + WRAP_MIRROR } TextureWrapMode; // Color blending modes (pre-defined) - typedef enum { - BLEND_ALPHA = 0, - BLEND_ADDITIVE, - BLEND_MULTIPLIED + typedef enum { + BLEND_ALPHA = 0, + BLEND_ADDITIVE, + BLEND_MULTIPLIED } BlendMode; // Shader location point type @@ -465,7 +465,7 @@ void SetShaderValuei(Shader shader, int uniformLoc, const int *value, int size); void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) -Matrix GetMatrixModelview(); // Get internal modelview matrix +Matrix GetMatrixModelview(); // Get internal modelview matrix // Texture maps generation (PBR) -- cgit v1.2.3 From 7b971e06236c581087a851c8ecda11bb7be12839 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 2 Jul 2018 18:53:46 +0200 Subject: Added Quaternion typedef --- release/include/raylib.h | 38 ++++++++++++++++++--------------- release/libs/win32/mingw32/libraylib.a | Bin 1116822 -> 1118066 bytes src/raylib.h | 2 ++ src/raymath.h | 16 +++++++------- 4 files changed, 31 insertions(+), 25 deletions(-) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index 5542db71..96bf2443 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -3,6 +3,8 @@ * raylib - A simple and easy-to-use library to learn videogames programming (www.raylib.com) * * FEATURES: +* - NO external dependencies, all required libraries included with raylib +* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. * - Written in plain C code (C99) in PascalCase/camelCase notation * - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2 - choose at compile) * - Unique OpenGL abstraction layer (usable as standalone module): [rlgl] @@ -12,10 +14,8 @@ * - Flexible Materials system, supporting classic maps and PBR maps * - Shaders support, including Model shaders and Postprocessing shaders * - Powerful math module for Vector, Matrix and Quaternion operations: [raymath] -* - Audio loading and playing with streaming support (WAV, OGG, FLAC, XM, MOD) -* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5. +* - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD) * - VR stereo rendering with configurable HMD device parameters -* - NO external dependencies, all required libraries included with raylib * - Complete bindings to LUA (raylib-lua) and Go (raylib-go) * * NOTES: @@ -33,14 +33,15 @@ * stb_image_resize (Sean Barret) for image resizing algorythms [textures] * stb_image_write (Sean Barret) for image writting (PNG) [utils] * stb_truetype (Sean Barret) for ttf fonts loading [text] +* stb_rect_pack (Sean Barret) for rectangles packing [text] * stb_vorbis (Sean Barret) for OGG audio loading [audio] * stb_perlin (Sean Barret) for Perlin noise image generation [textures] * par_shapes (Philip Rideout) for parametric 3d shapes generation [models] * jar_xm (Joshua Reisenauer) for XM audio module loading [audio] * jar_mod (Joshua Reisenauer) for MOD audio module loading [audio] * dr_flac (David Reid) for FLAC audio file loading [audio] +* dr_mp3 (David Reid) for MP3 audio file loading [audio] * rgif (Charlie Tangora, Ramon Santamaria) for GIF recording [core] -* tinfl for data decompression (DEFLATE algorithm) [rres] * * * LICENSE: zlib/libpng @@ -331,6 +332,8 @@ typedef struct Vector4 { float w; } Vector4; +typedef Vector4 Quaternion; + // Matrix type (OpenGL style 4x4 - right handed, column major) typedef struct Matrix { float m0, m4, m8, m12; @@ -540,12 +543,12 @@ typedef struct VrDeviceInfo { // Enumerators Definition //---------------------------------------------------------------------------------- // Trace log type -typedef enum { +typedef enum { LOG_INFO = 1, - LOG_WARNING = 2, - LOG_ERROR = 4, - LOG_DEBUG = 8, - LOG_OTHER = 16 + LOG_WARNING = 2, + LOG_ERROR = 4, + LOG_DEBUG = 8, + LOG_OTHER = 16 } LogType; // Shader location point type @@ -637,16 +640,16 @@ typedef enum { } TextureFilterMode; // Texture parameters: wrap mode -typedef enum { - WRAP_REPEAT = 0, - WRAP_CLAMP, - WRAP_MIRROR +typedef enum { + WRAP_REPEAT = 0, + WRAP_CLAMP, + WRAP_MIRROR } TextureWrapMode; // Color blending modes (pre-defined) -typedef enum { - BLEND_ALPHA = 0, - BLEND_ADDITIVE, +typedef enum { + BLEND_ALPHA = 0, + BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -964,6 +967,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest // Font loading/unloading functions RLAPI Font GetDefaultFont(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) +RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int padding, int packMethod); // Generate image font atlas using chars info RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) @@ -1018,7 +1022,7 @@ RLAPI void ExportMesh(const char *fileName, Mesh mesh); // Mesh manipulation functions RLAPI BoundingBox MeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits -RLAPI void MeshTangents(Mesh *mesh); // Compute mesh tangents +RLAPI void MeshTangents(Mesh *mesh); // Compute mesh tangents RLAPI void MeshBinormals(Mesh *mesh); // Compute mesh binormals // Mesh generation functions diff --git a/release/libs/win32/mingw32/libraylib.a b/release/libs/win32/mingw32/libraylib.a index 0bf3c421..675b11ea 100644 Binary files a/release/libs/win32/mingw32/libraylib.a and b/release/libs/win32/mingw32/libraylib.a differ diff --git a/src/raylib.h b/src/raylib.h index de78b8c3..96bf2443 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -332,6 +332,8 @@ typedef struct Vector4 { float w; } Vector4; +typedef Vector4 Quaternion; + // Matrix type (OpenGL style 4x4 - right handed, column major) typedef struct Matrix { float m0, m4, m8, m12; diff --git a/src/raymath.h b/src/raymath.h index a574dd0d..4e100bc3 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -114,6 +114,14 @@ float y; float z; } Vector3; + + // Quaternion type + typedef struct Quaternion { + float x; + float y; + float z; + float w; + } Quaternion; // Matrix type (OpenGL style 4x4 - right handed, column major) typedef struct Matrix { @@ -122,14 +130,6 @@ float m2, m6, m10, m14; float m3, m7, m11, m15; } Matrix; - - // Quaternion type - typedef struct Quaternion { - float x; - float y; - float z; - float w; - } Quaternion; #endif // NOTE: Helper types to be used instead of array return types for *ToFloat functions -- cgit v1.2.3 From 74fd0e7ca4faaa428c248a9ae714e2e7371e6ed4 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 3 Jul 2018 00:57:58 +0200 Subject: Added function: ImageColorReplace() --- release/include/raylib.h | 1 + release/libs/win32/mingw32/libraylib.a | Bin 1118066 -> 1118620 bytes src/raylib.h | 1 + src/textures.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+) (limited to 'src/raylib.h') diff --git a/release/include/raylib.h b/release/include/raylib.h index 96bf2443..43000318 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -937,6 +937,7 @@ RLAPI void ImageColorInvert(Image *image); RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void ImageColorReplace(Image *image, Color color, Color replace); // Modify image color: replace color // Image generation functions RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color diff --git a/release/libs/win32/mingw32/libraylib.a b/release/libs/win32/mingw32/libraylib.a index 675b11ea..e5a6a9bc 100644 Binary files a/release/libs/win32/mingw32/libraylib.a and b/release/libs/win32/mingw32/libraylib.a differ diff --git a/src/raylib.h b/src/raylib.h index 96bf2443..43000318 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -937,6 +937,7 @@ RLAPI void ImageColorInvert(Image *image); RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) +RLAPI void ImageColorReplace(Image *image, Color color, Color replace); // Modify image color: replace color // Image generation functions RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color diff --git a/src/textures.c b/src/textures.c index 81bbbf3c..f2dc7ca3 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1901,6 +1901,36 @@ void ImageColorBrightness(Image *image, int brightness) image->data = processed.data; } + +// Modify image color: replace color +void ImageColorReplace(Image *image, Color color, Color replace) +{ + Color *pixels = GetImageData(*image); + + for (int y = 0; y < image->height; y++) + { + for (int x = 0; x < image->width; x++) + { + if ((pixels[y*image->width + x].r == color.r) && + (pixels[y*image->width + x].g == color.g) && + (pixels[y*image->width + x].b == color.b) && + (pixels[y*image->width + x].a == color.a)) + { + pixels[y*image->width + x].r = replace.r; + pixels[y*image->width + x].g = replace.g; + pixels[y*image->width + x].b = replace.b; + pixels[y*image->width + x].a = replace.a; + } + } + } + + Image processed = LoadImageEx(pixels, image->width, image->height); + ImageFormat(&processed, image->format); + UnloadImage(*image); + free(pixels); + + image->data = processed.data; +} #endif // SUPPORT_IMAGE_MANIPULATION #if defined(SUPPORT_IMAGE_GENERATION) -- cgit v1.2.3