Ok, so I found something out. I tried to only change the terrain without going through the loop 256 times. However, that only changed the pixel coordineates of the pixel that was at the end of the terrain.
So this is what I have currently:
int vertexPointer = 0;
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
vertice[vertexPointer * 3] = (float)i / ((float)256 - 1) * SIZE;
if (i == x && j == y)
{
vertice[vertexPointer * 3 + 1] = 10;
heights[i][j] = vertice[vertexPointer * 3 + 1];
}
vertice[vertexPointer * 3 + 2] = (float)j / ((float)256 - 1) * SIZE;
textureCoord[vertexPointer * 2] = (float)i / ((float)256 - 1);
textureCoord[vertexPointer * 2 + 1] = (float)j / ((float)256 - 1);
vertexPointer++;
}
}
return loader.postToVAO(vertice, textureCoord, normal, indice);
As you can see, I have made the tex coords, vertices, normals, and indices global values, so they can be changed in real time if it is necessary, and then I follow up by reposting to the VAO, as I did some tests with it and doing so is not very taxing for the computer.
However, I tried the following code (approximately):
int vertexPointer = 0;
vertice[vertexPointer * 3] = (float)x / ((float)256 - 1) * SIZE;
vertice[vertexPointer * 3 + 1] = 10;
heights[x][y] = vertice[vertexPointer * 3 + 1];
vertice[vertexPointer * 3 + 2] = (float)x / ((float)256 - 1) * SIZE;
textureCoord[vertexPointer * 2] = (float)x / ((float)256 - 1);
textureCoord[vertexPointer * 2 + 1] = (float)x / ((float)256 - 1);
vertexPointer++;
return loader.postToVAO(vertice, textureCoord, normal, indice);
}
but this only moved the vertex point, not the rest of the terrain along with it, and it created this weird thing… but it was much quicker and less taxing because of the lack of a for loop.
