コード例 #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()
{
	if(!window.Init("Render To Texture", 640, 480, 32, 24, 8, WINDOWED_SCREEN))
		return 0;											//quit if not created

	camera.Init(VECTOR3D(0.0f, 0.0f, -2.5f), 2.0f, 100.0f);

	//Set up extensions
	if(	!SetUpWGL_ARB_extensions_string())
		return false;

	SetUpEXT_texture_filter_anisotropic();
	SetUpSGIS_generate_mipmap();
		
	//Get the WGL extensions string
	const char * wglExtensions;
	wglExtensions=wglGetExtensionsStringARB(window.hDC);

	//Set up wgl extensions
	if(	!SetUpWGL_ARB_pbuffer(wglExtensions) || !SetUpWGL_ARB_pixel_format(wglExtensions) ||
		!SetUpWGL_ARB_render_texture(wglExtensions))
		return false;


	//Init the pbuffer
	int pbufferExtraIAttribs[]={WGL_BIND_TO_TEXTURE_RGBA_ARB, true,
								0};

	int pbufferFlags[]={WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
						WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
						
						//request mipmap space if mipmaps are to be used
						SGIS_generate_mipmap_supported ? WGL_MIPMAP_TEXTURE_ARB : 0,
						SGIS_generate_mipmap_supported ? true : 0,

						0};

	if(!pbuffer.Init(pbufferSize, pbufferSize, 32, 24, 8, 1, pbufferExtraIAttribs, pbufferFlags))
		return false;
	

	//Create the texture object to relate to the pbuffer
	glGenTextures(1, &pbufferTexture);
	glBindTexture(GL_TEXTURE_2D, pbufferTexture);
	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);

	//Use generated mipmaps if supported
	if(SGIS_generate_mipmap_supported)
	{
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
		useMipmapFilter=true;
	}

	//Use maximum anisotropy if supported
	if(EXT_texture_filter_anisotropic_supported)
	{
		glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
		currentAnisotropy=maxAnisotropy;
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy);
	}



	//Load the decal texture
	//Note: This MUST be done when the pbuffer is the current context
	pbuffer.MakeCurrent();
	
	IMAGE decalImage;
	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);


	
	//reset timer for start
	timer.Reset();
	
	return true;
}
コード例 #3
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;
}