Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 30, 2008 GLchar** problem | ||||
---|---|---|---|---|
| ||||
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 :) |
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | On Thu, 30 Oct 2008 20:44:06 +0100, Saaa <empty@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 |
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | On Thu, 30 Oct 2008 20:57:56 +0100, Simen Kjaeraas <simen.kjaras@gmail.com> wrote: > A more D-like way of doing it would possibly be: > > char[] file; > file = read("program.frag"); > glShaderSource(f, 1, &file.ptr, &file.length); > Scratch this last part. I'd hoped it worked, but ptr and length aren't lvalues, so no can do. -- Simen |
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | Saaa 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 :) > > Assuming the C code works, here's what you do in D. GLuint shader; shader=glCreateShader(GL_FRAGMENT_SHADER); char[] file=cast(char[])read(`program.frag`); char* filep = toStringz(file); glShaderSource(f, 1, &filep,null); |
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to torhu | >
> Assuming the C code works, here's what you do in D.
>
> GLuint shader;
> shader=glCreateShader(GL_FRAGMENT_SHADER);
> char[] file=cast(char[])read(`program.frag`);
> char* filep = toStringz(file);
> glShaderSource(f, 1, &filep,null);
>
erm.. ok, thanks :)
Thought I tried this already.
But, how is filep now an char** ?
|
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | Saaa wrote:
>>
>> Assuming the C code works, here's what you do in D.
>>
>> GLuint shader;
>> shader=glCreateShader(GL_FRAGMENT_SHADER);
>> char[] file=cast(char[])read(`program.frag`);
>> char* filep = toStringz(file);
>> glShaderSource(f, 1, &filep,null);
>>
>
> erm.. ok, thanks :)
> Thought I tried this already.
> But, how is filep now an char** ?
It's not filep that's a char**, it's &filep. You're taking the address of a pointer, so you end up with a pointer to a pointer.
If this code doesn't work, then something else is the matter.
|
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | On Thu, 30 Oct 2008 21:02:41 +0100, Simen Kjaeraas <simen.kjaras@gmail.com> wrote: > On Thu, 30 Oct 2008 20:57:56 +0100, Simen Kjaeraas <simen.kjaras@gmail.com> wrote: > >> A more D-like way of doing it would possibly be: >> >> char[] file; >> file = read("program.frag"); >> glShaderSource(f, 1, &file.ptr, &file.length); >> > > Scratch this last part. I'd hoped it worked, but ptr and length aren't lvalues, so no can do. > BTW, shouldn't these be reference return values now (dmd v2.020)? -- Simen |
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to torhu | No no, it works.
I always read &x as the location of x in memory, which as a whole is
ofcourse a pointer :/
My bad.. too long since using them.
>
> It's not filep that's a char**, it's &filep. You're taking the address of a pointer, so you end up with a pointer to a pointer.
>
> If this code doesn't work, then something else is the matter.
|
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | Still D1 here.. :)
>>
>
> BTW, shouldn't these be reference return values now (dmd v2.020)?
>
> --
> Simen
|
October 30, 2008 Re: GLchar** problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | On Fri, Oct 31, 2008 at 5:20 AM, Saaa <empty@needmail.com> wrote:
>>
>> Assuming the C code works, here's what you do in D.
>>
>> GLuint shader;
>> shader=glCreateShader(GL_FRAGMENT_SHADER);
>> char[] file=cast(char[])read(`program.frag`);
>> char* filep = toStringz(file);
>> glShaderSource(f, 1, &filep,null);
>>
>
> erm.. ok, thanks :)
> Thought I tried this already.
> But, how is filep now an char** ?
It isn't filep is still char*. But &filep is a pointer to filep,
which is a (char*)*.
You realize that if you have TypeX x, then typeof(&x) is TypeX*, right?
--bb
|
Copyright © 1999-2021 by the D Language Foundation