Loading image textures on the fly
2 posters
Loading image textures on the fly
Hello.
I'm trying to change the texture of an object while the application is running. The object has an initial texture (applied using blender) and the new texture that I want to apply is of the exact same dimensions and format - in fact, the initial image is blue and the new one is red - that's the only diference.
I carefully looked at the code used on the SDK to load images (and all other objects too) from the .sio2 package file and I tried to copy and adapt it to my case. Here is the code I'm using (I know somethings are hardcoded, like array accesses and so, but this is just a proof-of-concept):
This code is executed when the user double-taps on the screen. The initial scene exported from blender loads perfectly fine (object has the blue texture).
I've debuged it and everything seems to run fine (the file is found, the file size matches the real file) and no erros are shown. However, all I see is the object's old texture disappearing and the object showing up with no texture (all white).
Am I missing any step?
Thanks in advance,
André
I'm trying to change the texture of an object while the application is running. The object has an initial texture (applied using blender) and the new texture that I want to apply is of the exact same dimensions and format - in fact, the initial image is blue and the new one is red - that's the only diference.
I carefully looked at the code used on the SDK to load images (and all other objects too) from the .sio2 package file and I tried to copy and adapt it to my case. Here is the code I'm using (I know somethings are hardcoded, like array accesses and so, but this is just a proof-of-concept):
- Code:
char *name = { "myfile.jpg" };
NSString *fname = [NSString stringWithFormat:@"%s%s", sio2->app_path, name];
NSData *imageFile = [NSData dataWithContentsOfFile:fname];
SIO2stream *_SIO2stream = sio2StreamInit( name );
_SIO2stream->size = [imageFile length];
_SIO2stream->buf = new unsigned char [_SIO2stream->size + 1];
[imageFile getBytes:_SIO2stream->buf length:_SIO2stream->size];
_SIO2stream->buf[_SIO2stream->size] = 0;
_SIO2stream->cur = _SIO2stream->buf;
SIO2image *_SIO2image = sio2ImageInit( name );
sio2ImageLoad( _SIO2image, _SIO2stream );
SIO2material *_SIO2material = _SIO2object->_SIO2vertexgroup[0]->_SIO2material;
_SIO2material->_SIO2image[0] = _SIO2image;
memset(_SIO2material->tname[0], 0, sizeof(_SIO2material->tname[0]));
strcpy(_SIO2material->tname[0], name);
sio2ObjectBindMatrix( _SIO2object );
This code is executed when the user double-taps on the screen. The initial scene exported from blender loads perfectly fine (object has the blue texture).
I've debuged it and everything seems to run fine (the file is found, the file size matches the real file) and no erros are shown. However, all I see is the object's old texture disappearing and the object showing up with no texture (all white).
Am I missing any step?
Thanks in advance,
André
Similar topics
» Some Info on PVR Textures for anyone interested
» Using Compressed Textures
» Textures Killing My App
» Need help with multiple textures
» A couple questions concerning textures...
» Using Compressed Textures
» Textures Killing My App
» Need help with multiple textures
» A couple questions concerning textures...
Permissions in this forum:
You cannot reply to topics in this forum