summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2014-12-20 07:19:23 +0000
committerManolo Gouy <Manolo>2014-12-20 07:19:23 +0000
commitf3a84c0ee5f88fe664d759106724f786c706f817 (patch)
tree3541953164e2d24c31ae46ef11f2c2e86b3873a3 /FL
parenta7dc3ea9e24399f318a9478fbcffe04ff2870de6 (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 'FL')
-rw-r--r--FL/Fl.H13
-rw-r--r--FL/Fl_Gl_Window.H23
-rw-r--r--FL/mac.H9
3 files changed, 42 insertions, 3 deletions
diff --git a/FL/Fl.H b/FL/Fl.H
index cc223dba8..259e14371 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -125,6 +125,9 @@ typedef void (*Fl_Clipboard_Notify_Handler)(int source, void *data);
class FL_EXPORT Fl {
Fl() {}; // no constructor!
+private:
+ static int use_high_res_GL_;
+
public: // should be private!
#ifndef FL_DOXYGEN
static int e_number;
@@ -1206,6 +1209,16 @@ public:
static void release_widget_pointer(Fl_Widget *&w);
static void clear_widget_pointer(Fl_Widget const *w);
/** @} */
+
+ /** sets whether GL windows should be drawn at high resolution on Apple
+ computers with retina displays
+ */
+ static void use_high_res_GL(int val) { use_high_res_GL_ = val; }
+ /** returns whether GL windows should be drawn at high resolution on Apple
+ computers with retina displays.
+ Default is no.
+ */
+ static int use_high_res_GL() { return use_high_res_GL_; }
#ifdef FLTK_HAVE_CAIRO
/** \defgroup group_cairo Cairo support functions and classes
diff --git a/FL/Fl_Gl_Window.H b/FL/Fl_Gl_Window.H
index 47fe04939..7bec39877 100644
--- a/FL/Fl_Gl_Window.H
+++ b/FL/Fl_Gl_Window.H
@@ -89,7 +89,7 @@ public:
\code
void mywindow::draw() {
if (!valid()) {
- glViewport(0,0,w(),h());
+ glViewport(0,0,pixel_w(),pixel_h());
glFrustum(...);
...other initialization...
}
@@ -168,7 +168,8 @@ public:
int mode(int a) {return mode(a,0);}
/** See Fl_Mode mode() const */
int mode(const int *a) {return mode(0, a);}
- /** void See void context(void* v, int destroy_flag) */
+ /** Returns a pointer to the GLContext that this window is using.
+ \see void context(void* v, int destroy_flag) */
void* context() const {return context_;}
void context(void*, int destroy_flag = 0);
void make_current();
@@ -201,6 +202,24 @@ public:
// Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
virtual Fl_Gl_Window* as_gl_window() {return this;}
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+ int pixel_w();
+ int pixel_h();
+#else
+ /** Gives the window width in OpenGL pixels.
+ Generally identical with the result of the w() function, but on macintosh computers
+ with a 'retina' display, and if Fl::use_high_res_GL(bool) is set to true,
+ pixel_w() returns 2 * w().
+ */
+ int pixel_w() { return w(); }
+ /** Gives the window height in OpenGL pixels.
+ Generally identical with the result of the h() function, but on macintosh computers
+ with a 'retina' display, and if Fl::use_high_res_GL(bool) is set to true,
+ pixel_h() returns 2 * h().
+ */
+ int pixel_h() { return h(); }
+#endif
+
~Fl_Gl_Window();
/**
Creates a new Fl_Gl_Window widget using the given size, and label string.
diff --git a/FL/mac.H b/FL/mac.H
index 85e40c12b..df234710f 100644
--- a/FL/mac.H
+++ b/FL/mac.H
@@ -74,8 +74,10 @@ typedef CGContextRef Fl_Offscreen;
#ifdef __OBJC__
@class NSCursor;
+@class NSOpenGLPixelFormat;
#else
class NSCursor;
+class NSOpenGLPixelFormat;
#endif // __OBJC__
typedef CGContextRef Fl_Offscreen;
@@ -151,6 +153,8 @@ public:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
bool mapped_to_retina(); // is window mapped to retina display?
void mapped_to_retina(bool); // sets whether window is mapped to retina display
+ bool changed_resolution(); // did window just moved to display with another resolution?
+ void changed_resolution(bool);// sets whether window just moved to display with another resolution
#endif
// Quartz additions:
CGContextRef gc; // graphics context (NULL when using QD)
@@ -160,6 +164,8 @@ public:
static void q_begin_image(CGRect&, int x, int y, int w, int h);
static void q_end_image();
// Cocoa additions
+ static int resolution_scaling_factor(Fl_Window*);
+ static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // computes NSOpenGLPixelFormat from Gl window's mode
void destroy(void);
void map(void);
void unmap(void);
@@ -183,7 +189,8 @@ public:
private:
#if FLTK_ABI_VERSION >= 10304
CGRect* subRect_; // makes sure subwindow remains inside its parent window
- unsigned mapped_to_retina_; // stores whether window is mapped to retina display
+ // stores 2 binary flags: whether window is mapped to retina display; whether resolution just changed
+ unsigned mapped_to_retina_;
#else
bool subwindow; // for ABI compatibility, useless with true subwindows
#endif