I would like to manage OpenGL shaders in a more C++ and OO way
So I wanted to write a class for it..
However I run into trouble making the shader code a bit more managable..
I want to store the shader code into my class and then compile it
OpenGL expects a constant pointer to a pointer to a char "const **GLchar"
Right now I have an array of Glchar where the shadercode is stored..
Is there any good way to stuff one into the other ??
Maybe it's me but I don't see it....
Thanks...
Does casting work? A const** to GLchar just means you cant change the GLchars in the array.
const ** GLChar psource = (const ** GLCchar)&source;
One thing to ask is do you need to make it a 2d array? Right now you just have an array, or a 2d array with one row. What does the shader expect?
This code compiles on the graphics card so I think I need a 2D array...
It doesn't just expect a concatenated string? A single one?
It compiles to one long string.
00001c60 69 6e 67 00 25 73 00 00 23 76 65 72 73 69 6f 6e |ing.%s..#version| 00001c70 20 31 35 30 20 63 6f 72 65 0a 20 69 6e 20 76 65 | 150 core. in ve| 00001c80 63 32 20 70 6f 73 69 74 69 6f 6e 3b 20 69 6e 20 |c2 position; in | 00001c90 76 65 63 33 20 43 6f 6c 6f 72 49 6e 3b 20 6f 75 |vec3 ColorIn; ou| 00001ca0 74 20 76 65 63 33 20 43 6f 6c 6f 72 46 72 61 67 |t vec3 ColorFrag| 00001cb0 6d 65 6e 74 3b 20 76 6f 69 64 20 6d 61 69 6e 28 |ment; void main(| 00001cc0 29 7b 43 6f 6c 6f 72 46 72 61 67 6d 65 6e 74 20 |){ColorFragment | 00001cd0 3d 20 43 6f 6c 6f 72 49 6e 3b 67 6c 5f 50 6f 73 |= ColorIn;gl_Pos| 00001ce0 69 74 69 6f 6e 20 3d 20 76 65 63 34 28 70 6f 73 |ition = vec4(pos| 00001cf0 69 74 69 6f 6e 2c 20 30 2e 30 2c 20 31 2e 30 29 |ition, 0.0, 1.0)| 00001d00 3b 7d 00 00 00 00 00 00 00 00 50 c1 00 00 c0 3f |;}........P....?|
Multiple literal strings that are one after the other get concatenated.
yeah, that's kind of what I meant
If you want to use a std::string: http://stackoverflow.com/questions/6047527/how-to-convert-stdstring-to-const-char
So basically it wants a pointer to a string? &source should be your "C string" (that is, a pointer to the beginning of the array of characters) so you may need to store that somewhere in order to take the address of that?
const GLchar * str = &source; const GLchar ** ptr = &str; // Here, eat ^ that and leave us alone!
Append:
That said, a non-const pointer to a string suggests that they may wish to change it on you, which may or may not throw you for a loop... Do make sure that what you're trying is safe.