Exemplo n.º 1
0
MaterialPtr createVideoMaterial(void)
{
    // Ok, now for the meat of the code...
    // first we need an Image to hold the picture(s) to show
    //image = Image::create();
    
    //beginEditCP(image);
    //{
        // set the image's size and type, and allocate memory
        // this example uses RGB. On some systems (e.g. Windows) BGR
        // or BGRA might be faster, it depends on how the images are 
        // acquired
    //    image->set(Image::OSG_RGB_PF, 2, 2);
    //}
    //endEditCP(image);
    
    // Now create the texture to be used for the background
    tex = TextureChunk::create();
    
    beginEditCP(tex);
    {
        // Associate image and texture
        //tex->setImage(image);
        
        // Set filtering modes. LINEAR is cheap and good if the image size
        // changes very little (i.e. the window is about the same size as 
        // the images).
        //tex->setMinFilter(GL_LINEAR);
        tex->setMinFilter(GL_NEAREST);
        tex->setMagFilter(GL_LINEAR);
        //tex->setMagFilter(GL_NEAREST);        
        
        // Set the wrapping modes. We don't need repetition, it might actually
        // introduce artifactes at the borders, so switch it off.
        tex->setWrapS(GL_CLAMP_TO_EDGE);
        tex->setWrapT(GL_CLAMP_TO_EDGE);             
        
        // Newer versions of OpenGl can handle NPOT textures directly.
        // OpenSG will do that internally automatically.
        //
        // Older versions need POT textures. By default OpenSG
        // will scale an NPOT texture to POT while defining it.
        // For changing textures that's too slow.
        // So tell OpenSG not to scale the image, but use the texture
        // matrix to scale. This only works if we're not using the
        // texture matrix for anything else, which is fine for video
        // backgrounds.
        // This does not do anything if NPOT textures are supported, so
        // it is safe to just set it.
        
        tex->setScale(false);            
        tex->setNPOTMatrixScale(true);
    }
    endEditCP(tex);

	ChunkMaterialPtr TheMaterial = ChunkMaterial::create();

	beginEditCP(TheMaterial, ChunkMaterial::ChunksFieldMask);
		TheMaterial->addChunk(tex);
		TheMaterial->addChunk(MaterialChunk::create());
	endEditCP(TheMaterial, ChunkMaterial::ChunksFieldMask);

	return TheMaterial;
}
Exemplo n.º 2
0
FBOViewportPtr createSceneFBO(void)
{
    //Create Camera Beacon
    Matrix CameraMat;
    CameraMat.setTranslate(0.0f,0.0f,4.0f);
    TransformPtr CameraBeconCore = Transform::create();
    beginEditCP(CameraBeconCore, Transform::MatrixFieldMask);
        CameraBeconCore->setMatrix(CameraMat);
    endEditCP(CameraBeconCore, Transform::MatrixFieldMask);

    NodePtr CameraBeconNode = Node::create();
    beginEditCP(CameraBeconNode, Node::CoreFieldMask);
        CameraBeconNode->setCore(CameraBeconCore);
    endEditCP(CameraBeconNode, Node::CoreFieldMask);

    //Create Camera
    PerspectiveCameraPtr TheCamera = PerspectiveCamera::create();
    beginEditCP(TheCamera);
        TheCamera->setFov(deg2rad(60.0f));
        TheCamera->setAspect(1.0f);
        TheCamera->setNear(0.1f);
        TheCamera->setFar(100.0f);
        TheCamera->setBeacon(CameraBeconNode);
    endEditCP(TheCamera);
    
    //Make the Material
    BlinnMaterialPtr TheMaterial = BlinnMaterial::create();
    beginEditCP(TheMaterial);
        TheMaterial->setDiffuse(0.8);
        TheMaterial->setColor(Color3f(1.0,1.0,1.0));
        TheMaterial->setAmbientColor(Color3f(1.0,1.0,1.0));
        TheMaterial->setNumLights(1);
    endEditCP(TheMaterial);

										
    // Make Torus Node (creates Torus in background of scene)
    NodePtr TorusGeometryNode = makeTorus(.5, 2, 24, 48);

    beginEditCP(TorusGeometryNode->getCore());
        GeometryPtr::dcast(TorusGeometryNode->getCore())->setMaterial(TheMaterial);
    endEditCP(TorusGeometryNode->getCore());
    calcVertexNormals(GeometryPtr::dcast(TorusGeometryNode->getCore()));
    calcVertexTangents(GeometryPtr::dcast(TorusGeometryNode->getCore()),0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId);

    RootTransformCore = Transform::create();

    NodePtr TorusTransformNode = Node::create();
    beginEditCP(TorusTransformNode, Node::CoreFieldMask);
        TorusTransformNode->setCore(RootTransformCore);
        TorusTransformNode->addChild(TorusGeometryNode);
    endEditCP(TorusTransformNode, Node::CoreFieldMask);

    //Create Light Beacon
    Matrix LightMat;
    LightMat.setTranslate(0.0f,10.0f,1.0f);
    TransformPtr LightBeconCore = Transform::create();
    beginEditCP(LightBeconCore, Transform::MatrixFieldMask);
        LightBeconCore->setMatrix(LightMat);
    endEditCP(LightBeconCore, Transform::MatrixFieldMask);

    NodePtr LightBeconNode = Node::create();
    beginEditCP(LightBeconNode, Node::CoreFieldMask);
        LightBeconNode->setCore(LightBeconCore);
    endEditCP(LightBeconNode, Node::CoreFieldMask);

    //Create Light
    TheLight = PointLight::create();
    beginEditCP(TheLight);
        TheLight->setBeacon(LightBeconNode);
    endEditCP(TheLight);

    NodePtr LightNode = Node::create();
    beginEditCP(LightNode, Node::CoreFieldMask);
        LightNode->setCore(TheLight);
        LightNode->addChild(TorusTransformNode);
    endEditCP(LightNode, Node::CoreFieldMask);


    //Create Root

    NodePtr TheRoot = Node::create();
    beginEditCP(TheRoot);
        TheRoot->setCore(Group::create());
        TheRoot->addChild(CameraBeconNode);
        TheRoot->addChild(LightNode);
        TheRoot->addChild(LightBeconNode);
    endEditCP(TheRoot);

    //Create Background
    SolidBackgroundPtr TheBackground = SolidBackground::create();
    TheBackground->setColor(Color3f(1.0,0.0,0.0));

    //DepthClearBackgroundPtr TheBackground = DepthClearBackground::create();

    //Create the Image
    ImagePtr TheColorImage = Image::create();
    TheColorImage->set(Image::OSG_RGB_PF,2,2,1,1,1,0.0f,0,Image::OSG_FLOAT16_IMAGEDATA);

    //Create the texture
    TextureChunkPtr TheColorTextureChunk = TextureChunk::create();
    beginEditCP(TheColorTextureChunk);
        TheColorTextureChunk->setImage(TheColorImage);

        TheColorTextureChunk->setMinFilter(GL_NEAREST);
        TheColorTextureChunk->setMagFilter(GL_NEAREST);

        TheColorTextureChunk->setWrapS(GL_CLAMP_TO_EDGE);
        TheColorTextureChunk->setWrapR(GL_CLAMP_TO_EDGE);

        TheColorTextureChunk->setScale(false);
        TheColorTextureChunk->setNPOTMatrixScale(true);
        
        TheColorTextureChunk->setEnvMode(GL_REPLACE);
        TheColorTextureChunk->setInternalFormat(GL_RGB16F);

    endEditCP(TheColorTextureChunk);


    //Create FBO
    FBOViewportPtr TheFBO = FBOViewport::create();
    beginEditCP(TheFBO);
        TheFBO->setBackground(TheBackground);
        TheFBO->setRoot(TheRoot);
        TheFBO->setCamera(TheCamera);

        TheFBO->setEnabled(true);
        TheFBO->getTextures().push_back(TheColorTextureChunk);

        TheFBO->setStorageWidth(TheColorTextureChunk->getImage()->getWidth());
        TheFBO->setStorageHeight(TheColorTextureChunk->getImage()->getHeight());
        
        TheFBO->setSize(0,0,TheColorTextureChunk->getImage()->getWidth()-1, TheColorTextureChunk->getImage()->getHeight()-1);
    endEditCP(TheFBO);
    return TheFBO;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
	
										
    // Make Torus Node (creates Torus in background of scene)
    NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodePtr scene = osg::Node::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
        scene->setCore(osg::Group::create());
        scene->addChild(TorusGeometryNode);
    endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);

    //Create the Image
    Path ImagePath("./Data/TutorialImage.jpg");
    ImagePtr TheImage = ImageFileHandler::the().read(ImagePath.string().c_str());

    //Create the texture
    TextureChunkPtr TheTextureChunk = TextureChunk::create();
    beginEditCP(TheTextureChunk);
        TheTextureChunk->setImage(TheImage);

        TheTextureChunk->setMinFilter(GL_NEAREST);
        TheTextureChunk->setMagFilter(GL_NEAREST);

        TheTextureChunk->setWrapS(GL_CLAMP_TO_EDGE);
        TheTextureChunk->setWrapR(GL_CLAMP_TO_EDGE);

        TheTextureChunk->setScale(false);
        TheTextureChunk->setNPOTMatrixScale(true);
        
        TheTextureChunk->setEnvMode(GL_REPLACE); 
    endEditCP(TheTextureChunk);

    //Create a Texture Source
    TextureSourceTextureFilterPtr TutorialTextureSourceTextureFilter = TextureSourceTextureFilter::create();
    beginEditCP(TutorialTextureSourceTextureFilter, TextureSourceTextureFilter::TextureFieldMask);
        TutorialTextureSourceTextureFilter->setTexture(TheTextureChunk);
    endEditCP(TutorialTextureSourceTextureFilter, TextureSourceTextureFilter::TextureFieldMask);

    //Create a Grayscale filter
    std::string GrayScaleFragProg = "uniform sampler2D Slot0Texture; void main() { gl_FragColor = vec4(vec3( dot(vec3(0.3,0.59,0.11), texture2D(Slot0Texture,gl_TexCoord[0].st).rgb)), 1.0); }";

    //Create a shader Filter
    ShaderTextureFilterPtr GrayscaleTextureFilter = ShaderTextureFilter::create();
    GrayscaleTextureFilter->attachSource(TutorialTextureSourceTextureFilter, 0, 0);
    GrayscaleTextureFilter->setFragmentSource(GrayScaleFragProg);

    //Create a Color Mult filter
    std::string ColorMultFragProg = "uniform sampler2D Slot0Texture; void main() { gl_FragColor = vec4(vec3(1.0,0.0,0.0) * texture2D(Slot0Texture,gl_TexCoord[0].st).rgb, 1.0); }";

    //Create a shader Filter
    ShaderTextureFilterPtr ColorMultTextureFilter = ShaderTextureFilter::create();
    ColorMultTextureFilter->attachSource(GrayscaleTextureFilter,0,0);
    ColorMultTextureFilter->setFragmentSource(ColorMultFragProg);

    
    ////Create a Blur filter
    //std::string BlurFragProg = "";
    //BlurFragProg += 
    //"uniform sampler2D Slot0Texture;"
    //"void main()"
    //"{"
    //"    vec2 offsets[9];"
    //"    offsets[0] = vec2(-0.000625,0.00111111111);"
    //"    offsets[1] = vec2(0.0,0.00111111111);"
    //"    offsets[2] = vec2(0.000625,0.00111111111);"
    //"    offsets[3] = vec2(-0.000625,0.0);"
    //"    offsets[4] = vec2(0.0,0.0);"
    //"    offsets[5] = vec2(0.0,0.0);"
    //"    offsets[6] = vec2(-0.000625,-0.00111111111);"
    //"    offsets[7] = vec2(0.0,-0.00111111111);"
    //"    offsets[8] = vec2(0.000625,-0.00111111111);"
    //"    vec4 kernel[9];"
    ////"    kernel[0] = vec4(0.0);"
    ////"    kernel[1] = vec4(0.0);"
    ////"    kernel[2] = vec4(0.0);"
    ////"    kernel[3] = vec4(0.0);"
    ////"    kernel[4] = vec4(1.0);"
    ////"    kernel[5] = vec4(0.0);"
    ////"    kernel[6] = vec4(0.0);"
    ////"    kernel[7] = vec4(0.0);"
    ////"    kernel[8] = vec4(0.0);"
    //"    kernel[0] = vec4(0.0);"
    //"    kernel[1] = vec4(0.15);"
    //"    kernel[2] = vec4(0.0);"
    //"    kernel[3] = vec4(0.15);"
    //"    kernel[4] = vec4(0.4);"
    //"    kernel[5] = vec4(0.15);"
    //"    kernel[6] = vec4(0.0);"
    //"    kernel[7] = vec4(0.15);"
    //"    kernel[8] = vec4(0.0);"
    //"    vec4 sum = vec4(0.0);"
    //"    int i;"
    //"    for(i = 0 ; i < 9 ; i++)"
    //"    {"
    //"        sum += kernel[i] * texture2D(Slot0Texture,gl_TexCoord[0].st + offsets[i]);"
    //"    }"
    //"    gl_FragColor = sum;"
    //"}";

    ////Create a shader Filter
    //ShaderTextureFilterPtr BlurTextureFilter = ShaderTextureFilter::create();
    //BlurTextureFilter->attachSource(ColorMultTextureFilter);
    //BlurTextureFilter->setFragmentSource(BlurFragProg);


	
	// Create the ImageProcessed Foreground Object
    ImageProcessedForegroundPtr TutorialImageProcessedForeground = ImageProcessedForeground::create();

    beginEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask);
        TutorialImageProcessedForeground->setFilter(ColorMultTextureFilter);
        TutorialImageProcessedForeground->setOutputSlot(0);
    endEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask);

    mgr->setRoot(scene);

    // Add the ImageProcessed Foreground Object to the Scene
    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialImageProcessedForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
            WinSize,
            "02SimpleImagePipeline");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
Exemplo n.º 4
0
int main( int argc, char *argv[] )
{
    osgInit(argc, argv);

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("OpenSG");
    glutKeyboardFunc(key);
    // glutReshapeFunc(resize);
    glutDisplayFunc(display);
    // glutMouseFunc(mouse);
    // glutMotionFunc(motion);

    glutIdleFunc(display);

    pImage = Image::create();

    // create the dummy structures

    // the window is needed for the chunks that access GLObjects

    win = GLUTWindow::create();
    win->frameInit(); // test for preliminary calls not messing up GLexts
    win->init();
    
    dact = DrawAction::create();
    dact->setWindow(get_pointer(win));

    win->init();

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 60, 1, 0.1, 10 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt( 3, 3, 3,  0, 0, 0,   0, 1, 0 );

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

    dlid = glGenLists( 1 );
    glNewList( dlid, GL_COMPILE );
    glutSolidSphere( .8, 24, 24 );
    glEndList();

    dlid2 = glGenLists( 1 );
    glNewList( dlid2, GL_COMPILE );
    glBegin( GL_POLYGON );
    glNormal3f( 0, 1, 0 );
    glColor3f( 1, 1, 1 );
    glTexCoord3f( 0, 0, 0 );
    glVertex3f( -1.5, -1, -1.5 );
    glTexCoord3f( 2, 0, 0 );
    glVertex3f(  1.5, -1, -1.5 );
    glTexCoord3f( 2, 2, 2 );
    glVertex3f(  1.5, -1,  1.5 );
    glTexCoord3f( 0, 2, 2 );
    glVertex3f( -1.5, -1,  1.5 );
    glEnd();
    glEndList();


    Matrix m;

    tchunk1 = TransformChunk::create();
    m.setTranslate( 0, 1, 0 );
    tchunk1->setMatrix( m );

    tchunk2 = TransformChunk::create();
    tchunk2->setMatrix( Matrix::identity() );


    mchunk1 = MaterialChunk::create();
    mchunk1->setDiffuse( Color4f( 1,0,0,0 ) );
    mchunk1->setAmbient( Color4f( 1,0,0,0 ) );
    mchunk1->setShininess( 20 );

    mchunk2 = MaterialChunk::create();
    mchunk2->setDiffuse( Color4f( 0,1,0,0 ) );
    mchunk2->setAmbient( Color4f( 0,1,0,0 ) );
    mchunk2->setShininess( 50 );

    // Texture chunk

//  UChar8 imgdata[] =
//      {  255,0,0,0,  0,255,0,0,  0,0,255,255,  255,255,255,255 };
    UChar8 imgdata[] =
        {  255,0,0,  255,0,0,  255,0,255,
           255,0,0,  255,0,0,  255,0,255,
           255,255,0,  255,255,0,  255,255,255,
           255,255,0,  255,255,0,  255,255,255, };
//  UChar8 limgdata[] =
//      {  0, 128, 64, 255 };
    pImage->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, imgdata );

    if ( argc > 1 )
        pImage->read( argv[1] );

    xchunk1 = TextureChunk::create();
    beginEditCP(xchunk1);
    xchunk1->setImage( pImage );
    xchunk1->setMinFilter( GL_LINEAR );
    xchunk1->setMagFilter( GL_NEAREST );
    xchunk1->setWrapS( GL_REPEAT );
    xchunk1->setWrapT( GL_REPEAT );
    xchunk1->setEnvMode( GL_REPLACE );
    xchunk1->setScale( false );
    endEditCP(xchunk1);

    xchunk1->imageContentChanged();

    beginEditCP(xchunk1);
    xchunk1->setImage( pImage );
    xchunk1->setLodBias( 10 );
    endEditCP(xchunk1);

    UChar8 imgdata2[] =
    {  255,0,0,  0,255,0,  0,0,255,  255,255,255 };

    ImagePtr pImage2 = Image::create();
    pImage2->set(Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, imgdata2);

    xchunk2 = TextureChunk::create();
    beginEditCP(xchunk2);
    xchunk2->setImage( pImage2 );
    xchunk2->setMinFilter( GL_LINEAR );
    xchunk2->setMagFilter( GL_NEAREST );
    xchunk2->setWrapS( GL_REPEAT );
    xchunk2->setWrapT( GL_REPEAT );
    xchunk2->setEnvMode( GL_MODULATE );
    xchunk2->setLodBias( 10 );
    endEditCP(xchunk2);
    
    // Cube Texture chunk
    
    UChar8 negz[] = {  255,0,0,  128,0,0,  64,0,0,   255,255,255 },
           posz[] = {  0,255,0,  0,128,0,  0,64,0,  255,255,255 },
           negy[] = {  0,0,255,  0,0,128,  0,0,64,  255,255,255 },
           posy[] = {  255,255,0,  128,128,0,  64,64,0,  255,255,255 },
           negx[] = {  255,0,255,  128,0,128,  64,0,64,  255,255,255 },
           posx[] = {  0,255,255,  0,128,128,  0,64,64,  255,255,255 };
    
    ImagePtr inegz = Image::create();
    ImagePtr iposz = Image::create();
    ImagePtr inegy = Image::create();
    ImagePtr iposy = Image::create();
    ImagePtr inegx = Image::create();
    ImagePtr iposx = Image::create();

    inegz->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, negz );
    iposz->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, posz );
    inegy->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, negy );
    iposy->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, posy );
    inegx->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, negx );
    iposx->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, posx );
        
    cchunk1 = CubeTextureChunk::create();
    beginEditCP(cchunk1);
    cchunk1->setImage( inegz );
    cchunk1->setPosZImage( iposz );
    cchunk1->setPosYImage( iposy );
    cchunk1->setNegYImage( inegy );
    cchunk1->setPosXImage( iposx );
    cchunk1->setNegXImage( inegx );
    cchunk1->setMinFilter( GL_LINEAR );
    cchunk1->setMagFilter( GL_NEAREST );
    cchunk1->setWrapS( GL_REPEAT );
    cchunk1->setWrapT( GL_REPEAT );
    cchunk1->setEnvMode( GL_MODULATE );
    cchunk1->setLodBias( 10 );
    endEditCP(cchunk1);
    
    gchunk1 = TexGenChunk::create();
    beginEditCP(gchunk1);
    gchunk1->setGenFuncS(GL_REFLECTION_MAP_ARB);
    gchunk1->setGenFuncT(GL_REFLECTION_MAP_ARB);
    gchunk1->setGenFuncR(GL_REFLECTION_MAP_ARB);
    endEditCP(gchunk1);
    
    // blend chunk

    blchunk = BlendChunk::create();
#ifndef WIN32
//    blchunk->setSrcFactor( GL_CONSTANT_ALPHA );
//    blchunk->setDestFactor( GL_ONE_MINUS_CONSTANT_ALPHA );
#endif
    blchunk->setColor( Color4f( 1,1,1,0.1 ) );

    // texture transform chunk

    txchunk = TextureTransformChunk::create();
    beginEditCP(txchunk);
//    txchunk->setMatrix( Matrix(4,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1) );
    endEditCP(txchunk);

    glutMainLoop();

    return 0;
}
Exemplo n.º 5
0
int main( int argc, char *argv[] )
{
    osgInit(argc, argv);

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("OpenSG");
    glutKeyboardFunc(key);
    // glutReshapeFunc(resize);
    glutDisplayFunc(display);
    // glutMouseFunc(mouse);
    // glutMotionFunc(motion);

    glutIdleFunc(display);

    pImage = Image::create();

    // create the dummy structures

    // the window is needed for the chunks that access GLObjects

    win = GLUTWindow::create();
    win->frameInit(); // test for preliminary calls not messing up GLexts
    win->init();
    
    dact = DrawAction::create();
    dact->setWindow(get_pointer(win));

    win->init();

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 60, 1, 0.1, 10 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt( 3, 3, 3,  0, 0, 0,   0, 1, 0 );

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

    dlid = glGenLists( 1 );
    glNewList( dlid, GL_COMPILE );
    glutSolidSphere( .8, 8, 8 );
    glEndList();

    dlid2 = glGenLists( 1 );
    glNewList( dlid2, GL_COMPILE );
    glBegin( GL_POLYGON );
    glNormal3f( 0, 1, 0 );
    glColor3f( 1, 1, 1 );
    glTexCoord2f( 0, 0 );
    glVertex3f( -1.5, -1, -1.5 );
    glTexCoord2f( 2, 0 );
    glVertex3f(  1.5, -1, -1.5 );
    glTexCoord2f( 2, 2 );
    glVertex3f(  1.5, -1,  1.5 );
    glTexCoord2f( 0, 2 );
    glVertex3f( -1.5, -1,  1.5 );
    glEnd();
    glEndList();


    Matrix m;

    tchunk1 = TransformChunk::create();
    m.setTranslate( 0, 1, 0 );
    tchunk1->setMatrix( m );

    tchunk2 = TransformChunk::create();
    tchunk2->setMatrix( Matrix::identity() );


    mchunk1 = MaterialChunk::create();
    mchunk1->setDiffuse( Color4f( 1,0,0,0 ) );
    mchunk1->setAmbient( Color4f( 1,0,0,0 ) );
    mchunk1->setShininess( 20 );

    mchunk2 = MaterialChunk::create();
    mchunk2->setDiffuse( Color4f( 0,1,0,0 ) );
    mchunk2->setAmbient( Color4f( 0,1,0,0 ) );
    mchunk2->setShininess( 50 );

    // Texture chunk

//  UChar8 imgdata[] =
//      {  255,0,0,0,  0,255,0,0,  0,0,255,255,  255,255,255,255 };
    UChar8 imgdata[] =
        {  255,0,0,  255,0,0,  255,0,255,
           255,0,0,  255,0,0,  255,0,255,
           255,255,0,  255,255,0,  255,255,255,
           255,255,0,  255,255,0,  255,255,255, };
//  UChar8 limgdata[] =
//      {  0, 128, 64, 255 };
    pImage->set( Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, imgdata );

    if ( argc > 1 )
        pImage->read( argv[1] );

    xchunk1 = TextureChunk::create();
    beginEditCP(xchunk1);
    xchunk1->setImage( pImage ); // NOTE: the image is NOT copied, the variable
                                 // needs to be kept around as long as the 
                                 // texture is used
    xchunk1->setMinFilter( GL_LINEAR );
    xchunk1->setMagFilter( GL_NEAREST );
    xchunk1->setWrapS( GL_REPEAT );
    xchunk1->setWrapT( GL_REPEAT );
    xchunk1->setEnvMode( GL_REPLACE );
    xchunk1->setEnvColor( Color4f(.5,.5,.5,0) );
    xchunk1->setScale( false );
    
//    xchunk1->setShaderOperation(GL_PASS_THROUGH_NV);
    
    endEditCP(xchunk1);

    xchunk1->imageContentChanged();

    beginEditCP(xchunk1);
    xchunk1->setImage( pImage );
    endEditCP(xchunk1);

    // blend chunk

    blchunk = BlendChunk::create();
#ifdef GL_EXT_blend_color
    blchunk->setSrcFactor( GL_CONSTANT_ALPHA );
    blchunk->setDestFactor( GL_ONE_MINUS_CONSTANT_ALPHA );
#endif
    blchunk->setColor( Color4f( .5,.5,.5,0.1 ) );
    blchunk->setEquation(GL_FUNC_SUBTRACT);

    std::cout << "BlendChunk is trans:" << blchunk->isTransparent() << std::endl;
    
    // texture transform chunk

    txchunk = TextureTransformChunk::create();
    beginEditCP(txchunk);
    txchunk->setMatrix( Matrix(4,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1) );
    endEditCP(txchunk);

    // polygon chunk

    pchunk1 = PolygonChunk::create();
    {
    UInt32 stipple[32] = {
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff,
        0xffff0000, 0x0000ffff, 0xffff0000, 0x0000ffff
        };

    pchunk1->editMFStipple()->clear();
    for ( int i = 0; i < 32; i++ )
        pchunk1->editMFStipple()->push_back( stipple[i] );
    }

    pchunk1->setFrontMode(GL_LINE);
    pchunk1->setBackMode(GL_FILL);
    
    pchunk2 = PolygonChunk::create();
    {
    UInt32 stipple[32] = {
        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
        0x00000000, 0x00000000, 0x00000000, 0x00000000,
        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
        0x00000000, 0x00000000, 0x00000000, 0x00000000,
        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
        0x00000000, 0x00000000, 0x00000000, 0x00000000,
        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
        0x00000000, 0x00000000, 0x00000000, 0x00000000,
        };

    pchunk2->editMFStipple()->clear();
    for ( int i = 0; i < 32; i++ )
        pchunk2->editMFStipple()->push_back( stipple[i] );
    }


    lichunk1 = LineChunk::create();
    lichunk1->setSmooth(true);
    lichunk1->setStipplePattern(0xf0f0);

    lichunk2 = LineChunk::create();
    lichunk2->setStippleRepeat(5);
    lichunk2->setStipplePattern(0xaaaa);

    glutMainLoop();

    return 0;
}