________________________________
Da: pli...@li...
[mailto:pli...@li...] Per conto di Noah =
Brickman
Inviato: luned=EC 2 luglio 2007 19.43
A: 'Noah Brickman'; pli...@li...
Oggetto: [Plib-devel] Dynamic Overlay Texture
=09
I=92m looking into adding a dynamic overlay texture to Plib. I=92ll be
copying frames of video data into the overlay texture for some HUD-like
features in Flightgear. If anyone could give me some suggestions as to =
where
to get started with this I would be most grateful. I=92ve set this up =
with
some other graphics libraries but I=92m totally new to Plib. I=92m =
guessing
that it needs to be added to the SSG component, but beyond that I=92m =
starting
from scratch.
I'm not sure to have understood your needs, yet updating an SSG texture
(i.e. the texture set for a ssgSimpleState, i.e. the SSG "material" =
node)
can be done this way:
1. in your update_texture function, which could be called by your GLUT =
idle
callback,
- get the state pointer in some way (could be the state set for a leaf
node), then its texture handle:
ssgSimpleState *state /* =3D leaf->getState() */; // or any other way
to get it
ssgTexture *tex =3D state->getTexture();
if ( tex ) GLuint tex_id =3D tex->getTextureHandle();
- bind and update it through OpenGL calls:
glBindTexture( GL_TEXTURE_2D, tex_id );
glTexSubImage2D(
GL_TEXTURE_2D,
0 /* map level */,
x, y, dx, dy, /* offset, size */
GL_RGB /* internal format */, // or whatever
GL_UNSIGNED_BYTE /* type */, // or whatever
bmp_data /* image data */
);
glBindTexture( GL_TEXTURE_2D, 0 ); // unbind
2. now your texture gets updated, so the next ssgCullAndDraw will use =
the
update texture. If you need to modify the texture matrix, just do it =
through
leaf pre/post-draw callbacks, not in state pre-apply (since you'll not =
get
the control on the state post-apply for resetting the matrix):
// in the setup stage, find the leaf node using the state with
texture update facility
// in some way, e.g. searching by name
ssgLeaf *leaf =3D scene->getByName( "leaf name here" );
if ( leaf ) {
leaf->setCallback( SSG_CALLBACK_PREDRAW, leaf_pre_cb );
leaf->setCallback( SSG_CALLBACK_POSTDRAW, leaf_post_cb );
}
// these are sample callbacks for changing the texture matrix
int leaf_pre_cb( ssgEntity *obj ) {
glMatrixMode( GL_TEXTURE );
glLoadMatrixf( (float *)tex_matrix ); // as far as tex_matrix is a
sgMat4
// more tex xforms here such as glTranslatef, ...
return TRUE;
}
int leaf_post_cb( ssgEntity *obj ) {
// resetting texture matrix and matrix mode
glMatrixMode( GL_TEXTURE );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
return TRUE;
}
Such approach is suitable when the texture to be updated is used by some =
SSG
node - alternatively if you need to draw a full-screen texture quad in =
HUD
mode with no relation to 3D and the scene graph you could prefer to do =
it
entirely in OpenGL by setting up a gluOrtho2D projection mode.
Thanks,
-Noah
Greetings -
Paolo
|