Quote:Original post by Erik RufeltQuote:Original post by Calneon
I don't know what the stride is, and I'm not using a vertex buffer. What you're saying makes sense, but I'm not sure what to do.
In your case the vertex buffer is inside the ID3DX10Mesh. In order to make it work, you must add the texcoord to the input-layout as well as to the vertex, as for example "TEXCOORD", 0, DXGI_FORMAT_R32G32, 0, 28, PER_VERTEX, 0. Then you need to change the creation of the input-layout to match this by setting the element count to 3 instead of 2, for D3DX10CreateMesh and CreateInputLayout, and you must also modify the effect so that the vertex shader input contains a float2 texcoord : TEXCOORD.
Ok, I've changed all that but it's not working, could you take a look at my code:
Vertex structure
*********************************
struct vertex
{
D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texCoords;
vertex()
{
}
vertex(D3DXVECTOR3 p, D3DXVECTOR4 c)
{
pos = p;
color = c;
}
vertex(D3DXVECTOR3 p, D3DXVECTOR4 c, D3DXVECTOR2 tex)
{
pos = p;
color = c;
texCoords = tex;
}
};
const D3D10_INPUT_ELEMENT_DESC vertexInputLayout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXTURE", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};
Shader file:
***************************************
//--------------------------------------------------------------------------------------
// basicEffect.fx
//--------------------------------------------------------------------------------------
matrix World;
matrix View;
matrix Projection;
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
float2 Tex : TEXCOORD;
};
struct VS_INPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
float2 Tex : TEXCOORD;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
PS_INPUT output;
output.Pos = mul( input.Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Color = input.Color;
output.Tex = input.Tex;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input ) : SV_Target
{
return input.Color;
}
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique10 render
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}
Create input layout:
*****************************************
UINT numElements = sizeof( vertexInputLayout ) / sizeof( vertexInputLayout[0] );
//create input layout
D3D10_PASS_DESC PassDesc;
pBasicTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
if ( FAILED( pD3DDevice->CreateInputLayout( vertexInputLayout,
numElements,
PassDesc.pIAInputSignature,
PassDesc.IAInputSignatureSize,
&pVertexLayout ) ) ) return fatalError("Could not create Input Layout!");
// Set the input layout//
pD3DDevice->IASetInputLayout( pVertexLayout );
Creating mesh:
****************************************
vertex v[4];
v[0] = vertex( D3DXVECTOR3(-width, height, 0), D3DXVECTOR4(1,1,1,1) ); // front top left
v[1] = vertex( D3DXVECTOR3(width, height, 0), D3DXVECTOR4(1,1,1,1) ); // front top right
v[2] = vertex( D3DXVECTOR3(width, -height, 0), D3DXVECTOR4(1,1,1,1) ); // front bottom right
v[3] = vertex( D3DXVECTOR3(-width, -height, 0), D3DXVECTOR4(1,1,1,1) ); // front bottom left
// create indexes
unsigned int i[6] = {0, 1, 2,
0, 3, 2};
// create mesh
D3DX10CreateMesh( dx.getD3DDevice(), vertexInputLayout, 3, "POSITION", 4, 2, D3DX10_MESH_32_BIT, &sqMesh);