## Recommended Posts

SouthernMunk    124
I was wondering if someone more experienced than myself is willing to show me what I'm doing wrong. I'm basically just drawing a rectangle (two triangles in a triangle strip) with a texture applied to it. I'm trying to make the whole program very object-orientated, so the source code is plucked from different areas.
[SOURCE]
// Defines:
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE)

// Structures:
struct CUSTOMVERTEX
{
float x, y, z;
float u, v;
DWORD colour;
};

// Initialise Direct3D and Device, etc.
// ...

// Initialise vertex buffer and texture.
void* pVertexBuffer = NULL;
CUSTOMVERTEX vertices[] =
{
-1.0, 1.0, 1.0, 0.0, 0.0, 0x00ff0000,
1.0, 1.0, 1.0, 1.0, 0.0, 0x0000ff00,
-1.0, -1.0, 1.0, 0.0, 1.0, 0x0000ff00,
1.0, -1.0, 1.0, 1.0, 1.0, 0x000000ff,
};

m_pDevice-&gt;CreateVertexBuffer(sizeof(vertices), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL);

m_pVB-&gt;Lock(0, sizeof(vertices), &pData, 0);

memcpy(pData, vertices, sizeof(vertices));

m_pVB-&gt;Unlock();

D3DXCreateTextureFromFile(m_pDevice, "texture128.bmp", &m_pTexture);

// Rendering.
m_pDevice-&gt;Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0, 0);

m_pDevice-&gt;BeginScene();
m_pDevice-&gt;SetRenderState(D3DRS_LIGHTING, FALSE);
m_pDevice-&gt;SetFVF(D3DFVF_CUSTOMVERTEX);
m_pDevice-&gt;SetStreamSource(0, m_pVB, 0, sizeof(CUSTOMVERTEX));
m_pDevice-&gt;SetTexture(0, m_pTexture);
m_pDevice-&gt;SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
m_pDevice-&gt;SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pDevice-&gt;DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
m_pDevice-&gt;EndScene();

m_pDevice-&gt;Present(NULL, NULL, NULL, NULL);
[/SOURCE]
The image is stretched when rendered. Like 1 column for the whole thing.

##### Share on other sites
When using an FVF the data must come in a specific order. In this case, position, color, then UVs.

The order things must come in is here.

##### Share on other sites
SouthernMunk    124
Quote:
 Original post by NamethatnobodyelsetookWhen using an FVF the data must come in a specific order. In this case, position, color, then UVs.The order things must come in is here.

LOL! Thanks so much. I'm new to DirectX (and 3D programming in general) so I should have known it would be something obvious. Funny thing is, when I add:

m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );

it works (though it's kinda like the MIRROR texturing method).

Thanks again buddy!

BTW: I was going to choose your username when I signed up. ;)

EDIT: Also, the colours were turning out funny too. Guess I know why now! :D