LWJGL/Slick Spawning objects/overlapping

Hey all java developers i am new to OpenGL and fairly ok in java its self but i cant figure this one out atm i have a for loop that keeps creating objects i want it to only create the needed objects once then stop but since its in the game loop it keeps repeating and at the moment theres nothing wrong with it because its a small area of blocks im spawning but if it does this on a larger scale terrain it will slow down FPS a hole lot here is the for loop in my game loop

for(int i = 0; i < 20; i++)
			{ 
				BlockID.add(i);
				BlocksCreated += i;
				System.out.println("BlockID["+i+"]");
				CubeObject.Spawn(i+2,0,0);
				CubeObject.Spawn(0,0,i+2);
				CubeObject.Spawn(0,i+2,0);
			}

EDIT: I forgot to add this befor this is my hole gameloop

public static void GameLoop()
	{
		Camera cam = new Camera(70,(float)Display.getWidth()/(float)Display.getHeight(),0.3f,1000);
		while(!Display.isCloseRequested())
		{
			cam.CameraMovmentInputs();
			DisplayHandler.ClearBuffers();
			cam.useView();
			for(int i = 0; i < 20; i+=2)
			{ 
				BlocksCreated++;
				BlockID.add(BlocksCreated);
				System.out.println("BlockID["+i+"]");
				CubeObject.dirtcracked.bind();
				CubeObject.Spawn(i+2,0,0);
				CubeObject.SpawnLine(i, 2);
				CubeObject.SpawnLine(i, 4);
				CubeObject.SpawnLine(i, 6);
				//CubeObject.grass.bind();
				//CubeObject.Spawn(0,0,i+2);
				//CubeObject.grassdead.bind();
				//CubeObject.Spawn(0,i+2,0);
			}
			
			Display.update();
		}
		
	}

the CubeObject.Spawn is basically a java file with vertex points and all i do is translate them and create a new instance of that object.
any help would be awesome :slight_smile: since im new advice would be great as well.
Thanks and sorry for my poor english

I can’t say for sure without the rest of the code, however if you want to just create those objects a single time, you could just move the for-loop into your initialization method instead of the game loop. That way the objects are created when the game starts and then, if need be, control the objects in the game loop.

Since you’re using Slick, you could put that loop in the init method of your game state so it’ll only run once (as bigbass1997 said). I haven’t used Slick in a while, but I’m mildly confused and intrigued on why your cube object has a set of 3D coordinates when Slick is a 2D graphics engine.

Ah im using slick to load the textures onto the faces the XYZ cords have nothing to do with it, also iv tryed moving the for loop out of the game loop but the screen just goes black

Anyone please i still need help with this topic iv enabled backface culling and it has helped a little but but not enough for me to continue a terrain generating method