Jump to content
  • Advertisement
Sign in to follow this  
SouthernMunk

[C++] Textured Quads

This topic is 4637 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

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->CreateVertexBuffer(sizeof(vertices), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL);

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

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

m_pVB->Unlock();

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

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

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

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

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Namethatnobodyelsetook
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.


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

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!