Right now I'm trying to get a simple OpenGL ES example working with Nimious' GL ES bindings. I'm hitting a bit of a wall when trying to get the proc glShaderSource() to accept my shader's source code (which is gotten through the readFile() proc, which outputs a nim string). Here is a link to that proc: https://github.com/nimious/gles/blob/master/src/gles2/gl2.nim#L1545
In C, this usually is the way someone loads a shader source:
const char* vertexShaderSrc =
"#version 400"
""
"in vec3 pos;"
""
"void main() {"
" gl_Position = vec4(pos, 1.0);"
"}";
// ...
GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertShader, 1, &vertexShaderSrc, NULL)
I'm fine up until that 3rd parameter to something that GLES' glShaderSource() proc will accept? It needs a ptr ptr GlChar. GlChar is defined here
ptr GlChar should be compatible with cstring. Therefore I would suggest that this should work:
let vertexShaderSrc = """
#version 400
in vec3 pos;
void main() {
gl_Position = vec4(pos, 1.0);
}
"""
GLuint vertShader = glCreateShader(GL_VERTEX_SHADER)
var charPtr : ptr GlChar = (ptr GlChar)(cstring(vertexShaderSrc))
glShaderSource(vertShader, 1, charPtr.addr, nil)
if it still doesn't work, use force: var charPtr : ptr GlChar = cast[ptr GlChar](cstring(vertexShaderSrc))
That second one "with force," is what did the trick. (That first one didn't compile).
Thanks!