Beispiel #1
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;
}
Beispiel #2
0
bool WINDOW::Init(	char * windowTitle, int newWidth, int newHeight,
					int newRedBits, int newGreenBits, int newBlueBits, int newAlphaBits,
					int newDepthBits, int newStencilBits,
					bool newFullscreen, bool newVSync, bool dialogBox)
{
	//Set member variables
	title=windowTitle;
	
	width=newWidth;
	height=newHeight;
	redBits=newRedBits;
	greenBits=newGreenBits;
	blueBits=newBlueBits;
	alphaBits=newAlphaBits;
	depthBits=newDepthBits;
	stencilBits=newStencilBits;
	fullscreen=newFullscreen;
	vSync=newVSync;

	LOG::Instance()->OutputSuccess("Creating temporary window");
	LOG::Instance()->OutputNewLine();

	//Init dummy window to get extension pointers
	if(!InitDummy())
		return false;
	
	LOG::Instance()->OutputNewLine();

	bool revertToStandard=false;

	//Initiate the WGL extensions. If not supported, use the standard window
	if(	!SetUpWGL_ARB_extensions_string())
		revertToStandard=true;
		
	//If ARB_extensions_string is supported,
	if(!revertToStandard)
	{
		//Get the WGL extensions string
		const char * wglExtensions;
		wglExtensions=wglGetExtensionsStringARB(hDC);
	
		//If the necessary extensions are not supported, use the standard window
		if(	!SetUpWGL_ARB_pixel_format(wglExtensions)	||
			!SetUpWGL_EXT_swap_control(wglExtensions))
			revertToStandard=true;
	
		//Also initialise ARB_multisample
		SetUpWGL_ARB_multisample(wglExtensions);
	}

	//If we need to revert to standard, shut down the dummy window, Create standard window
	//and return
	if(revertToStandard)
	{
		LOG::Instance()->OutputNewLine();
		LOG::Instance()->OutputSuccess("Destroying temporary window");
	
		ShutdownDummy();

		LOG::Instance()->OutputNewLine();
		LOG::Instance()->OutputSuccess("Replacing with standard, non WGL_extension window");
		LOG::Instance()->OutputNewLine();

		InitStandard();

		return true;
	}

	//If we have reached here, the ARB extensions are supported.
	//Shutdown this window and create a window using ARB_pixel_format etc

	//Find supported AA samples with given color bits, if ARB_multisample is supported
	for(int i=0; i<17; ++i)
		samplesSupported[i]=false;

	if(WGL_ARB_multisample_supported)
	{
		FindSamplesSupported();
	}
	else
	{
		samplesSupported[0]=true;
	}

	//Destroy temporary window
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputSuccess("Destroying temporary window");
	
	ShutdownDummy();

	//Creat WGL extension window
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputSuccess("Replacing with WGL_extension window");
	LOG::Instance()->OutputNewLine();

	if(InitExtended(dialogBox))
		return true;

	//If we reached here, InitExtended failed.
	//Try a standard window as a last resort

	//Destroy extended window
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputSuccess("Extended window creation failed - Destroying");
	
	ShutdownDummy();	//Use ShutdownDummy as we have not hidden the cursor yet.
						//So, we do not want the call to show it

	//Create standard window
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputSuccess("Replacing with standard window");
	LOG::Instance()->OutputNewLine();

	if(InitStandard())
		return true;

	//All window creation attempts failed
	LOG::Instance()->OutputNewLine();
	LOG::Instance()->OutputError("All window Creation attempts failed!");
	Shutdown();
	return false;
}