/* Called to update the display. Note that this function is called in the event loop in the wrapper
   class because we registered display as a callback function */
void display()
{
	/* Define the background colour */
	if (weather == 0)
		glClearColor(0.25f, 0.7f, 1.0f, 1.0f);
	else 
		glClearColor(0.25f, 0.25f, 0.25f, 1.0f);

	/* Clear the colour and frame buffers */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* Enable depth test  */
	glEnable(GL_DEPTH_TEST);

	/* Make the compiled shader program current */
	glUseProgram(program);


	/* Bind cube colours. Note that this is in attribute index 1 */
	glBindBuffer(GL_ARRAY_BUFFER, colourObject);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);


	// Define the model transformations for the cube
	glm::mat4 model = glm::mat4(1.0f);
	model = glm::translate(model, glm::vec3(x, y, z));
	model = glm::scale(model, glm::vec3(scale, scale, scale));//scale equally in all axis
	model = glm::rotate(model, -angle_x, glm::vec3(1, 0, 0)); //rotating in clockwise direction around x-axis
	model = glm::rotate(model, -angle_y, glm::vec3(0, 1, 0)); //rotating in clockwise direction around y-axis
	model = glm::rotate(model, -angle_z, glm::vec3(0, 0, 1)); //rotating in clockwise direction around z-axis

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
	glm::mat4 Projection = glm::perspective(30.0f, aspect_ratio, 0.1f, 100.0f);

	// Camera matrix
	glm::mat4 View = glm::lookAt(
		glm::vec3(0, 0.8, 6), // Camera is at (0,0,4), in World Space
		glm::vec3(0, 0.8, 0), // and looks at 1 on the y
		glm::vec3(0, 1, 0)  // Head is up (set to 0,-1,0 to look upside-down)
		);

	// Send our uniforms variables to the currently bound shader,
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model[0][0]);
	glUniform1ui(colourmodeID, weather);
	glUniformMatrix4fv(viewID, 1, GL_FALSE, &View[0][0]);
	glUniformMatrix4fv(projectionID, 1, GL_FALSE, &Projection[0][0]);

	flooring.drawFloor();
	walls.drawRoom();
	//sky.drawSky();

	for (int i = 0; i < planters.size(); i++) {
		SquarePlanter planter = planters[i];
		planter.drawSquarePlanter();
	}

	glm::mat4 model2 = model;
	model2 = glm::scale(model2, glm::vec3(3.0f, 3.0f, 3.0f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model2[0][0]);

	birchTree.drawObject();

	glm::mat4 model3 = glm::translate(model2, glm::vec3(1.0f, 0.0f, -0.5f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model3[0][0]);
	tree2.drawObject();

	glm::mat4 model4 = glm::translate(model2, glm::vec3(-0.6f, 0.0f, -0.5f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model4[0][0]);
	tree3.drawObject();

	glm::mat4 model5 = glm::translate(model2, glm::vec3(0.4f, 0.0f, 0.2f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model5[0][0]);
	tree4.drawObject();

	glm::mat4 model6 = glm::translate(model2, glm::vec3(-0.4f, 0.0f, -0.2f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model6[0][0]);
	tree5.drawObject();

	glm::mat4 model7 = glm::translate(model2, glm::vec3(0.1f, 0.0f, 0.8f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model7[0][0]);
	tree6.drawObject();

	glm::mat4 model8 = glm::translate(model2, glm::vec3(0.0f, 0.0f, -0.5f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model8[0][0]);
	tree7.drawObject();

	glm::mat4 model9 = glm::translate(model2, glm::vec3(-1.0f, 0.0f, 0.2f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model9[0][0]);
	tree8.drawObject();

	glm::mat4 model10 = glm::translate(model2, glm::vec3(0.5f, 0.0f, -0.4f));
	glUniformMatrix4fv(modelID, 1, GL_FALSE, &model10[0][0]);
	tree9.drawObject();

	if (weather == 2)
		snow->drawObject(0);

	/* Modify our animation variables */
	angle_x += angle_inc_x;
	angle_y += angle_inc_y;
	angle_z += angle_inc_z;

	glm::mat4 ParticleView = glm::lookAt(
		glm::vec3(0, 0, 4),
		glm::vec3(-px, -py, -pz),
		glm::vec3(0, 1, 0)
		);
	/* Update and draw our particle animation */
	if (weather != 0)
		particleObject.drawParticles(Projection, ParticleView, colourmodeID, weather);


}