Hello there,
I'm having a problem with extreme flickering.
In fact it's like I only draw every 50th frame something - the other frames are the background color.
I figured out, if I remove the clear call it doesn't flicker at all, but it's drawn with these "letfovers" from the previous frame.
It also doesn't flicker when I don't update the constant buffers.
I'm using the backbuffer.
I'm drawing in a wxWigets window in the idle event. (This shouldn't matter as wxWidgets uses native controls and windows...)
This is my render loop:
float color[] = {0.0f,0.25f,0.5f,1.0f};
_devcon->ClearRenderTargetView(_target, color);
_devcon->ClearDepthStencilView(_depthStencil, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f,0);
//Do rendering stuff here
//Set the primitive Topology
_devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
//Set index & vertex buffers
_devcon->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
UINT stride = sizeof(Vertex), offset = 0;
_devcon->IASetVertexBuffers(0, 1, &_vertexBuffer, &stride, &offset);
//update the constant buffer
HRESULT hRes;
static float rotation = 0;
rotation += 0.001f;
D3D11_MAPPED_SUBRESOURCE mbuf;
hRes = _devcon->Map(_matrixBuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &mbuf);
if (FAILED(hRes))
return false;
MatrixBuffer *matrices;
matrices = (MatrixBuffer*)(mbuf.pData);
matrices->world = XMMatrixRotationY(rotation) * XMMatrixRotationX(rotation / 2);
matrices->world = XMMatrixTranspose(matrices->world);
_devcon->Unmap(_matrixBuf, 0);
_devcon->VSSetConstantBuffers(0, 1, &_matrixBuf);
//Activate the shaders
_devcon->IASetInputLayout(_inputLayout);
_devcon->VSSetShader(_vertexShader, 0, 0);
_devcon->PSSetShader(_pixelShader, 0, 0);
_devcon->DrawIndexed(18, 0, 0);
_swapchain->Present(0,0);
return true;