Hi.
Some time ago I wrote about a problem (see "TextureChunk, Threads and
Videos") of which I thought that it is related to - guess what:
TextureChunks, Threads and Videos. After trying around again, I found
that there seems to be a bug in TextureChunk (or Image?) and that this
had nothing to do with threads or the avcodec/avformat libs. The
attached little program reproduces this error:
In this program, there are two planes, two TextureChunks with different
two images. They have absolutely nothing in common. If I use only one of
them, everything looks ok.
http://www.uni-koblenz.de/~dominikr/texchunk1.png
http://www.uni-koblenz.de/~dominikr/texchunk2.png
But if both planes are enabled, I get the same color on both planes.
http://www.uni-koblenz.de/~dominikr/texchunk3.png
You can enable the one or the other with the boolean values enable1 and
enable2.
Any idea?
Regards,
Dominik
// OpenSG Tutorial Example: Move An Object
//
// This example shows how to use Transform nodes to move objects aroung
//
// Headers
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGImage.h>
#include <OpenSG/OSGChunkMaterial.h>
#include <OpenSG/OSGTextureChunk.h>
#include <OpenSG/OSGBaseFunctions.h>
#include <OpenSG/OSGTransform.h>
OSG_USING_NAMESPACE
TransformPtr trans1;
TransformPtr trans2;
NodePtr transNode1;
NodePtr transNode2;
TextureChunkPtr texChunk1;
TextureChunkPtr texChunk2;
ImagePtr img1;
ImagePtr img2;
UInt8 *buffer1;
UInt8 *buffer2;
SimpleSceneManager *mgr;
bool enable1=true;
bool enable2=true;
int setupGLUT( int *argc, char *argv[] );
void display( void )
{
// create the matrix
Matrix m1,m2;
Real32 t = glutGet(GLUT_ELAPSED_TIME );
if(enable1){
m1.setTransform(Vec3f(0,0,0),Quaternion( Vec3f(0,1,0), t / 1000.f));
beginEditCP(trans1, Transform::MatrixFieldMask);
trans1->setMatrix(m1);
endEditCP (trans1, Transform::MatrixFieldMask);
}
if(enable2){
m2.setTransform(Vec3f(0,0,0),Quaternion( Vec3f(0,1,0), -1*t / 1000.f));
beginEditCP(trans2, Transform::MatrixFieldMask);
trans2->setMatrix(m2);
endEditCP (trans2, Transform::MatrixFieldMask);
}
mgr->redraw();
}
int main(int argc, char **argv)
{
osgInit(argc,argv);
int winid = setupGLUT(&argc, argv);
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
if(enable1){
transNode1=Node::create();
trans1 = Transform::create();
NodePtr plane1 = makePlane(1 ,1 ,1 ,1);
beginEditCP(transNode1, Node::CoreFieldMask | Node::ChildrenFieldMask);
transNode1->setCore(trans1);
transNode1->addChild(plane1);
endEditCP (transNode1, Node::CoreFieldMask | Node::ChildrenFieldMask);
texChunk1=TextureChunk::create();
buffer1=new UInt8[255*255*3];
for(int i=0;i<255*255*3;i=i+3){
buffer1[i]=255-(i%255);
buffer1[i+1]=0;
buffer1[i+2]=0;
}
img1=Image::create();
beginEditCP(img1);
img1->setWidth(255);
img1->setHeight(255);
img1->setPixelFormat(OSG::Image::OSG_RGB_PF);
img1->setDataType(OSG::Image::OSG_UINT8_IMAGEDATA);
img1->setData(buffer1);
endEditCP(img1);
texChunk1=OSG::TextureChunk::create();
beginEditCP(texChunk1);
texChunk1->setMinFilter(GL_LINEAR);
texChunk1->setMagFilter(GL_LINEAR);
texChunk1->setEnvMode(GL_REPLACE);
texChunk1->setWrapS(GL_CLAMP);
texChunk1->setWrapT(GL_CLAMP);
texChunk1->setImage(img1);
endEditCP(texChunk1);
ChunkMaterialPtr cm1=ChunkMaterialPtr::dcast(GeometryPtr::dcast(plane1->getCore())->getMaterial());
beginEditCP(cm1);
cm1->addChunk(texChunk1);
endEditCP(cm1);
}
if(enable2){
transNode2=Node::create();
trans2 = Transform::create();
NodePtr plane2 = makePlane(1 ,1 ,1 ,1);
beginEditCP(transNode2, Node::CoreFieldMask | Node::ChildrenFieldMask);
transNode2->setCore(trans2);
transNode2->addChild(plane2);
endEditCP (transNode2, Node::CoreFieldMask | Node::ChildrenFieldMask);
texChunk2=TextureChunk::create();
buffer2=new UInt8[255*255*3];
for(int i=0;i<255*255*3;i=i+3){
buffer2[i]=i%255;
buffer2[i+1]=255;
buffer2[i+2]=0;
}
img2=Image::create();
beginEditCP(img2);
img2->setWidth(255);
img2->setHeight(255);
img2->setPixelFormat(OSG::Image::OSG_RGB_PF);
img2->setDataType(OSG::Image::OSG_UINT8_IMAGEDATA);
img2->setData(buffer2);
endEditCP(img2);
texChunk2=OSG::TextureChunk::create();
beginEditCP(texChunk2);
texChunk2->setMinFilter(GL_LINEAR);
texChunk2->setMagFilter(GL_LINEAR);
texChunk2->setEnvMode(GL_REPLACE);
texChunk2->setWrapS(GL_CLAMP);
texChunk2->setWrapT(GL_CLAMP);
texChunk2->setImage(img2);
endEditCP(texChunk2);
ChunkMaterialPtr cm2=ChunkMaterialPtr::dcast(GeometryPtr::dcast(plane2->getCore())->getMaterial());
beginEditCP(cm2);
cm2->addChunk(texChunk2);
endEditCP(cm2);
}
NodePtr scene = Node::create();
GroupPtr group=OSG::Group::create();
beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
scene->setCore(group);
if(enable1)
scene->addChild(transNode1);
if(enable2)
scene->addChild(transNode2);
endEditCP (scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
mgr = new SimpleSceneManager;
mgr->setWindow(gwin );
mgr->setRoot (scene);
mgr->showAll();
glutMainLoop();
return 0;
}
void reshape(int w, int h)
{
mgr->resize(w, h);
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 27:
{
OSG::osgExit();
exit(0);
}
break;
}
}
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
// call the redraw function whenever there's nothing else to do
glutIdleFunc(display);
return winid;
}