Glitter icon indicating copy to clipboard operation
Glitter copied to clipboard

How to add files?

Open syaifulnizamyahya opened this issue 5 years ago • 5 comments

I want to add shader files. I copied the shader file to \Glitter\Glitter\Sources directory but during runtime the file cannot be found. I placed the file in \Glitter\Build\Glitter\Debug, yet the file cannot be found.

This is how I assign the file. Shader ourShader("3.3.shader.vs", "3.3.shader.fs"); // you can name your shader files however you like

Could you explain how the cmake generated solution configure folder/path? AFAIK, its weird than normal which makes this not really suitable for beginners.

syaifulnizamyahya avatar Jan 25 '19 02:01 syaifulnizamyahya

I want to add shader files. I copied the shader file to \Glitter\Glitter\Sources directory but during runtime the file cannot be found. I placed the file in \Glitter\Build\Glitter\Debug, yet the file cannot be found.

You might find it helpful to print the working directory of your application, as your shader files will most likely be loaded relative to that directory; this is platform-specific, so without having provided your OS, I can't be of too much further help here.

You can also try putting shader files in /Glitter/Shaders/ with the appropriate extension *.{comp,frag,geom,vert} and your IDE should pick it up accordingly (if you are using one).

This is how I assign the file. Shader ourShader("3.3.shader.vs", "3.3.shader.fs"); // you can name your shader files however you like

I'm not sure I understand this bit. Where did you get this code? Are you following along with a specific tutorial? Glitter is designed as a starting point, and is not opinionated about how you structure your files on disk as long as they are contained within the Glitter subfolder.

Could you explain how the cmake generated solution configure folder/path? AFAIK, its weird than normal which makes this not really suitable for beginners.

Could you describe what you mean by "its weird than normal"? What would be an example of something normal? I'd be happy to correct this deficiency if you have suggestions about how to make this more friendly to beginners.

CMake takes code in your source directory and creates a makefile (or IDE configuration) that knows how to build an executable (in the Build/ directory). You really only need to modify code in the Glitter/Glitter/ directory and the changes should be picked up in your next build. If you are unfamiliar with CMake, you might want to do a quick tutorial on that first, of which there are several on the internet.

Polytonic avatar Jan 25 '19 02:01 Polytonic

Finally got it working.

I need to change the file path like this

`Shader ourShader("..\Glitter\Sources\3.3.shader.vert", "..\Glitter\Sources\3.3.shader.frag");

The code is from this tutorial, https://learnopengl.com/Getting-started/Shaders

What I mean by weird is that when you add file from visual studio, the file would not be where you expected. The file will be added to Build directory instead of the directory where main.cpp resides. This caused lots of weird error like the compiler cannot find the file and file is missing during runtime. To solve this, i had to print working directory and make modification to the path. I believe most people who use this project are from learnopengl.org since this project is referenced from there.

If possible, could you make a folder where all related project files(source, library used) resides in the same folder (and subfolder)? Also why the solution includes library projects? Can we remove the library projects from the solution?

Apart from this, I had no other major issue with Glitter.

syaifulnizamyahya avatar Jan 25 '19 08:01 syaifulnizamyahya

I was having the same issue. It's not immediately clear that the path is relative to the build folder and not the binary nor the source file. A simpler solution is to use the shaders that end up in the build folder.

Shader ourShader("Glitter/shader.vert", "Glitter/shader.frag");

whiitehead avatar Sep 23 '19 02:09 whiitehead

image

copy shaders to Glitter/Shaders, it works.

zinwalin avatar Apr 07 '20 05:04 zinwalin

shader files acting like the data, I think the best practice is placed in other directory, referenced with absolute path, independent of this project.

wnear avatar Nov 29 '21 15:11 wnear