Beispiel #1
0
//Set up variables
bool DemoInit()
{
	if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN))
		return 0;											//quit if not created

	SetUpARB_multitexture();
	SetUpARB_texture_cube_map();
	SetUpEXT_texture_edge_clamp();
	SetUpNV_register_combiners();
	SetUpNV_register_combiners2();
	SetUpNV_vertex_program();

	//Check for necessary extensions
	if(	!ARB_multitexture_supported || !ARB_texture_cube_map_supported ||
		!EXT_texture_edge_clamp_supported || !NV_register_combiners_supported ||
		!NV_vertex_program_supported)
		return false;

	//Check for single-pass chromatic aberration states
	GLint maxTextureUnits;
	glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits);
	if( NV_register_combiners2_supported && maxTextureUnits>=4)
	{
		errorLog.OutputSuccess("Single Pass Chromatic Aberration Supported!");
		pathOneSupported=true;
		renderPath=CHROMATIC_SINGLE;
	}

	camera.Init(VECTOR3D(0.0f, 0.0f, 4.0f), 2.5f, 10.0f);

	if(	!cubeMapPosX.Load("cube_face_posx.tga") ||
		!cubeMapNegX.Load("cube_face_negx.tga") ||
		!cubeMapPosY.Load("cube_face_posy.tga") ||
		!cubeMapNegY.Load("cube_face_negy.tga") ||
		!cubeMapPosZ.Load("cube_face_posz.tga") ||
		!cubeMapNegZ.Load("cube_face_negz.tga"))
		return false;

	//Build a texture from the data
	glGenTextures(1, &cubeMapTexture);								//Generate Texture ID
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture);					//Bind texture
	
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
					0, GL_RGBA8, cubeMapPosX.width, cubeMapPosX.height, 0,
					cubeMapPosX.format, GL_UNSIGNED_BYTE, cubeMapPosX.data);
	
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
					0, GL_RGBA8, cubeMapNegX.width, cubeMapNegX.height, 0,
					cubeMapNegX.format, GL_UNSIGNED_BYTE, cubeMapNegX.data);

	glTexImage2D(	GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
					0, GL_RGBA8, cubeMapPosY.width, cubeMapPosY.height, 0,
					cubeMapPosY.format, GL_UNSIGNED_BYTE, cubeMapPosY.data);
	
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
					0, GL_RGBA8, cubeMapNegY.width, cubeMapNegY.height, 0,
					cubeMapNegY.format, GL_UNSIGNED_BYTE, cubeMapNegY.data);

	glTexImage2D(	GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
					0, GL_RGBA8, cubeMapPosZ.width, cubeMapPosZ.height, 0,
					cubeMapPosZ.format, GL_UNSIGNED_BYTE, cubeMapPosZ.data);
	
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
					0, GL_RGBA8, cubeMapNegZ.width, cubeMapNegZ.height, 0,
					cubeMapNegZ.format, GL_UNSIGNED_BYTE, cubeMapNegZ.data);

	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

	
	//reset timer for start
	timer.Reset();
	
	return true;
}
Beispiel #2
0
//Set up variables
bool DemoInit()
{
	SetUpARB_multitexture();
	SetUpARB_texture_cube_map();
	SetUpEXT_compiled_vertex_array();
	SetUpEXT_texture_edge_clamp();
	SetUpNV_register_combiners();
	SetUpNV_vertex_program();
	SetUpNV_texture_shader();

	if(	!GL_ARB_texture_cube_map || !GL_EXT_compiled_vertex_array ||
		!GL_ARB_multitexture || !GL_NV_register_combiners ||
		!GL_NV_vertex_program || !GL_EXT_texture_edge_clamp)
		return false;

	//Get some useful info
	int maxTextureUnitsARB;
	glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB);
	int maxGeneralCombinersNV;
	glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &maxGeneralCombinersNV);

	if(	GL_NV_texture_shader &&
		maxTextureUnitsARB>=4 &&
		maxGeneralCombinersNV>=4)
	{
		Util::log("Higher Quality bump mapping supported");
		paths1And2Supported=true;
		currentTechnique=TEXTURE_LOOKUP;
	}
	else
		Util::log("Higher Quality bump mapping unsupported");

	
	//Load Textures
	//normal map - put gloss map in alpha
	normalMapImage.Load("Normal Map.bmp");
	normalMapImage.LoadAlphaTGA("gloss.tga");
	glGenTextures(1, &normalMapTexture);
	glBindTexture(GL_TEXTURE_2D, normalMapTexture);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_RGBA8, normalMapImage.width, normalMapImage.height,
					0, normalMapImage.format, GL_UNSIGNED_BYTE, normalMapImage.data);
	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);

	//decal
	decalImage.Load("Decal.bmp");
	glGenTextures(1, &decalTexture);
	glBindTexture(GL_TEXTURE_2D, decalTexture);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height,
					0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data);
	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);

	//Create normalisation cube map
	glGenTextures(1, &normalisationCubeMap);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalisationCubeMap);
	GenerateNormalisationCubeMap();
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

	if(paths1And2Supported)
	{
		//Create signed normap map
		//Create space for signed data
		GLbyte * signedData=new GLbyte[normalMapImage.width*normalMapImage.height*3];
		if(!signedData)
		{
			Util::log("Unable to allocate memory for signed normal map data");
			return false;
		}

		//Convert unsigned to signed RGB data, ignoring alpha
		for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; i++)
		{
			for(unsigned int j=0; j<3; j++)
			{
				signedData[i*3+j]=normalMapImage.data[i*4+j]-128;
			}
		}
	
		glGenTextures(1, &signedNormalMap);
		glBindTexture(GL_TEXTURE_2D, signedNormalMap);
		glTexImage2D(	GL_TEXTURE_2D, 0, GL_SIGNED_RGBA8_NV, normalMapImage.width, normalMapImage.height,
						0, GL_RGB, GL_BYTE, signedData);
		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);

		if(signedData)
			delete [] signedData;
		signedData=NULL;
	}

	//make sure texImage2D is finished with normalMapImage before we change the image
	glFinish();

	//Flatten the bumps in the normal map
	for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; ++i)
	{
		normalMapImage.data[i*4]=128;
		normalMapImage.data[i*4+1]=128;
		normalMapImage.data[i*4+2]=255;
	}

	//create flat normal map with gloss map in alpha
	glGenTextures(1, &flatNormalMap);
	glBindTexture(GL_TEXTURE_2D, flatNormalMap);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_RGBA8, normalMapImage.width, normalMapImage.height,
					0, normalMapImage.format, GL_UNSIGNED_BYTE, normalMapImage.data);
	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);

	if(paths1And2Supported)
	{
		//Create signed flat normap map
		//Create space for signed data
		GLbyte * signedData=new GLbyte[normalMapImage.width*normalMapImage.height*3];
		if(!signedData)
		{
			Util::log("Unable to allocate memory for signed normal map data");
			return false;
		}

		//Convert unsigned to signed RGB data, ignoring alpha
		for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; i++)
		{
			for(unsigned int j=0; j<3; j++)
			{
				signedData[i*3+j]=normalMapImage.data[i*4+j]-128;
			}
		}
	
		glGenTextures(1, &signedFlatNormalMap);
		glBindTexture(GL_TEXTURE_2D, signedFlatNormalMap);
		glTexImage2D(	GL_TEXTURE_2D, 0, GL_SIGNED_RGBA8_NV, normalMapImage.width, normalMapImage.height,
						0, GL_RGB, GL_BYTE, signedData);
		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);

		if(signedData)
			delete [] signedData;
		signedData=NULL;
		
		//Create specular ramp texture
		unsigned char specularRampValues[256];
		for(unsigned int i=0; i<256; i++)
		{
			double poweredValue=(double)i/255;
			//raise to 16th power
			poweredValue=	poweredValue*poweredValue*poweredValue*poweredValue*
							poweredValue*poweredValue*poweredValue*poweredValue*
							poweredValue*poweredValue*poweredValue*poweredValue*
							poweredValue*poweredValue*poweredValue*poweredValue;
			specularRampValues[i] = char(poweredValue*255);
		}

		glGenTextures(1, &specularRamp);
		glBindTexture(GL_TEXTURE_2D, specularRamp);
		glTexImage2D(	GL_TEXTURE_2D, 0, GL_RGBA8, 256, 1,
						0, GL_LUMINANCE, GL_UNSIGNED_BYTE, specularRampValues);
		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_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	}

	//reset timer for start
	timer.Reset();
	
	return true;
}