I want to create a forest like terrain using OpenGL and C++ in Visual Studio. Naturally, I want to place objects such as trees or bushes at random so it looks more natural. I wanted to do this by using the rand() function, but by using it, while the program is running, my objects are constantly changing location. I get that the program is in loop and because of that rand() is acting the way it is. I wanted to ask you guys if there is a good alternative to this. I just want to get a random location value for each object upon his creation and that that value stays constant. Here is a small part of the code which has this issue:
for (int i = -5.0; i < 5.0; i++){
for (int j = -5.0; j < 5.0; j++){
double k = i * 10.0 + ((rand() % 20 + 10) + ((rand() % 8 + 1) / 10.));
double l = j * 10.0 + ((rand() % 20 + 10) + ((rand() % 8 + 1) / 10.));
if (i % 2 == 0 && j % 2 == 0)
{
drvo(k, l);
}
}
}
Any help I get will be much appreciated!