Skip to content

Instantly share code, notes, and snippets.

@kodai100
Last active February 1, 2018 17:44
Show Gist options
  • Save kodai100/caa555fbedd97cded689d857145c6baf to your computer and use it in GitHub Desktop.
Save kodai100/caa555fbedd97cded689d857145c6baf to your computer and use it in GitHub Desktop.
Frame caputurer for GLFW (with FreeImage)
#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