Original Post
So, over the weekend I decided to look into this D3D10 lark and generally fiddle with 'stuff', however despite things not crashing my output isn't quite right and I'm having a hard time spotting why [smile] In short, I'm trying to draw a quad on the X-Z plane (which I'm assuming is flat with Y up, but that's kinda by the by), however what I'm getting is a flicking mess which seems to indicate I've screwed up somewhere [grin] I've checked over MSDN a few times and while I can't see anything off hand I'm new to this D3D10 game so I might have just missed something subtle, who knows. anyways, enough jabbering, onto the code! Setup; and render; For the record the referenced variables are the right sort (as noted it neither crashes nor gives me any warnings in the debug output). I'm using the DXUT framework for current window setup and copied the code from the D3D10 skinning example, stripping out bits which weren't directly related to what I was doing (mostly the skinning example stuff). The render thread is fed via the following chunk of code; edit: crud, forgot the .fx file; And if it makes any difference I'm running in x64 mode and on an NV 8800GT card. OK, feel free to point out my stupid mistake now [grin]
HRESULT CreatePlane(ID3D10Device* pd3dDevice)
{
HRESULT hr;
// Read the D3DX effect file
WCHAR str[MAX_PATH];
V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"md5renderer.fx" ) );
DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3D10_SHADER_DEBUG;
#endif
V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL, NULL, &g_pPlaneEffect10, NULL, NULL ) );
// Get effects techniques
g_pPlaneRenderModel = g_pPlaneEffect10->GetTechniqueByName("RenderModelBasic");
// Get effects variables
g_pmPlaneWorldViewProj = g_pPlaneEffect10->GetVariableByName( "g_mWorldViewProj" )->AsMatrix();
g_pmPlaneWorld = g_pPlaneEffect10->GetVariableByName( "g_mWorld" )->AsMatrix();
const D3D10_INPUT_ELEMENT_DESC datalayout[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};
const int numElements = sizeof(datalayout)/sizeof(datalayout[0]);
D3D10_PASS_DESC PassDesc;
g_pPlaneRenderModel->GetPassByIndex( 0 )->GetDesc( &PassDesc );
V_RETURN( pd3dDevice->CreateInputLayout( datalayout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &PlanemodelInputLayout ) );
float vertexdata[] =
{
1,0,1,0,1,0,
1,0,-1,0,1,0,
-1,0,-1,0,1,0,
-1,0,1,0,1,0
};
// next we need to create a VB and IB pair for the data
D3D10_BUFFER_DESC vb;
vb.Usage = D3D10_USAGE_DEFAULT;
vb.ByteWidth = sizeof(float) * 24;
vb.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vb.CPUAccessFlags = 0;
vb.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA VertInitData;
VertInitData.pSysMem = vertexdata;
VertInitData.SysMemPitch = 0;
VertInitData.SysMemSlicePitch = 0;
V_RETURN(pd3dDevice->CreateBuffer(&vb, &VertInitData, &g_pPlaneVertexBuffer));
// unsigned int indices[] = {3,2,0,0,2,1 };
unsigned int indices[] = {0,2,1,2,0,3 };
D3D10_BUFFER_DESC bufferDesc;
bufferDesc.Usage = D3D10_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof(unsigned int) * 6;
bufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA InitData;
InitData.pSysMem = indices;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
hr = pd3dDevice->CreateBuffer( &bufferDesc, &InitData, &g_pPlaneIndexBuffer );
return hr;
}
void RenderPlane(ID3D10Device* pd3dDevice, D3DXMATRIX &mViewProj)
{
D3DXMATRIX mWorld;
D3DXMatrixIdentity( &mWorld );
D3DXMATRIX mWorldViewProj = mWorld * mViewProj;
g_pmPlaneWorldViewProj->SetMatrix( (float*)&mWorldViewProj );
g_pmPlaneWorld->SetMatrix( (float*)&mWorld );
pd3dDevice->IASetInputLayout( PlanemodelInputLayout );
// Set vertex buffer
UINT stride = sizeof( float ) * 6;
UINT offset = 0;
pd3dDevice->IASetVertexBuffers( 0, 1, &g_pPlaneVertexBuffer, &stride, &offset );
pd3dDevice->IASetIndexBuffer( g_pPlaneIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );
D3D10_TECHNIQUE_DESC techDesc;
g_pPlaneRenderModel->GetDesc( &techDesc );
for(int i = 0; i < techDesc.Passes; i++)
{
pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
g_pPlaneRenderModel->GetPassByIndex( i )->Apply(0);
// pd3dDevice->DrawIndexed(meshes_[0].tri_indices_.size(), 0,0);
pd3dDevice->DrawIndexed(6, 0, 0);
}
return;
}
D3DXMATRIX mWorldViewProj;
D3DXMATRIX mViewProj;
D3DXMATRIX mWorld;
D3DXMATRIX mView;
D3DXMATRIX mProj;
float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f };
ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
// Clear the depth stencil
ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );
// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
// Get the projection & view matrix from the camera class
D3DXMatrixIdentity( &mWorld );
mProj = *g_Camera.GetProjMatrix();
mView = *g_Camera.GetViewMatrix();
mViewProj = mView * mProj;
RenderPlane(pd3dDevice,mViewProj);
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
RenderText();
g_HUD.OnRender( fElapsedTime );
g_SampleUI.OnRender( fElapsedTime );
DXUT_EndPerfEvent();
// MD5 rendering .fx file
struct VSDataIn
{
float3 Pos : POSITION;
float3 Norm : NORMAL;
};
struct PSDataIn
{
float4 Pos : SV_Position;
float4 vPos : POSWORLD;
float3 Norm : NORMAL;
};
// Constant buffers
cbuffer cb0
{
float4x4 g_mWorldViewProj;
float4x4 g_mWorld;
};
// State
DepthStencilState EnableDepth
{
DepthEnable = TRUE;
DepthWriteMask = ALL;
};
// Vertex Shader
PSDataIn VSSimpleBind(VSDataIn input)
{
PSDataIn output;
output.Pos = mul (input.Pos, g_mWorldViewProj);
output.vPos = mul (input.Pos, g_mWorld );
output.Norm = normalize(mul(input.Norm, (float3x3)g_mWorld));
return output;
}
// Fragment shader
float4 PSSimpleShader(PSDataIn input) : SV_Target
{
return float4(1.0, 1.0, 1.0, 1.0);
}
// Technique
technique10 RenderModelBasic
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VSSimpleBind() ) );
SetGeometryShader ( NULL );
SetPixelShader( CompileShader( ps_4_0, PSSimpleShader() ) );
SetDepthStencilState( EnableDepth, 0 );
}
}