GLchar** problem
Simen Kjaeraas
simen.kjaras at gmail.com
Thu Oct 30 12:57:56 PDT 2008
On Thu, 30 Oct 2008 20:44:06 +0100, Saaa <empty at needmail.com> wrote:
> glshaderSource needs a GLchar** and all I get from cast(char[])
> read(filename) is a single *
>
> How do I get this extra pointer ? :D
>
> The C code is:
>
> char *file;
> shader = glCreateShader(GL_FRAGMENT_SHADER);
> file = textFileRead("program.frag");
> const char * filep = file;
> glShaderSource(f, 1, &filep,NULL);
> free(filep);
>
> my D attempt:
>
> char[] file;
> GLuint shader;
> shader=glCreateShader(GL_FRAGMENT_SHADER);
> file=cast(char[])read(`program.frag`);
> glShaderSource(f, 1, cast(char **) toStringz(file),null);
> //let gc collect file
>
> Error: Access Violation :)
I believe this should work:
char[] file;
file = toStringz(read("program.frag"));
glShaderSource(f, 1, &file, null);
What your program does, is treat the first chars of toStringz(file)
as a pointer, then wander off wildly in that direction.
A more D-like way of doing it would possibly be:
char[] file;
file = read("program.frag");
glShaderSource(f, 1, &file.ptr, &file.length);
--
Simen
More information about the Digitalmars-d-learn
mailing list