Пример #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();
    SetUpEXT_texture3D();
    SetUpEXT_texture_edge_clamp();
    SetUpNV_register_combiners();
    SetUpNV_texture_shader();
    SetUpNV_vertex_program();

    if(	!EXT_texture_edge_clamp_supported || !ARB_multitexture_supported ||
            !NV_vertex_program_supported || !NV_register_combiners_supported)
        return false;

    //Check we have at least 3 texture units
    GLint maxTextureUnitsARB;
    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB);

    if(maxTextureUnitsARB<3)
    {
        errorLog.OutputError("I require at least 3 texture units");
        return false;
    }

    //Set light colors
    lightColors[0].Set(1.0f, 1.0f, 1.0f, 1.0f);
    lightColors[1].Set((float)47/255, (float)206/255, (float)240/255, 1.0f);
    lightColors[2].Set((float)254/255, (float)48/255, (float)18/255, 1.0f);
    lightColors[3].Set((float)83/255, (float)243/255, (float)29/255, 1.0f);



    //Load textures
    //Decal image
    decalImage.Load("decal.tga");
    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 light textures
    if(!InitLightTextures(	atten1DTexture, atten2DTexture, atten3DTexture,
                            gaussian1DTexture, gaussian2DTexture))
        return false;


    camera.Init(VECTOR3D(0.0f, 0.0f, 3.5f));

    //reset timer for start
    timer.Reset();

    return true;
}
Пример #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;
}