After a lot of reading and googling I now have this in my render loop.
[edit] Totally changed from what I posted before
I think I am close now.
This is my render loop...
// Start Frame
float clearColor[4]={0.5f,0.5f,1.0f,1.0f};
d3dContext->ClearRenderTargetView(d3dBackBufferTarget,clearColor);
// tell DX11 to use this shader for the next renderable object
d3dContext->VSSetShader(pVS,0,0);
d3dContext->PSSetShader(pPS,0,0);
d3dContext->PSSetShaderResources(0,1,&colorMap);
d3dContext->PSSetSamplers(0,1,&colorMapSampler);
// Set up the view
XMMATRIX viewMatrix=XMMatrixIdentity();
XMMATRIX projMatrix=XMMatrixOrthographicOffCenterLH(0.0f,(float)width,0.0f,(float)height,0.0f,100.0f); // 800 x 600
viewMatrix=XMMatrixTranspose(viewMatrix); // What is this for?
projMatrix=XMMatrixTranspose(projMatrix); // What is this for?
// position the object
XMMATRIX scaleMatrix=XMMatrixScaling(1.0f*256.0f,1.0f*256.0f,1.0f ); // use variables later
XMMATRIX translationMatrix=XMMatrixTranslation(0.0f,0.0f,0.0f); // position at 0,0,0
XMMATRIX worldMat=scaleMatrix*translationMatrix;
d3dContext->UpdateSubresource(worldCB,0,0,&worldMat,0,0);
d3dContext->UpdateSubresource(viewCB,0,0,&viewMatrix,0,0);
d3dContext->UpdateSubresource(projCB,0,0,&projMatrix,0,0);
d3dContext->VSSetConstantBuffers(0,1,&worldCB);
d3dContext->VSSetConstantBuffers(1,1,&worldCB);
d3dContext->VSSetConstantBuffers(2,1,&worldCB);
// Render Geometry
UINT stride = sizeof(VERTEX);
UINT offset = 0;
d3dContext->IASetInputLayout(pLayout);
d3dContext->IASetVertexBuffers(0,1,&pVBuffer,&stride,&offset);
d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
d3dContext->Draw(4,0);
And this is my shader...
Texture2D colorMap_ : register( t0 );
SamplerState colorSampler_ : register( s0 );
cbuffer cbChangesEveryFrame : register(b0)
{
matrix worldMatrix;
};
cbuffer cbNeverChanges : register(b1)
{
matrix viewMatrix;
};
cbuffer cbChangeOnResize : register(b2)
{
matrix projMatrix;
}
struct VS_Input
{
float4 pos : POSITION;
float2 tex0 : TEXCOORD0;
};
struct PS_Input
{
float4 pos : SV_POSITION;
float2 tex0 : TEXCOORD0;
};
PS_Input VShader( VS_Input vertex )
{
PS_Input vsOut = ( PS_Input )0;
vsOut.pos=mul(vertex.pos,worldMatrix);
vsOut.pos=mul(vsOut.pos,viewMatrix);
vsOut.pos=mul(vsOut.pos,projMatrix);
// vsOut.pos = vertex.pos;
vsOut.tex0 = vertex.tex0;
return vsOut;
}
float4 PShader( PS_Input frag ) : SV_TARGET
{
return colorMap_.Sample( colorSampler_, frag.tex0 );
}
The problem that I have not is that when I run the code I get an exception and the debug window reports this
ID3D11DeviceContext::UpdateSubresource: First parameter is corrupt or NULL [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1]
Which relates to this code...
d3dContext->UpdateSubresource(worldCB,0,0,&worldMat,0,0);
d3dContext->UpdateSubresource(viewCB,0,0,&viewMatrix,0,0);
d3dContext->UpdateSubresource(projCB,0,0,&projMatrix,0,0);
Am I on the right track with how I am going about this? And any help as to what this error is would be awesome