Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multitexturing - second texture with offset

Started by kFk Jul 18, 2008 at 2:19 AM 4 replies 950+ views
Original Post
kFk
kFk
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.
kFk
kFk
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
kFk
kFk
Do you know a DirectX8.1 analog for this?
Sorry that I didn't tell about DirectX version in the first post.
kFk
kFk
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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.