FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Loading image textures on the fly

2 posters

Go down

Loading image textures on the fly Empty Loading image textures on the fly

Post  andre.brito Fri Feb 06, 2009 3:18 am

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):

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é
andre.brito
andre.brito

Posts : 13
Join date : 2009-01-05
Location : Lisbon, Portugal

http://www.evolve.pt/

Back to top Go down

Loading image textures on the fly Empty Re: Loading image textures on the fly

Post  sio2interactive Fri Feb 06, 2009 6:01 am

sio2ImageGenId Wink
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Loading image textures on the fly Empty Re: Loading image textures on the fly

Post  andre.brito Fri Feb 06, 2009 6:45 am

It's working! Thanks so much for the help.

André
andre.brito
andre.brito

Posts : 13
Join date : 2009-01-05
Location : Lisbon, Portugal

http://www.evolve.pt/

Back to top Go down

Loading image textures on the fly Empty Re: Loading image textures on the fly

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum