Passing dynamic arrays into C.

Bernard Helyer b.helyer at gmail.com
Sun Apr 25 01:45:13 PDT 2010


I was having a problem interfacing with OpenGL from D, as demonstrated 
by this program, written once in D, and again in C:

http://gist.github.com/378273

Now the 'gist' of it is, doing things like this (D):

     glBufferData(GL_ARRAY_BUFFER, vertices.sizeof,
                  vertices.ptr, GL_STATIC_DRAW);

     glVertexPointer(2, GL_FLOAT, GLfloat.sizeof * 2, cast(void*)0);

With this data (D):

     const GLfloat[] vertices = [-1.0f, -1.0f, 1.0f, -
                                  1.0f, -1.0f, 1.0f, 1.0f, 1.0f];

and the same data in C:

     const GLfloat vertices[] = {-1.0f, -1.0f, 1.0f,
                                 -1.0f, -1.0f, 1.0f, 1.0f, 1.0f};


I was getting nothing but a blank screen. I'm sure you smart folks know 
what comes next.

      GLfloat[] vertices = {1.0f, 1.0f};  // vertices is a dynamic array.

      GLfloat[2] vertices = {1.0f, 1.0f};  // vertices is a static array.

The second version enables the program to work as the C one does.


My question is, why doesn't passing the `GLfloat[] vertex ...` 
declaration work? I've looked through the docs, and can't see anything 
too obvious.


Thanks.


More information about the Digitalmars-d-learn mailing list