Jump to content
  • Advertisement
Sign in to follow this  
Six222

Textured Quad Problems

This topic is 2398 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 I'm trying to draw a textured quad in DX11, the quad draws fine but i'm having troubles putting a texture on it.
Here's my problem:

NSyvtl.png

As you can see the texture isn't getting applied properly and doesn't make much sense to me as to why it is doing it. If anyone could explain why it'd be really appreciated!

Texture:
sOCL1l.png

Vertex, Texcoords and Indicies

struct VERTEX
{
FLOAT X, Y, Z; FLOAT U, V;
};

VERTEX Verts[] =
{
{0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
{1.0f, 0.0f, 1.0f, 1.0f, 0.0f},
{0.0f, -1.0f, 1.0f, 0.0f, 1.0f},
{1.0f, -1.0f, 1.0f, 1.0f, 1.0f}

};

VertBuffer.MapData(pDevCon, &Verts[0], sizeof(Verts));

DWORD Indices[] =
{
0, 1, 2, 2, 1, 3
};

IndBuffer.MapData(pDevCon, &Indices[0], sizeof(Indices));
D3DX11CreateShaderResourceViewFromFile(pDevice, "Bricks.png", NULL, NULL, &pTexture, NULL)

//Draw Call

UINT stride = sizeof(VERTEX);
UINT offset = 0;
ID3D11Buffer* buf = VertBuffer.GetBuffer();
pDevCon->IASetVertexBuffers(0, 1, &buf, &stride, &offset);
pDevCon->IASetIndexBuffer(IndBuffer.GetBuffer(), DXGI_FORMAT_R32_UINT, 0);
pDevCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
pDevCon->PSSetShaderResources(0, 1, &pTexture);
pDevCon->DrawIndexed(6, 0, 0);


Shader

struct VOut
{
float4 color : COLOR;
float2 texcoord : TEXCOORD;
float4 position : SV_POSITION;

};

VOut VShader(float4 position : POSITION, float2 texcoord : TEXCOORD)
{
VOut output;

output.position = position;
output.color = 1.0f;
output.texcoord = texcoord;

return output;
}

Texture2D Texture;
SamplerState ss;

float4 PShader(float4 color : COLOR, float2 texcoord: TEXCOORD) : SV_TARGET
{
return color * Texture.Sample(ss, texcoord);
}

Share this post


Link to post
Share on other sites
Advertisement
After lots of scanning through checking everything... turns out that my input layout was incorrect. The texcoord was being offset by 24, needed to be 12.

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!