aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2014-12-31 18:03:32 +0100
committerraysan5 <raysan5@gmail.com>2014-12-31 18:03:32 +0100
commit905b6ec53df01a4f660c12c08c32e2cc301f7ad6 (patch)
tree8b5c43267c6056e45be8807e0867b8fd50777a2d /src/utils.c
parent08a4ee34ebe97e679a27f43b9f25525982029d17 (diff)
downloadraylib-905b6ec53df01a4f660c12c08c32e2cc301f7ad6.tar.gz
raylib-905b6ec53df01a4f660c12c08c32e2cc301f7ad6.zip
Added full support for HTML5 (emscripten)
Corrected some bugs on the way... Automatically convert textures to POT on RPI and WEB
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/utils.c b/src/utils.c
index 27b72870..c3c20b47 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -133,18 +133,25 @@ void WriteBitmap(const char *fileName, unsigned char *imgData, int width, int he
FILE *bmpFile = fopen(fileName, "wb"); // Define a pointer to bitmap file and open it in write-binary mode
- // NOTE: fwrite parameters are: data pointer, size in bytes of each element to be written, number of elements, file-to-write pointer
- fwrite(bmpFileHeader, sizeof(unsigned char), 14, bmpFile); // Write BMP file header data
- fwrite(bmpInfoHeader, sizeof(unsigned char), 40, bmpFile); // Write BMP info header data
-
- // Write pixel data to file
- for (int y = 0; y < height ; y++)
+ if (bmpFile == NULL)
+ {
+ TraceLog(WARNING, "[%s] BMP file could not be created", fileName);
+ }
+ else
{
- for (int x = 0; x < width; x++)
+ // NOTE: fwrite parameters are: data pointer, size in bytes of each element to be written, number of elements, file-to-write pointer
+ fwrite(bmpFileHeader, sizeof(unsigned char), 14, bmpFile); // Write BMP file header data
+ fwrite(bmpInfoHeader, sizeof(unsigned char), 40, bmpFile); // Write BMP info header data
+
+ // Write pixel data to file
+ for (int y = 0; y < height ; y++)
{
- fputc(imgData[(x*4)+2 + (y*width*4)], bmpFile);
- fputc(imgData[(x*4)+1 + (y*width*4)], bmpFile);
- fputc(imgData[(x*4) + (y*width*4)], bmpFile);
+ for (int x = 0; x < width; x++)
+ {
+ fputc(imgData[(x*4)+2 + (y*width*4)], bmpFile);
+ fputc(imgData[(x*4)+1 + (y*width*4)], bmpFile);
+ fputc(imgData[(x*4) + (y*width*4)], bmpFile);
+ }
}
}
@@ -264,6 +271,23 @@ const char *GetExtension(const char *fileName)
return (dot + 1);
}
+// Calculate next power-of-two value for a given num
+int GetNextPOT(int num)
+{
+ if (num != 0)
+ {
+ num--;
+ num |= (num >> 1); // Or first 2 bits
+ num |= (num >> 2); // Or next 2 bits
+ num |= (num >> 4); // Or next 4 bits
+ num |= (num >> 8); // Or next 8 bits
+ num |= (num >> 16); // Or next 16 bits
+ num++;
+ }
+
+ return num;
+}
+
//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------