void Renderer::initialize( D3D& pd3d )
{
	this->d3d = &pd3d;
	gbuffer.initialize(pd3d);

	objectCB.initialize(pd3d);
	objectAnimationCB.initialize(pd3d);

	gpuEnv.initialize(pd3d);
	fxEnvironment.initialize(pd3d);

	fx::make_shade_gbuffer_ctx(d3d, &shade_gbuffer_ctx);
	fx::make_tonemap_ctx(d3d, &tonemap_ctx);


	animatedGeometryDrawer.initialize(pd3d, L"shaders/standard_animated.hlsl", gfx::eAnimatedStandard);
	standardGeometryDrawer.initialize(pd3d, L"shaders/standard.hlsl", gfx::eStandard);
	pointSpriteBokehDof.initialize(d3d, &gpuEnv);
	diffusionDof.initialize(d3d, &gpuEnv, &fxEnvironment);
	diffusionDofCR.initialize(d3d, &gpuEnv, &fxEnvironment);
	visualizeStructuredBuffer.initialize(d3d, &gpuEnv, &fxEnvironment);

	IFW1Factory *drawtext_fac;
	HRESULT hResult = FW1CreateFactory(FW1_VERSION, &drawtext_fac);

	hResult = drawtext_fac->CreateFontWrapper(d3d->device, L"Arial", &drawtext);
	drawtext_fac->Release();
}
Exemple #2
0
void TextClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* devCon)
{
	this->mDevice = device;
	this->mDevCon = devCon;

	FW1CreateFactory(FW1_VERSION, &mFW1Factory);
	// Comic sans mayhaps?
	mFW1Factory->CreateFontWrapper(mDevice, L"Lucida Console", &mFontWrapper);
}
bool PostPlayScreen::Load()
{
	D3DX11CreateShaderResourceViewFromFile( gScreenData->DEVICE, "DATA/POST_PLAY_SCREEN.png", 0, 0, &gBackground, 0 );

	IFW1Factory				*pFW1Factory = 0;
	FW1CreateFactory(FW1_VERSION, &pFW1Factory);
	pFW1Factory->CreateFontWrapper(gDevice, L"Apocalypse 1", &gTextInstance);
	pFW1Factory->Release();

	return true;
}
Exemple #4
0
Label::Label(cgl::PD3D11Effect pEffect, int x, int y, int width, int height)
	: cgl::drawing::CGLLabel(pEffect, width, height)
{
	SetX((float)x);
	SetY((float)y);

	m_pFactory = NULL;
	m_pFontWrapper = NULL;
	FW1CreateFactory(FW1_VERSION, &m_pFactory);

	m_pFactory->CreateFontWrapper(Device(), L"Consolas", &m_pFontWrapper);
}
D3D11TextRenderer::D3D11TextRenderer( ID3D11Device* pDevice, ID3D11DeviceContext* pDeviceContext, const std::string& font_name, const unsigned int font_size )
{
	this->pDeviceContext = pDeviceContext;
	this->font_size = font_size;
	this->font_name = std::wstring(font_name.begin(), font_name.end());
    this->font_name.assign(font_name.begin(), font_name.end());

	if( !pFW1Factory )	
		if( FAILED( FW1CreateFactory(FW1_VERSION, &pFW1Factory) ) )
			printf( "could not create factory\n" );

	if( font_wrappers.count(font_name) )
		pFontWrapper = font_wrappers[font_name];	
	else
	{
		if( FAILED( pFW1Factory->CreateFontWrapper(pDevice, L"Arial", &pFontWrapper) ) )
			printf( "could not create font wrappr\n" );
		font_wrappers[font_name] = pFontWrapper;
	}
}
Exemple #6
0
	bool Text::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext)
	{
		HRESULT result;
	
		D3D11_VIEWPORT vp = {0};
		UINT i = 1;
		deviceContext->RSGetViewports(&i, &vp);
		m_viewport = &D3D11_VIEWPORT(vp);

		//create the font wrapper
		IFW1Factory *pFW1Factory;
		result = FW1CreateFactory(FW1_VERSION, &pFW1Factory);
		if (FAILED(result)) { return false; }

		result = pFW1Factory->CreateFontWrapper(device, L"Arial", &m_fontwrapper);
		if (FAILED(result)) { return false; }

		pFW1Factory->Release();

		return true;
	}
Exemple #7
0
HRESULT BLOCO_API HumanView::VOnRestore()
{
	HRESULT hr = S_OK;

	// Initialize the font
	m_pFontFactory = NULL;
	FW1CreateFactory(FW1_VERSION, &m_pFontFactory);
	if(!m_pFontFactory)
	{
		return S_FALSE;
	}

	if(!m_pFont)
	{
		m_pFont = DEBUG_CLIENTBLOCK CD3D11Font(L"Arial");
	}
	if(!m_pFont->VCreate(m_pFontFactory))
	{
		return S_FALSE;
	}
	
	if( !m_pRenderer )
	{
		m_pRenderer = DEBUG_CLIENTBLOCK CD3D11Renderer();
	}
	if (!m_pRenderer->VOnRestore())
	{
		return S_FALSE;
	}

	for(ScreenElementList::iterator i=m_ScreenElements.begin(); i!=m_ScreenElements.end(); ++i)
	{
		( (*i)->VOnRestore() );
	}

	return hr;
}
D3DManager::D3DManager(HWND hwnd, int screenWidth, int screenHeight, bool fullscreen)
{
	HRESULT result;

	ID3D11Texture2D* backBufferPtr;
	D3D11_TEXTURE2D_DESC depthBufferDesc;
	D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
	D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
	D3D11_RASTERIZER_DESC rasterDesc;

	D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;

	//////////////////////////////////////////////////////////// Swap chain, device, device context, rtv //////////////////////////////////////////////////////////
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
	swapChainDesc.BufferCount = 1;

	swapChainDesc.BufferDesc.Width = screenWidth;
	swapChainDesc.BufferDesc.Height = screenHeight;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;

	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.OutputWindow = hwnd;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;

	if (fullscreen)
		swapChainDesc.Windowed = false;
	else
		swapChainDesc.Windowed = true;

	swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	swapChainDesc.Flags = 0;

	//Create the swap chain, device, and device context
	//result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, NULL, &deviceContext);
	result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, NULL, &deviceContext);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating swap chain");

	//Get the pointer to the back buffer
	result = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Could not get swap chain pointer");

	// Create the render target view with the back buffer pointer
	result = device->CreateRenderTargetView(backBufferPtr, NULL, &renderTargetView);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating render target view");

	backBufferPtr->Release();
	backBufferPtr = nullptr;

	//////////////////////////////////////////////////////////////////////// Depth buffer /////////////////////////////////////////////////////////////////////////
	ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));

	depthBufferDesc.Width = screenWidth;
	depthBufferDesc.Height = screenHeight;
	depthBufferDesc.MipLevels = 1;
	depthBufferDesc.ArraySize = 1;
	depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthBufferDesc.SampleDesc.Count = 1;
	depthBufferDesc.SampleDesc.Quality = 0;
	depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	depthBufferDesc.CPUAccessFlags = 0;
	depthBufferDesc.MiscFlags = 0;

	result = device->CreateTexture2D(&depthBufferDesc, NULL, &depthBuffer);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating depth buffer");

	///////////////////////////////////////////////////////////////////// Depth stencil states ////////////////////////////////////////////////////////////////////
	ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));

	depthStencilDesc.DepthEnable = true;
	depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
	depthStencilDesc.StencilEnable = true;
	depthStencilDesc.StencilReadMask = 0xFF;
	depthStencilDesc.StencilWriteMask = 0xFF;
	depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
	depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
	depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

	//Create depth enable
	result = device->CreateDepthStencilState(&depthStencilDesc, &dsDepthEnable);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating depth stencil ENABLE");

	depthStencilDesc.DepthEnable = false;

	//Create depth disable
	result = device->CreateDepthStencilState(&depthStencilDesc, &dsDepthDisable);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating depth stencil DISABLE");



	////////////////////////////////////////////////////////////////////// Depth stencil view /////////////////////////////////////////////////////////////////////
	ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));

	depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	depthStencilViewDesc.Texture2D.MipSlice = 0;

	result = device->CreateDepthStencilView(depthBuffer, &depthStencilViewDesc, &depthView);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating depth stencil view");

	///////////////////////////////////////////////////////////////////////// Raster states ///////////////////////////////////////////////////////////////////////
	rasterDesc.AntialiasedLineEnable = false;
	rasterDesc.CullMode = D3D11_CULL_BACK;
	rasterDesc.DepthBias = 0;
	rasterDesc.DepthBiasClamp = 0.0f;
	rasterDesc.DepthClipEnable = true;
	rasterDesc.FillMode = D3D11_FILL_SOLID;
	rasterDesc.FrontCounterClockwise = false;
	rasterDesc.MultisampleEnable = false;
	rasterDesc.ScissorEnable = false;
	rasterDesc.SlopeScaledDepthBias = 0.0f;

	//Create raster state BACK
	result = device->CreateRasterizerState(&rasterDesc, &rsBackCulling);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating raster state BACK");

	//Create raster state FRONT
	rasterDesc.CullMode = D3D11_CULL_FRONT;
	result = device->CreateRasterizerState(&rasterDesc, &rsFrontCulling);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating raster state FRONT");

	//Create raster state FRONT
	rasterDesc.CullMode = D3D11_CULL_NONE;
	result = device->CreateRasterizerState(&rasterDesc, &rsNoCulling);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating raster state NONE");

	////////////////////////////////////////////////////////////////////////// FontWrapper ////////////////////////////////////////////////////////////////////////
	result = FW1CreateFactory(FW1_VERSION, &FW1Factory);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating FW1Factory");

	result = FW1Factory->CreateFontWrapper(device, L"Arial", &fontWrapper);
	if (FAILED(result))
		throw std::runtime_error("D3DManager: Error creating FontWrapper");

	///////////////////////////////////////////////////////////////////////////// Other ///////////////////////////////////////////////////////////////////////////

	//Setup the viewport for rendering
	viewport.Width = (float)screenWidth;
	viewport.Height = (float)screenHeight;
	viewport.MinDepth = 0.0f;
	viewport.MaxDepth = 1.0f;
	viewport.TopLeftX = 0.0f;
	viewport.TopLeftY = 0.0f;

	deviceContext->OMSetDepthStencilState(dsDepthEnable, 1);
	deviceContext->OMSetRenderTargets(1, &renderTargetView, depthView);
	deviceContext->RSSetState(rsBackCulling);
	deviceContext->RSSetViewports(1, &viewport);
}
Exemple #9
0
	dx11render::dx11render(ID3D11Device* device, IDXGISwapChain* swapChain) : m_device(device), m_swapChain(swapChain)
	{
		if (m_device == NULL && m_swapChain)
			m_swapChain->GetDevice(__uuidof(m_device), (void**)&m_device);
		HRESULT hResult = FW1CreateFactory(FW1_VERSION, &m_fontFactory);
		if (SUCCEEDED(hResult))
		{
			log.write(log.INFO, "Created font factory\n");
		}
		else
		{
			log.write(log.ERRO, "Error creating font factory\n");
			return;
		}

		ID3DBlob* compiledFX = NULL;
		HRESULT hr = compileShaderFromMem(fillfx, sizeof fillfx, "FillFx.fx", "FillTech", "fx_5_0", &compiledFX);

		if (SUCCEEDED(hr))
		{
			log.write(log.INFO, "Compiled fillfx shader\n");
		}

		hr = D3DX11CreateEffectFromMemory( compiledFX->GetBufferPointer(), compiledFX->GetBufferSize(), 0, m_device, &m_pEffect );

		if (SUCCEEDED(hr))
		{
			log.write(log.INFO, "Created effect from shader\n");
		}

		compiledFX->Release();
		m_pTechnique = m_pEffect->GetTechniqueByName( "FillTech" );
		if (m_pTechnique)
		{
			log.write(log.INFO, "Success getting 'FillTech' technique\n");
		}

		D3D11_INPUT_ELEMENT_DESC lineRectLayout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },  
			{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
		};

		D3DX11_PASS_DESC passDesc;

		if( FAILED( m_pTechnique->GetPassByIndex( 0 )->GetDesc( &passDesc ) ) )
		{
			log.write(log.ERRO, "Failed to GetPassByIndex\n");
			return;
		}

		if( FAILED( m_device->CreateInputLayout( 
			lineRectLayout, 
			sizeof( lineRectLayout ) / sizeof( lineRectLayout[0] ), 
			passDesc.pIAInputSignature, 
			passDesc.IAInputSignatureSize, 
			&m_pInputLayout ) ) )
		{
			log.write(log.INFO, "Failed to CreateInputLayout\n");
			return;
		}

		D3D11_BUFFER_DESC bufferDesc;

		bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
		bufferDesc.ByteWidth = 4 * sizeof( COLOR_VERTEX );
		bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		bufferDesc.MiscFlags = 0;

		if( FAILED( m_device->CreateBuffer( &bufferDesc, NULL, &m_pVertexBuffer ) ) )
		{
			log.write(log.ERRO, "device->CreateBuffer failed\n");
			return;
		}
		log.write(log.INFO, "Success initializing DX11 draw resources\n");
	}
Exemple #10
0
 FontFactory::FontFactory() : fw1Factory(nullptr) {
     if (FAILED(FW1CreateFactory(FW1_VERSION, &fw1Factory))) {
         throw Exception("FontFactory: Cannot create FW1Factory.");
     }
 }