Sign in to follow this  
Anddos

texture automatically wraps the whole mesh?

Recommended Posts

Can anyone tell me why in Dx viewer the texture is right but in rendering it wraps the whole mesh and not just 1 polygon?

http://img837.imageshack.us/img837/149/texpq.jpg

Share this post


Link to post
Share on other sites
The texture get applied exactly how you specified and not by some .x file magic. A file is just a container, there is not logic to dictate any action. Like swiftcoder said...does your renderer apply the texture correctly?

Share this post


Link to post
Share on other sites
It looks like you're not applying the materials to the specified sub-meshes found in the .x file. It's probably just applying the first material's texture for all sub-meshes rather than deciding which sub-meshes use which materials.
This might happen if you're combining all sub-meshes into a single mesh.

Share this post


Link to post
Share on other sites
AFAIK the .x format can't support multiple vertex formats. So if you assign UV to one face of something the rest will probably get some default UVs. If you assign the texture and draw the model it will texture over the whole thing.
.

Share this post


Link to post
Share on other sites
If your box uses two textures, your renderer must:

1) Bind the first texture;
2) Draw the sub-mesh that uses the first texture;
3) Bind the second texture;
4) Draw the sub-mesh that uses the second texture.

That's what the DX viewer does.

Share this post


Link to post
Share on other sites
can you help me with this code


HR(BoxEffect->SetTexture(gTex,mTex)); //wood.bmp //texture sampler1
HR(BoxEffect->SetTexture(gTex2,mTex2)); //planks.bmp //texture sampler2
HR(BoxEffect->SetTechnique(BoxTech));

HR(BoxEffect->Begin(&numPasses, 0));
HR(BoxEffect->BeginPass(0));
for(DWORD i = 0; i < numMaterials; i++) // loop through each subset
{
Mesh->DrawSubset(i); // draw the subset
}
HR(BoxEffect->EndPass());
HR(BoxEffect->End());

Share this post


Link to post
Share on other sites
You have to move your apply texture code into the loop.




HR(BoxEffect->SetTechnique(BoxTech));



HR(BoxEffect->Begin(&numPasses, 0));

HR(BoxEffect->BeginPass(0));

for(DWORD i = 0; i < numMaterials; i++) { // loop through each subset
HR(BoxEffect->SetTexture(gTex,mTex)); //wood.bmp //texture sampler1

HR(BoxEffect->SetTexture(gTex2,mTex2)); //planks.bmp //texture sampler2
Mesh->DrawSubset(i); // draw the subset

}

HR(BoxEffect->EndPass());

HR(BoxEffect->End());



The code will not work for models with multiple textures. You can see why if you look at the fact you only set the first texture once before the loop, then you are drawing the rest of the submeshes using the same texture. You have to have different textures as well. The above code is not correct, but it should give you an idea of why your previous code was not working.

Make sure to load the other textures, then place them in the loop, like I did above.

Share this post


Link to post
Share on other sites
@smasherprog:
Quote:
The above code is not correct

You're right. If you want to set effect variables inside the loop, you also need effect->CommitChanges().

@Anddos: Can you post the shader?

Also, it may not be necessary in your specific case, but for correctness, you should loop on the passes also.

In any case, you code should like more like:

for(DWORD i=0; i<numMaterials; i++)
{
effect->SetTexture(gTex,textureForThisSubset); // may be NULL if no texture
effect->CommitChanges();
mesh->DrawSubset(i);
}

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