R: [Plib-devel] textures
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2004-10-20 12:52:00
|
-----Messaggio originale----- Da: pli...@li... [mailto:pli...@li...] Per conto di Mihnea Galeteanu Inviato: mercoled=EC 20 ottobre 2004 13.04 A: pli...@li... Oggetto: [Plib-devel] textures > Is there any way that I can update a texture in the middle of my game. Assume I loaded up my 3d environment in plib and now > I'm going around in this environment using my own game that wraps plib. ... You can do it in several way, depending on your code structure. For updating a texture you have to go to the ssgSimpleState node (holds material properties, the texture pointer and OGL states), usually kid of a ssgLeaf (geometry, usually a ssgVtxArray), get the texture handle, bind it, update the texture, finally unbind. The texture related to that state is thus updated, for each leaf pointing to that state. Here is some code: ssgLeaf *leaf =3D ...; // how you will get the leaf pointer is up to you If ( leaf->hasState() ) { ssgSimpleState *state =3D (ssgSimpleState *) leaf->getState(); If ( state->hasTexture() ) { Gluint tex_handle =3D state->getTextureHandle(); glBindTexture ( GL_TEXTURE_2D, tex_handle ); // update the texture through glTexSubImage2D(), glCopyTexImage2D() or whatever glBindTexture ( GL_TEXTURE_2D, 0 ); } } > Is there a way to hook up a call back method in plib > that asks my game whether i want to update a particular texture?=20 No, AFAIK. But, what such a mechanism should be activated by? How SSG should know when you are ready to update the texture? If you store that state pointer as to the previous code somewhere, you could update whenever you want. You can also reach it by name (root->getByName("Textured_Material_name")), or do an recursive deep search of the graph searching for a state with a texture with a certain name (state->getTexture()->getName()). Alternatively you could use some native callback mechanism, either pre/post- leaf draw: leaf->setCallback( SSG_CALLBACK_PREDRAW, your_leaf_predraw_cb ); Or pre/post- state apply: state->setCallback( SSG_CALLBACK_PREAPPLY, your_state_preapply_cb ); > Thanks, > Mihnea (Mike) Galeteanu=20 Welcome on board, ciao - Paolo |