Sign in to follow this  
Anddos

need help with putting texture on mesh

Recommended Posts

Anddos    588
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[i]);    // set the material for the subset
		 d3ddev->SetTexture(0 , &D3DTexture[i]);
		
         meshSpaceship->DrawSubset(i);    // draw the subset
		
    }

Share this post


Link to post
Share on other sites
Gage64    1235
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
Evil Steve    2017
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
Evil Steve    2017
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
Anddos    588
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[i]); // set the material for the subset
meshSpaceship->DrawSubset(i); // draw the subset
}

Share this post


Link to post
Share on other sites
Evil Steve    2017
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
Anddos    588
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
Evil Steve    2017
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
Evil Steve    2017
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
Evil Steve    2017
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this