Esempio n. 1
0
GLuint LoadTexture( const char * filename)
{
    GLuint id;
    // Load image from tga file
    //TGA *TGAImage	= new TGA("./sphericalenvironmentmap/house2.tga");
    TGA *TGAImage	= new TGA(filename);
    //TGA *TGAImage	= new TGA("./cubicenvironmentmap/cm_right.tga");

    // Use to dimensions of the image as the texture dimensions
    uint width	= TGAImage->GetWidth();
    uint height	= TGAImage->GetHeigth();

    // The parameters for actual textures are changed

    glGenTextures(1, &id);

    glBindTexture(GL_TEXTURE_2D, id);


    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


    // Finaly build the mipmaps
    glTexImage2D (GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, TGAImage->GetPixels());

    gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, TGAImage->GetPixels());


    glEnable( GL_TEXTURE_2D );

    glBindTexture (GL_TEXTURE_2D, id);

    delete TGAImage;
    return id;
}
Esempio n. 2
0
void DisplayFunc(void) 
{
    GLuint id ;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//load projection and viewing transforms
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
        
	gluPerspective(60,(GLdouble) WindowWidth/WindowHeight,0.01,10000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(CameraRadius*cos(CameraTheta)*sin(CameraPhi),
			  CameraRadius*cos(CameraPhi),
			  CameraRadius*sin(CameraTheta)*sin(CameraPhi),
			  0,0,0,
			  0,1,0);

	glEnable(GL_DEPTH_TEST);	
	glEnable(GL_TEXTURE_2D);

		setParameters(program);
	
	// Load image from tga file
	char* tgaFile = "";
	if(texture == 0 && mapping == 0)
		tgaFile = "./planartexturemap/abstract2.tga";
	else if(texture == 1 && mapping == 0)
		tgaFile = "./sphericaltexturemap/earth2.tga";
	else if(mapping == 1)
		tgaFile = "./sphericalenvironmentmap/house2.tga";
	else
		tgaFile = "./planartexturemap/abstract2.tga";
		//tgaFile = "./planarbumpmap/abstract_gray2.tga";

	TGA *TGAImage = new TGA(tgaFile);

	// Use to dimensions of the image as the texture dimensions
	uint width	= TGAImage->GetWidth();
	uint height	= TGAImage->GetHeigth();
	
	// The parameters for actual textures are changed

	glGenTextures(1, &id);

	glBindTexture(GL_TEXTURE_2D, id);


	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


	// Finaly build the mipmaps
	glTexImage2D (GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, TGAImage->GetPixels());

	gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, TGAImage->GetPixels());

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	glEnable( GL_TEXTURE_2D );

	glBindTexture (GL_TEXTURE_2D, id); 

    delete TGAImage;
	if (object == 0)
	{
		float w = .1;
		for (float i = -20; i < 20; i += w)
			for (float j = -20; j < 20; j += w)
			{
				point v1, v2, v3, v4;
				v1.x = i;
				v1.y = j;
				v1.z = 0;
				v2.x = i+w;
				v2.y = j;
				v2.z = 0;
				v3.x = i;
				v3.y = j+w;
				v3.z = 0;
				v4.x = i+w;
				v4.y = j+w;
				v4.z = 0;
				drawTriangle(v1, v2, v3);
				drawTriangle(v2, v3, v4);
			}	
	}
	else if(object == 1)
	{
		gluQuadricTexture(quad,1);
		gluSphere(quad,2,20,20);
	}
	else if (object == 2)
		for (int i = 0; i < faces; i++)
			drawTriangle(vertList[faceList[i].v1], vertList[faceList[i].v2], vertList[faceList[i].v3]);



	//glutSolidTeapot(1);
	//setParameters(program);
	glutSwapBuffers();
}