aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pugl_shader_demo.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-11 18:05:26 +0100
committerDavid Robillard <d@drobilla.net>2020-12-11 18:05:26 +0100
commitf829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7 (patch)
tree14e963b9feac2b3135eb1f800e716abbd08e0581 /examples/pugl_shader_demo.c
parent07c8253c2621daab8a08713aae557ae1fdea5df0 (diff)
downloadpugl-f829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7.tar.gz
pugl-f829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7.tar.bz2
pugl-f829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7.zip
Make demo programs work from any directory, and install them
Diffstat (limited to 'examples/pugl_shader_demo.c')
-rw-r--r--examples/pugl_shader_demo.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c
index 800b8f0..8ebbe60 100644
--- a/examples/pugl_shader_demo.c
+++ b/examples/pugl_shader_demo.c
@@ -35,6 +35,7 @@
*/
#include "demo_utils.h"
+#include "file_utils.h"
#include "rects.h"
#include "shader_utils.h"
#include "test/test_utils.h"
@@ -62,6 +63,7 @@ typedef struct
typedef struct
{
+ const char* programPath;
PuglWorld* world;
PuglView* view;
PuglTestOptions opts;
@@ -203,14 +205,18 @@ makeRects(const size_t numRects)
}
static char*
-loadShader(const char* const path)
+loadShader(const char* const programPath, const char* const name)
{
+ char* const path = resourcePath(programPath, name);
+ fprintf(stderr, "Loading shader %s\n", path);
+
FILE* const file = fopen(path, "r");
if (!file) {
logError("Failed to open '%s'\n", path);
return NULL;
}
+ free(path);
fseek(file, 0, SEEK_END);
const size_t fileSize = (size_t)ftell(file);
@@ -303,9 +309,14 @@ setupGl(PuglTestApp* app)
: "shaders/header_420.glsl");
// Load shader sources
- char* const headerSource = loadShader(headerFile);
- char* const vertexSource = loadShader("shaders/rect.vert");
- char* const fragmentSource = loadShader("shaders/rect.frag");
+ char* const headerSource = loadShader(app->programPath, headerFile);
+
+ char* const vertexSource = loadShader(app->programPath,
+ "shaders/rect.vert");
+
+ char* const fragmentSource = loadShader(app->programPath,
+ "shaders/rect.frag");
+
if (!vertexSource || !fragmentSource) {
logError("Failed to load shader sources\n");
return PUGL_FAILURE;
@@ -405,6 +416,7 @@ main(int argc, char** argv)
{
PuglTestApp app = {0};
+ app.programPath = argv[0];
app.glMajorVersion = 3;
app.glMinorVersion = 3;