From f027f3810baaa93bd4b8273b774421053e8e1cac Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 2 May 2012 20:49:13 +0000 Subject: Remove GLU dependency. Fix compilation errors on X11. Make default resize function set up a 2D view. Set appropriate reshape callback in pugl_test. --- pugl/pugl.h | 2 -- pugl/pugl_internal.h | 12 ++++++++++++ pugl/pugl_osx.m | 15 +++------------ pugl/pugl_win.cpp | 15 +++------------ pugl/pugl_x11.c | 26 ++++++++------------------ pugl_test.c | 20 ++++++++++++++++++++ 6 files changed, 46 insertions(+), 44 deletions(-) diff --git a/pugl/pugl.h b/pugl/pugl.h index 7512aa1..4a8a599 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -30,13 +30,11 @@ */ #ifdef __APPLE__ # include "OpenGL/gl.h" -# include "OpenGL/glu.h" #else # ifdef _WIN32 # include /* Broken Windows GL headers require this */ # endif # include "GL/gl.h" -# include "GL/glu.h" #endif #ifdef PUGL_SHARED diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 5235db3..981c0fb 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -64,6 +64,18 @@ puglGetModifiers(PuglView* view) return view->mods; } +void +puglDefaultReshape(PuglView* view, int width, int height) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, height, 0, 0, 1); + glViewport(0, 0, width, height); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + void puglIgnoreKeyRepeat(PuglView* view, bool ignore) { diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 3c5425e..2f4a0e9 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -93,22 +93,13 @@ int height = bounds.size.height; if (view->reshapeFunc) { - // User provided a reshape function, defer to that view->reshapeFunc(view, width, height); } else { - // No custom reshape function, do something reasonable - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45.0f, width/(float)height, 1.0f, 10.0f); - glViewport(0, 0, width, height); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + puglDefaultReshape(view, width, height); } - view->width = width; - view->height = height; - view->redisplay = true; + view->width = width; + view->height = height; } - (void) drawRect:(NSRect)rect diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp index 3128daf..cc69036 100644 --- a/pugl/pugl_win.cpp +++ b/pugl/pugl_win.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include "pugl_internal.h" @@ -123,21 +122,13 @@ puglReshape(PuglView* view, int width, int height) wglMakeCurrent(view->impl->hdc, view->impl->hglrc); if (view->reshapeFunc) { - // User provided a reshape function, defer to that view->reshapeFunc(view, width, height); } else { - // No custom reshape function, do something reasonable - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45.0f, view->width/(float)view->height, 1.0f, 10.0f); - glViewport(0, 0, view->width, view->height); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + puglDefaultReshape(view, width, height); } - view->width = width; - view->height = height; + view->width = width; + view->height = height; } void diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 755dd87..d80b71b 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -174,22 +173,13 @@ puglReshape(PuglView* view, int width, int height) glXMakeCurrent(view->impl->display, view->impl->win, view->impl->ctx); if (view->reshapeFunc) { - // User provided a reshape function, defer to that view->reshapeFunc(view, width, height); } else { - // No custom reshape function, do something reasonable - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45.0f, width/(float)height, 1.0f, 10.0f); - glViewport(0, 0, width, height); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + puglDefaultReshape(view, width, height); } - view->width = width; - view->height = height; - view->redisplay = true; + view->width = width; + view->height = height; } void @@ -310,11 +300,11 @@ puglProcessEvents(PuglView* view) if (view->mouseFunc && (event.xbutton.button < 4 || event.xbutton.button > 7)) { view->mouseFunc(view, - event.xbutton.button, event.type == ButtonPress, - event.xbutton.x, event.xbutton.y); + event.xbutton.button, event.type == ButtonPress, + event.xbutton.x, event.xbutton.y); } break; - case KeyPress: + case KeyPress: { setModifiers(view, event.xkey.state); KeySym sym; char str[5]; @@ -329,7 +319,7 @@ puglProcessEvents(PuglView* view) } else if (view->specialFunc) { view->specialFunc(view, true, key); } - break; + } break; case KeyRelease: { setModifiers(view, event.xkey.state); bool repeated = false; @@ -355,7 +345,7 @@ puglProcessEvents(PuglView* view) view->specialFunc(view, false, special); } } - } + } break; case ClientMessage: if (!strcmp(XGetAtomName(view->impl->display, event.xclient.message_type), diff --git a/pugl_test.c b/pugl_test.c index 6eeed1a..8338d51 100644 --- a/pugl_test.c +++ b/pugl_test.c @@ -23,11 +23,30 @@ #include "pugl/pugl.h" +// Argh! +#ifdef __APPLE__ +# include +#else +# include +#endif + static int quit = 0; static float xAngle = 0.0f; static float yAngle = 0.0f; static float dist = 10.0f; +static void +onReshape(PuglView* view, int width, int height) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glViewport(0, 0, width, height); + gluPerspective(45.0f, width/(float)height, 1.0f, 10.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + static void onDisplay(PuglView* view) { @@ -162,6 +181,7 @@ main(int argc, char** argv) puglSetScrollFunc(view, onScroll); puglSetSpecialFunc(view, onSpecial); puglSetDisplayFunc(view, onDisplay); + puglSetReshapeFunc(view, onReshape); puglSetCloseFunc(view, onClose); while (!quit) { -- cgit v1.2.3