Jump to content

  • Log In with Google      Sign In   
  • Create Account


thefatshizms

Member Since 05 Jul 2013
Offline Last Active Sep 17 2014 01:00 AM

Topics I've Started

class design

01 September 2014 - 01:32 PM

Okay so I'm creating a small game engine based in directx11 (both for educaational purposes and fun) and I've come into a bit of bother with designing my c++ classes. Basically I want to have a default graphics class which will do all the minimum required stuff for directx and then I have sub classes which will inherit from this class so I can use functions like onrender etc. This is where I've got an issue... I'm not sure how to make it so I can create my subclasses and inherit these functions easily without adding their onrender functions etc to the programs main loop in order for them to be called. I hope this makes sense... I'm on my mobile so its hard to type. In conclusion I want to be able to make subclasses or "subsystems" in which the functions that they've overwritten/etc get automatically called in the main loop without having to create an object of every class and calling the function.

If you need more explaining please say so.

High cpu usage

05 August 2014 - 07:11 PM

Okay so I'm having a slight problem with cpu usage with my directx 11 application. The cpu usage isn't that high but for the things it's doing (which isn't a lot, rendering 2 cubes with textures and then rotating etc) it shouldn't be that high.

 

4a87a81aa5.png

 

The code is located at: https://github.com/thefatshizms/MEngine/tree/master/src

 

Sorry, at the moment the code is in a bit of a state and I'll clean it up tomorrow.


World, view & projection spaces

17 December 2013 - 04:26 PM

Was trying to do this tutorial: http://www.braynzarsoft.net/index.php?p=D3D11WVP

 

After compiling it crashes with this message: Unhandled exception at 0x008F1CDA in Directx11.exe: 0xC0000005: Access violation reading location 0x00000000.

 

and highlights this line:  g_Device->CreateVertexShader( pVertexShaderBytecode->GetBufferPointer(), pVertexShaderBytecode->GetBufferSize(), NULL, &g_pVertexShader );

 

Full code:

#include "directx.h"
#include <D3Dcompiler.h>

struct Vertex {
	DirectX::XMFLOAT3 position;
	DirectX::XMFLOAT4 color;
};

struct PerObject
{
	DirectX::XMMATRIX  WVP;
};

PerObject PerObj;

Vertex triangle[] = {

	DirectX::XMFLOAT3( -0.5f, -0.5f, 0.5f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f ),
	DirectX::XMFLOAT3( -0.5f,  0.5f, 0.5f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f ),
	DirectX::XMFLOAT3(  0.5f,  0.5f, 0.5f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f ),
	DirectX::XMFLOAT3(  0.5f, -0.5f, 0.5f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f ),
};

Directx::Directx() : g_Swapchain(NULL), g_Device(NULL), g_Devicecontext(NULL), g_Rendertarget(NULL){}

Directx::~Directx() {}

bool Directx::InitializeD3D(HWND hwnd, int width, int height, bool fullscreen) { 
	
	DXGI_SWAP_CHAIN_DESC sd;

	ZeroMemory(&sd, sizeof(sd));

	sd.BufferCount = 1;
    sd.BufferDesc.Width = width;
    sd.BufferDesc.Height = height;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = hwnd;
    sd.SampleDesc.Count = 4;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = (fullscreen) ? false : true;


	D3D_FEATURE_LEVEL featurelevels[] = 
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_1,
	};

	int numfeaturelevels = 5;

	if(FAILED(D3D11CreateDeviceAndSwapChain(NULL,  D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, featurelevels, numfeaturelevels, D3D11_SDK_VERSION, &sd, &g_Swapchain, &g_Device, NULL, &g_Devicecontext)))
		return false;


	ID3D11Texture2D *pBackBuffer;
	HRESULT hr;

	if(FAILED(g_Swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer)))
			return false;

	hr = g_Device->CreateRenderTargetView(pBackBuffer, NULL, &g_Rendertarget);
	pBackBuffer->Release();

	if(FAILED(hr))
			return false;

	g_Devicecontext->OMSetRenderTargets(1, &g_Rendertarget, g_DepthStencilview);

	D3D11_VIEWPORT vp;

	vp.Height = (FLOAT)height;
	vp.Width = (FLOAT)width;
	vp.MaxDepth = 1.0f;
	vp.MinDepth = 0.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;

	D3D11_TEXTURE2D_DESC depthstencil;

	ZeroMemory(&depthstencil, sizeof(depthstencil));

	depthstencil.Width = width;
	depthstencil.Height = height;
	depthstencil.MipLevels = 1;
	depthstencil.ArraySize = 1;
	depthstencil.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthstencil.SampleDesc.Count = 1;
	depthstencil.SampleDesc.Quality = 0;
	depthstencil.Usage = D3D11_USAGE_DEFAULT;
	depthstencil.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	depthstencil.CPUAccessFlags = 0;
	depthstencil.MiscFlags = 0;

	g_Device->CreateTexture2D(&depthstencil, NULL, &g_Depthbuffer);
	g_Device->CreateDepthStencilView(g_Depthbuffer, NULL, &g_DepthStencilview);

	g_Devicecontext->RSSetViewports(1, &vp);

	D3D11_BUFFER_DESC cb;

	cb.Usage = D3D11_USAGE_DEFAULT;
	cb.ByteWidth = sizeof(g_PerObjectbuffer);
	cb.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	cb.CPUAccessFlags = 0;
	cb.MiscFlags = 0;

	g_Device->CreateBuffer(&cb, NULL, &g_PerObjectbuffer);

	camPosition = DirectX::XMVectorSet(0.0f, 0.0f, -0.5f, 0.0f);
	camTarget = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	camUp = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	camView = DirectX::XMMatrixLookAtLH(camPosition, camTarget, camUp);

	camProjection = DirectX::XMMatrixPerspectiveFovLH(0.4f * 3.14f, (float)width/height, 1.0f, 1000.0f);

	return true; 
}

void Directx::Render() {

	float ClearColor[4] = { 0.0f, 0.125f, 0.6f, 1.0f };
	g_Devicecontext->ClearRenderTargetView(g_Rendertarget, ClearColor);
	g_Devicecontext->ClearDepthStencilView(g_DepthStencilview, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	World = DirectX::XMMatrixIdentity();

	WVP = World * camView * camProjection;

	PerObj.WVP = DirectX::XMMatrixTranspose(WVP);

	g_Devicecontext->UpdateSubresource(g_PerObjectbuffer, 0, NULL, &PerObj, 0, 0);
	g_Devicecontext->VSGetConstantBuffers(0, 1, &g_PerObjectbuffer);


	g_Devicecontext->DrawIndexed(6, 0, 0);
	g_Swapchain->Present(0, 0);
}

void Directx::DrawTriangle() {

	DWORD indices[] = {
		0, 1, 2,
		0, 2, 3,
	};

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));

	bd.ByteWidth = sizeof(DWORD) * 2 * 3;
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	bd.CPUAccessFlags = 0;
	bd.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA data;

	ZeroMemory(&data, sizeof(data));

	data.pSysMem = indices;
	g_Device->CreateBuffer(&bd, &data, &g_Indexbuffer);

	g_Devicecontext->IASetIndexBuffer(g_Indexbuffer, DXGI_FORMAT_R32_UINT, 0);

	D3D11_BUFFER_DESC vertexBufferDesc;
	ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );

	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof( Vertex ) * 4;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA vertexBufferData; 

	ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
	vertexBufferData.pSysMem = triangle;
	g_Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &g_Vertexbuffer);


	CHAR* pVertexShaderCode =   "cbuffer cbPerObject { float4x4 WVP;};"
							"void vertex_shader( in float4 posIn : POSITION, in float4 colorIn : COLOR,"
                            "out float4 posOut : SV_POSITION, out float4 colorOut : COLOR )"
                            "{ VS_OUTPUT output; posOut = posIn; output.Pos = mul(inPos, WVP);"
                            "  colorOut = colorIn; return output; }";

	CHAR* pPixelShaderCode =    "float4 pixel_shader( VS_OUTPUT input) : SV_TARGET"    
                            "{ return input.color; }";

	ID3D10Blob* pVertexShaderBytecode = NULL;  
    ID3D10Blob* pCompileErrors = NULL;
	
	D3DCompile(pVertexShaderCode, lstrlenA( pVertexShaderCode ) + 1, "vertex shader", NULL, NULL, "vertex_shader", "vs_4_0", NULL, 0, &pVertexShaderBytecode, &pCompileErrors );                  
  
    if( pCompileErrors != NULL ) {         
		OutputDebugStringA( (CHAR*)pCompileErrors->GetBufferPointer() );    
        pCompileErrors->Release();   
    }   


    g_Device->CreateVertexShader( pVertexShaderBytecode->GetBufferPointer(), pVertexShaderBytecode->GetBufferSize(), NULL, &g_pVertexShader );      


    ID3D10Blob* pPixelShaderBytecode = NULL;  
    D3DCompile( pPixelShaderCode, lstrlenA( pPixelShaderCode ) + 1, "pixel shader", NULL, NULL, "pixel_shader", "ps_4_0", NULL, 0, &pPixelShaderBytecode, &pCompileErrors );    
        
	
	if( pCompileErrors != NULL ) {          
        OutputDebugStringA( (CHAR*)pCompileErrors->GetBufferPointer() );      
        pCompileErrors->Release();    
    }     



    g_Device->CreatePixelShader( pPixelShaderBytecode->GetBufferPointer(), pPixelShaderBytecode->GetBufferSize(), NULL, &g_pPixelShader );    
    pPixelShaderBytecode->Release();  



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

    UINT numElements = ARRAYSIZE( inputLayoutDesc );

    g_Device->CreateInputLayout( inputLayoutDesc, numElements, pVertexShaderBytecode->GetBufferPointer(), pVertexShaderBytecode->GetBufferSize(), &g_pInputLayout );    
    pVertexShaderBytecode->Release();    

    
    g_Devicecontext->IASetInputLayout( g_pInputLayout ); 
    UINT stride = sizeof( Vertex );  
    UINT offset = 0; 
    g_Devicecontext->IASetVertexBuffers(0, 1, &g_Vertexbuffer, &stride, &offset );       

    g_Devicecontext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );  

    g_Devicecontext->VSSetShader( g_pVertexShader, NULL, 0 );   
    g_Devicecontext->PSSetShader( g_pPixelShader, NULL, 0 );

}

void Directx::ShutdownDirectx() {

	g_Swapchain->Release();
	g_Device->Release();
	g_Devicecontext->Release();
	g_Rendertarget->Release();
	g_Vertexbuffer->Release();
	g_Indexbuffer->Release();
	g_pPixelShader->Release();
	g_pInputLayout->Release();
	g_pVertexShader->Release();
	g_Depthbuffer->Release();
	g_DepthStencilview->Release();
	g_PerObjectbuffer->Release();
}

Square not showing

03 December 2013 - 03:43 PM

Okay I've managed to create a triangle within directx11 so I tried making a square but it seems that nothing is being show (http://puu.sh/5yiWg.png)

 

Here's the code:

#include "directx.h"
#include <D3Dcompiler.h>

struct Vertex {
	DirectX::XMFLOAT3 position;
	DirectX::XMFLOAT4 color;
};

Vertex triangle[] = {

	DirectX::XMFLOAT3( -0.5f, -0.5f, 0.5f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f ),
	DirectX::XMFLOAT3( -0.5f,  0.5f, 0.5f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f ),
	DirectX::XMFLOAT3(  0.5f,  0.5f, 0.5f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f ),
	DirectX::XMFLOAT3(  0.5f, -0.5f, 0.5f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f ),
};

Directx::Directx() : g_Swapchain(NULL), g_Device(NULL), g_Devicecontext(NULL), g_Rendertarget(NULL){}

Directx::~Directx() {}

bool Directx::InitializeD3D(HWND hwnd, int width, int height, bool fullscreen) { 
	
	DXGI_SWAP_CHAIN_DESC sd;

	ZeroMemory(&sd, sizeof(sd));

	sd.BufferCount = 1;
    sd.BufferDesc.Width = width;
    sd.BufferDesc.Height = height;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = hwnd;
    sd.SampleDesc.Count = 4;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = TRUE;


	D3D_FEATURE_LEVEL featurelevels[] = 
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_1,
	};

	int numfeaturelevels = 5;

	if(FAILED(D3D11CreateDeviceAndSwapChain(NULL,  D3D_DRIVER_TYPE_HARDWARE, NULL, 0, featurelevels, numfeaturelevels, D3D11_SDK_VERSION, &sd, &g_Swapchain, &g_Device, NULL, &g_Devicecontext)))
		return false;

	ID3D11Texture2D *pBackBuffer;
	HRESULT hr;

	if(FAILED(g_Swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer)))
			return false;

	hr = g_Device->CreateRenderTargetView(pBackBuffer, NULL, &g_Rendertarget);
	pBackBuffer->Release();

	if(FAILED(hr))
			return false;
	g_Devicecontext->OMSetRenderTargets(1, &g_Rendertarget, NULL);

	D3D11_VIEWPORT vp;

	vp.Height = (FLOAT)height;
	vp.Width = (FLOAT)width;
	vp.MaxDepth = 1.0f;
	vp.MinDepth = 0.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;

	g_Devicecontext->RSSetViewports(1, &vp);


	return true; 
}

void Directx::Render() {

	float ClearColor[4] = { 0.0f, 0.125f, 0.6f, 1.0f };
	g_Devicecontext->ClearRenderTargetView(g_Rendertarget, ClearColor);
	g_Devicecontext->DrawIndexed(6, 0, 0);
	g_Swapchain->Present(0, 0);
}

void Directx::DrawTriangle() {

	DWORD indices[] = {
		0, 1, 2,
		0, 2, 3,
	};

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));

	bd.ByteWidth = sizeof(DWORD) * 2 * 3;
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.BindFlags = D3D11_BIND_INDEX_BUFFER;

	D3D11_SUBRESOURCE_DATA data;

	ZeroMemory(&data, sizeof(data));

	data.pSysMem = indices;
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.ByteWidth = sizeof( Vertex ) * 4;
	bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bd.CPUAccessFlags = 0;
	bd.MiscFlags = 0;
	g_Device->CreateBuffer(&bd, &data, &g_buffer);

	g_Devicecontext->IASetIndexBuffer(g_buffer, DXGI_FORMAT_R32_UINT, 0);

	


	CHAR* pVertexShaderCode =   "void vertex_shader( in float4 posIn : POSITION, in float4 colorIn : COLOR,"
                            "out float4 posOut : SV_POSITION, out float4 colorOut : COLOR )"
                            "{ posOut = posIn;"
                            "  colorOut = colorIn; }";

	CHAR* pPixelShaderCode =    "float4 pixel_shader( float4 pos : SV_POSITION, float4 color: COLOR) : SV_TARGET"    
                            "{ return color; }";

	ID3D10Blob* pVertexShaderBytecode = NULL;  
    ID3D10Blob* pCompileErrors = NULL;
	
	D3DCompile(pVertexShaderCode, lstrlenA( pVertexShaderCode ) + 1, "vertex shader", NULL, NULL, "vertex_shader", "vs_4_0", NULL, 0, &pVertexShaderBytecode, &pCompileErrors );                  
  
    if( pCompileErrors != NULL ) {         
		OutputDebugStringA( (CHAR*)pCompileErrors->GetBufferPointer() );    
        pCompileErrors->Release();   
    }   


    g_Device->CreateVertexShader( pVertexShaderBytecode->GetBufferPointer(), pVertexShaderBytecode->GetBufferSize(), NULL, &g_pVertexShader );   


    ID3D10Blob* pPixelShaderBytecode = NULL;  
    D3DCompile( pPixelShaderCode, lstrlenA( pPixelShaderCode ) + 1, "pixel shader", NULL, NULL, "pixel_shader", "ps_4_0", NULL, 0, &pPixelShaderBytecode, &pCompileErrors );    
        
	
	if( pCompileErrors != NULL ) {          
        OutputDebugStringA( (CHAR*)pCompileErrors->GetBufferPointer() );      
        pCompileErrors->Release();    
    }     



    g_Device->CreatePixelShader( pPixelShaderBytecode->GetBufferPointer(), pPixelShaderBytecode->GetBufferSize(), NULL, &g_pPixelShader );    
    pPixelShaderBytecode->Release();  



    D3D11_INPUT_ELEMENT_DESC inputLayoutDesc[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
    };

    UINT numElements = ARRAYSIZE( inputLayoutDesc );

    g_Device->CreateInputLayout( inputLayoutDesc, numElements, pVertexShaderBytecode->GetBufferPointer(), pVertexShaderBytecode->GetBufferSize(), &g_pInputLayout );    
    pVertexShaderBytecode->Release();    

    
    g_Devicecontext->IASetInputLayout( g_pInputLayout ); 
    UINT stride = sizeof( Vertex );  
    UINT offset = 0; 
    g_Devicecontext->IASetVertexBuffers(0, 1, &g_buffer, &stride, &offset );       

    g_Devicecontext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );  

    g_Devicecontext->VSSetShader( g_pVertexShader, NULL, 0 );   
    g_Devicecontext->PSSetShader( g_pPixelShader, NULL, 0 );

}

void Directx::ShutdownDirectx() {

	g_Swapchain->Release();
	g_Device->Release();
	g_Devicecontext->Release();
	g_Rendertarget->Release();
	g_buffer->Release();
	g_pPixelShader->Release();
	g_pInputLayout->Release();
	g_pVertexShader->Release();
}

Direct x failing

05 July 2013 - 12:51 PM

I have the following code:

HRESULT result = S_OK;
	ID3D11Device* g_pd3dDevice = NULL;
	IDXGISwapChain* g_pSwapChain = NULL;
	ID3D11DeviceContext* g_pImmediateContext = NULL;
	D3D_FEATURE_LEVEL	FeatureLevelsSupported;

	RECT deminsions;
	GetClientRect(hwnd, &deminsions);
	LONG width = deminsions.right - deminsions.left;
	LONG height = deminsions.top - deminsions.bottom;

	DXGI_SWAP_CHAIN_DESC sd;
	ZeroMemory( &sd, sizeof( sd ) );
	sd.BufferCount = 1;
	sd.BufferDesc.Width = static_cast<unsigned int>(width);
	sd.BufferDesc.Height = static_cast<unsigned int>(height);
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.OutputWindow = hwnd;
	sd.SampleDesc.Count = 1;
	sd.SampleDesc.Quality = 0;
	sd.Windowed = TRUE;

	D3D_FEATURE_LEVEL FeatureLevelsRequested[] =
	{
		D3D_FEATURE_LEVEL_9_1,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_11_0
	};

	result = D3D11CreateDeviceAndSwapChain( NULL, 
                D3D_DRIVER_TYPE_HARDWARE, 
                NULL, 
                0,
                FeatureLevelsRequested, 
                3, 
                D3D11_SDK_VERSION, 
                &sd, 
                &g_pSwapChain, 
                &g_pd3dDevice, 
                &FeatureLevelsSupported,
                &g_pImmediateContext );

	if(FAILED(result)) return -1;


	ID3D11RenderTargetView* p_BackBufferTarget = NULL;
	ID3D11Texture2D* p_RT;

	result = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&p_RT);
	if(FAILED(result)) return -2;

	result = g_pd3dDevice->CreateRenderTargetView(p_RT, 0, &p_BackBufferTarget);
	if(FAILED(result)) return -3;
	if(p_RT) p_RT->Release(); p_RT = NULL;
	g_pImmediateContext->OMSetRenderTargets(1, &p_BackBufferTarget, 0);

	D3D11_VIEWPORT viewport;
	viewport.Height = static_cast<float>(height);
	viewport.Width = static_cast<float>(width);
	viewport.MaxDepth = 1.0f;
	viewport.MinDepth = 0.0f;
	viewport.TopLeftX = 0.0f;
	viewport.TopLeftY = 0.0f;

	g_pImmediateContext->RSSetViewports(1, &viewport);

    UpdateWindow(hwnd);

the program fails and returns -1 which means there is something wrong with this:

result = D3D11CreateDeviceAndSwapChain( NULL, 
                D3D_DRIVER_TYPE_HARDWARE, 
                NULL, 
                0,
                FeatureLevelsRequested, 
                3, 
                D3D11_SDK_VERSION, 
                &sd, 
                &g_pSwapChain, 
                &g_pd3dDevice, 
                &FeatureLevelsSupported,
                &g_pImmediateContext );

But I'm not sure what?

 

Thanks, thefatshizms


PARTNERS