diff options
| author | Manolo Gouy <Manolo> | 2014-12-20 07:19:23 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2014-12-20 07:19:23 +0000 |
| commit | f3a84c0ee5f88fe664d759106724f786c706f817 (patch) | |
| tree | 3541953164e2d24c31ae46ef11f2c2e86b3873a3 /src/Fl_Gl_Device_Plugin.cxx | |
| parent | a7dc3ea9e24399f318a9478fbcffe04ff2870de6 (diff) | |
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx
where string drawing wrongly claimed to support @symbol, not possible
because symbols are drawn using non-GL primitives.
Unchanged application code can use the new FLTK code.
In addition, the new code allows mac applications to draw OpenGL scenes
at high resolution on so-called 'retina' displays, but this requires some
support from app code. They must call, before opening GL windows,
Fl::use_high_resolution(1);
and change their glViewport() calls as follows
glViewport(0, 0, pxel_w(), pixel_h());
This uses 2 new member functions of the Fl_Gl_Window class,
pixel_w() and pixel_h() returning the window dimensions in pixel
units, that is, twice the w() and h() when the window is mapped
on a retina display.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Gl_Device_Plugin.cxx')
| -rw-r--r-- | src/Fl_Gl_Device_Plugin.cxx | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx index ed2889dbe..7475deb60 100644 --- a/src/Fl_Gl_Device_Plugin.cxx +++ b/src/Fl_Gl_Device_Plugin.cxx @@ -53,10 +53,13 @@ static Fl_RGB_Image* capture_gl_rectangle(Fl_Gl_Window *glw, int x, int y, int w { #if defined(__APPLE__) const int bytesperpixel = 4; + if (Fl_X::resolution_scaling_factor(glw) > 1) { + w = 2*w; h = 2*h; x = 2*x; y = 2*y; + } #else const int bytesperpixel = 3; #endif - glw->flush(); // forces a GL redraw necessary for the glpuzzle demo + glw->flush(); // forces a GL redraw, necessary for the glpuzzle demo // Read OpenGL context pixels directly. // For extra safety, save & restore OpenGL states that are changed glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); @@ -68,7 +71,7 @@ static Fl_RGB_Image* capture_gl_rectangle(Fl_Gl_Window *glw, int x, int y, int w int mByteWidth = w * bytesperpixel; mByteWidth = (mByteWidth + 3) & ~3; // Align to 4 bytes uchar *baseAddress = new uchar[mByteWidth * h]; - glReadPixels(x, glw->h() - (y+h), w, h, + glReadPixels(x, glw->pixel_h() - (y+h), w, h, #if defined(__APPLE__) GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, #else @@ -85,6 +88,11 @@ static Fl_RGB_Image* capture_gl_rectangle(Fl_Gl_Window *glw, int x, int y, int w return img; } +static void imgProviderReleaseData (void *info, const void *data, size_t size) +{ + delete (Fl_RGB_Image *)info; +} + /** This class will make sure that OpenGL printing/screen capture is available if fltk_gl was linked to the program @@ -97,7 +105,27 @@ public: Fl_Gl_Window *glw = w->as_gl_window(); if (!glw) return 0; Fl_RGB_Image *img = capture_gl_rectangle(glw, 0, 0, glw->w(), glw->h()); - fl_draw_image(img->array + (glw->h() - 1) * img->ld(), x, y , glw->w(), glw->h(), 3, - img->ld()); +#ifdef __APPLE__ + if (Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) { + // convert the image to CGImage, and draw it at full res (useful on retina display) + CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef provider = CGDataProviderCreateWithData(img, img->array, img->ld() * img->h(), imgProviderReleaseData); + CGImageRef cgimg = CGImageCreate(img->w(), img->h(), 8, 24, img->ld(), cSpace, + (CGBitmapInfo)(kCGImageAlphaNone), + provider, NULL, false, kCGRenderingIntentDefault); + CGColorSpaceRelease(cSpace); + CGDataProviderRelease(provider); + CGContextDrawImage(fl_gc, CGRectMake(0, 0, glw->w(), glw->h()), cgimg); + CFRelease(cgimg); + return 1; + } else if (img->w() > glw->w()) { + Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(glw->w(), glw->h()); + delete img; + img = img2; + } +#endif + int ld = img->ld() ? img->ld() : img->w() * img->d(); + fl_draw_image(img->array + (img->h() - 1) * ld, x, y , img->w(), img->h(), 3, - ld); delete img; return 1; } |
