diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-02-01 01:47:12 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-02-01 01:47:12 (GMT) |
commit | 466490a55a22495d7fe7cb7f5572cfe36e7b33a3 (patch) | |
tree | 770c813982758a1ce18a092c3c706d96848427b3 /src/OffscreenContextAll.hpp | |
parent | f8ebf1c963cbd4feb3a188aa41801de0ee3932f1 (diff) |
properly indent code
Diffstat (limited to 'src/OffscreenContextAll.hpp')
-rw-r--r-- | src/OffscreenContextAll.hpp | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/src/OffscreenContextAll.hpp b/src/OffscreenContextAll.hpp index 42563be..b07cea0 100644 --- a/src/OffscreenContextAll.hpp +++ b/src/OffscreenContextAll.hpp @@ -6,49 +6,49 @@ void bind_offscreen_context(OffscreenContext *ctx) { - if (ctx) fbo_bind(ctx->fbo); + if (ctx) fbo_bind(ctx->fbo); } /* - Capture framebuffer from OpenGL and write it to the given filename as PNG. -*/ + Capture framebuffer from OpenGL and write it to the given filename as PNG. + */ bool save_framebuffer(OffscreenContext *ctx, const char *filename) { - std::ofstream fstream(filename,std::ios::out|std::ios::binary); - if (!fstream.is_open()) { - std::cerr << "Can't open file " << filename << " for writing"; - return false; - } else { - save_framebuffer(ctx, fstream); - fstream.close(); - } - return true; + std::ofstream fstream(filename,std::ios::out|std::ios::binary); + if (!fstream.is_open()) { + std::cerr << "Can't open file " << filename << " for writing"; + return false; + } else { + save_framebuffer(ctx, fstream); + fstream.close(); + } + return true; } /*! Capture framebuffer from OpenGL and write it to the given ostream. - Called by save_framebuffer() from platform-specific code. -*/ + Called by save_framebuffer() from platform-specific code. + */ bool save_framebuffer_common(OffscreenContext *ctx, std::ostream &output) { - if (!ctx) return false; - int samplesPerPixel = 4; // R, G, B and A - std::vector<GLubyte> pixels(ctx->width * ctx->height * samplesPerPixel); - glReadPixels(0, 0, ctx->width, ctx->height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); + if (!ctx) return false; + int samplesPerPixel = 4; // R, G, B and A + std::vector<GLubyte> pixels(ctx->width * ctx->height * samplesPerPixel); + glReadPixels(0, 0, ctx->width, ctx->height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); - // Flip it vertically - images read from OpenGL buffers are upside-down - int rowBytes = samplesPerPixel * ctx->width; + // Flip it vertically - images read from OpenGL buffers are upside-down + int rowBytes = samplesPerPixel * ctx->width; - unsigned char *flippedBuffer = (unsigned char *)malloc(rowBytes * ctx->height); - if (!flippedBuffer) { - std::cerr << "Unable to allocate flipped buffer for corrected image."; - return 1; - } - flip_image(&pixels[0], flippedBuffer, samplesPerPixel, ctx->width, ctx->height); + unsigned char *flippedBuffer = (unsigned char *)malloc(rowBytes * ctx->height); + if (!flippedBuffer) { + std::cerr << "Unable to allocate flipped buffer for corrected image."; + return 1; + } + flip_image(&pixels[0], flippedBuffer, samplesPerPixel, ctx->width, ctx->height); - bool writeok = write_png(output, flippedBuffer, ctx->width, ctx->height); + bool writeok = write_png(output, flippedBuffer, ctx->width, ctx->height); - free(flippedBuffer); + free(flippedBuffer); return writeok; } @@ -58,17 +58,17 @@ OffscreenContext *create_offscreen_context_common(OffscreenContext *ctx) { if (!ctx) return NULL; GLenum err = glewInit(); // must come after Context creation and before FBO c$ - if (GLEW_OK != err) { - std::cerr << "Unable to init GLEW: " << glewGetErrorString(err) << "\n"; - return NULL; - } - //cerr << glew_dump(0); + if (GLEW_OK != err) { + std::cerr << "Unable to init GLEW: " << glewGetErrorString(err) << "\n"; + return NULL; + } + //cerr << glew_dump(0); - ctx->fbo = fbo_new(); - if (!fbo_init(ctx->fbo, ctx->width, ctx->height)) { - return NULL; - } + ctx->fbo = fbo_new(); + if (!fbo_init(ctx->fbo, ctx->width, ctx->height)) { + return NULL; + } - return ctx; + return ctx; } |