summaryrefslogtreecommitdiff
path: root/src/OffscreenContext.h
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-01-26 05:30:02 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-01-26 05:30:02 (GMT)
commit395628cb4ef7f8559c667af22fb273e21e4a5ad8 (patch)
tree9fc4cd53eda3370de06c872f9df299ee1d9629de /src/OffscreenContext.h
parenta66ad9c4bc10696cd3167d3217c9aad532167705 (diff)
refactor to remove duplicate code
Diffstat (limited to 'src/OffscreenContext.h')
-rw-r--r--src/OffscreenContext.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/OffscreenContext.h b/src/OffscreenContext.h
index a1792b4..3494898 100644
--- a/src/OffscreenContext.h
+++ b/src/OffscreenContext.h
@@ -2,13 +2,33 @@
#define OFFSCREENCONTEXT_H_
#include <iostream>
+#include <fstream>
#include <string>
struct OffscreenContext *create_offscreen_context(int w, int h);
-void bind_offscreen_context(OffscreenContext *ctx);
bool teardown_offscreen_context(OffscreenContext *ctx);
-bool save_framebuffer(OffscreenContext *ctx, const char *filename);
bool save_framebuffer(OffscreenContext *ctx, std::ostream &output);
std::string offscreen_context_getinfo(OffscreenContext *ctx);
+void bind_offscreen_context(OffscreenContext *ctx)
+{
+ if (ctx) fbo_bind(ctx->fbo);
+}
+
+/*
+ Capture framebuffer from OpenGL and write it to the given filename as PNG.
+*/
+inline bool save_framebuffer(OffscreenContext *ctx, const char *filename)
+{
+ std::ofstream fstream(filename);
+ if (!fstream.is_open()) {
+ std::cerr << "Can't open file " << filename << " for writing";
+ return false;
+ } else {
+ save_framebuffer(ctx, fstream);
+ fstream.close();
+ }
+ return true;
+}
+
#endif
contact: Jan Huwald // Impressum