From e756cdca27d1ce11ae4839ca571e43834a971670 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 29 Apr 2012 04:12:50 +0000 Subject: Implement reshape more properly. It's not a GL demo if it's not a cube. --- pugl/pugl_x11.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index f85e18b..3634c68 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -163,16 +164,42 @@ puglDestroy(PuglWindow* win) free(win); } +void +puglReshape(PuglWindow* win, int width, int height) +{ + glXMakeCurrent(win->impl->display, win->impl->win, win->impl->ctx); + + if (win->reshapeFunc) { + // User provided a reshape function, defer to that + win->reshapeFunc(win, width, height); + } else { + // No custom reshape function, do something reasonable + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0f, win->width/(float)win->height, 1.0f, 10.0f); + glViewport(0, 0, win->width, win->height); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + } + + win->width = width; + win->height = height; + win->redisplay = true; +} + void puglDisplay(PuglWindow* win) { glXMakeCurrent(win->impl->display, win->impl->win, win->impl->ctx); - glViewport(0, 0, win->width, win->height); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); if (win->displayFunc) { win->displayFunc(win); } + glFlush(); if (win->impl->doubleBuffered) { glXSwapBuffers(win->impl->display, win->impl->win); } @@ -194,16 +221,15 @@ puglProcessEvents(PuglWindow* win) puglDisplay(win); win->redisplay = false; break; + case MapNotify: + puglReshape(win, win->width, win->height); + break; case ConfigureNotify: if ((event.xconfigure.width != win->width) || (event.xconfigure.height != win->height)) { - if (win->reshapeFunc) { - win->reshapeFunc(win, - event.xconfigure.width, - event.xconfigure.height); - } - win->width = event.xconfigure.width; - win->height = event.xconfigure.height; + puglReshape(win, + event.xconfigure.width, + event.xconfigure.height); } break; case MotionNotify: -- cgit v1.2.1