• Advertisement
Sign in to follow this  

(VS 2008 VC++) DirectX9 Problem - SetTexture

This topic is 3677 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

Hey all. I am having a 'problem'when calling set texture (My previous texture loading problems were due to threading confusions XD) Anyways - I have a problem here; d3ddevice->SetTexture(0,NULL); -- It just crashs. Is it due to the arguement NULL(which is effectively 0), or the 0? I am confused. I am using DirectX9 object, or is this due to another threading problem? The way I am writing my peice is that I am storing all the DirectX code in a seperate DLL(Dynamic), and another application which calls apon that DLL. The actual DirectX code is not within the same project.

Share this post


Link to post
Share on other sites
Advertisement
I looked it up and for the second parameter you are supposed to be sending in a texture object.

I'm guessing you are trying to make it so that there is no texture currently selected?

Share this post


Link to post
Share on other sites
Yup yup. I was more concerned with the first arguement in all actuality, since in DirectX9 the second parameter sends fine, however from DirectX8, SetTexture had arguements (Stage,Texture) where as in DirectX9 its (Sampler, Texture) - I am not too sure what a Sampler is to begin with.

Share this post


Link to post
Share on other sites
Setting a empty texture but telling to draw with textures will probably crash. It's like saying to start at 0 in memory and use whatever is there to use as a texture. In OpenGL you could simply do a glDisable(GL_TEXTURE_2D); instead, but texturing doesn't seem to be in DirectX state machine with SetRenderState. It's been a while since I did any DirectX and I'm forgetting things, but you might try to disable the first texture stage state instead:
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);

If there's a better way, tell :)

Share this post


Link to post
Share on other sites
If you're working from a mesh, the default will be no texture applied at all. So for each submesh, you can check to see if you loaded a texture, and then when rendering, only apply a texture if it's there...

render step:
if (texture != NULL) d3ddev->SetTexture(0, texture); // if there is a texture, apply it

Load:
if (FAILED(D3DXCreateTextureFromFile(d3ddev,
tempMaterials.pTextureFilename,
&texture))) texture=NULL;
// if there's a texture loaded, the array gets the texture, if not, the array get's set to NULL

(these two lines are very very close to the example http://www.directxtutorial.com/Tutorial9/C-Direct3DMeshes/dx9C3.aspx)

-TF

Share this post


Link to post
Share on other sites
Setting a texture stage to NULL is completely valid, and should not be crashing on you. What is the exact crash you're getting? I think it's more likely there's something wrong with your device interface pointer.

As for sampler/texture stage, the difference is really just cosmetic as they just refer to how textures are used by either the fixed-function pipeline or programmable shaders. With FFP you bind textures to texture stages and define operations to be performed with each texture stage (via IDirect3DDevice9::SetTextureStageState). With shaders, textures are bound to samplers that you use in your HLSL to retrieve the texels from the texture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement