Jump to content
  • Advertisement
Sign in to follow this  
Klashnikov Kid

DirectX10 - Simple texture initialization problem

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I've been slowly but surely working my way through learning how to use DirectX10 and I've recently ran into a dead end.

I've been trying to get a simple texture mapped onto a cube and although based on my reading material it seems like I'm doing everything right, I'm obviously missing something.

First I'm creating a Shader resource view to the image file. Then I'm getting a handle to the texture variable in the shader. Followed by setting that shader value to the resource view.

HRESULT _hr = D3DX10CreateShaderResourceViewFromFile(device, TEXT("CubeFace.png"), NULL, NULL, &fxDiffuseMapRV, NULL);

if (FAILED(_hr))
FatalError(_hr, TEXT("Failed to create diffuse map view for ground tile."));

fxDiffuseMapV = fx->GetVariableByName("diffuseMap")->AsShaderResource();


Here is my simple shader. All the relevant buffer data is set, including an identity matrix for the texture matrix.

Texture2D diffuseMap;

cbuffer cbPerObject
float4x4 wvpM;
float4x4 worldM;
float4x4 texM;

struct VS_IN
float3 posL : POSITION;
float2 texC : TEXCOORD;

struct VS_OUT
float4 posH : SV_POSITION;
float2 texC : TEXCOORD;

SamplerState Sampler

VS_OUT vOut;

vOut.posH = mul(float4(vIn.posL, 1.0f), wvpM);

vOut.texC = mul(float4(vIn.texC, 0.0f, 1.0f), texM);

return vOut;

float4 PS(VS_OUT pIn) : SV_Target
float4 diffuse = diffuseMap.Sample(Sampler, pIn.texC);

return diffuse;

technique10 Render
pass P0
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );

And just in case it is causing the problem (however, I'm fairly sure it isn't) my vertex data.

vertices[0].position = D3DXVECTOR3(-2.0f, -4.0, -2.0f);
vertices[1].position = D3DXVECTOR3( 2.0f, -4.0, -2.0f);
vertices[2].position = D3DXVECTOR3(-2.0f, -6.0, -2.0f);
vertices[3].position = D3DXVECTOR3( 2.0f, -6.0, -2.0f);
vertices[4].position = D3DXVECTOR3(-2.0f, -4.0, 2.0f);
vertices[5].position = D3DXVECTOR3( 2.0f, -4.0, 2.0f);
vertices[6].position = D3DXVECTOR3(-2.0f, -6.0, 2.0f);
vertices[7].position = D3DXVECTOR3( 2.0f, -6.0, 2.0f);

vertices[0].textureCoordinate = D3DXVECTOR2(0.0f, 1.0f);
vertices[1].textureCoordinate = D3DXVECTOR2(1.0f, 1.0f);
vertices[2].textureCoordinate = D3DXVECTOR2(1.0f, 1.0f);
vertices[3].textureCoordinate = D3DXVECTOR2(0.0f, 1.0f);
vertices[4].textureCoordinate = D3DXVECTOR2(0.0f, 0.0f);
vertices[5].textureCoordinate = D3DXVECTOR2(1.0f, 0.0f);
vertices[6].textureCoordinate = D3DXVECTOR2(1.0f, 0.0f);
vertices[7].textureCoordinate = D3DXVECTOR2(0.0f, 0.0f);

(I'm using an index buffer and I'm aware that only the top and bottom might not look screwy. It's going to be a floor tile.)

I've have no problem drawing a white cube when I override the returned color in the shader but when I don't, it's solid black.

My debug output reads "The Pixel Shader unit expects a Shader Resource View at Slot 0, but none is bound." so is my shader resource view just not getting set for somereason?


Share this post

Link to post
Share on other sites
After you set the resource you must call


replace mTech with your ID3D10EffectTechnique* var.

Also, you dont have to multiply your texC by an identity matrix...
So replace:

vOut.texC = mul(float4(vIn.texC, 0.0f, 1.0f), texM);


vOut.texC = float4(vIn.texC, 0.0f, 1.0f);

[Edited by - Aqua Costa on October 24, 2010 11:13:09 AM]

Share this post

Link to post
Share on other sites
Here is my draw technique. I believe I'm applying the shader as far as I know.

device->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0);
device->IASetVertexBuffers(0, 1, &vertexBuffer, &vertexStride, &vertexOffset);

for (UINT p = 0; p < fxTechniqueDescription.Passes; ++p)

device->DrawIndexed(indicesSize, 0, 0);

Also you mentioned not transforming the texture coordinates, but I think ya accidentally duplicated the code. :P

I believe the book I'm learning from included the texture matrix for animated texture effects. Which you are right since I'm definitely not doing anything of the sort yet.

Share this post

Link to post
Share on other sites

Geez... my cube's constructor didn't have the call to my texture initialization... Excuse me while I go kick myself.

One last question though, is not using an index buffer the only way to map a cube with conflicting UV coordinates?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!