aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-29 05:22:50 +0000
committerDavid Robillard <d@drobilla.net>2012-04-29 05:22:50 +0000
commit48c439c06576092e1b3de89146c7f201a3f4453b (patch)
tree761b9ae14fadd9c95c62b45a4a391f5a5d8b8c37
parente756cdca27d1ce11ae4839ca571e43834a971670 (diff)
Support window closing on Windows.
-rw-r--r--pugl/pugl_win.cpp65
-rw-r--r--pugl/pugl_x11.c14
-rw-r--r--wscript2
3 files changed, 61 insertions, 20 deletions
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index 63c6051..5441409 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -14,11 +14,10 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <stdio.h>
-
#include <windows.h>
#include <windowsx.h>
-#include <gl/gl.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
#include "pugl_internal.h"
@@ -28,6 +27,23 @@ struct PuglPlatformDataImpl {
HGLRC hglrc;
};
+LRESULT CALLBACK
+wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message) {
+ case WM_CREATE:
+ PostMessage(hwnd, WM_SHOWWINDOW, TRUE, 0);
+ return 0;
+ case WM_CLOSE:
+ PostQuitMessage(0);
+ return 0;
+ case WM_DESTROY:
+ return 0;
+ default:
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+}
+
PuglWindow*
puglCreate(PuglNativeWindow parent,
const char* title,
@@ -43,7 +59,7 @@ puglCreate(PuglNativeWindow parent,
WNDCLASS wc;
wc.style = CS_OWNDC;
- wc.lpfnWndProc = DefWindowProc;
+ wc.lpfnWndProc = wndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = 0;
@@ -59,7 +75,6 @@ puglCreate(PuglNativeWindow parent,
0, 0, width, height,
(HWND)parent, NULL, NULL, NULL);
-
impl->hdc = GetDC(impl->hwnd);
PIXELFORMATDESCRIPTOR pfd;
@@ -95,14 +110,40 @@ puglDestroy(PuglWindow* win)
}
void
+puglReshape(PuglWindow* win, int width, int height)
+{
+ wglMakeCurrent(win->impl->hdc, win->impl->hglrc);
+
+ 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;
+}
+
+void
puglDisplay(PuglWindow* win)
{
- glViewport(0, 0, win->width, win->height);
+ wglMakeCurrent(win->impl->hdc, win->impl->hglrc);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
if (win->displayFunc) {
win->displayFunc(win);
}
+ glFlush();
SwapBuffers(win->impl->hdc);
win->redisplay = false;
}
@@ -124,18 +165,18 @@ puglProcessEvents(PuglWindow* win)
PAINTSTRUCT ps;
int button;
bool down = true;
- while (PeekMessage(&msg, win->impl->hwnd, 0, 0, PM_REMOVE)) {
+ while (PeekMessage(&msg, /*win->impl->hwnd*/0, 0, 0, PM_REMOVE)) {
switch (msg.message) {
+ case WM_CREATE:
+ case WM_SHOWWINDOW:
+ case WM_SIZE:
+ puglReshape(win, win->width, win->height);
+ break;
case WM_PAINT:
BeginPaint(win->impl->hwnd, &ps);
puglDisplay(win);
EndPaint(win->impl->hwnd, &ps);
break;
- case WM_SIZE:
- if (win->reshapeFunc) {
- win->reshapeFunc(win, LOWORD(msg.lParam), HIWORD(msg.lParam));
- }
- break;
case WM_MOUSEMOVE:
if (win->motionFunc) {
win->motionFunc(
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index 3634c68..d8685b2 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -214,13 +214,6 @@ puglProcessEvents(PuglWindow* win)
while (XPending(win->impl->display) > 0) {
XNextEvent(win->impl->display, &event);
switch (event.type) {
- case Expose:
- if (event.xexpose.count != 0) {
- break;
- }
- puglDisplay(win);
- win->redisplay = false;
- break;
case MapNotify:
puglReshape(win, win->width, win->height);
break;
@@ -232,6 +225,13 @@ puglProcessEvents(PuglWindow* win)
event.xconfigure.height);
}
break;
+ case Expose:
+ if (event.xexpose.count != 0) {
+ break;
+ }
+ puglDisplay(win);
+ win->redisplay = false;
+ break;
case MotionNotify:
if (win->motionFunc) {
win->motionFunc(win, event.xmotion.x, event.xmotion.y);
diff --git a/wscript b/wscript
index 9986250..a76cf00 100644
--- a/wscript
+++ b/wscript
@@ -81,7 +81,7 @@ def build(bld):
if Options.platform == 'win32':
lang = 'cxx'
lib_source = ['pugl/pugl_win.cpp']
- libs = ['opengl32', 'gdi32', 'user32']
+ libs = ['opengl32', 'glu32', 'gdi32', 'user32']
defines = []
else:
lang = 'c'