Exemplo n.º 1
0
void Viewer::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glClearColor(backgroundCol.x(), backgroundCol.y(), backgroundCol.z(), 1.0f);

    if (mySky.wantSky())
         mySky.Render( );

    glEnable(GL_LIGHTING);

    if (applyGLSL)
        {
            glEnable(GL_VERTEX_PROGRAM_ARB);
            glEnable(GL_FRAGMENT_PROGRAM_ARB);
            light.position[3] = 1;
            light.setLight();
        }
    else{
        light.position[3] = 0;
        light.setLight();
    }

    QVector4D ltmp(light.position[0],light.position[1],light.position[2],light.position[3]);
    ltmp.normalize();
    GLfloat lpos[4] = {ltmp.x(),ltmp.y(),ltmp.z(),ltmp.w()};
    glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, lpos);

    // Draws a terrain
    if (curTerr>=0 && curTerr<terrains.size()){

        Terrain * terrain =  terrains[curTerr];
        if (applyTexture)   glBindTexture( GL_TEXTURE_2D, terrain->texid );
        else glBindTexture( GL_TEXTURE_2D, 0);
        terrain->Draw();

        //glLineWidth(10.0);
        //glPointSize(10.0);

        //glColor3f(1.0f,0.0f,0.0f);
        for (int i=0; i<terrain->artifacts.size(); i++){
            glColor3f(terrain->severity[i]/2.2f, 0.0f, 0.0f);
                drawFlag(terrain->artifacts[i]);
        }
    }

    glDisable(GL_VERTEX_PROGRAM_ARB);
    glDisable(GL_FRAGMENT_PROGRAM_ARB);

    glDisable(GL_LIGHTING);

    //glLineWidth(1.0);
    //glPointSize(1.0);



}
Exemplo n.º 2
0
int main() 
{ 
    // Create the main window 
	int width = 600;
	int height = 600;
	bool wireframe = true;

	sf::Texture sea; //texture object called car
	sf::Texture sand; //texture object called car
	sf::Texture grass; //texture object called car
	sf::Texture rock; //texture object called car
	sf::Texture snowrock; //texture object called car

	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

	sea.loadFromFile("../water.png");
	sand.loadFromFile("../sand.png");
	grass.loadFromFile("../grass.png");
	rock.loadFromFile("../rock.png");
	snowrock.loadFromFile("../snowyrock.png");

	// create the window
	sf::RenderWindow App(sf::VideoMode(width, height), "OpenGL", sf::Style::Default, sf::ContextSettings(24));
    // Create a clock for measuring time elapsed     
    sf::Clock Clock; 

	aiVector3D position(0,10,-30);
	Camera camera;
    camera.Init(position); //create a camera

	//prepare OpenGL surface for HSR 
	glClearDepth(1.f);
	glClearColor(0.3f, 0.3f, 0.6f, 0.f); //background colour
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);

	//// Setup a perspective projection & Camera position 
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	GLfloat light_color[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_position[] = { 5.0, 2.6, 0.0, 0.0 };
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color); // set color of diffuse component
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_color); // set color of specular component
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);   // set position
	///////////////////////////setting material
	GLfloat materialAmbDiff[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // create an array of RGBA values
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialAmbDiff); // set the diffuse & ambient reflection colour for the front of faces
	GLfloat materialSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // create an array of RGBA values (White)
	GLfloat materialShininess[] = { 128.0f }; // select value between 0-128, 128=shiniest
	glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); // set the colour of specular reflection
	glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess); // set shininess of the material
   
	
	//set up a 3D Perspective View volume
    gluPerspective(90.f, (float)width/height, 1.f, 300.0f);//fov, aspect, zNear, zFar 

	//load & bind the shader
	sf::Shader shader;
	//all the lighting & texture blending code should  be put in 'fragment.glsl'
	if(!shader.loadFromFile("vertex.glsl","fragment.glsl")){
        exit(1);
    }

	shader.setParameter("sea", sea);
	shader.setParameter("sand", sand);
	shader.setParameter("grass", grass);
	shader.setParameter("rock", rock);
	shader.setParameter("snowrock", snowrock);


	//Create our Terrain
	Terrain terrain;
	terrain.Init();

    // Start game loop 
    while (App.isOpen()) 
    { 
        // Process events 
        sf::Event Event; 
        while (App.pollEvent(Event)) 
        { 
            // Close window : exit 
            if (Event.type == sf::Event::Closed) 
                App.close(); 
   
            // Escape key : exit 
            if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) 
                App.close(); 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::O))
			{
				// select the projection matrix and clear it out
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				
				// set up an orthographic projection with the same near clip plane
				glOrtho(-16.0, 16.0, -10.0, 16.0, 1.f, 300.0f);

				// select modelview matrix and clear it out
				glMatrixMode(GL_MODELVIEW);
			}
			else if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::P))
			{	
				// select the projection matrix and clear it out
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				
				glFrustum(-5.0, 5.0, -5.0, 5.0, 5, 100);

				// select modelview matrix and clear it out
				glMatrixMode(GL_MODELVIEW);
			}
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::I))
			{
				wireframe = !wireframe;

				if (wireframe == true)
				{
					glPolygonMode(GL_FRONT, GL_FILL);
					glPolygonMode(GL_BACK, GL_FILL);
				}
				else
				{
					glPolygonMode(GL_FRONT, GL_LINE);
					glPolygonMode(GL_BACK, GL_LINE);
				}				
			}			

			//update the camera
			camera.Update(Event);
        } 	

        //Prepare for drawing 
        // Clear color and depth buffer 
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
		sf::Shader::bind(&shader);
		GLfloat light_position[] = { 5.0, 2, 0.5, 0.1 };
		glLightfv(GL_LIGHT0, GL_POSITION, light_position);   // set position
        // Apply some transformations 
        //initialise the worldview matrix
		glMatrixMode(GL_MODELVIEW); 
        glLoadIdentity(); 

		//get the viewing transform from the camera
		camera.ViewingTransform();

		//make the world spin
		//TODO:probably should remove this in final
		//static float ang=0.0;
		//ang+=0.01f;
		//glRotatef(ang*2,0,1,0);//spin about y-axis
		
		//draw the world
		terrain.Draw();

        // Finally, display rendered frame on screen 
        App.display(); 
    } 
   
    return EXIT_SUCCESS; 
}
Exemplo n.º 3
0
int main() {
	

		
	Display window("Window", 1500, 800);
	Camera camera(glm::vec3(0.0f, 0.0f, 0.0f), 70.0f, (float)window.GetReference().getSize().x / (float)window.GetReference().getSize().y, 0.1f, 1800.0f);
	
	
	BasicShader terrain_shader;
	terrain_shader.loadFromFile("./res/shader/BasicShader");
	BasicShader skaybox_shader;
	skaybox_shader.loadFromFile("./res/shader/BasicShader");
	BasicShader grass_shader;
	grass_shader.loadFromFile("./res/shader/BasicShader");
	grass_shader.SetMinLightStr(0.7);
	grass_shader.SetMaxLightStr(1.0);
	BasicShader model_shader; 
	model_shader.loadFromFile("./res/shader/BasicShader");


	Skaybox skaybox;
	skaybox.SetShader(skaybox_shader);
	skaybox.AtachCamera(camera);
	skaybox.SetBack("./res/skybox2/skybox_back.bmp");
	skaybox.SetFront("./res/skybox2/skybox_front.bmp");
	skaybox.SetLeft("./res/skybox2/skybox_left.bmp");
	skaybox.SetRight("./res/skybox2/skybox_right.bmp");
	skaybox.SetBotom("./res/skybox2/skybox_bottom.bmp");
	skaybox.SetTop("./res/skybox2/skybox_top.bmp");
	skaybox.SetSize(1000);
	skaybox.Init();

	Terrain terrain;
	terrain.LoadFromFile("./res/height_maps/TestMap.png");
	terrain.SetTexture("./res/texture/grass_m.jpg");
	terrain.SetShader(terrain_shader);
	terrain.AtachCamera(camera);
	terrain.SetHeight(25);
	terrain.Init();

	
	Mesh Grass[100];
	Mesh Tree[25];
	for (int i = 0; i < 100; i++) {

		Grass[i].LoadMesh("./res/models/Grass pack/Grass_02.obj");
		Grass[i].SetShader(grass_shader);
		Grass[i].AtachCamera(camera);
		int x = 0 + rand() % (int)terrain.GetSize().x ;
		int y = 0 + rand() % (int)terrain.GetSize().y ;

		Grass[i].SetPosition(x,terrain.GetHeightOnPoint(x,y)-0.4,y);
	}

	for (int i = 0; i < 25; i++) {
		Tree[i].LoadMesh("./res/models/Tree/Tree.obj");
		Tree[i].SetShader(model_shader);
		Tree[i].AtachCamera(camera);
		int x = 0 + rand() % (int)terrain.GetSize().x;
		int y = 0 + rand() % (int)terrain.GetSize().y;

		Tree[i].SetPosition(x, terrain.GetHeightOnPoint(x, y) - 0.4, y);
	}
	
	sf::Clock clock;
	float speed;

	camera.setPosition(glm::vec3(terrain.GetSize().x / 2, 8, terrain.GetSize().y / 2-3));

	

	while (window.GetHandle()->isOpen())
	{
		speed = clock.getElapsedTime().asSeconds()*70;
		clock.restart();
		sf::Event event;
		while (window.GetHandle()->pollEvent(event))
		{
			//debug.Event(event, window.GetReference());
			if (event.type == sf::Event::Closed) {
				window.GetHandle()->close();
				return EXIT_SUCCESS;		
		    }

			if (event.type == sf::Event::Resized) {
				camera.forResize((float)window.GetReference().getSize().x / (float)window.GetReference().getSize().y);
				window.Resize();
			}

			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
				window.GetHandle()->close();
				return EXIT_SUCCESS;
				
			}

		}

		if (window.GetReference().hasFocus() && !sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) {
			camera.Update(window.GetReference(),speed);
		}
		else {
			ShowCursor(true);
		}
		
	//	camera.setPosition(glm::vec3(camera.getPosition().x, terrain.GetHeightOnPoint(camera.getPosition().x, camera.getPosition().z)+3,camera.getPosition().z));
		window.Clear();
		skaybox.Draw();
	
		terrain.Draw();
		for (int i = 0; i < 100 ; i++) {
			Grass[i].Draw();
		}

		for (int i = 0; i < 25; i++) {
			Tree[i].Draw();
		}
		window.Update();	
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 4
0
void DuckHuntMain::DrawScene()
{
	//
	// Render the scene to the shadow map.
	//

	mSmap->BindDsvAndSetNullRenderTarget(md3dImmediateContext);

	md3dImmediateContext->RSSetState(0);
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
	md3dImmediateContext->RSSetViewports(1, &mScreenViewport);

	mSsao->SetNormalDepthRenderTarget(mDepthStencilView);

	//
	// Restore the back and depth buffer and viewport to the OM stage.
	//
	ID3D11RenderTargetView* renderTargets[1] = { mRenderTargetView };
	md3dImmediateContext->OMSetRenderTargets(1, renderTargets, mDepthStencilView);

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Silver));

	XMMATRIX view = mCam.View();
	XMMATRIX proj = mCam.Proj();
	XMMATRIX viewProj = mCam.ViewProj();

	float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f };

	// Set per frame constants.
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mCam.GetPosition());
	Effects::BasicFX->SetCubeMap(mSky->CubeMapSRV());
	Effects::BasicFX->SetShadowMap(mSmap->DepthMapSRV());
	Effects::BasicFX->SetSsaoMap(mSsao->AmbientSRV());

	ID3DX11EffectTechnique* tech = Effects::BasicFX->Light3TexTech;
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	XMMATRIX world;
	XMMATRIX worldInvTranspose;
	XMMATRIX worldViewProj;

	// Transform NDC space [-1,+1]^2 to texture space [0,1]^2
	XMMATRIX toTexSpace(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, -0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.0f, 1.0f);

	XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform);

	UINT stride = sizeof(Vertex::PosNormalTexTan);
	UINT offset = 0;

	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);

	if (GetAsyncKeyState('1') & 0x8000)
		md3dImmediateContext->RSSetState(RenderStates::WireframeRS);

	mTerrain.Draw(md3dImmediateContext, mCam, mDirLights);
	//
	// Draw opaque objects.
	//
	D3DX11_TECHNIQUE_DESC techDesc;
	tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT modelIndex = 0; modelIndex < mModelInstances.size(); ++modelIndex)
		{
			world = XMLoadFloat4x4(&mModelInstances[modelIndex].World);
			worldInvTranspose = MathHelper::InverseTranspose(world);
			worldViewProj = world*view*proj;

			Effects::BasicFX->SetWorld(world);
			Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
			Effects::BasicFX->SetWorldViewProj(worldViewProj);
			Effects::BasicFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
			Effects::BasicFX->SetShadowTransform(world*shadowTransform);
			Effects::BasicFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));

			for (UINT subset = 0; subset < mModelInstances[modelIndex].Model->SubsetCount; ++subset)
			{
				Effects::BasicFX->SetMaterial(mModelInstances[modelIndex].Model->Mat[subset]);
				Effects::BasicFX->SetDiffuseMap(mModelInstances[modelIndex].Model->DiffuseMapSRV[subset]);
				//Effects::BasicFX->SetNormalMap(mModelInstances[modelIndex].Model->NormalMapSRV[subset]);

				tech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
				mModelInstances[modelIndex].Model->ModelMesh.Draw(md3dImmediateContext, subset);
			}
		}
	}
	// Turn off wireframe.
	md3dImmediateContext->RSSetState(0);

	// Restore from RenderStates::EqualsDSS
	md3dImmediateContext->OMSetDepthStencilState(0, 0);

	// Debug view SSAO map.
	//DrawScreenQuad(mSsao->AmbientSRV());

	mSky->Draw(md3dImmediateContext, mCam);
	mCrosshair->Draw(md3dImmediateContext, mCam, mScreenViewport.Width, mScreenViewport.Height);
	// restore default states, as the SkyFX changes them in the effect file.
	md3dImmediateContext->RSSetState(0);
	md3dImmediateContext->OMSetDepthStencilState(0, 0);

	// Unbind shadow map and AmbientMap as a shader input because we are going to render
	// to it next frame.  These textures can be at any slot, so clear all slots.
	ID3D11ShaderResourceView* nullSRV[16] = { 0 };
	md3dImmediateContext->PSSetShaderResources(0, 16, nullSRV);



	HR(mSwapChain->Present(0, 0));
}
Exemplo n.º 5
0
int main()
{
	// Create the main window 



	bool wireFrame = false;
	int width = 600, height = 600;
	sf::ContextSettings Settings;
	Settings.depthBits = 24; // Request a 24 bits depth buffer
	Settings.stencilBits = 8;  // Request a 8 bits stencil buffer
	Settings.antialiasingLevel = 16;  // Request 2 levels of antialiasing
	sf::RenderWindow App(sf::VideoMode(width, height, 32), "SFML OpenGL" , sf::Style::Close, Settings);
	// Create a clock for measuring time elapsed     
	sf::Clock Clock;

	aiVector3D position(0, 10, -30);
	Camera camera;
	camera.Init(position); //create a camera

	//prepare OpenGL surface for HSR 
	glClearDepth(1.f);
	glClearColor(0.3f, 0.3f, 0.6f, 0.f); //background colour
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);


	//to enable texture tiling
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	//// Setup a perspective projection & Camera position 
	glMatrixMode(GL_PROJECTION);

	glEnable(GL_LIGHTING); // switch on lighting
	glEnable(GL_LIGHT0); // switch on light0

	GLfloat light_color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat light_position[] = { 15.0f, -20.0f, -10.0f, 0 };


	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color); // set color of diffuse component
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_color); // set color of specular component

	glLightfv(GL_LIGHT0, GL_POSITION, light_position);   // set position


	GLfloat materialAmbDiff[] = { 1, 1, 1, 1.0f }; // create an array of RGBA values


	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialAmbDiff);
	// set the diffuse & ambient reflection colour for the front of faces

	GLfloat materialSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // create an array of RGBA values (White)
	GLfloat materialShininess[] = { 120 }; // select value between 0-128, 128=shiniest


	glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); // set the colour of specular reflection
	glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess); // set shininess of the material
	glLoadIdentity();

	//set up a 3D Perspective View volume
	gluPerspective(90.f, (float)width / height, 1.f, 300.0f);//fov, aspect, zNear, zFar 


	//load in different textures
	sf::Texture seaTexture;
	seaTexture.loadFromFile("sea.png");
	sf::Texture grassTexture;
	grassTexture.loadFromFile("grass.png");
	sf::Texture rockTexture;
	rockTexture.loadFromFile("rock.png");

	//load the shader
	sf::Shader shader;
	//all the lighting & texture blending code should  be put in 'fragment.glsl'
	if (!shader.loadFromFile("vertex.glsl", "fragment.glsl")){
		exit(1);
	}
	//set textures in the shader
	shader.setParameter("seaTexture", seaTexture);
	shader.setParameter("grassTexture", grassTexture);
	shader.setParameter("rockTexture", rockTexture);
	//load the height map image
	sf::Image heightMap;
	heightMap.loadFromFile("heightmap.png");

	//Create our Terrain
	Terrain terrain;
	terrain.Init(heightMap); //create from height map
	shader.setParameter("heightScale", terrain.getHeightScale()); //set the height scaler in the shader

	// Start game loop 
	while (App.isOpen())
	{
		// Process events 
		sf::Event Event;
		while (App.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				App.close();

			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
				App.close();

			//update the camera
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::I))
				wireFrame = !wireFrame;
			//update the camera
			camera.Update(Event);
		}

		//Prepare for drawing 
		// Clear color and depth buffer 
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		sf::Shader::bind(&shader); //shader has to be binded here to allow changing textures
		//glEnable(GL_TEXTURE_2D);

		if (wireFrame)
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		else
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

		glLightfv(GL_LIGHT0, GL_POSITION, light_position);   // set position
		// Apply some transformations 
		//initialise the worldview matrix
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();


		glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

		//get the viewing transform from the camera
		camera.ViewingTransform();


		//make the world spin
		//TODO:probably should remove this in final
		//static float ang=0.0;
		//ang+=0.01f;
		//glRotatef(ang*2,0,1,0);//spin about y-axis



		//draw the world
		terrain.Draw();


		// Finally, display rendered frame on screen 
		App.display();
	}

	return EXIT_SUCCESS;
}
int main() 
{ 
    // Create the main window 
	sf::ContextSettings Settings;
	Settings.depthBits = 24;			// Request a 24 bits depth buffer
	Settings.stencilBits = 8;			// Request a 8 bits stencil buffer
	Settings.antialiasingLevel = 16;	// Request 2 levels of antialiasing
	sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Terrain Assignment", sf::Style::Close, Settings);
    int width=600,height=600;
    // Create a clock for measuring time elapsed     
    sf::Clock Clock; 

	aiVector3D position(0,10,-30);
	Camera camera;
	camera.Init(&App, position);  //create a camera

      
    //prepare OpenGL surface for HSR 
    glClearDepth(1.f); 
    glClearColor(0.0f, 0.0f, 0.0f, 0.f); //background colour
	glEnable(GL_DEPTH_TEST); // check for depth
	glEnable(GL_NORMALIZE); // automatically convert normals to unit normals
	glEnable(GL_LIGHTING); //This enables the possibility of lighting
	glEnable(GL_LIGHT0); //This enables a single light
    glEnable(GL_DEPTH_TEST); 
    glDepthMask(GL_TRUE); 
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);

	//Giving the light positions
	GLfloat light_color[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_position[] = { 10.0, 10.0, -100.0, 0.0 };
	GLfloat light_amb[] = { 3.0, 3.0, 3.0, 1.0 };

	GLfloat materialSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // create an array of RGBA values (White)
	GLfloat materialShininess[] = { 128.0f }; // select value between 0-128, 128=shiniest

   
    //// Setup a perspective projection & Camera position 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
     
    //set up a 3D Perspective View volume
    gluPerspective(90.f, (float)width/height, 1.f, 300.0f);//fov, aspect, zNear, zFar 

	//load & bind the shader
	sf::Shader shader;
	//all the lighting & texture blending code should  be put in 'fragment.glsl'
	if(!shader.loadFromFile("vertex.glsl","fragment.glsl")){
        exit(1);
    }

#pragma region Textures
	// Textures
	sf::Texture waterTexture;
	if (!waterTexture.loadFromFile("water.png")) { std::cout << "Could not load water image"; }

	sf::Texture grassTexture;
	if (!grassTexture.loadFromFile("grass.png")){ std::cout << "Could not load grass image"; }

	sf::Texture snowTexture;
	if (!snowTexture.loadFromFile("snowy rock.png")) { std::cout << "Could not load rock image"; }
#pragma endregion
	shader.setParameter("waterTex", waterTexture);
	shader.setParameter("grassTex", grassTexture);
	shader.setParameter("snowTex", snowTexture);



	//Create our Terrain
	Terrain terrain;
	terrain.InitWithFileName("heightmap.bmp");

	shader.setParameter("tallestPoint", terrain.tallestPoint);

    // Start game loop 
    while (App.isOpen()) 
    { 
        // Process events 
        sf::Event Event; 
        while (App.pollEvent(Event)) 
        { 
            // Close window : exit 
            if (Event.type == sf::Event::Closed) 
                App.close(); 
   
            // Escape key : exit 
            if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) 
                App.close(); 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::I))
			{ 
				terrain.swapWireFrame();
			}
			//update the camera
			camera.Update(Event, &App);
        } 

		camera.UpdatePosition();
           

		// Clear color and depth buffer 
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Apply some transformations 
		//initialise the worldview matrix
		glMatrixMode(GL_MODELVIEW);

		glLoadIdentity();


		//get the viewing transform from the camera
		camera.ViewingTransform();


		//make the world spin
		//TODO:probably should remove this in final
		static float ang = 0.0;
		ang += 0.01f;
		glRotatef(ang * 2, 0, 1, 0);//spin about y-axis

		sf::Shader::bind(&shader);


		glLightfv(GL_LIGHT0, GL_AMBIENT, light_amb); // set color of diffuse component
		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color); // set color of diffuse component
		glLightfv(GL_LIGHT0, GL_SPECULAR, light_color); // set color of specular component

		glLightfv(GL_LIGHT0, GL_POSITION, light_position);   // set position



		//make the world spin
		//TODO:probably should remove this in final
		//static float ang=0.0;
		//ang+=0.01f;
		//glRotatef(ang*2,0,1,0);//spin about y-axis
		

		
		//draw the world
		terrain.Draw();

		   
        // Finally, display rendered frame on screen 
        App.display(); 
    } 
   
    return EXIT_SUCCESS; 
}