Jump to content
  • Advertisement
Sign in to follow this  
kFk

Multitexturing - second texture with offset

This topic is 3744 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 want to use single pass multitexturing. Declaring vertex format: #define D3DFVF_HGEVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2) Declaring vertex structure: struct Vertex { float x, y, z; DWORD col; float tx, ty; float tx_mask, ty_mask; }; Now I have two sets of texture coordinates. But! I need to render second texture with offset. Not by the same coordinates as first. Please advice me how can I do it? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Thanks.

On the beginning I have this situation:
Image1

Then I'm doing something like this:

----
pD3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);

D3DXMATRIX mat1;
D3DXMatrixIdentity(&mat1);
mat1(2, 0) = .5f; // x offset
mat1(2, 1) = .0f; // y offset
pD3DDevice->SetTransform(D3DTS_TEXTURE1, &mat1);

pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, nPrim<<2, 0, nPrim<<1);
----


Now the second texture renders with offset, but this results in not exactly what I want to have. The second texture region that not under the first texture not clamping, but rendering like scrolled:
Image2

Share this post


Link to post
Share on other sites
Do you know a DirectX8.1 analog for this?
Sorry that I didn't tell about DirectX version in the first post.

Share this post


Link to post
Share on other sites
Everything works good now. Thanks to all!

What we have: two textures that renders in one pass one above other -
Image1

What we want: to render second texture with offset (half of texture to right for example) and to clamp that region of texture that is not above the first

What we do:

#define D3DFVF_HGEVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2)

struct Vertex
{
float x, y, z;
DWORD col;
float tx, ty;
float tx_mask, ty_mask;
};

pD3DDevice->SetTextureStageState(1,D3DTSS_ADDRESSU,D3DTADDRESS_CLAMP);
pD3DDevice->SetTextureStageState(1,D3DTSS_ADDRESSV,D3DTADDRESS_CLAMP);


pD3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
D3DXMATRIX mat1;
D3DXMatrixIdentity(&mat1);
mat1(2, 0) = -.5f; // x offset
mat1(2, 1) = .0f; // y offset
pD3DDevice->SetTransform(D3DTS_TEXTURE1, &mat1);

pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, nPrim<<2, 0, nPrim<<1);

What we get: everything is as needed -
Image2

If you see any bad moments please write.

Thanks to all once again!

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!