Mac OS X build fixes

felipesanches-svg
Marius Kintel 2013-01-28 14:56:17 -05:00
parent 5eed194f15
commit 256eb2c2f2
4 changed files with 12 additions and 26 deletions

View File

@ -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

View File

@ -1,6 +1,9 @@
// Functions shared by OffscreenContext[platform].cc
// #include this directly after definition of struct OffscreenContext.
#include <vector>
#include <ostream>
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<GLubyte> pixels(ctx->width * ctx->height * samplesPerPixel);
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
@ -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);

View File

@ -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;

View File

@ -1,6 +1,5 @@
#include <ApplicationServices/ApplicationServices.h>
#include <iostream>
#include <CGDataConsumer.h>
#include "imageutils.h"
#include <assert.h>
@ -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