Ok, so I have a model class that contains a pointer to (what will be) an array of point3 objects:
point3* _vertices_colors;
Point3 has the following typedef:
typedef GLfloat point3[3];
Essentially making an array of point3 objects an array of arrays. Then in a derived classes' constructor, I allocate memory for the number of vertices and colors I want to store as follows:
_vertices_colors = new point3[16];
This means my object has 8 vertices with their own colors stored. I then define the following array on stack ready to copy to the pointer:
point3 verticesColors[] = {
{1.0, 1.0, 1.0}, {1.0, 0.0, 0.0},
{-1.0, 1.0, 1.0}, {1.0, 0.0, 0.0},
{-1.0, -1.0, 1.0},{1.0, 0.0, 0.0},
{1.0, -1.0, 1.0},{1.0, 0.0, 0.0},
{1.0, 1.0, -1.0}, {1.0, 0.0, 0.0},
{-1.0, 1.0, -1.0}, {1.0, 0.0, 0.0},
{-1.0, -1.0, -1.0},{1.0, 0.0, 0.0},
{1.0, -1.0, -1.0},{1.0, 0.0, 0.0}
};
Then, I use a for loop to copy to the array on heap:
for(int i = 0; i < 16; i++)
{
*_vertices_colors[i,0] = *verticesColors[i, 0];
*_vertices_colors[i,1] = *verticesColors[i, 1];
*_vertices_colors[i,2] = *verticesColors[i, 2];
printf("%15f", *_vertices_colors[i,0]);
printf("\t");
printf("%15f", *_vertices_colors[i,1]);
printf("\t");
printf("%15f", *_vertices_colors[i,2]);
printf("\n");
}
However, this appears to assign 1.0, 1.0, -1.0 to each of the 16 rows of the array. I've tried other ways of assigning the pointer to the array, for example the line:
_vertices_colors = verticesColors;
As verticesColors is a constant pointer to an array, I thought this would work, however it produces the same results. I also tried using memcpy:
memcpy(_vertices_colors, verticesColors, sizeof(_vertices_colors));
But this seems to produce some uncontrollable results. It assigns each of the first columns as 1.0 and the rest as very large negative integers. Can anyone see why my first method doesn't work?