• Advertisement
Sign in to follow this  

need help with putting texture on mesh

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

ok i have
        HRESULT hr;
	hr =D3DXCreateTextureFromFile(d3ddev , "taps.bitmap",&D3DTexture);
        if(hr)
	{
		MessageBox(NULL,"valid texture","",0);
	}
hr returns ok now in render loop i have
for(DWORD i = 0; i < numMaterials; i++)    // loop through each subset
    {
         d3ddev->SetMaterial(&material);    // set the material for the subset
		 d3ddev->SetTexture(0 , &D3DTexture);
		
         meshSpaceship->DrawSubset(i);    // draw the subset
		
    }

Share this post


Link to post
Share on other sites
Advertisement
So what's the problem?

Also, this:
if (hr) ...

is incorrect because not all non-zero HRESULT values indicate success. Instead you should write:
if (SUCCEEDED(hr)) ...

Share this post


Link to post
Share on other sites
ok ive corrected that but still the texture isnt displayed on the mesh subsets?

Share this post


Link to post
Share on other sites
Ok. Do you have a question? What do the Debug Runtimes say? And that's not the correct way to test for errors. In fact, you'll get your "valid texture" only if the function fails with one of the 2 billion possible codes, or if it succeeds with any of the other 2 billion ones.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anddos
yes my question is , i want to display this texture on the mesh
That's still not a question [smile]

However, as I said in my post, what do the debug runtimes tell you? Does the function fail? Are you useing SUCCEEDED() or FAILED() now, and you've just not updated your post?
Does SetTexture succeed or fail? Any debug output? Is the texture pointer null? Does the mesh render, just without textures?

Share this post


Link to post
Share on other sites
the mesh does render without textures
loading the texture , hr returns success
both meshs ive turned a grey color , which cant be right

this code in in Render();


d3ddev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
d3ddev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
d3ddev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
d3ddev->SetTexture(0 , D3DTexture);
//Ignored

for(DWORD i = 0; i < numMaterials; i++) // loop through each subset
{
d3ddev->SetMaterial(&material); // set the material for the subset
meshSpaceship->DrawSubset(i); // draw the subset
}

Share this post


Link to post
Share on other sites
When you say it "returns success", you mean you've changed the code to:
if(SUCCEEDED(hr))
Right?
Any debug output from the debug runtimes? Does SetTexture() fail? Is the texture pointer null?

Share this post


Link to post
Share on other sites
When you say it "returns success", you mean you've changed the code to:
if(SUCCEEDED(hr))
Right?
Any debug output from the debug runtimes? Does SetTexture() fail? Is the texture pointer null?

yes i have changed the code to if(SUCCEEDED(hr))
theres no debug runtimes ,
the texture pointer is NULL as global
SetTexture SUCCEEDED

Share this post


Link to post
Share on other sites
Quote:
Original post by Anddos
When you say it "returns success", you mean you've changed the code to:
if(SUCCEEDED(hr))
Right?
Any debug output from the debug runtimes? Does SetTexture() fail? Is the texture pointer null?

yes i have changed the code to if(SUCCEEDED(hr))
theres no debug runtimes ,
the texture pointer is NULL as global
SetTexture SUCCEEDED
There are debug runtimes. If the texture pointer is NULL, then the texture load failed, or you're releasing it, or you've discarded it in some way. If the pointer is NULL, it means "No texture", so SetTexture will succeed.

Share this post


Link to post
Share on other sites
texture pointer is not NULL now and still shows as a wierd grey mesh , want a screenshot?

Share this post


Link to post
Share on other sites
What colour is the top left pixel of your texture? Is it the same colour by any chance? Do you know if the UV coords of the mesh are valid? Have you tried loading one of the meshes from the SDK, and just applying your texture instead? Is your texture a power of two? Do the debug runtimes give you any warnings or errors? The debug runtimes are the single most useful tool when debugging D3D errors. If any call fails, you get told about it. If you have memory leaks, you get told about it. If there's anything that might not work correctly on other cards, you're sometimes told about it.

Share this post


Link to post
Share on other sites
Have you tried to load your model into another application to make sure everithong is OK? There should be messed UV coordinates maybe.

Share this post


Link to post
Share on other sites
Quote:
Original post by amigocz
Have you tried to load your model into another application to make sure everithong is OK? There should be messed UV coordinates maybe.
Also a good point. The .x file viewer should be a good example.

Share this post


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

  • Advertisement