mirror of
https://github.com/fltk/fltk.git
synced 2026-06-04 23:42:15 +08:00
Resizing of OpenGL subwindows was broken on OSX (STR #804)
Added a FPS indicator to the fractals demo for testing purposes. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4342 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -2,6 +2,7 @@ CHANGES IN FLTK 1.1.7
|
|||||||
|
|
||||||
- Documentation fixes (STR #648, STR #692, STR #730, STR
|
- Documentation fixes (STR #648, STR #692, STR #730, STR
|
||||||
#744, STR #745)
|
#744, STR #745)
|
||||||
|
- Resizing of OpenGL subwindows was broken on OSX (STR #804)
|
||||||
- The fltk-config script now supports running from a
|
- The fltk-config script now supports running from a
|
||||||
source directory (STR #840)
|
source directory (STR #840)
|
||||||
- Fl_Browser_ didn't update the position properly when an
|
- Fl_Browser_ didn't update the position properly when an
|
||||||
|
|||||||
+30
-58
@@ -137,27 +137,30 @@ void Fl_Gl_Window::make_current() {
|
|||||||
mode_ &= ~NON_LOCAL_CONTEXT;
|
mode_ &= ~NON_LOCAL_CONTEXT;
|
||||||
context_ = fl_create_gl_context(this, g);
|
context_ = fl_create_gl_context(this, g);
|
||||||
valid(0);
|
valid(0);
|
||||||
|
|
||||||
//#ifdef __APPLE__
|
|
||||||
// GLint xywh[4];
|
|
||||||
//
|
|
||||||
// if (parent() && parent()->window()) {
|
|
||||||
// xywh[0] = x();
|
|
||||||
// xywh[1] = parent()->window()->h() - y() - h();
|
|
||||||
// } else {
|
|
||||||
// xywh[0] = 0;
|
|
||||||
// xywh[1] = 0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// xywh[2] = w();
|
|
||||||
// xywh[3] = h();
|
|
||||||
// aglSetInteger(context_, AGL_BUFFER_RECT, xywh);
|
|
||||||
// printf("make_current: xywh=[%d %d %d %d]\n", xywh[0], xywh[1], xywh[2], xywh[3]);
|
|
||||||
//
|
|
||||||
// aglUpdateContext(context_);
|
|
||||||
//#endif // __APPLE__
|
|
||||||
}
|
}
|
||||||
fl_set_gl_context(this, context_);
|
fl_set_gl_context(this, context_);
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Set the buffer rectangle here, since in resize() we won't have the
|
||||||
|
// correct parent window size to work with...
|
||||||
|
GLint xywh[4];
|
||||||
|
|
||||||
|
if (window()) {
|
||||||
|
xywh[0] = x();
|
||||||
|
xywh[1] = window()->h() - y() - h();
|
||||||
|
} else {
|
||||||
|
xywh[0] = 0;
|
||||||
|
xywh[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
xywh[2] = w();
|
||||||
|
xywh[3] = h();
|
||||||
|
|
||||||
|
aglEnable(context_, AGL_BUFFER_RECT);
|
||||||
|
aglSetInteger(context_, AGL_BUFFER_RECT, xywh);
|
||||||
|
// printf("make_current: xywh=[%d %d %d %d]\n", xywh[0], xywh[1], xywh[2], xywh[3]);
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
#if defined(WIN32) && USE_COLORMAP
|
#if defined(WIN32) && USE_COLORMAP
|
||||||
if (fl_palette) {
|
if (fl_palette) {
|
||||||
fl_GetDC(fl_xid(this));
|
fl_GetDC(fl_xid(this));
|
||||||
@@ -358,49 +361,18 @@ void Fl_Gl_Window::flush() {
|
|||||||
|
|
||||||
void Fl_Gl_Window::resize(int X,int Y,int W,int H) {
|
void Fl_Gl_Window::resize(int X,int Y,int W,int H) {
|
||||||
// printf("Fl_Gl_Window::resize(X=%d, Y=%d, W=%d, H=%d)\n", X, Y, W, H);
|
// printf("Fl_Gl_Window::resize(X=%d, Y=%d, W=%d, H=%d)\n", X, Y, W, H);
|
||||||
if (W != w() || H != h()) {
|
// printf("current: x()=%d, y()=%d, w()=%d, h()=%d\n", x(), y(), w(), h());
|
||||||
valid(0);
|
|
||||||
#ifdef __APPLE_QD__
|
|
||||||
GLint xywh[4];
|
|
||||||
|
|
||||||
if (window()) {
|
if (W != w() || H != h()) valid(0);
|
||||||
// MRS: This isn't quite right, but the parent window won't have its W and H updated yet...
|
|
||||||
xywh[0] = x();
|
|
||||||
xywh[1] = window()->h() - y() - h();
|
|
||||||
} else {
|
|
||||||
xywh[0] = 0;
|
|
||||||
xywh[1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
xywh[2] = W;
|
#ifdef __APPLE__
|
||||||
xywh[3] = H;
|
if (X != x() || Y != y() || W != w() || H != h()) aglUpdateContext(context_);
|
||||||
aglSetInteger(context_, AGL_BUFFER_RECT, xywh);
|
|
||||||
// printf("resize: xywh=[%d %d %d %d]\n", xywh[0], xywh[1], xywh[2], xywh[3]);
|
|
||||||
|
|
||||||
aglUpdateContext(context_);
|
|
||||||
#elif defined(__APPLE_QUARTZ__)
|
|
||||||
GLint xywh[4];
|
|
||||||
|
|
||||||
if (window()) {
|
|
||||||
// MRS: This isn't quite right, but the parent window won't have its W and H updated yet...
|
|
||||||
xywh[0] = x();
|
|
||||||
xywh[1] = window()->h() - y() - h();
|
|
||||||
} else {
|
|
||||||
xywh[0] = 0;
|
|
||||||
xywh[1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
xywh[2] = W;
|
|
||||||
xywh[3] = H;
|
|
||||||
aglSetInteger(context_, AGL_BUFFER_RECT, xywh);
|
|
||||||
// printf("resize: xywh=[%d %d %d %d]\n", xywh[0], xywh[1], xywh[2], xywh[3]);
|
|
||||||
|
|
||||||
aglUpdateContext(context_);
|
|
||||||
#elif !defined(WIN32)
|
#elif !defined(WIN32)
|
||||||
if (!resizable() && overlay && overlay != this)
|
if ((W != w() || H != h()) && !resizable() && overlay && overlay != this) {
|
||||||
((Fl_Gl_Window*)overlay)->resize(0,0,W,H);
|
((Fl_Gl_Window*)overlay)->resize(0,0,W,H);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Fl_Window::resize(X,Y,W,H);
|
Fl_Window::resize(X,Y,W,H);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-9
@@ -612,25 +612,30 @@ void myGLInit(void)
|
|||||||
/************************ GLUT STUFF ***************************/
|
/************************ GLUT STUFF ***************************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
|
int winwidth = 1;
|
||||||
|
int winheight = 1;
|
||||||
|
|
||||||
void reshape(int w, int h)
|
void reshape(int w, int h)
|
||||||
{
|
{
|
||||||
glViewport(0,0,w,h);
|
glViewport(0,0,w,h);
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glLoadIdentity();
|
winwidth = w;
|
||||||
gluPerspective(60.0, (GLdouble)w/h, 0.01, 100);
|
winheight = h;
|
||||||
glPushMatrix();
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glFlush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(void)
|
void display(void)
|
||||||
{
|
{
|
||||||
|
time_t curtime;
|
||||||
|
char buf[255];
|
||||||
|
static time_t fpstime = 0;
|
||||||
|
static int fpscount = 0;
|
||||||
|
static int fps = 0;
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glLoadIdentity();
|
||||||
glPushMatrix(); /* clear of last viewing xform, leaving perspective */
|
gluPerspective(60.0, (GLdouble)winwidth/winheight, 0.01, 100);
|
||||||
|
|
||||||
agvViewTransform();
|
agvViewTransform();
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@@ -646,12 +651,31 @@ void display(void)
|
|||||||
if (DrawAxes)
|
if (DrawAxes)
|
||||||
glCallList(AXES);
|
glCallList(AXES);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
gluOrtho2D(0.0, winwidth, 0.0, winheight);
|
||||||
|
|
||||||
|
sprintf(buf, "FPS=%d", fps);
|
||||||
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
|
gl_font(FL_HELVETICA, 12);
|
||||||
|
gl_draw(buf, 10, 10);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use glFinish() instead of glFlush() to avoid getting many frames
|
// Use glFinish() instead of glFlush() to avoid getting many frames
|
||||||
// ahead of the display (problem with some Linux OpenGL implementations...)
|
// ahead of the display (problem with some Linux OpenGL implementations...)
|
||||||
//
|
//
|
||||||
|
|
||||||
glFinish();
|
glFinish();
|
||||||
|
|
||||||
|
// Update frames-per-second
|
||||||
|
fpscount ++;
|
||||||
|
curtime = time(NULL);
|
||||||
|
if ((curtime - fpstime) >= 2)
|
||||||
|
{
|
||||||
|
fps = (fps + fpscount / (curtime - fpstime)) / 2;
|
||||||
|
fpstime = curtime;
|
||||||
|
fpscount = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void visible(int v)
|
void visible(int v)
|
||||||
|
|||||||
Reference in New Issue
Block a user