• Create Account

### #Actualkavaari

Posted 07 June 2012 - 01:13 PM

I have a really weird problem, which I have tried to solve the whole day, yet no solution. I'm using DirectX10.

This is a dead simple case:
I have a grid based on number of tiles and spacing (size of one quad).

int vCounter = 0;
int iCounter = 0;
int indicesIndex = 0;
for (int x = 0; x < numSideTiles; x++)
for (int z = 0; z < numSideTiles; z++)
{
float xPos = x * spacing;
float zPos = z * spacing;

vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos, 0, zPos + spacing, 1.0f), Normal = normal, UV = new Vector2(1, 1) };
vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos + spacing, 0, zPos + spacing, 1.0f), Normal = normal, UV = new Vector2(0, 1) };
vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos, 0, zPos, 1.0f), Normal = normal, UV = new Vector2(1, 0) };
vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos + spacing, 0, zPos, 1.0f), Normal = normal, UV = new Vector2(0, 0) };

indices[iCounter++] = (ushort)(indicesIndex + 0);
indices[iCounter++] = (ushort)(indicesIndex + 1);
indices[iCounter++] = (ushort)(indicesIndex + 2);
indices[iCounter++] = (ushort)(indicesIndex + 1);
indices[iCounter++] = (ushort)(indicesIndex + 3);
indices[iCounter++] = (ushort)(indicesIndex + 2);
indicesIndex += 4;
}

DataStream vertexStream = new DataStream(36 * numVertices, true, true);
vertexStream.WriteRange(vertices);
DataStream indexStream = new DataStream(2 * numIndices, true, true);
indexStream.WriteRange(indices);
BufferDescription vertexBufferDesc = new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 36 * numVertices,
Usage = ResourceUsage.Default
};
BufferDescription indexBufferDesc = new BufferDescription()
{
BindFlags = BindFlags.IndexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 2 * numIndices,
Usage = ResourceUsage.Default
};
vertexStream.Position = 0;
indexStream.Position = 0;
vertexBuffer = new SlimDX.Direct3D10.Buffer(device, vertexStream, vertexBufferDesc);
indexBuffer = new SlimDX.Direct3D10.Buffer(device, indexStream, indexBufferDesc);

device.Flush();

//More code between...

//Final drawing code

device.InputAssembler.SetInputLayout(InputElements.pntInputLayout);
device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
device.InputAssembler.SetIndexBuffer(indexBuffer, SlimDX.DXGI.Format.R16_UInt, 0);
device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 36, 0));

effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply();
device.DrawIndexed(numIndices,0, 0);



The quads seems fine, but the texture is placed wrong on quads along left edge and on the last quad, on top left corner.

If spacing is two (quad size is two), then the texture will get stretched on Z-axis, even though the quad's vertices are fine.

For one quad it works as it should.

Any help is appreciated.

### #1kavaari

Posted 07 June 2012 - 01:10 PM

I have a really weird problem, which I have tried to solve the whole day, yet no solution. I'm using DirectX10.

This is a dead simple case:
I have a grid based on number of tiles and spacing (size of one quad).

int vCounter = 0;
int iCounter = 0;
int indicesIndex = 0;
for (int x = 0; x < numSideTiles; x++)
for (int z = 0; z < numSideTiles; z++)
{
float xPos = x * spacing;
float zPos = z * spacing;

vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos, 0, zPos + spacing, 1.0f), Normal = normal, UV = new Vector2(1, 1) };
vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos + spacing, 0, zPos + spacing, 1.0f), Normal = normal, UV = new Vector2(0, 1) };
vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos, 0, zPos, 1.0f), Normal = normal, UV = new Vector2(1, 0) };
vertices[vCounter++] = new PositionNormalTextured() { Position = new Vector4(xPos + spacing, 0, zPos, 1.0f), Normal = normal, UV = new Vector2(0, 0) };

indices[iCounter++] = (ushort)(indicesIndex + 0);
indices[iCounter++] = (ushort)(indicesIndex + 1);
indices[iCounter++] = (ushort)(indicesIndex + 2);
indices[iCounter++] = (ushort)(indicesIndex + 1);
indices[iCounter++] = (ushort)(indicesIndex + 3);
indices[iCounter++] = (ushort)(indicesIndex + 2);
indicesIndex += 4;
}

DataStream vertexStream = new DataStream(36 * numVertices, true, true);
vertexStream.WriteRange(vertices);
DataStream indexStream = new DataStream(2 * numIndices, true, true);
indexStream.WriteRange(indices);
BufferDescription vertexBufferDesc = new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 36 * numVertices,
Usage = ResourceUsage.Default
};
BufferDescription indexBufferDesc = new BufferDescription()
{
BindFlags = BindFlags.IndexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 2 * numIndices,
Usage = ResourceUsage.Default
};
vertexStream.Position = 0;
indexStream.Position = 0;
vertexBuffer = new SlimDX.Direct3D10.Buffer(device, vertexStream, vertexBufferDesc);
indexBuffer = new SlimDX.Direct3D10.Buffer(device, indexStream, indexBufferDesc);

device.Flush();

//More code between...

//Final drawing code

device.InputAssembler.SetInputLayout(InputElements.pntInputLayout);
device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
device.InputAssembler.SetIndexBuffer(indexBuffer, SlimDX.DXGI.Format.R16_UInt, 0);
device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 36, 0));

effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply();
device.DrawIndexed(numIndices,0, 0);



The quads seems fine, but the texture is placed wrong on quads along left edge and on the last quad, on top left corner.