Original Post
There is something that puzzles me about using glTexCoordPointer and the way I allocate memory. Take a look at the following code:
Now, if I use the static array glTexCoordPointer(2, GL_FLOAT, 0, terrainTexCoords2); everything renders fine, if I use the dynamic array glTexCoordPointer(2, GL_FLOAT, 0, terrainTexCoords); texture coordinates are messed up.
I'm puzzled because as I wrote earlier, both arrays have the same identical values.
float **terrainTexCoords; // dynamic array
float terrainTexCoords2[128*128][2]; // static array
terrainTexCoords = new float*[gridSize*gridSize];
for(int i = 0; i < gridSize*gridSize; ++i)
{
terrainTexCoords = new float[2];
} // this initialize the dynamic array
// now I fill both the static and dynamic array with values
for (int i=0; i<gridSize; i++)
for (int j=0; j<gridSize; j++)
{
terrainTexCoords[i*gridSize+j][0]=(float(j+0)/float(gridSize-1));
terrainTexCoords[i*gridSize+j][1]=1.0 - (float(i+0)/float(gridSize-1));
terrainTexCoords2[i*gridSize+j][0]=(float(j+0)/float(gridSize-1));
terrainTexCoords2[i*gridSize+j][1]=1.0 - (float(i+0)/float(gridSize-1));
}
Now, if I use the static array glTexCoordPointer(2, GL_FLOAT, 0, terrainTexCoords2); everything renders fine, if I use the dynamic array glTexCoordPointer(2, GL_FLOAT, 0, terrainTexCoords); texture coordinates are messed up.
I'm puzzled because as I wrote earlier, both arrays have the same identical values.