Sign in to follow this  

DirectX9 Texture Coordinates Problem

This topic is 4105 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'm currently tring to draw a texture onto the square, but the square is showing up black. The D3DFVF I'm using is D3DFVF_XYZ | D3DFVF_TEX1. I've set all the Sampler States, loading in the texture, set the texture to which one I'm using, well here is my code: The vertices and indices, with the texture coordinates (which I believe are wrong)
Vector* vertices;
g_pBGVertex->Lock(0, 0, (void**)&vertices, 0);
                    // (x, y, z, u, v)
vertices[0] = Vector(-(w/2.0f), 0.0f, 0.0f, 0.0f, 1.0f);
vertices[1] = Vector(-(w/2.0f),    h, 0.0f, 0.0f, 0.0f);
vertices[2] = Vector( (w/2.0f),    h, 0.0f, 1.0f, 0.0f);
vertices[3] = Vector( (w/2.0f), 0.0f, 0.0f, 1.0f, 1.0f);
g_pBGVertex->Unlock();

WORD* indices;
g_pBGIndex->Lock(0, 0, (void**)&indices, 0);
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
g_pBGIndex->Unlock();


RenderFrame (part where I'm displaying the square)
g_pDevice->SetTexture(0, g_pBackground);
g_pDevice->SetStreamSource(0, g_pBGVertex, 0, sizeof(Vector));
g_pDevice->SetIndices(g_pBGIndex);
g_pDevice->SetFVF(Vector::FVF);
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);


Thank you ahead of time of your replies, and help. = ]

Share this post


Link to post
Share on other sites
I changed the FVF to D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, and how the texture is showing up.

Could someone explain this to me, because I thought that when D3DFVF_NORMAL was used it was used to calculate the normals of a polygon for lighting, I didn't think that it had to be used for textures as well.

I'm new to this can you tell (hahaha), so much to learn, so much fun, so many sleepless nice. = ]

Edit: now that i'm thinking about it, it makes since why the normals would be needed.

Share this post


Link to post
Share on other sites
I assume that you haven't set the texture stage state, which you should do. It defaults to modulating the diffuse colour with the texture. Since it looks like you just want the pure texture, set stage 0 to 'selectarg1 texture'. That should do the trick.

Share this post


Link to post
Share on other sites
You can try it,for example:
#define D3DFVF_TEXCOORDSIZE3(CoordIndex) (D3DFVF_TEXTUREFORMAT3 << (CoordIndex*2 + 16))

DWORD dwFVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0);

Share this post


Link to post
Share on other sites

This topic is 4105 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this