function startGameworldDraw()
	if game_resize then
		Camera.height = game.height
		Camera.width = game.width
		Canvas.Darkness:recreate()
	end
	pcr, pcg, pcb, pca = love.graphics.getColor()
	love.graphics.setScale(game.scale,game.scale)
	love.graphics.setColor(1,1,1,1)
end

function endGameworldDraw()
	love.graphics.setColor(pcr, pcg, pcb, pca)
	pcr, pcg, pcb, pca = nil, nil, nil, nil
end

function drawGameworldBackground()
	-- obscure a bit
	love.graphics.setColor(0.7,0.7,0.7)
	for i = 1, #LevelTiles do
		for j = 1, #LevelTiles[i] do
			if LevelTiles[i][j].id ~= 0 then

				local depth = TileData[LevelTiles[i][j].id].depth
				drawTile(
					LevelTiles[i][j],
					tile_properties.scale * j * tile_properties.width	+ tile_properties.scale * (level_properties.offset.x - tile_properties.width)	- Camera.pos.x,
					tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.height) - Camera.pos.y,
					"background"
				)

			end
		end
	end
end

function drawGameworldParticles()
	love.graphics.setColor(0.7,0.7,0.7)
	for _, particle in pairs(LoadedObjects.Particles) do
		particle:handleAnimation()
	end
end

function drawGameworldEntitiesBackground()
	for _, enty in pairs(LoadedObjects.Entities) do
		enty:drawBackground()
	end
end

function drawGameworldEntities()
	love.graphics.setColor(0.7,0.7,0.7)
	for _, enty in pairs(LoadedObjects.Entities) do
		enty:handleAnimation()
	end
end

function drawGameworldForeground()
	love.graphics.setColor(1,1,1)
	for i = 1, #LevelTiles do
		for j = 1, #LevelTiles[i] do
			if LevelTiles[i][j].id ~= 0 then

				local depth = TileData[LevelTiles[i][j].id].depth
				drawTile(
					LevelTiles[i][j],
					tile_properties.scale * j * tile_properties.width	+ tile_properties.scale * (level_properties.offset.x - tile_properties.width)	- Camera.pos.x,
					tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.height) - Camera.pos.y,
					"foreground"
				)

			end
		end
	end
end

function drawGameworldDarkness()
	Canvas.Darkness:reset()
	Canvas.Darkness:startDrawing()
	love.graphics.setBlendMode("replace")
	love.graphics.setColor(0,0,0,0)
	for _, light in pairs(LoadedObjects.Lights) do
		if light.range ~= 0 then
			local position = {
				x = (light.pos.x - Camera.pos.x) / game.scale,
				y = (light.pos.y - Camera.pos.y) / game.scale
			}
			local range = (light.range + light.flicker_value) / game.scale
			love.graphics.circle(
					"fill",
					position.x,
					position.y,
					range
				)
		end
	end
	Canvas.Darkness:endDrawing()
	Canvas.Darkness:draw()
end

function drawGameworldLights()
	for _, light in pairs(LoadedObjects.Lights) do
		if light.range ~= 0 then
			love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)

			shader.circle_gradient:send("pos_x",- Camera.pos.x + light.pos.x)
			shader.circle_gradient:send("pos_y",- Camera.pos.y + light.pos.y)
			shader.circle_gradient:send("range",light.range)
			shader.circle_gradient:send("scale",game.scale)

			love.graphics.setShader(shader.circle_gradient)
			love.graphics.circle(
				"fill",
				- Camera.pos.x + light.pos.x,
				- Camera.pos.y + light.pos.y,
				light.range
			)
			love.graphics.setShader()
		end
	end
end

function updateGameWorldLights()
	for _, light in pairs(LoadedObjects.Lights) do
		light:flicker()
	end
end
