Swapping a texture
2 posters
Swapping a texture
Hello,
I am new to 3d programming, however after a few days of learning Blender and watching the wonderful tutorials for SIO2 - I was able to get a demo up. Currently I have a Sphere with a an earth texture mapped to it. It displays fine and I am able to rotate it with finger and accelerometer on the iphone. I would like to be able to switch the texture via code in real time. For example, if I tap the screen, I want to switch the "earth" texture with a "mars" texture. Is it possible to swap texture in real time on the same object? Can someone please point me in the direction to accomplish this? Do I need to set this up in blender and export? Or can I place another texture in my project and call some SIO2 function to swap out the texture on the object?
Thank you in advance!
I am new to 3d programming, however after a few days of learning Blender and watching the wonderful tutorials for SIO2 - I was able to get a demo up. Currently I have a Sphere with a an earth texture mapped to it. It displays fine and I am able to rotate it with finger and accelerometer on the iphone. I would like to be able to switch the texture via code in real time. For example, if I tap the screen, I want to switch the "earth" texture with a "mars" texture. Is it possible to swap texture in real time on the same object? Can someone please point me in the direction to accomplish this? Do I need to set this up in blender and export? Or can I place another texture in my project and call some SIO2 function to swap out the texture on the object?
Thank you in advance!
xtreo- Posts : 3
Join date : 2009-03-03
Re: Swapping a texture
Hi there.
Please take a look at http://forum.sio2interactive.com/about-the-sdk-f1/loading-image-textures-on-the-fly-t330.htm.
Take note that I had a constraint that the image was loaded from the iPhone's memory, so I really had to do this in runtime. In your case, it seems like you have access to the new texture image (mars) at compile time, which may open other options for you, like doing it in blender somehow (can't help you here, sorry).
André
Please take a look at http://forum.sio2interactive.com/about-the-sdk-f1/loading-image-textures-on-the-fly-t330.htm.
Take note that I had a constraint that the image was loaded from the iPhone's memory, so I really had to do this in runtime. In your case, it seems like you have access to the new texture image (mars) at compile time, which may open other options for you, like doing it in blender somehow (can't help you here, sorry).
André
Re: Swapping a texture
Andre,
Thank you so much! I did a search for "texture" and did not see your post! I asked pretty much the same question.
I copied and pasted your code (just to test) and I am having problem with 1 function:
sio2ObjectBindMatrix( _SIO2object );
sio2ObjectBindMatrix does not seem to exist in my header files anywhere, I even checked in Tutorial 02 which claims it uses this function and its not there either.
Has this function been changed recently? Or am I missing something?
Thanks!
Thank you so much! I did a search for "texture" and did not see your post! I asked pretty much the same question.
I copied and pasted your code (just to test) and I am having problem with 1 function:
sio2ObjectBindMatrix( _SIO2object );
sio2ObjectBindMatrix does not seem to exist in my header files anywhere, I even checked in Tutorial 02 which claims it uses this function and its not there either.
Has this function been changed recently? Or am I missing something?
Thanks!
xtreo- Posts : 3
Join date : 2009-03-03
Re: Swapping a texture
Yes, that function changed to sio2TransformBindMatrix : "sio2TransformBindMatrix(_SIO2object ->_SIO2transform);".
However, it's useless in my code, since I'm not transforming the object in any way (rotation, translation, etc.). You can remove it and replace that instruction with "sio2ImageGenId(_SIO2material->_SIO2image[0], _SIO2material->tflags[0], _SIO2material->tfilter[0]);", which I forgot to add on my initial code.
EDIT: forgot the tfilter: "sio2ImageGenId(_SIO2material->_SIO2image[0], _SIO2material->tflags[0], _SIO2material->tfilter[0]);"
André
However, it's useless in my code, since I'm not transforming the object in any way (rotation, translation, etc.). You can remove it and replace that instruction with "sio2ImageGenId(_SIO2material->_SIO2image[0], _SIO2material->tflags[0], _SIO2material->tfilter[0]);", which I forgot to add on my initial code.
EDIT: forgot the tfilter: "sio2ImageGenId(_SIO2material->_SIO2image[0], _SIO2material->tflags[0], _SIO2material->tfilter[0]);"
André
Last edited by andre.brito on Tue Mar 03, 2009 8:25 am; edited 1 time in total (Reason for editing : tfilter)
Re: Swapping a texture
Andre,
Thank you so much! it works great! I guess I just have to consider what you told me initially. I know all the possible textures I will need at compile time, so your dynamic method might be over kill, but maybe your method uses less memory?
Based on the code it looks like it just overwrites the original texture with the new one, so technically I can swap out unlimited textures with this method correct? I do notice a slight pause when swapping, but this is ok for my needs.
Thank you so much! it works great! I guess I just have to consider what you told me initially. I know all the possible textures I will need at compile time, so your dynamic method might be over kill, but maybe your method uses less memory?
Based on the code it looks like it just overwrites the original texture with the new one, so technically I can swap out unlimited textures with this method correct? I do notice a slight pause when swapping, but this is ok for my needs.
xtreo- Posts : 3
Join date : 2009-03-03
Re: Swapping a texture
Yes, you can swap the texture as many times as you want, since it basically overwrites the previous texture. My opinion is that you need to weight the importance of memory consumption and cpu usage of your application, in order to decide what method to use. If you have plenty of memory, load all the textures initially and swap them in memory (or do that via blender - don't ask me how though). If memory is a concern, then use my code to swap textures.
If you expect to load the same textures multiple times during an execution of the application, I think you should consider somehow keeping the image in memory. You can maybe keep the SIO2Image objects in memory...
If you expect to load the same textures multiple times during an execution of the application, I think you should consider somehow keeping the image in memory. You can maybe keep the SIO2Image objects in memory...
Similar topics
» Draw font to texture or render to texture possible?
» texture transform
» Material and Texture
» Not able to view texture
» Why md2 can not do a transparent texture?
» texture transform
» Material and Texture
» Not able to view texture
» Why md2 can not do a transparent texture?
Permissions in this forum:
You cannot reply to topics in this forum