コード例 #1
0
GLvoid NEHE22::InitGL(){
	
	multitextureSupported=initMultitexture();
	
	if(!LoadGLTextures()){
        cout<<"Fail to load textures"<<endl;
    }
	
	// Enable Texture Mapping
	glEnable(GL_TEXTURE_2D);
	
	// Enables Smooth Shading
	glShadeModel(GL_SMOOTH);
	
	// clear background as black
	glClearColor(0.0f,0.0f,0.0f,0.5f);
	
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	
	// want the best perspective correction to be done
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	
	initLights();
}
コード例 #2
0
ファイル: lesson22.cpp プロジェクト: alexrao/nehe
int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
{
	multitextureSupported=initMultitexture();
	if (!LoadGLTextures()) return false;				// Jump To Texture Loading Routine
	
	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping
	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
	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

	initLights();										// Initialize OpenGL Light	
	return true;										// Initialization Went OK
}
コード例 #3
0
void Terrain::GenerateHeightMap(int Iterations, double Height, double HDecay)
{
	HeightMap.calculate(Iterations, Height, HDecay);	
	int Select = 1 + rand() % (4 - 1 + 1);		
	// Load .3DS file into model structure	
	if(Select == 1)
	{
		GenerateTerrainObjects(50, 2 , 40, 10);
		g_Load3ds.Import3DS(&g_3DModel, "Textures/Tilesets/Desert/Models/PILLAR.3DS");
		double Ratio = 0.25;
		O1Offset = 0.0f;
		BuildLists(Ratio, 1, g_3DModel);		
		for(int i = 0; i < g_3DModel.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel.pObject[i].pFaces;
			delete [] g_3DModel.pObject[i].pNormals;
			delete [] g_3DModel.pObject[i].pVerts;
			delete [] g_3DModel.pObject[i].pTexVerts;
		}	
		
		g_Load3ds.Import3DS(&g_3DModel1, "Textures/Tilesets/Desert/Models/STATUE.3DS");
		Ratio = 0.25;
		O1Offset = 0.0f;
		BuildLists(Ratio, 2, g_3DModel1);

		// Go through all the objects in the scene
		for(int i = 0; i < g_3DModel1.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel1.pObject[i].pFaces;
			delete [] g_3DModel1.pObject[i].pNormals;
			delete [] g_3DModel1.pObject[i].pVerts;
			delete [] g_3DModel1.pObject[i].pTexVerts;
		}			
	}
	else if(Select == 2)
	{		
		GenerateTerrainObjects(100, 2 , 50, 50);
		g_Load3ds.Import3DS(&g_3DModel, "Textures/Tilesets/Mountains/Models/PINE.3DS");
		double Ratio = 0.25;
		O1Offset = 15.5f;
		BuildLists(Ratio, 1, g_3DModel);		
		for(int i = 0; i < g_3DModel.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel.pObject[i].pFaces;
			delete [] g_3DModel.pObject[i].pNormals;
			delete [] g_3DModel.pObject[i].pVerts;
			delete [] g_3DModel.pObject[i].pTexVerts;
		}	
		
		g_Load3ds.Import3DS(&g_3DModel1, "Textures/Tilesets/Mountains/Models/MAPLE.3DS");
		Ratio = 5.0;
		O2Offset = 0.0f;
		BuildLists(Ratio, 2, g_3DModel1);

		// Go through all the objects in the scene
		for(int i = 0; i < g_3DModel1.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel1.pObject[i].pFaces;
			delete [] g_3DModel1.pObject[i].pNormals;
			delete [] g_3DModel1.pObject[i].pVerts;
			delete [] g_3DModel1.pObject[i].pTexVerts;
		}		
	}
	else if(Select == 3)
	{
		GenerateTerrainObjects(100, 2 , 50, 50);
		g_Load3ds.Import3DS(&g_3DModel, "Textures/Tilesets/Tropics/Models/TREE3.3DS");
		double Ratio = 0.5;
		O1Offset = 0.0f;
		BuildLists(Ratio, 1, g_3DModel);		
		for(int i = 0; i < g_3DModel.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel.pObject[i].pFaces;
			delete [] g_3DModel.pObject[i].pNormals;
			delete [] g_3DModel.pObject[i].pVerts;
			delete [] g_3DModel.pObject[i].pTexVerts;
		}	
		
		g_Load3ds.Import3DS(&g_3DModel1, "Textures/Tilesets/Tropics/Models/PALM.3DS");
		Ratio = 0.75;
		O2Offset = 10.0f;
		BuildLists(Ratio, 2, g_3DModel1);

		// Go through all the objects in the scene
		for(int i = 0; i < g_3DModel1.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel1.pObject[i].pFaces;
			delete [] g_3DModel1.pObject[i].pNormals;
			delete [] g_3DModel1.pObject[i].pVerts;
			delete [] g_3DModel1.pObject[i].pTexVerts;
		}		
	
	}
	else if(Select == 4)
	{		
		GenerateTerrainObjects(100, 2 , 75, 15);
		g_Load3ds.Import3DS(&g_3DModel, "Textures/Tilesets/Volcanic/Models/DEADTREE.3DS");
		double Ratio = 0.1;
		O1Offset = -1.0f;
		BuildLists(Ratio, 1, g_3DModel);		
		for(int i = 0; i < g_3DModel.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel.pObject[i].pFaces;
			delete [] g_3DModel.pObject[i].pNormals;
			delete [] g_3DModel.pObject[i].pVerts;
			delete [] g_3DModel.pObject[i].pTexVerts;
		}	
		
		g_Load3ds.Import3DS(&g_3DModel1, "Textures/Tilesets/Volcanic/Models/TREE1.3DS");
		Ratio = 0.15;
		O2Offset = 2.0f;
		BuildLists(Ratio, 2, g_3DModel1);

		// Go through all the objects in the scene
		for(int i = 0; i < g_3DModel1.numOfObjects; i++)
		{
			// Free the faces, normals, vertices, and texture coordinates.
			delete [] g_3DModel1.pObject[i].pFaces;
			delete [] g_3DModel1.pObject[i].pNormals;
			delete [] g_3DModel1.pObject[i].pVerts;
			delete [] g_3DModel1.pObject[i].pTexVerts;
		}	
	
	}
	SurfaceCreator s1 = SurfaceCreator(HeightMap.Height_Map, HeightMap.getTerrainSize() - 1, static_cast<float>(Height), Select);
	multitextureSupported = initMultitexture();

	TriangleTree.ExpandNode(TriangleTree.root);
	Node* Current = TriangleTree.root;
	
	//Create Triangle t1	
	Vector Apex = Vector(0, 0, HeightMap.Height_Map[0][0]);
	Vector Left = Vector(0, static_cast<float>(HeightMap.getTerrainSize() - 1), HeightMap.Height_Map[0][HeightMap.getTerrainSize() - 1]);
	Vector Right = Vector(static_cast<float>(HeightMap.getTerrainSize() - 1), 0,HeightMap.Height_Map[HeightMap.getTerrainSize() - 1][0] );
	Triangle t = Triangle(Apex, Left, Right);
	for(int i = 0; i < 100; i++)
	{	
		if(PointInTriangle(Vector(Forests[i].x, Forests[i].y), Apex, Left, Right))	
		{
			t.Tree.push_back(Forests[i]);
		}
	}
	double E = CalculateError(Left, Right);		
	Current->LeftChild->BaseNeighbour = Current->RightChild;
	TriangleTree.InsertAtNode(Current->LeftChild, t, E);	

	// Create Triangle t2	
	Apex.set(static_cast<float>(HeightMap.getTerrainSize() - 1) , static_cast<float>(HeightMap.getTerrainSize() - 1), HeightMap.Height_Map[HeightMap.getTerrainSize() - 1][HeightMap.getTerrainSize() - 1]);
	Left.set(static_cast<float>(HeightMap.getTerrainSize() - 1), 0, HeightMap.Height_Map[HeightMap.getTerrainSize() - 1][0]);
	Right.set(0, static_cast<float>(HeightMap.getTerrainSize() - 1), HeightMap.Height_Map[0][HeightMap.getTerrainSize() - 1]);
	Triangle t2 = Triangle(Apex, Left, Right);	
	for(int i = 0; i < 100; i++)
	{	
		if(PointInTriangle(Vector(Forests[i].x, Forests[i].y), Apex, Left, Right))
		{
			t2.Tree.push_back(Forests[i]);
		}
	}	
	Current->RightChild->BaseNeighbour = Current->LeftChild;
	TriangleTree.InsertAtNode(Current->RightChild, t2, E);	

	LoadTGA(&SkyBoxTexture, "SkyBox/CLOUDS.tga");
	LoadGLTextures(&WaterTexture, "Textures/WATER1.bmp");
	LoadGLTextures(&SurfaceTexture , "Data/Surface.bmp");
	LoadGLTextures(&ShadowTexture  , "Data/Shadows.bmp");	
}