Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a game using XNA. I have some simple objects like cube and sphere, and I would like to change the texture of one face of these objects based on picking. That is, when the cursor is over one face, it turns red. The only way I've seen to do this is to overload the content processor as here: http://xbox.create.msdn.com/en-US/education/catalog/sample/picking_triangle

but it seems like it shouldn't be this complicated. I'm using .x models, and would like to be able to implement this for more complex models in the future beyond cubes/spheres/etc. Is this the best/only way to go about it? I'll figure that out if that's what is necessary, but it seems that there would be a simpler solution to load a different texture to a face than I've seen, I just don't know what it is.

share|improve this question
add comment

2 Answers

Triangle picking aside, generally you can only have 1 texture per draw call. (Technically, I think it's effectively one shader effect per vertex buffer. If multi-texturing occurs here then it would be done by having multiple texture samplers in the shader, or by using a texture atlas) What this means is you need to split models up into parts when you want these parts to have differing textures.

share|improve this answer
    
Ok, I think that makes sense. That's stuff I'll have to look up because I've never used a texture atlas or tried to implement multiple texture samplers in the shader, but thank you for the information –  Thomas Carmichael Dec 13 '12 at 18:15
add comment

If you know the name of the texture that's highlighted, you can simply do this to first get the Texture2D:

public void ChangeTexture(Effect effect, string name, Texture2D newTexture, out Texture2D oldTexture)
{
    oldTexture = effect.Parameters[@name].GetValueTexture2D();
    effect.Parameters[@name].SetValue(newTexture);
}

then store the old texture somewhere and when the area that's highlighted is changed, you simply restore the texture the same way.

share|improve this answer
    
Won't that set the texture for the entire object, though? –  Thomas Carmichael Dec 13 '12 at 17:59
    
But you wanted the entire object to be highlighted in red? And you store the old texture, so when it's not highlighted you just reset the original texture. –  Deukalion Dec 14 '12 at 7:58
    
Well, if you know the name of the texture say it's not "Texture" on the model. Say it's called "Face/Arm/Legs" and such for a Model, I believe you use "effect.Parameters[NAME_OF_TEXTURE].SetValue()" or something similiar. –  Deukalion Dec 14 '12 at 7:59
    
well the idea is to get a single face to be highlighted red. Getting the whole object to change isn't too bad, but changing one face on the fly seems to be difficult –  Thomas Carmichael Dec 15 '12 at 17:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.