Hi!
I'm trying to render a simple 2d triangle. The code I've written compiles and executes fine. But the call to CompileD3DShader returns false causing a message box saying "Error loading vertex shader!" as you can see in the code below.
Implementation of the LoadContent function:
bool TriangleDemo::LoadContent()
{
//shader loading code
ID3DBlob* vsBuffer = 0;
bool compileResult = CompileD3DShader("SolidGreenColor.fx", "VS_Main", "vs_4_0", &vsBuffer);
if(compileResult == false)
{
MessageBox(0, "Error loading vertex shader!","CompileError", MB_OK);
return false;
}
HRESULT d3dResult;
d3dResult = d3dDevice_->CreateVertexShader(vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), 0, &solidColorVS_);
if (FAILED(d3dResult))
{
if(vsBuffer)
vsBuffer->Release();
return false;
}
D3D11_INPUT_ELEMENT_DESC solidColorLayout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA,0 }
};
unsigned int totalLayoutElements = ARRAYSIZE(solidColorLayout);
d3dResult = d3dDevice_->CreateInputLayout(solidColorLayout, totalLayoutElements, vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), &inputLayout_);
vsBuffer->Release();
if(FAILED(d3dResult))
{
return false;
}
//Geometry loading code
VertexPos vertices[] =
{
XMFLOAT3(0.5f,0.5f,0.5f),
XMFLOAT3(0.5f,-0.5f,0.5f),
XMFLOAT3(-0.5f,-0.5f,0.5f)
};
D3D11_BUFFER_DESC vertexDesc;
ZeroMemory(&vertexDesc, sizeof(vertexDesc));
vertexDesc.Usage = D3D11_USAGE_DEFAULT;
vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexDesc.ByteWidth = sizeof(VertexPos) * 3;
D3D11_SUBRESOURCE_DATA resourceData;
ZeroMemory(&resourceData,sizeof(resourceData));
resourceData.pSysMem = vertices;
d3dResult = d3dDevice_->CreateBuffer(&vertexDesc, &resourceData, &vertexBuffer_);
if(FAILED(d3dResult))
{
return false;
}
return true;
}
Implementation of CompileD3DShader
bool Dx11DemoBase::CompileD3DShader(char* filePath, char* entry, char* shaderModel, ID3DBlob** buffer)
{
DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined (DEBUG) || defined(_DEBUG)
shaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* errorBuffer = 0;
HRESULT result;
result = D3DX11CompileFromFile(filePath, 0, 0,entry,shaderModel,shaderFlags,0 ,0 ,buffer,&errorBuffer,0);
if(FAILED(result))
{
if(errorBuffer != 0)
{
OutputDebugStringA((char*)errorBuffer->GetBufferPointer());
errorBuffer->Release();
}
return false;
}
if(errorBuffer !=0)
errorBuffer->Release();
return true;
}
My shader code looks like this
float4 VS_Main(float4 pos : POSITION) : SV_POSITION
{
return pos;
}
float4 PS_Main(float4 pos : SV_POSITION) : SV_TARGET
{
return float4(0.0f 1.0f, 0.0f, 1.0f);
}
What could be wrong? I'm new to DirectX programming
BEST!
www.memblockgames.com