diff options
author | David Robillard <d@drobilla.net> | 2012-04-29 04:12:50 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-04-29 04:12:50 +0000 |
commit | e756cdca27d1ce11ae4839ca571e43834a971670 (patch) | |
tree | 6331ae841ff2d0df44904d2c40e6b6f925fbb313 /pugl/pugl_x11.c | |
parent | 94b9e452ebd9438a917b825d8d01137ddaa9e398 (diff) | |
download | pugl-e756cdca27d1ce11ae4839ca571e43834a971670.tar.gz pugl-e756cdca27d1ce11ae4839ca571e43834a971670.tar.bz2 pugl-e756cdca27d1ce11ae4839ca571e43834a971670.zip |
Implement reshape more properly.
It's not a GL demo if it's not a cube.
Diffstat (limited to 'pugl/pugl_x11.c')
-rw-r--r-- | pugl/pugl_x11.c | 42 |
1 files changed, 34 insertions, 8 deletions
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 <string.h> #include <GL/gl.h> +#include <GL/glu.h> #include <GL/glx.h> #include <X11/Xatom.h> #include <X11/Xlib.h> @@ -164,15 +165,41 @@ puglDestroy(PuglWindow* 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: |