0

I'm writing a program in OpenGL, and I wanted to compile the shader file into the executable directly, so the user can't ruin the program (by deleting the shader file or editing it) without knowing what he's doing.

I compiled the shader into an object file with:

ld -r -b binary -o basic_shader.o res/shaders/Basic.gl

And I got these symbols:

SYMBOL TABLE:
0000000000000000 l    d  .data  0000000000000000 .data
00000000000000e5 g       *ABS*  0000000000000000 _binary_res_shaders_Basic_gl_size
00000000000000e5 g       .data  0000000000000000 _binary_res_shaders_Basic_gl_end
0000000000000000 g       .data  0000000000000000 _binary_res_shaders_Basic_gl_start

I already created a class for managing shaders. But the constructor is supposed to get as a param, the shader file path, to open it and read it.

So is it possible to read the symbol _binary_res_shaders_Basic_gl_start (which is a char[]) line by line ?

PrograMed IP
  • 19
  • 1
  • 8
  • You are aware that reading in that text cannot reproduce the shader, aren't you? – Yunnosch Mar 29 '19 at 05:36
  • Why ? Before I implemented the "read file" stuff, I was writing the shaders into strings directly. But now I've changed the thing a little bit, so I can't do same. – PrograMed IP Mar 29 '19 at 05:46
  • Do you think it would be possible for a user here (e.g. me) to copy that text and recreate your shader? Isn't it obvious that the shader consists of more than the sizes of the different parts? – Yunnosch Mar 29 '19 at 05:51
  • I meant is there a way of reading a char string (e.g. `foo`) line by line ? That's what I'm asking about. – PrograMed IP Mar 29 '19 at 05:57
  • Please [edit] your question to clarify. Please show what you have coded and what is missing/failing/misbehaving. – Yunnosch Mar 29 '19 at 06:06
  • Possible duplicate: https://stackoverflow.com/questions/4158900/embedding-resources-in-executable-using-gcc https://stackoverflow.com/questions/6689410/how-to-compile-all-resources-into-one-executable-file https://stackoverflow.com/questions/4864866/c-c-with-gcc-statically-add-resource-files-to-executable-library https://stackoverflow.com/questions/5479691/is-there-any-standard-way-of-embedding-resources-into-linux-executable-image – Jerry Jeremiah Mar 29 '19 at 06:31
  • What is wrong with strings for shader code in C++ code? Btw. I do this a little bit different: writing shaders in separate files but translate them into C++ code (strings) and compile them with the rest. For this, I'm using something like described here: [SO: How to include data object files (images, etc.) in program and access the symbols?](https://stackoverflow.com/a/47415163/7478597). – Scheff's Cat Mar 29 '19 at 06:37
  • @Scheff But I want to embed the file into the executable directly, your solution is using `ofstream` so external files, and that's what I'm trying to avoid – PrograMed IP Mar 29 '19 at 06:44
  • No, you misunderstood. I "translate" the shader files to a C++ file which contains the original file contents as const string variable definition. Then I compile this generated C++ file with the rest of C++ sources. Needless to say that all this pre-processing is managed automatically in our build chain. – Scheff's Cat Mar 29 '19 at 06:47
  • Um it's okey, but won't it be good too, to implement the shaders into the executable ? That's what I'm asking for – PrograMed IP Mar 29 '19 at 06:51

0 Answers0