aboutsummaryrefslogtreecommitdiff
path: root/src/core.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2014-01-23 12:36:18 +0100
committerraysan5 <raysan5@gmail.com>2014-01-23 12:36:18 +0100
commit2cf5fa77658af7f5e72245e798db6b3a3f256371 (patch)
tree8c47e3ed0d5c711e39fc9e45e898459a5eae9d86 /src/core.c
parent762befb967f984f1529af6ff390b34347c6934a1 (diff)
downloadraylib-1.0.4.tar.gz
raylib-1.0.4.zip
Updated raylib to version 1.0.41.0.4
Lots of changes added, check CHANGELOG for detailed description
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/core.c b/src/core.c
index 920f34a3..78525483 100644
--- a/src/core.c
+++ b/src/core.c
@@ -35,6 +35,7 @@
#include <time.h> // Useful to initialize random seed
#include <math.h> // Math related functions, tan() on SetPerspective
#include "vector3.h" // Basic Vector3 functions
+#include "utils.h" // WritePNG() function
//#define GLFW_DLL // Using GLFW DLL on Windows -> No, we use static version!
@@ -81,7 +82,6 @@ static char currentGamepadState[32] = {0}; // Required to check if gamepad btn
//----------------------------------------------------------------------------------
extern void LoadDefaultFont(); // [Module: text] Loads default font on InitWindow()
extern void UnloadDefaultFont(); // [Module: text] Unloads default font from GPU memory
-extern void WriteBitmap(const char *fileName, const pixel *imgDataPixel, int width, int height); // [Module: textures] Writes a bitmap (BMP) file
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
@@ -354,6 +354,15 @@ int GetRandomValue(int min, int max)
return (rand()%(abs(max-min)+1) + min);
}
+// Fades color by a percentadge
+Color Fade(Color color, float alpha)
+{
+ if (alpha < 0.0) alpha = 0.0;
+ else if (alpha > 1.0) alpha = 1.0;
+
+ return (Color){color.r, color.g, color.b, color.a*alpha};
+}
+
//----------------------------------------------------------------------------------
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
//----------------------------------------------------------------------------------
@@ -737,21 +746,36 @@ static void TakeScreenshot()
char buffer[20]; // Buffer to store file name
int fbWidth, fbHeight;
- Color *imgDataPixel; // Pixel image data array
+ unsigned char *imgData; // Pixel image data array
glfwGetFramebufferSize(window, &fbWidth, &fbHeight); // Get framebuffer size of current window
- imgDataPixel = (Color *)malloc(fbWidth * fbHeight * sizeof(Color));
+ imgData = (unsigned char *)malloc(fbWidth * fbHeight * sizeof(unsigned char) * 4);
// NOTE: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
- glReadPixels(0, 0, fbWidth, fbHeight, GL_RGBA, GL_UNSIGNED_BYTE, imgDataPixel);
+ glReadPixels(0, 0, fbWidth, fbHeight, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
+
+ // TODO: Flip image vertically!
+
+ unsigned char *imgDataFlip = (unsigned char *)malloc(fbWidth * fbHeight * sizeof(unsigned char) * 4);
+
+ for (int y = fbHeight-1; y >= 0; y--)
+ {
+ for (int x = 0; x < (fbWidth*4); x++)
+ {
+ imgDataFlip[x + (fbHeight - y - 1)*fbWidth*4] = imgData[x + (y*fbWidth*4)];
+ }
+ }
+
+ free(imgData);
- sprintf(buffer, "screenshot%03i.bmp", shotNum);
+ sprintf(buffer, "screenshot%03i.png", shotNum);
// NOTE: BMP directly stores data flipped vertically
- WriteBitmap(buffer, imgDataPixel, fbWidth, fbHeight); // Writes pixel data array into a bitmap (BMP) file
+ //WriteBitmap(buffer, imgDataPixel, fbWidth, fbHeight); // Writes pixel data array into a bitmap (BMP) file
+ WritePNG(buffer, imgDataFlip, fbWidth, fbHeight);
- free(imgDataPixel);
+ free(imgDataFlip);
shotNum++;
} \ No newline at end of file