Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add files? #53

Open
syaifulnizamyahya opened this issue Jan 25, 2019 · 5 comments
Open

How to add files? #53

syaifulnizamyahya opened this issue Jan 25, 2019 · 5 comments

Comments

@syaifulnizamyahya
Copy link

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.

@Polytonic
Copy link
Owner

Polytonic commented Jan 25, 2019

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.

@syaifulnizamyahya
Copy link
Author

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.

@whiitehead
Copy link

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");

@zinwalin
Copy link

zinwalin commented Apr 7, 2020

image

copy shaders to Glitter/Shaders, it works.

@wnear
Copy link

wnear commented Nov 29, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants