aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pugl/pugl.h2
-rw-r--r--pugl/pugl_internal.h12
-rw-r--r--pugl/pugl_osx.m15
-rw-r--r--pugl/pugl_win.cpp15
-rw-r--r--pugl/pugl_x11.c26
-rw-r--r--pugl_test.c20
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 <windows.h> /* 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
@@ -65,6 +65,18 @@ puglGetModifiers(PuglView* view)
}
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)
{
view->ignoreKeyRepeat = 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 <windows.h>
#include <windowsx.h>
#include <GL/gl.h>
-#include <GL/glu.h>
#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 <string.h>
#include <GL/gl.h>
-#include <GL/glu.h>
#include <GL/glx.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
@@ -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,12 +23,31 @@
#include "pugl/pugl.h"
+// Argh!
+#ifdef __APPLE__
+# include <OpenGL/glu.h>
+#else
+# include <GL/glu.h>
+#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)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -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) {