digitalmars.D.learn - GLchar** problem
- "Saaa" <empty needmail.com> Oct 30 2008
- "Simen Kjaeraas" <simen.kjaras gmail.com> Oct 30 2008
- "Saaa" <empty needmail.com> Oct 30 2008
- "Simen Kjaeraas" <simen.kjaras gmail.com> Oct 30 2008
- torhu <no spam.invalid> Oct 30 2008
- "Saaa" <empty needmail.com> Oct 30 2008
- torhu <no spam.invalid> Oct 30 2008
- "Saaa" <empty needmail.com> Oct 30 2008
- "Bill Baxter" <wbaxter gmail.com> Oct 30 2008
- "Simen Kjaeraas" <simen.kjaras gmail.com> Oct 30 2008
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
Still D1 here.. :)
BTW, shouldn't these be reference return values now (dmd v2.020)? -- 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
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: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.
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: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
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: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
Oct 30 2008









"Saaa" <empty needmail.com> 