aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pugl_gl3_demo.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-09 21:50:02 +0100
committerDavid Robillard <d@drobilla.net>2020-03-09 22:17:44 +0100
commit7099dc568ccbe206ceb6f861263f49adc8e4aef3 (patch)
tree8dc5c77aab8e38103e1e4c55964ab319edeb529b /examples/pugl_gl3_demo.c
parentdd903f46e74d4a5a99eb7d34a9d2f9ba34e8b706 (diff)
downloadpugl-7099dc568ccbe206ceb6f861263f49adc8e4aef3.tar.gz
pugl-7099dc568ccbe206ceb6f861263f49adc8e4aef3.tar.bz2
pugl-7099dc568ccbe206ceb6f861263f49adc8e4aef3.zip
GL3 Demo: Set up and tear down GL on PUGL_CREATE and PUGL_DESTROY
This eliminates the use of puglEnterContext().
Diffstat (limited to 'examples/pugl_gl3_demo.c')
-rw-r--r--examples/pugl_gl3_demo.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/examples/pugl_gl3_demo.c b/examples/pugl_gl3_demo.c
index c999e5a..a18c902 100644
--- a/examples/pugl_gl3_demo.c
+++ b/examples/pugl_gl3_demo.c
@@ -90,6 +90,12 @@ typedef struct
int quit;
} PuglTestApp;
+static PuglStatus
+setupGl(PuglTestApp* app);
+
+static void
+teardownGl(PuglTestApp* app);
+
static void
onConfigure(PuglView* view, double width, double height)
{
@@ -164,6 +170,12 @@ onEvent(PuglView* view, const PuglEvent* event)
printEvent(event, "Event: ", app->opts.verbose);
switch (event->type) {
+ case PUGL_CREATE:
+ setupGl(app);
+ break;
+ case PUGL_DESTROY:
+ teardownGl(app);
+ break;
case PUGL_CONFIGURE:
onConfigure(view, event->configure.width, event->configure.height);
break;
@@ -389,24 +401,13 @@ main(int argc, char** argv)
// Create and configure world and view
setupPugl(&app, frame);
- // Create window
+ // Create window (which will send a PUGL_CREATE event)
const PuglStatus st = puglCreateWindow(app.view, "Pugl OpenGL 3");
if (st) {
return logError("Failed to create window (%s)\n", puglStrerror(st));
}
- // Enter context to set up GL stuff
- puglEnterContext(app.view, false);
-
- // Set up OpenGL
- if (setupGl(&app)) {
- puglFreeView(app.view);
- puglFreeWorld(app.world);
- return 1;
- }
-
- // Finally ready to go, leave GL context and show the window
- puglLeaveContext(app.view, false);
+ // Show window
puglShowWindow(app.view);
// Grind away, drawing continuously
@@ -417,13 +418,10 @@ main(int argc, char** argv)
puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn);
}
- // Delete GL stuff
- puglEnterContext(app.view, false);
- teardownGl(&app);
- puglLeaveContext(app.view, false);
-
- // Tear down view and world
+ // Destroy window (which will send a PUGL_DESTROY event)
puglFreeView(app.view);
+
+ // Free everything else
puglFreeWorld(app.world);
free(app.rects);