summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-29 04:12:50 +0000
committerDavid Robillard <d@drobilla.net>2012-04-29 04:12:50 +0000
commite756cdca27d1ce11ae4839ca571e43834a971670 (patch)
tree6331ae841ff2d0df44904d2c40e6b6f925fbb313
parent94b9e452ebd9438a917b825d8d01137ddaa9e398 (diff)
Implement reshape more properly.
It's not a GL demo if it's not a cube.
-rw-r--r--pugl/pugl_x11.c42
-rw-r--r--pugl_test.c44
-rw-r--r--wscript2
3 files changed, 71 insertions, 17 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:
diff --git a/pugl_test.c b/pugl_test.c
index c209aef..03afac0 100644
--- a/pugl_test.c
+++ b/pugl_test.c
@@ -43,16 +43,44 @@ onDisplay(PuglWindow* win)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
- glRotatef(xAngle, 1.0f, 0.0f, 0.0f);
+ glTranslatef(0.0f, 0.0f, -10.0f);
glRotatef(xAngle, 0.0f, 1.0f, 0.0f);
+ glRotatef(yAngle, 1.0f, 0.0f, 0.0f);
+
+ /* We tell we want to draw quads */
+ glBegin(GL_QUADS);
+
+ /* Every four calls to glVertex, a quad is drawn */
+ glColor3f(0, 0, 0); glVertex3f(-1, -1, -1);
+ glColor3f(0, 0, 1); glVertex3f(-1, -1, 1);
+ glColor3f(0, 1, 1); glVertex3f(-1, 1, 1);
+ glColor3f(0, 1, 0); glVertex3f(-1, 1, -1);
+
+ glColor3f(1, 0, 0); glVertex3f( 1, -1, -1);
+ glColor3f(1, 0, 1); glVertex3f( 1, -1, 1);
+ glColor3f(1, 1, 1); glVertex3f( 1, 1, 1);
+ glColor3f(1, 1, 0); glVertex3f( 1, 1, -1);
+
+ glColor3f(0, 0, 0); glVertex3f(-1, -1, -1);
+ glColor3f(0, 0, 1); glVertex3f(-1, -1, 1);
+ glColor3f(1, 0, 1); glVertex3f( 1, -1, 1);
+ glColor3f(1, 0, 0); glVertex3f( 1, -1, -1);
+
+ glColor3f(0, 1, 0); glVertex3f(-1, 1, -1);
+ glColor3f(0, 1, 1); glVertex3f(-1, 1, 1);
+ glColor3f(1, 1, 1); glVertex3f( 1, 1, 1);
+ glColor3f(1, 1, 0); glVertex3f( 1, 1, -1);
+
+ glColor3f(0, 0, 0); glVertex3f(-1, -1, -1);
+ glColor3f(0, 1, 0); glVertex3f(-1, 1, -1);
+ glColor3f(1, 1, 0); glVertex3f( 1, 1, -1);
+ glColor3f(1, 0, 0); glVertex3f( 1, -1, -1);
+
+ glColor3f(0, 0, 1); glVertex3f(-1, -1, 1);
+ glColor3f(0, 1, 1); glVertex3f(-1, 1, 1);
+ glColor3f(1, 1, 1); glVertex3f( 1, 1, 1);
+ glColor3f(1, 0, 1); glVertex3f( 1, -1, 1);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex3f(-1.0f, -1.0f, 0.0f);
- glColor3f(0.0f, 0.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
}
diff --git a/wscript b/wscript
index 6643408..9986250 100644
--- a/wscript
+++ b/wscript
@@ -86,7 +86,7 @@ def build(bld):
else:
lang = 'c'
lib_source = ['pugl/pugl_x11.c']
- libs = ['X11', 'GL']
+ libs = ['X11', 'GL', 'GLU']
defines = []
if bld.env['MSVC_COMPILER']:
libflags = []