Example #1
0
int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
{
	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearColor(1.0f, 1.0f, 1.0f, 0.5f);				// Full brightness with apha 50%
	glClearDepth(1.0f);									// Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations	
	quadric = gluNewQuadric();
	
	// Initialize camera
	myCamera = new Camera(Vector3D(100, 300, 300), Vector3D(0, 0, -1));

	#pragma region Fog
	glFogi(GL_FOG_MODE, fogMode[fogfilter]); // Fog Mode
	glFogfv(GL_FOG_COLOR, fogColor);		 // Set Fog Color
	glFogf(GL_FOG_DENSITY, 0.35f);			 // How Dense Will The Fog Be
	glHint(GL_FOG_HINT, GL_DONT_CARE);		 // Fog Hint Value
	glFogf(GL_FOG_START, 1.0f);				 // Fog Start Depth
	glFogf(GL_FOG_END, 1000.0f);			 // Fog End Depth
	glEnable(GL_FOG);						 // Enable Fog
	#pragma endregion
	#pragma region Global Light
	light = new Light(LightAmbient, LightSpecular, LightDiffuse, LightPosition, GL_LIGHT0);
	light->setUpLight();
	#pragma endregion
	#pragma region Tank Lights
	tank_Leftlight = new Light(tank_LightAmbient, tank_LightSpecular, tank_LightDiffuse,
		tank_LightPosition, tank_LightDirection, 10, GL_LIGHT1);
	tank_Rightlight = new Light(tank_LightAmbient,tank_LightSpecular,tank_LightDiffuse,
		tank_LightPosition,tank_LightDirection,10,GL_LIGHT2);
	#pragma endregion
	#pragma region Terrain Load
	// Terrain
	terrain = new Terrain();
	// Terrain Texture
	terrain->LoadTexture("Data/terrain ground.bmp");
	// Load Heightmap
	terrain->LoadHeightMap("Data/terrain height.bmp");
	// Draw Terrain
	terrain->Draw(0, -71, 0);
	#pragma endregion
	#pragma region Load Tank Model & Texture
	// Tank
	tank = new Model_3DS();
	// Load Model
	tank->Load("Data/Models/FinalTank.3ds");
	// Load Tank textures
	body.LoadBMP("Data/tanktexture/teext.bmp");
	MGunM.LoadBMP("Data/tanktexture/GunM.bmp");
	MGun.LoadBMP("Data/tanktexture/MGun.bmp");
	#pragma endregion
	#pragma region Decors
	Decor1 = new Model_3DS();
	Decor2 = new Model_3DS();
	Decor3 = new Model_3DS();
	Decor4 = new Model_3DS();
	Decor5 = new Model_3DS();
	Decor6 = new Model_3DS();

	Decor1->Load("Data/Models/Decor1.3DS");	
	Decor2->Load("Data/Models/Decor1.3DS");
	Decor3->Load("Data/Models/Decor1.3DS");
	Decor4->Load("Data/Models/Decor1.3DS");
	Decor5->Load("Data/Models/Decor1.3DS");
	Decor6->Load("Data/Models/Decor1.3DS");

	Decor1->pos.x = 520;
	Decor2->pos.x = 520;
	Decor3->pos.x = 620;
	Decor4->pos.x = 620;
	Decor5->pos.x = 480;
	Decor6->pos.x = 480;

	Decor1->pos.y = -5;
	Decor2->pos.y = -5;
	Decor3->pos.y = -5;
	Decor4->pos.y = -5;
	Decor5->pos.y = -5;
	Decor6->pos.y = -5;

	Decor1->pos.z = 10;
	Decor2->pos.z = 70;
	Decor3->pos.z = 160;
	Decor4->pos.z = 220;
	Decor5->pos.z = 180;
	Decor6->pos.z = 240;

	Decor1->scale *= 0.8;
	Decor2->scale *= 0.8;
	Decor3->scale *= 0.8;
	Decor4->scale *= 0.8;
	Decor5->scale *= 0.8;
	Decor6->scale *= 0.8;

	Decor3->rot.y = 180;
	Decor4->rot.y = 180;
	Decor1texture.LoadBMP("Data/decorstextures/tank.bmp");
	#pragma endregion
	#pragma region Load Sky Box
	// Skybox with load texture
	skyBox = new SkyBox("data/skybox/top.bmp", "data/skybox/down.bmp", "data/skybox/left.bmp", 
					"data/skybox/right.bmp", "data/skybox/front.bmp", "data/skybox/back.bmp");
	#pragma endregion
	#pragma region Load Textures
	blackTexture.loadTexture("data/black.bmp");
	woodTexture.loadTexture("data/wood.bmp");
	woodTexture1.loadTexture("data/wood1.bmp");
	road.loadTexture("data/road.bmp");
	road1.loadTexture("data/road1.bmp");
	ground.loadTexture("data/ground.bmp");
	buildingTexture.loadTexture("data/Building2.bmp");
	buildingTexture1.loadTexture("data/Building1.bmp");
	buildingTexture2.loadTexture("data/Building.bmp");
	glassTexture.loadTexture("data/glass.bmp");
	glassTexture1.loadTexture("data/glass block.bmp");
	wall.loadTexture("data/WallBlack.bmp");
	#pragma endregion
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);					// Set The Blending Function For Translucency

	return true;										// Initialization Went OK
}