コード例 #1
0
ファイル: testFboVP.cpp プロジェクト: mlimper/OpenSG1x
// redraw the window
void display(void)
{
    WindowPtr win = mgr->getWindow();
    
    //mgr->redraw();
    win->activate();
    win->frameInit();
    
    //RenderAction *rAct = (RenderAction*)mgr->getAction();
    
    if (multipass)
    {
        RenderAction *rAct = RenderAction::create();
        
        fbo_vp->setParent(win);
        
        rAct->setWindow(get_pointer(win));
        
        fbo_vp->render(rAct);
        
        fbo_vp->setParent(NullFC);
        
        delete rAct;
        
        //multipass = false;
    }

    win->getPort(0)->render(dynamic_cast<RenderAction *>(mgr->getAction()));
    //win->renderAllViewports(rAct);

    win->swap();
    win->frameExit();
    win->deactivate();
}
コード例 #2
0
void
display(void)
{
    float t = glutGet( GLUT_ELAPSED_TIME );

    win->frameInit();

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    Matrix m;
    Quaternion q;
    q.setValueAsAxisDeg( 0,1,0, -t/20 );
    m.setRotate( q );
    tchunk1->setMatrix( m );

    tchunk1->activate( dact );
    mchunk1->activate( dact );

    glCallList( dlid );

    m.setIdentity();
    m.setTranslate( cos(t/1000), 0, sin(t/1000) );
    tchunk2->setMatrix( m );


    tchunk2->changeFrom( dact, get_pointer(tchunk1));
    mchunk2->changeFrom( dact, get_pointer(mchunk1));
    blchunk->activate( dact );
    blchunk->activate( dact );
    cchunk1->activate( dact );
    gchunk1->activate( dact );

    glCallList( dlid );

    tchunk2->deactivate( dact );
    mchunk2->deactivate( dact );
    blchunk->deactivate( dact );
    cchunk1->deactivate( dact );
    gchunk1->deactivate( dact );

    xchunk1->activate( dact );
    txchunk->activate( dact );

    glCallList( dlid2 );

    xchunk1->deactivate( dact );
    txchunk->deactivate( dact );

    win->frameExit();

    glutSwapBuffers();
}
コード例 #3
0
void
display(void)
{
    float t = glutGet( GLUT_ELAPSED_TIME );

    win->frameInit();

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    Matrix m;
    Quaternion q;
    q.setValueAsAxisDeg( 0,1,0, -t/20 );
    m.setRotate( q );
    tchunk1->setMatrix( m );

    tchunk1->activate( dact );
    mchunk1->activate( dact );
    pchunk1->activate( dact );
    lichunk1->activate( dact );

    glCallList( dlid );

    m.setIdentity();
    m.setTranslate( cos(t/1000), 0, sin(t/1000) );
    tchunk2->setMatrix( m );


    pchunk2->changeFrom( dact, get_pointer(pchunk1) );
    tchunk2->changeFrom( dact, get_pointer(tchunk1) );
    mchunk2->changeFrom( dact, get_pointer(mchunk1) );
    lichunk2->changeFrom( dact, get_pointer(lichunk1) );
    blchunk->activate( dact );

    glCallList( dlid );

    tchunk2->deactivate( dact );
    mchunk2->deactivate( dact );
    pchunk2->deactivate( dact );
    lichunk2->deactivate( dact );
    blchunk->deactivate( dact );


    xchunk1->activate( dact );
    txchunk->activate( dact );

#if 0
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_PASS_THROUGH_NV);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV,34102
);
glTexEnvf(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_SCALE_NV, 0.0000 );
glTexEnvf(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_BIAS_NV, 0.0000 );

glEnable(GL_TEXTURE_SHADER_NV);
GLint consistent;
glGetTexEnviv(GL_TEXTURE_SHADER_NV, GL_SHADER_CONSISTENT_NV,
      &consistent);
if(!consistent)
{
    FWARNING(("Texture shaders not consistent!\n"));
}
#endif
   
    glCallList( dlid2 );

// glDisable(GL_TEXTURE_SHADER_NV);
    xchunk1->deactivate( dact );
    txchunk->deactivate( dact );

    win->frameExit();

    glutSwapBuffers();
}
コード例 #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;
}
コード例 #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;
}