Daniel Grest wrote:
Hello,
I have a rather short question:
How to exchange Textures on geometries efficiently?
I tried it with the SimpleTextureMaterial by just setting a new image.
Thats horrible slow :(
I guess there is a better way. Maybe an example?
Thanks in advance,
Daniel Grest
Hi,
// Create textured material.
image = Image::create();
beginEditCP(image);
image->set(Image::OSG_RGBA_PF, width, height, 1, 1, 1, 0, NULL);
endEditCP(image);
xchunk = TextureChunk::create();
beginEditCP(xchunk);
xchunk->setImage(image);
xchunk->setMinFilter(GL_LINEAR);
xchunk->setMagFilter(GL_LINEAR);
xchunk->setWrapS(GL_REPEAT);
xchunk->setWrapT(GL_REPEAT);
endEditCP(xchunk);
SimpleMaterialPtr smat = SimpleMaterial::create();
beginEditCP(smat);
smat->setAmbient(Color3f(0.1, 0.1, 0.2));
smat->setDiffuse(Color3f(0.2, 0.2, 0.8));
smat->setSpecular(Color3f(0.8, 0.8, 0.8));
smat->setShininess(10);
smat->addChunk(xchunk);
endEditCP(smat);
// Change image and texture.
unsigned int *dst = (unsigned int *) _image->getData();
// now copy some pixels into the image
*dst++ = ...
beginEditCP(image);
endEditCP(image);
beginEditCP(xchunk, TextureChunk::ImageFieldMask);
xchunk->imageContentChanged();
endEditCP(xchunk, TextureChunk::ImageFieldMask);
I use this kind of code for a video texture. The image should have a
size of 2^n!
Andreas
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users