Last active
February 1, 2018 17:44
-
-
Save kodai100/caa555fbedd97cded689d857145c6baf to your computer and use it in GitHub Desktop.
Frame caputurer for GLFW (with FreeImage)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <string> | |
#include <GLFW\glfw3.h> | |
#include <FreeImage\FreeImage.h> | |
using namespace std; | |
class FrameCapturer { | |
private: | |
int width, height; | |
BYTE* buffer; | |
public: | |
static int count; | |
FrameCapturer(int width, int height); | |
~FrameCapturer(); | |
void capture(const string directory, const string filename) const; | |
}; | |
int FrameCapturer::count = 0; | |
FrameCapturer::FrameCapturer(int width, int height) { | |
this->width = width; | |
this->height = height; | |
this->buffer = new BYTE[3 * width * height]; | |
count = 0; | |
} | |
FrameCapturer::~FrameCapturer() { | |
delete[] buffer; | |
} | |
void FrameCapturer::capture(const string dir, const string name) const { | |
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer); | |
FIBITMAP* image = FreeImage_ConvertFromRawBits(buffer, width, height, 3 * width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false); | |
string filename = dir + "\\" + name + "_" + to_string(count) + ".png"; | |
FreeImage_Save(FIF_PNG, image, filename.c_str(), 0); | |
FreeImage_Unload(image); | |
count++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment