First thread on gamedev stackexchange. I am currently creating a cube with a single texture on each side. I got my cube up and running. But when I apply my texture, I get this:
It blends the texture into a single color and apply it. I have various of examples that look near identical but do not have the same problem. Anyone know what can be the cause of this issue?
3D programming in general contains quite a bit of code. I wont copy paste all of it. If you want to see anything specific, you can request it. But here are some of the functions. Thanks in advance.
HRESULT Cubes::Render(ID3D11DeviceContext* _deviceContext, Camera _camera)
{
HRESULT hr = S_OK;
unsigned int stride = sizeof(Vertex);
unsigned int offset = 0;
_deviceContext->IASetVertexBuffers(0, 1, &this->mVertexBuffer, &stride, &offset);
_deviceContext->IASetIndexBuffer(this->mIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
D3D11_MAPPED_SUBRESOURCE ms;
hr = _deviceContext->Map(this->mMatrixBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms );
if(FAILED(hr))
{
OutputDebugString("Failed to map matrixbuffer in Cubes.\n");
return hr;
}
WVPBuffer* dataPtr;
dataPtr = (WVPBuffer*)ms.pData;
dataPtr->worldMatrix = DirectX::XMMatrixTranspose( this->mWorld);
dataPtr->viewMatrix = DirectX::XMMatrixTranspose( _camera.GetView());
dataPtr->projectionMatrix = DirectX::XMMatrixTranspose( _camera.GetProj());
_deviceContext->Unmap(this->mMatrixBuffer, NULL );
// Set the position of the constant buffer in the vertex shader.
int bufferNumber = 0;
_deviceContext->VSSetConstantBuffers( 0, 1, &this->mMatrixBuffer );
// Set the vertex input layout.
_deviceContext->IASetInputLayout(this->mInputLayout);
// Set the vertex and pixel shaders that will be used to render this triangle.
_deviceContext->VSSetShader(this->mVertexShader, NULL, 0);
_deviceContext->PSSetShader(this->mPixelShader, NULL, 0);
_deviceContext->RSSetState(this->mRasterState);
// Set shader texture resource in the pixel shader.
_deviceContext->PSSetShaderResources(0, 1, &this->mTexture);
_deviceContext->PSSetSamplers(0, 1, &this->mSamplerState);
// Render the triangle.
_deviceContext->DrawIndexed(this->mNoIndex, 0, 0);
return hr;
}
HRESULT Cubes::LoadTexture(ID3D11Device* _device)
{
HRESULT hr = S_OK;
hr = D3DX11CreateShaderResourceViewFromFile(_device, "../Pictures/cube.png", nullptr, nullptr, &this->mTexture, nullptr);
if(FAILED(hr))
{
OutputDebugString("Failed to create Cubes texture.\n");
return hr;
}
return hr;
}
Pixelshader:
Texture2D shaderTexture;
SamplerState Sampler;
struct PSIn
{
float4 Position : SV_POSITION;
float2 Tex : TEX;
};
float4 PS_Cubes(PSIn _input) : SV_TARGET
{
float4 textureColor;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(Sampler, _input.Tex);
return textureColor;
}