digitalmars.D.learn - GLchar** problem
- Saaa (18/18) Oct 30 2008 glshaderSource needs a GLchar** and all I get from cast(char[])
- Simen Kjaeraas (13/31) Oct 30 2008 I believe this should work:
- Simen Kjaeraas (6/10) Oct 30 2008 Scratch this last part. I'd hoped it worked, but ptr and length aren't
- Simen Kjaeraas (5/15) Oct 30 2008 BTW, shouldn't these be reference return values now (dmd v2.020)?
- Saaa (1/5) Oct 30 2008
- torhu (7/33) Oct 30 2008 Assuming the C code works, here's what you do in D.
- Saaa (3/9) Oct 30 2008 erm.. ok, thanks :)
- torhu (4/17) Oct 30 2008 It's not filep that's a char**, it's &filep. You're taking the address
- Saaa (4/7) Oct 30 2008 No no, it works.
- Bill Baxter (5/17) Oct 30 2008 It isn't filep is still char*. But &filep is a pointer to filep,
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 :)
Oct 30 2008
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
Oct 30 2008
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
Oct 30 2008
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:BTW, shouldn't these be reference return values now (dmd v2.020)? -- SimenA 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.
Oct 30 2008
Still D1 here.. :)BTW, shouldn't these be reference return values now (dmd v2.020)? -- Simen
Oct 30 2008
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);
Oct 30 2008
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** ?
Oct 30 2008
Saaa wrote: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.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** ?
Oct 30 2008
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.
Oct 30 2008
On Fri, Oct 31, 2008 at 5:20 AM, Saaa <empty needmail.com> wrote: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? --bbAssuming 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** ?
Oct 30 2008