Converting (casting?) a dynamic array to a fixed array?

rsw0x via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 3 19:53:20 PDT 2015


On Monday, 4 May 2015 at 02:47:24 UTC, WhatMeWorry wrote:
> This following code works fine. A triangle is displayed.
>
>         GLfloat[6] verts = [  0.0,  1.0,
>                              -1.0, -1.0,
>                               1.0, -1.0 ];
>
>         glGenBuffers(1, &vbo);
>         glBindBuffer(GL_ARRAY_BUFFER, vbo);  //   Some of the 
> types are:
>
>         glBufferData(GL_ARRAY_BUFFER, verts.sizeof, &verts, 
> GL_STATIC_DRAW);
>
>
>
> Then, all I do is take out the 6 so that the static array 
> becomes a dynamic one. It compiles fine.
>
>          GLfloat[] verts = [  0.0,  1.0,
>                              -1.0, -1.0,
>                               1.0, -1.0 ];
>
> However, when I run it, the triangle disappears.
>
> According to OpenGL, glBufferData shows:  void glBufferData( 
> ignore, GLsizeiptr size, const GLvoid * data, ignore);
>
> So I thought the best solution would be to simply cast the 
> dynamic array to a pointer?
>
> So I tried:
> glBufferData(GL_ARRAY_BUFFER, verts.sizeof, cast(const GLvoid 
> *) &verts, GL_STATIC_DRAW);
> and
> glBufferData(GL_ARRAY_BUFFER, verts.sizeof, cast(const GLvoid 
> *) verts, GL_STATIC_DRAW);
> and
> glBufferData(GL_ARRAY_BUFFER, verts.sizeof, verts.ptr, 
> GL_STATIC_DRAW);
> and
> glBufferData(GL_ARRAY_BUFFER, verts.sizeof, cast(const GLvoid 
> *) verts.ptr, GL_STATIC_DRAW);
> and
> nothing but more blank screens.
>
> Any ideas?  Thanks.

sizeof on a slice doesn't do what you think it does, it returns 
the size of the actual slice object I believe.


More information about the Digitalmars-d-learn mailing list