[Blending] Multi-shader pass over objects

TL:DR: So how do I make my light-boxes go behind eachother?

I’m trying to make a lighting-toy thing, and I’ve noticed a problem with my blending when I was implementing forward-rendering in 2D.

The first shader-pass just renders the texture, but then it passes over the all the lit objects again and does the lighting calculation. But my problem is that its calculating the lighting twice, one for the texture above, then for the texture behind it. I think this can be solved by just rendering the lit boxes at different Z locations, but I’m worried that would cause some problems. Is there any other way I can figure this out? Thanks.

Here’s my current render code:

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

ambient.bind();
	ambient.setUniformM4("projMatrix", true, camera.getProjection());
	ambient.setUniformM4("viewMatrix", true, camera.getView());
	
	ambient.setUniformf("ambientLight", 1f, 1f, 1f, 1f);
	//Render textured-boxes
        for (Box b : boxes) {
		ambient.setUniformM4("modelMatrix", false, b.model.transform.getM());
		b.render();
	}
ambient.unbind();

GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);

//Render lit-boxes
for(Light light : lights){
	for (Box b : boxes) {
		light.bind(camera, b);
		b.render();
		light.unbind();
	}
}

With just the light boxes (Removed the texture render):

...
-b.render();
...

With just the texture boxes (removed the light-box render):


light.bind(camera, b);
...
-b.render();
...
light.unbind();