Disabling Texturing ?

Started by
5 comments, last by Namethatnobodyelsetook 16 years, 10 months ago
Hi guys, I define my custom vertex with D3DFVF_XYZRHW|D3DFVF_DIFFUSE|3DFVF_TEX1, I don't want to use the texture in certain areas so I've just been doing this: g_d3d_device->BeginScene(); // don't want texture g_d3d_device->SetTexture(0,NULL); g_d3d_device->DrawPrimitive(...); // want texture g_d3d_device->SetTexture(0,g_texture); g_d3d_device->DrawPrimitive(...); g_d3d_device->EndScene(); ...and everything seems fine. Am I doing it right ? Thanks.
Advertisement
That should be just fine. If you need more detail on where the texture is you could use an alpha map or texture splat. But as long as what you have works thats fine.
The results are undefined, so no, not right. And it does vary by card, so you're just lucky so far.

You should change your TextureStageStates to not refer to textures. Each stage has an alphaop and a colorop. Operations have 1, 2, or 3 arguments (oddly, ARG0 is the third rarely used argument).

By default you normally have 1 active stage, which modulates color by texture.
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
When not using textures you should change this to just use diffuse (result of lighting, or vertex color if lighting is off)
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
Quote:Original post by Namethatnobodyelsetook
The results are undefined, so no, not right. And it does vary by card, so you're just lucky so far.

You should change your TextureStageStates to not refer to textures. Each stage has an alphaop and a colorop. Operations have 1, 2, or 3 arguments (oddly, ARG0 is the third rarely used argument).

By default you normally have 1 active stage, which modulates color by texture.*** Source Snippet Removed ***When not using textures you should change this to just use diffuse (result of lighting, or vertex color if lighting is off)
*** Source Snippet Removed ***


Oh yeah :(

Disregard my original post lol.
Ahhh, that helps a lot Namethatnobodyelsetook. I was worried about my method.

Does it matter if I call SetTexture() before or after I set the states ?

Also, if I never call SetTexture() with the sampler greater than 0 do I have to worry about disabling those stage states ?

Thanks man.
Quote:Original post by Namethatnobodyelsetook
The results are undefined, so no, not right. And it does vary by card, so you're just lucky so far.

Are you sure about this? I remember from somewhere that the fixed pipeline always returns black for null textures. It is, however, undefined when using pixel shaders.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
It could be that the fixed pipe does return *white*. I know it's unreliable in a shader, but I didn't know that the fixed pipe way was any better.

It shouldn't matter when you call SetShader. If fact, it probably doesn't matter too much if you call it at all, as the states will already tell it to ignore texturing.

It's a good habit to setup your full effect, including disabling the next stage. At some point you're going to use a 2 stage effect, or one will be set for you by a helper library (fonts, some heightmap library, or whatever). You can either make it the responsiblity of that effect to disable all the stages it setup, or have each effect include a final disable. It doesn't matter to you now, but it will, so it's a good habit to get into.

This topic is closed to new replies.

Advertisement