[cogl/cogl-latest-win: 7/27] cogl-crate.c: Add fallback for data search on Windows
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/cogl-latest-win: 7/27] cogl-crate.c: Add fallback for data search on Windows
- Date: Mon, 18 Oct 2021 10:53:46 +0000 (UTC)
commit 531a89aafd2a10fc88c9e3e7af0d9eb42a0d349c
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Oct 18 18:19:35 2021 +0800
cogl-crate.c: Add fallback for data search on Windows
Things on Windows tend to be relocatable, so if cogl-crate failed to
find crate.jpg with the hard-coded path on Windows, try again using a
dynamically-constructed path.
examples/cogl-crate.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/examples/cogl-crate.c b/examples/cogl-crate.c
index 7b5256f0..0c70cd3d 100644
--- a/examples/cogl-crate.c
+++ b/examples/cogl-crate.c
@@ -152,6 +152,8 @@ main (int argc, char **argv)
PangoRectangle hello_label_size;
float fovy, aspect, z_near, z_2d, z_far;
CoglDepthState depth_state;
+ const char *data_filename = "crate.jpg";
+ char *datapath;
ctx = cogl_context_new (NULL, &error);
if (!ctx) {
@@ -219,11 +221,35 @@ main (int argc, char **argv)
6 * 6);
/* Load a jpeg crate texture from a file */
- printf ("crate.jpg (CC by-nc-nd http://bit.ly/9kP45T) ShadowRunner27 http://bit.ly/m1YXLh\n");
+ printf ("%s (CC by-nc-nd http://bit.ly/9kP45T) ShadowRunner27 http://bit.ly/m1YXLh\n", data_filename);
+
+ datapath = g_build_filename (COGL_EXAMPLES_DATA, data_filename, NULL);
+
data.texture =
cogl_texture_2d_new_from_file (ctx,
- COGL_EXAMPLES_DATA "crate.jpg",
+ datapath,
&error);
+
+ g_free (datapath);
+
+#ifdef G_OS_WIN32
+ /* Windows: try again from the dynamically-constructed path if needed */
+ if (!data.texture)
+ {
+ char *prefix = g_win32_get_package_installation_directory_of_module (NULL);
+ datapath = g_build_filename (prefix, "share", "cogl", "examples-data", data_filename, NULL);
+
+ g_clear_error (&error);
+
+ data.texture =
+ cogl_texture_2d_new_from_file (ctx,
+ datapath,
+ &error);
+ g_free (datapath);
+ g_free (prefix);
+ }
+#endif
+
if (!data.texture)
g_error ("Failed to load texture: %s", error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]