[cogl/cogl-latest-win: 1/21] 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: 1/21] cogl-crate.c: Add fallback for data search on Windows
- Date: Tue, 19 Oct 2021 07:35:04 +0000 (UTC)
commit 839973a370b66244340536bc9950652a89e6d5ec
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]