diff options
Diffstat (limited to 'src/OffscreenContextCGL.mm')
-rw-r--r-- | src/OffscreenContextCGL.mm | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/OffscreenContextCGL.mm b/src/OffscreenContextCGL.mm index a0995fa..b3a5501 100644 --- a/src/OffscreenContextCGL.mm +++ b/src/OffscreenContextCGL.mm @@ -111,6 +111,22 @@ bool teardown_offscreen_context(OffscreenContext *ctx) */ bool save_framebuffer(OffscreenContext *ctx, const char *filename) { + std::ofstream fstream(filename); + if (!fstream.is_open()) { + PRINTB("Can't open file \"%s\" for writing", filename); + return false; + } else { + save_framebuffer(ctx, fstream); + fstream.close(); + } + return true; +} + +/*! + Capture framebuffer from OpenGL and write it to the given ostream +*/ +bool save_framebuffer(OffscreenContext *ctx, std::ostream &output) +{ if (!ctx || !filename) return false; // Read pixels from OpenGL int samplesPerPixel = 4; // R, G, B and A @@ -132,7 +148,7 @@ bool save_framebuffer(OffscreenContext *ctx, const char *filename) } flip_image(bufferData, flippedBuffer, samplesPerPixel, ctx->width, ctx->height); - bool writeok = write_png(filename, flippedBuffer, ctx->width, ctx->height); + bool writeok = write_png(output, flippedBuffer, ctx->width, ctx->height); free(flippedBuffer); free(bufferData); @@ -140,7 +156,3 @@ bool save_framebuffer(OffscreenContext *ctx, const char *filename) return writeok; } -void bind_offscreen_context(OffscreenContext *ctx) -{ - fbo_bind(ctx->fbo); -} |