Show
Ignore:
Timestamp:
01/11/07 12:47:01 (8 years ago)
Author:
robert
Message:

Ported follow examples to osgViewer:

osgshape
osgsimplifier
osgsimulation
osgslice
osgspacewarp
osgspheresegment
osgspotlight
osgstereoimage

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgslice/osgslice.cpp

    r4805 r5959  
    55 
    66#include <osg/Timer> 
     7#include <osg/GraphicsContext> 
     8#include <osg/ApplicationUsage> 
    79#include <osgUtil/SceneView> 
    810#include <osgDB/ReadFile> 
    911#include <osgDB/WriteFile> 
    1012 
    11 #include <osgProducer/Viewer> 
    12  
    1313#include <sstream> 
     14#include <iostream> 
    1415 
    1516#define MIN_NEARFAROFFSET 0.1 
     
    109110    } 
    110111     
    111     // create the window to draw to. 
    112     osg::ref_ptr<Producer::RenderSurface> renderSurface = new Producer::RenderSurface; 
    113     renderSurface->setWindowName("osgsimple"); 
    114     renderSurface->setWindowRectangle(100,100,numberSlices,numberSlices); 
    115     renderSurface->useBorder(true); 
    116  
    117     // make sure we have a alpha channel in the colour buffer, to enable  
    118     // alpha on read back. 
    119     Producer::VisualChooser* rs_vc = renderSurface->getVisualChooser(); 
    120     if (!rs_vc) 
    121     { 
    122         rs_vc = new Producer::VisualChooser; 
    123         rs_vc->setSimpleConfiguration(); 
    124         renderSurface->setVisualChooser(rs_vc); 
    125     } 
    126     rs_vc->setAlphaSize(8); 
    127  
    128     // create the graphics context. 
    129     renderSurface->realize(); 
    130      
     112 
     113 
     114    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 
     115    traits->x = 100; 
     116    traits->y = 100; 
     117    traits->width = numberSlices; 
     118    traits->height = numberSlices; 
     119    traits->alpha = 8; 
     120    traits->windowDecoration = true; 
     121    traits->doubleBuffer = true; 
     122    traits->sharedContext = 0; 
     123    traits->pbuffer = false; 
     124 
     125    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 
     126    if (!gc || !gc->valid()) 
     127    { 
     128        osg::notify(osg::NOTICE)<<"Error: unable to create graphics window"<<std::endl; 
     129        return 1; 
     130    } 
     131     
     132    gc->realize(); 
     133    gc->makeCurrent(); 
     134 
    131135    // create the view of the scene. 
    132136    osg::ref_ptr<osgUtil::SceneView> sceneView = new osgUtil::SceneView; 
     
    158162     
    159163    // main loop (note, window toolkits which take control over the main loop will require a window redraw callback containing the code below.) 
    160     for( unsigned int i = 0 ; i < sp->_sliceNumber && renderSurface->isRealized() ; ++i ) 
     164    for( unsigned int i = 0 ; i < sp->_sliceNumber && gc->isRealized() ; ++i ) 
    161165    { 
    162166        // set up the frame stamp for current frame to record the current time and frame number so that animtion code can advance correctly 
     
    169173         
    170174        // update the viewport dimensions, incase the window has been resized. 
    171         sceneView->setViewport(0,0,renderSurface->getWindowWidth(),renderSurface->getWindowHeight()); 
     175        sceneView->setViewport(0,0,traits->width,traits->height); 
    172176         
    173177         
     
    190194                 
    191195        // Swap Buffers 
    192         renderSurface->swapBuffers(); 
     196        gc->swapBuffers(); 
    193197         
    194198        std::cout << "before readPixels: _r = " << sp->_image->r() << std::endl;