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 only have a basic understanding of OpenGL, so I'm probably showing my ignorance here.

I'm looking for a great iPhone/OpenGL-ES example of applying a texture (preferably from a texture atlas, but not really a requirement) to specific parts of some arbitrary object/model.

I have a game where 3D tiles "flip" to reveal some other texture on the backside of the tile. I created the model in Blender and exported it to an Objective-C header. The tile isn't a simple "cube", but it is relatively cube-shaped. Everything works great when I use a single texture that simply wraps the entire model. But I'm struggling to figure out how I can restrict that texture to just specific parts of the model.

To complicate things even more, I ultimately want to texture it with three different images. The top will have "image x", the sides of the tile will have "image y", and the back will have "image z".

Thanks!

share|improve this question
    
Did you texture the 'cube' in Blender and export the texture or is this a new texture you want to use? –  Dave Aug 21 '10 at 11:03
    
I only have a simple material on the cube in Blender just so the texture coordinates export. The textures on the top and bottom faces are runtime textures. The sides can be exported with the object (if possible). Maybe this is a limitation of exporting everything as an Objective-C header file... ?? –  Tim Reddy Aug 21 '10 at 18:01
add comment

1 Answer

up vote 4 down vote accepted

You're doomed.

The iPhone only has 2 multitexturing units, so you can't use 3 textures at the same time. This leaves you with the following options :

  • Make a single texture with your 3 images on it. If the combination of textures is not a compile-time constant, either recompute the new texture each time you need it, or pre-compute every possibility.
  • Split your cube into 3 meshes, display each independently with its own texture
  • Hybrid approach : Split your cube in 2, first half with 1 texture, second half with multitexturing.

Hope this helps.

share|improve this answer
    
Thanks for the answer. Do you have some source code for your first answer? I guess that's why I started investigating texture atlases... –  Tim Reddy Aug 22 '10 at 15:21
    
@TReddy : No, not really, but simply create a texture large enough so that the 3 fit (and still power of two), memcpy (or the C# equivalent) 3 times, render. –  Calvin1602 Aug 22 '10 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.