From 256eb2c2f2a4a7363898900335b217efc5c79ce4 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 28 Jan 2013 14:56:17 -0500 Subject: [PATCH] Mac OS X build fixes --- openscad.pro | 4 ++-- src/OffscreenContextAll.hpp | 7 +++++-- src/OffscreenContextCGL.mm | 22 +++------------------- src/imageutils-macosx.cc | 5 ++--- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/openscad.pro b/openscad.pro index 37e6fe3f..b5190edf 100644 --- a/openscad.pro +++ b/openscad.pro @@ -68,7 +68,7 @@ macx { APP_RESOURCES.path = Contents/Resources APP_RESOURCES.files = OpenSCAD.sdef QMAKE_BUNDLE_DATA += APP_RESOURCES - LIBS += -framework Carbon + LIBS += -framework Cocoa } else { TARGET = openscad @@ -312,7 +312,7 @@ unix:!macx { } macx { SOURCES += src/imageutils-macosx.cc - SOURCES += src/OffscreenContextCGL.mm + OBJECTIVE_SOURCES += src/OffscreenContextCGL.mm } win32* { SOURCES += src/imageutils-lodepng.cc diff --git a/src/OffscreenContextAll.hpp b/src/OffscreenContextAll.hpp index b0df83d1..42563be6 100644 --- a/src/OffscreenContextAll.hpp +++ b/src/OffscreenContextAll.hpp @@ -1,6 +1,9 @@ // Functions shared by OffscreenContext[platform].cc // #include this directly after definition of struct OffscreenContext. +#include +#include + void bind_offscreen_context(OffscreenContext *ctx) { if (ctx) fbo_bind(ctx->fbo); @@ -30,7 +33,7 @@ bool save_framebuffer_common(OffscreenContext *ctx, std::ostream &output) { if (!ctx) return false; int samplesPerPixel = 4; // R, G, B and A - vector pixels(ctx->width * ctx->height * samplesPerPixel); + std::vector 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 @@ -56,7 +59,7 @@ 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) { - cerr << "Unable to init GLEW: " << glewGetErrorString(err) << "\n"; + std::cerr << "Unable to init GLEW: " << glewGetErrorString(err) << "\n"; return NULL; } //cerr << glew_dump(0); diff --git a/src/OffscreenContextCGL.mm b/src/OffscreenContextCGL.mm index ab3cc1b3..76c54182 100644 --- a/src/OffscreenContextCGL.mm +++ b/src/OffscreenContextCGL.mm @@ -21,7 +21,7 @@ struct OffscreenContext #include "OffscreenContextAll.hpp" -std::string offscreen_context_getinfo(OffscreenContext *ctx) +std::string offscreen_context_getinfo(OffscreenContext *) { std::stringstream out; @@ -83,7 +83,7 @@ OffscreenContext *create_offscreen_context(int w, int h) std::cerr << "Unable to init GLEW: " << glewGetErrorString(err) << std::endl; return NULL; } - glew_dump(); + glew_dump(false); ctx->fbo = fbo_new(); if (!fbo_init(ctx->fbo, w, h)) { @@ -108,28 +108,12 @@ bool teardown_offscreen_context(OffscreenContext *ctx) return true; } -/*! - 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()) { - 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; + if (!ctx) return false; // Read pixels from OpenGL int samplesPerPixel = 4; // R, G, B and A int rowBytes = samplesPerPixel * ctx->width; diff --git a/src/imageutils-macosx.cc b/src/imageutils-macosx.cc index e3a19836..4c7c446b 100644 --- a/src/imageutils-macosx.cc +++ b/src/imageutils-macosx.cc @@ -1,6 +1,5 @@ #include #include -#include #include "imageutils.h" #include @@ -15,13 +14,13 @@ size_t write_bytes_to_ostream (void *info,const void *buffer,size_t count) try { output->write( (const char *)buffer, count ); endpos = output->tellp(); - } catch (const std::ios_base::failure& e) + } catch (const std::ios_base::failure& e) { std::cerr << "Error writing to ostream:" << e.what() << "\n"; } return (endpos-startpos); } -CGDataConsumerRef dataconsumer CGDataConsumerCreateWithOstream(std::ostream &output) +CGDataConsumerRef CGDataConsumerCreateWithOstream(std::ostream &output) { dc_callbacks.putBytes = write_bytes_to_ostream; dc_callbacks.releaseConsumer = NULL; // ostream closed by caller of write_png