Search code examples
opengldderelict3

Having trouble glShaderSource( GLuint,GLsizei,const( GLchar* )*,const( GLint )* ) from D


Language: D
Library: DerelictGL3

I'm trying to call glShaderSource( GLuint,GLsizei,const( GLchar* )*,const( GLint )* ) from D

I have the shader source in a string and the shader id for the first argument.

What I'm having problems with is the syntax for the last 3 arguments, all I've managed to get are compiler errors. I don't know how to go from the string containing the shader's source to what I need for the last 3 arguments, particularly the 3rd argument const( GLchar* )*
I'm looking for example code that does this along with explanation on what the code is doing, to go from the string to what ever is needed for the last 3 arguments.


Solution

  • You'll need to convert the D string to a C zero terminated char*:

    immutable(char*) sourceC = toStringz(vertexShaderSource);
    glShaderSource(vertexShaderId, 1, &sourceC, null);
    

    The last parameter can be null, because then it will treat the string as zero terminated. See the documentation: https://www.opengl.org/sdk/docs/man/html/glShaderSource.xhtml

    The third parameter is actually supposed to be an array of strings, that's why it's const(char*)*. In C, a pointer can be used to simulate an array like this.