Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Texture not getting sampled


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 12 October 2012 - 01:18 PM

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 © 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]

Sponsor:

#2 eppo   Crossbones+   -  Reputation: 2608

Like
0Likes
Like

Posted 13 October 2012 - 02:42 AM

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().

#3 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 13 October 2012 - 03:30 AM

Solved it,it was something wrong in the initialization of the texture.I move the initialization in the same function where I set the texture to be used by the effect file.It works now.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS