So I draw a simple rectangle and I want to cover that rectangle with a texture.
The problem is that instead of the texture,it gets covered in black!
Effect file:
[source lang="cpp"]//***************************************************************************************
// color.fx by Frank Luna (C) 2011 All Rights Reserved.
//
// Transforms and colors geometry.
//***************************************************************************************
RasterizerState Wire
{
FillMode = Solid;
CullMode = None;
FrontCounterClockwise = false;
};
SamplerState simple
{
AddressU = WRAP;
AddressV = WRAP;
};
cbuffer cbPerObject
{
float4x4 gWorldViewProj;
};
Texture2D gDiffuseMap;
struct VertexIn
{
float2 PosL : POSITION;
float4 Color : COLOR;
float2 Tex : TEXCOORD;
};
struct VertexOut
{
float4 PosH : SV_POSITION;
float4 Color : COLOR;
float2 Tex : TEXCOORD;
};
VertexOut VS(VertexIn vin)
{
VertexOut vout;
// Transform to homogeneous clip space.
vout.PosH = mul(float4(vin.PosL, 0.0f,1.0f), gWorldViewProj);
// Just pass vertex color into the pixel shader.
vout.Color = vin.Color;
vout.Tex = vin.Tex;
return vout;
}
float4 PS(VertexOut pin) : SV_Target
{
return gDiffuseMap.Sample( simple, pin.Tex );
}
technique11 ColorTech
{
pass P0
{
SetVertexShader( CompileShader( vs_5_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_5_0, PS() ) );
SetRasterizerState(Wire);
}
}
[/source]
And here's the code in the c++ file:
[source lang="cpp"] Vertex vertices[] =
{
{ XMFLOAT2(-100.0f, -100.0f), (const float*)&Colors::White, XMFLOAT2(0.0f,1.0f) },
{ XMFLOAT2(-100.0f, +100.0f), (const float*)&Colors::Black, XMFLOAT2(0.0f,0.0f) },
{ XMFLOAT2(+100.0f, +100.0f), (const float*)&Colors::Red, XMFLOAT2(1.0f,0.0f) },
{ XMFLOAT2(+100.0f, -100.0f), (const float*)&Colors::Green,XMFLOAT2(1.0f,1.0f) }
};
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * 4;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = vertices;
HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));
ID3DX11EffectShaderResourceVariable* DiffuseMap;
ID3D11ShaderResourceView* mDiffuseMap;
DiffuseMap = mFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
DiffuseMap->SetRawValue(mDiffuseMap,0,0);[/source]
Texture not getting sampled
I don't know what the Vertex structure exactly looks like, but it seems like you're passing a pointer to a static member of Colors. That would mean you're passing a pointer value sizeof(*) instead of a color sizeof(float4) as initialization data to CreateBuffer().
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement