Skip to main content
gamedev.net
🔒 Locked

Problem with multitexturing

Started by timmay314 Jan 18, 2004 at 9:59 PM 3 replies 350+ views
Original Post
timmay314
timmay314
I''m trying to figure out how to use multitexturing from the book Special Effects Game Programming with DirectX. It talks about how to do it, but for some reason gives no code samples about it. It seemed fairly straightforward, but when I try to do it modulating the color nothing is rendered, and when I try adding or subtracing color it is the same as if I only used the first texture. I''m trying to do light mapping - here''s my code:
g_pD3DDevice->SetTexture(0, m_Texture);
g_pD3DDevice->SetTexture(1, m_LightTexture);

g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
g_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
g_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

g_pD3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
g_pD3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
I don''t know that it matters, but at this point I have alpha blending enabled, lighting disabled, and Z writing disabled. I know that both textures are valid, and when I set the same texture as 0 and 1 the same things happens, so the problem is probably something simple. Any ideas?
Namethatnobodyelsetook
Namethatnobodyelsetook
If you''re using older hardware, it may not like TEXTURE as ARG2. Try swapping CURRENT and TEXTURE. Also, some older hardware doesn''t like colorop and alphaop being different. Though you are using the same operations, I just thought I''d warn you, for future reference.

Also, if you''re using REALLY old hardware, it might not support multitexturing.

You might want to ensure you have good texture coordinates for stage 1. Try setting TEXCOORDINDEX to 0 in stage 1.

Everything else looks fine as far as I can tell.
timmay314
timmay314
Thanks for your suggestion - I fixed it with the line

g_pD3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);

I don''t understand what this line does, though. What was wrong and why did this fix it?
Namethatnobodyelsetook
Namethatnobodyelsetook
In your vertex, you can have multiple sets of UV coordinates... or not. You''ve only defined UV set 0. (D3DFVF_TEX1, and only one set of "float u,v" in your vertex structure). By default D3D sets stage 0 to use uv set 0, stage 1 to use uv set 1, etc. This line tells D3D that you want to use UV set 0 on stage 1.

You can also have D3D automatically generate texture coordinates based on normals (for spheremapping), or position of your vertices... check the SDK help for details in your want to do that.
Chadivision
Chadivision
I''ve got the same book. I really like it, but I agree that the section on texture mapping was a little vague. About two days ago, I just got stuck on the same thing as you. I figued it out by digging through the SDK documentation, but it would have been nice if the description in the book was a little more clear.
Atari 2600 Homebrew Author - Someone who is smart enough to learn 6502 assembly language but dumb enough to actually want to use it.

Topic Locked

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

Sign in to reply to this topic.