Hi all,

sorry that it took some time, but I need to come back to using
several aspects with OpenSG 2.0.

On 23.11.2011 12:54, Gerrit Voß wrote:
>
>> But using several aspects might be an alternative ;)
>
> At the moment, yes.
>
>>>>> Or can StatsCollector be switched off completely?
>>> By default the render action does not have a StatCollector; I changed 
>>> the code to only add the attachment and collect statistics if there is a 
>>> collector present (otherwise it's a waste of time anyway).
>>> Incidentally this also fixes a bug where we were counting triangles twice.
>>>
>>>>> How are resources handled during traversal on different windows?
>>> Sorry for being slow, but I don't quite get what you are asking for, can 
>>> you rephrase the question or give an example of what handling for which 
>>> resources you are interested in?
>>
>> If you have 2 windows/contexts and 2 render actions, the display lists are 
>> created and stored for each one, for example?
>
> yes, all OpenGL objects are bound and maintained by the window, so for n
> windows you will have n times the OpenGL resources allocated. Currently
> we do not support sharing of contexts out of the box. The render action
> will carry some traversal dependent OpenSG elements.
>
>> Currently, I am not seeing anything. Perhaps I may send the debug log 
>> offline?
>
> As there can be quite some reasons for not seeing anything that would
> be helpful. A good starting point would be to use a OpenGL debugger and
> see if the OpenGL command stream looks as expected.
>
>> I will try to use several aspects. 
>> How is the max number of aspects set with OpenSG 2.0 ?
>
> that part is gone. Aspects copies are allocated on the fly (sync) and
> not while creating the initial container copy, so there is no need to
> specify the maximum number of aspect in the beginning anymore.
>
> The complex scenemanager contains a reference implementation for
> parallel drawers on multiple aspects (DrawManager/Drawer) so it might
> be a convenient reference. I'll have to check if I have the multiple
> windows CSM Example committed.
>
Attached is an example program using two windows:
a GLUT window and a WIN32 window (created with WIN32 API directly; sorry 
Windows only ;) ).
The only place where aspects are assigned is the thread start
    thread->runFunction(::ThreadProc, // thread function
            1,            // aspect id
            NULL);        // thread argument

I am totally unsure if it is correct like that? I would really appreciate if 
someone
who used it before could have a look ..
Unfortunately, it crashes when accessing one of the texture images in the 
thread function, see call stack
(MS Visual Studio 2008 SE, Windows 7 64bit).
I can offer to document or summarize this part of the system
when I finished exploring :)

Thanks a lot,
Christoph
-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!               
Jetzt informieren: http://www.gmx.net/de/go/freephone
        
OSGSystemRN.dll!OSG::PointerSFieldCommon<OSG::ChildAccessHandler<OSG::UnrecordedRefCountPolicy>,1>::ptrStoreGet()
  Ligne 97 + 0x5 octets        C++
        OSGSystemRN.dll!OSG::ChildPointerSField<OSG::Image * 
__ptr64,OSG::UnrecordedRefCountPolicy,1>::getValue()  Ligne 102    C++
        OSGSystemRN.dll!OSG::TextureObjChunkBase::getImage()  Ligne 82  C++
        OSGSystemRN.dll!OSG::TextureObjChunk::handleGL(OSG::DrawEnv * 
pEnv=0x0000000003d9b718, unsigned int osgid=6, OSG::Window::GLObjectStatusE 
mode=initialize, unsigned int uiOptions=0)  Ligne 1544 + 0xd octets   C++
        OSGSystemRN.dll!boost::_mfi::mf4<unsigned 
int,OSG::TextureObjChunk,OSG::DrawEnv * __ptr64,unsigned int,enum 
OSG::Window::GLObjectStatusE,unsigned 
int>::call<OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy>,OSG::DrawEnv
 * __ptr64,unsigned int,enum OSG::Window::GLObjectStatusE,unsigned 
int>(OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy> & u={...}, 
const void * __formal=0x0000000000000000, OSG::DrawEnv * & 
b1=0x0000000003d9b718, unsigned int & b2=6, OSG::Window::GLObjectStatusE & 
b3=initialize, unsigned int & b4=0)  Ligne 498  C++
        OSGSystemRN.dll!boost::_mfi::mf4<unsigned 
int,OSG::TextureObjChunk,OSG::DrawEnv * __ptr64,unsigned int,enum 
OSG::Window::GLObjectStatusE,unsigned 
int>::operator()<OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy> 
>(OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy> & u={...}, 
OSG::DrawEnv * a1=0x0000000003d9b718, unsigned int a2=6, 
OSG::Window::GLObjectStatusE a3=initialize, unsigned int a4=0)  Ligne 513       
 C++
        
OSGSystemRN.dll!boost::_bi::list5<boost::_bi::value<OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy>
 >,boost::arg<1>,boost::arg<2>,boost::arg<3>,boost::arg<4> 
>::operator()<unsigned int,boost::_mfi::mf4<unsigned 
int,OSG::TextureObjChunk,OSG::DrawEnv * __ptr64,unsigned int,enum 
OSG::Window::GLObjectStatusE,unsigned int>,boost::_bi::list4<OSG::DrawEnv * 
__ptr64 & __ptr64,unsigned int & __ptr64,enum OSG::Window::GLObjectStatusE & 
__ptr64,unsigned int & __ptr64> >(boost::_bi::type<unsigned int> 
__formal={...}, boost::_mfi::mf4<unsigned int,OSG::TextureObjChunk,OSG::DrawEnv 
*,unsigned int,enum OSG::Window::GLObjectStatusE,unsigned int> & f={...}, 
boost::_bi::list4<OSG::DrawEnv * &,unsigned int &,enum 
OSG::Window::GLObjectStatusE &,unsigned int &> & a={...}, 
boost::_bi::type<unsigned int> __formal={...})  Ligne 516      C++
        OSGSystemRN.dll!boost::_bi::bind_t<unsigned 
int,boost::_mfi::mf4<unsigned int,OSG::TextureObjChunk,OSG::DrawEnv * 
__ptr64,unsigned int,enum OSG::Window::GLObjectStatusE,unsigned 
int>,boost::_bi::list5<boost::_bi::value<OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy>
 >,boost::arg<1>,boost::arg<2>,boost::arg<3>,boost::arg<4> > 
>::operator()<OSG::DrawEnv * __ptr64,unsigned int,enum 
OSG::Window::GLObjectStatusE,unsigned int>(OSG::DrawEnv * & 
a1=0x0000000003d9b718, unsigned int & a2=6, OSG::Window::GLObjectStatusE & 
a3=initialize, unsigned int & a4=0)  Ligne 146      C++
        
OSGSystemRN.dll!boost::detail::function::function_obj_invoker4<boost::_bi::bind_t<unsigned
 int,boost::_mfi::mf4<unsigned int,OSG::TextureObjChunk,OSG::DrawEnv * 
__ptr64,unsigned int,enum OSG::Window::GLObjectStatusE,unsigned 
int>,boost::_bi::list5<boost::_bi::value<OSG::MTRefCountPtr<OSG::TextureObjChunk,OSG::NoRefCountPolicy>
 >,boost::arg<1>,boost::arg<2>,boost::arg<3>,boost::arg<4> > >,unsigned 
int,OSG::DrawEnv * __ptr64,unsigned int,enum 
OSG::Window::GLObjectStatusE,unsigned 
int>::invoke(boost::detail::function::function_buffer & function_obj_ptr={...}, 
OSG::DrawEnv * a0=0x0000000003d9b718, unsigned int a1=6, 
OSG::Window::GLObjectStatusE a2=initialize, unsigned int a3=0)  Ligne 133   C++
        OSGSystemRN.dll!boost::function4<unsigned int,OSG::DrawEnv * 
__ptr64,unsigned int,enum OSG::Window::GLObjectStatusE,unsigned 
int>::operator()(OSG::DrawEnv * a0=0x0000000003d9b718, unsigned int a1=6, 
OSG::Window::GLObjectStatusE a2=initialize, unsigned int a3=0)  Ligne 1014      
 C++
        OSGSystemRN.dll!OSG::Window::validateGLObject(unsigned int osgId=6, 
OSG::DrawEnv * pEnv=0x0000000003d9b718, unsigned int uiOptions=0)  Ligne 687 + 
0x33 octets  C++
        OSGSystemRN.dll!OSG::TextureObjChunk::activate(OSG::DrawEnv * 
pEnv=0x0000000003d9b718, unsigned int idx=0)  Ligne 1707  C++
        OSGSystemRN.dll!OSG::DrawEnv::activate(OSG::State * 
pState=0x0000000003d923c0, OSG::StateOverride * pOverride=0x0000000003d9f190)  
Ligne 400    C++
        OSGSystemRN.dll!OSG::DrawEnv::activateState(OSG::State * 
pNewState=0x0000000003d923c0, OSG::StateOverride * 
pNewStateOverride=0x0000000003d9f190)  Ligne 345    C++
        OSGSystemRN.dll!OSG::TreeBuilderBase::drawNode(OSG::RenderTreeNode * 
pNode=0x0000000003da2910, OSG::DrawEnv & denv={...}, OSG::RenderPartitionBase * 
part=0x0000000003d9b6b0)  Ligne 148        C++
        OSGSystemRN.dll!OSG::TreeBuilderBase::drawNode(OSG::RenderTreeNode * 
pNode=0x0000000003da29f0, OSG::DrawEnv & denv={...}, OSG::RenderPartitionBase * 
part=0x0000000003d9b6b0)  Ligne 160        C++
        OSGSystemRN.dll!OSG::TreeBuilderBase::drawNode(OSG::RenderTreeNode * 
pNode=0x0000000003da1280, OSG::DrawEnv & denv={...}, OSG::RenderPartitionBase * 
part=0x0000000003d9b6b0)  Ligne 160        C++
        OSGSystemRN.dll!OSG::TreeBuilderBase::drawNode(OSG::RenderTreeNode * 
pNode=0x0000000003d9eab0, OSG::DrawEnv & denv={...}, OSG::RenderPartitionBase * 
part=0x0000000003d9b6b0)  Ligne 160        C++
        OSGSystemRN.dll!OSG::TreeBuilderBase::drawNode(OSG::RenderTreeNode * 
pNode=0x0000000003d9e990, OSG::DrawEnv & denv={...}, OSG::RenderPartitionBase * 
part=0x0000000003d9b6b0)  Ligne 160        C++
        OSGSystemRN.dll!OSG::StateSortTreeBuilder::draw(OSG::DrawEnv & 
denv={...}, OSG::RenderPartitionBase * pPart=0x0000000003d9b6b0)  Ligne 189     
 C++
        OSGSystemRN.dll!OSG::RenderPartition::doExecution(bool 
bRestoreViewport=true)  Ligne 519        C++
        OSGSystemRN.dll!OSG::RenderAction::drawBuffer(unsigned int buf=0)  
Ligne 698    C++
        OSGSystemRN.dll!OSG::RenderAction::stop(OSG::ActionBase::ResultE 
res=Continue)  Ligne 622       C++
        OSGSystemRN.dll!OSG::Action::callStop(OSG::ActionBase::ResultE 
res=Continue)  Ligne 615 + 0x14 octets   C++
        OSGSystemRN.dll!OSG::Action::apply(std::_Vector_iterator<OSG::Node 
*,std::allocator<OSG::Node *> > begin=0x0000000003d955f0 {_sfVolume={...} 
_sfParent={...} _mfChildren={...} ...}, std::_Vector_iterator<OSG::Node 
*,std::allocator<OSG::Node *> > end=0x0000000005d23150 {_sfVolume={...} 
_sfParent={...} _mfChildren={...} ...})  Ligne 271 + 0xe octets    C++
        OSGSystemRN.dll!OSG::Action::apply(OSG::Node * const 
node=0x0000000003d8d530)  Ligne 288 + 0x6b octets  C++
        OSGSystemRN.dll!OSG::Viewport::render(OSG::RenderActionBase * 
action=0x0000000003cd60b0)  Ligne 370     C++
        OSGSystemRN.dll!OSG::Window::doRenderAllViewports(OSG::RenderActionBase 
* action=0x0000000003cd60b0)  Ligne 2382        C++
        OSGSystemRN.dll!OSG::Window::render(OSG::RenderActionBase * 
action=0x0000000003cd60b0)  Ligne 1994      C++
        testStatisticsRender.exe!ThreadProc(void * __formal=0x0000000000000000) 
 Ligne 354      C++
        OSGBaseRN.dll!OSG::BaseWinThreadBase::threadFunc(void * 
pThreadArg=0x0000000003d92da8)  Ligne 519       C++
        kernel32.dll!00000000770ff33d()         
        [Les frames ci-dessous sont peut-être incorrects et/ou manquants, aucun 
symbole chargé pour kernel32.dll]       
        ntdll.dll!0000000077332cc1()    
#include "OSGGLUT.h"
#include "OSGConfig.h"
#include "OSGSimpleGeometry.h"
#include "OSGGLUTWindow.h"
#include "OSGSimpleSceneManager.h"
#include "OSGSceneFileHandler.h"

#include <OSGImageFileHandler.h>
#include <OSGMatrixUtility.h>
#include <OSGNameAttachment.h>
#include <OSGSceneFileHandler.h>
#include <OSGShaderProgram.h>
#include <OSGShaderProgramChunk.h>
#include <OSGSimpleGeometry.h>
#include <OSGSimpleSceneManager.h>
#include <OSGSkinnedGeometry.h>
#include <OSGSkyBackground.h>
#include <OSGTextureObjChunk.h>
#include <OSGNavigationManager.h>

#include "OSGDrawable.h"
#include "OSGSimpleStatisticsForeground.h"
#include "OSGStatElemTypes.h"
#include "OSGStatCollector.h"
#include "OSGRenderAction.h"
#include "OSGTextureObjChunk.h"
#include "OSGMaterialChunk.h"
#include "OSGSimpleSHLChunk.h"
#include "OSGSolidBackground.h"
#include "OSGPerspectiveCamera.h"
#include "OSGProjectionCameraDecorator.h"
#include "OSGSimpleGeometry.h"

OSG::Real32 skySize = 5.0f;
unsigned win_width = 500;
unsigned win_height = 500;

OSG::SimpleSceneManager*   mgr  = NULL;
OSG::RenderAction*         ract = NULL;

bool show = true;
bool bGLFinish = false;

// WIN32 data for win2
HDC          hDC;               // Private GDI Device Context
HWND         hWnd;              // Holds Our Window Handle
HGLRC        hRC;
HINSTANCE    hInstance;         // Holds The Instance Of The Application

// windows
unsigned winId = 0;
OSG::GLUTWindowRecPtr    win;
OSG::WIN32WindowUnrecPtr win2;

// GLUT redraw the window
void display(void)
{
   //glutSetWindow(winId);
   mgr->redraw();
}

// GLUT react to size changes
void reshape(int w, int h)
{
    glViewport(0, 0, w, h);

    mgr->resize(w,h);
    //glutPostRedisplay();
}

// GLUT react to mouse button presses
void mouse(int button, int state, int x, int y)
{
   if (state) {
        mgr->mouseButtonRelease(button, x, y);
   } else {
        mgr->mouseButtonPress(button, x, y);
   }

   glutPostRedisplay();
}

// GLUT react to mouse motions with pressed buttons
void motion(int x, int y)
{
    mgr->mouseMove(x, y);
    glutPostRedisplay();
}

// GLUT react to keys
void keyboard(unsigned char k, int, int)
{
    switch(k) {
        case 27:
        {
            delete mgr;

            win   = NULL;

            OSG::osgExit();
            exit(0);
        }

        // Output help about the controls
        // - If you add an option, please add it here too.
       case '?':
       case '/':
       case 'h':
       {
          std::cerr << "\nControls:"
                    << "v: Toggle drawing of volumes.\n"
                    << "z: Toggle zwrite on rendering action.\n"
                    << "r: switch to render action.\n"
                    << "t: switch to traversal action.\n"
                    << "n: toggle state sorting on action.\n"
                    << "m: set keygen to 0.\n"
                    << "s: set keygen for shaders.\n"
                    << "g: toggle using gl finish.\n"
                    << "x: toggle stat mode.\n"
                    << std::endl;
       }
       break;

        case 'v':
        {
            mgr->getRenderAction()->setVolumeDrawing(
                !mgr->getRenderAction()->getVolumeDrawing());
            std::cerr << "Volume Drawing: "
                      << (mgr->getRenderAction()->getVolumeDrawing() ?
                          "on":"off")
                      << std::endl;
        }
        break;

        case 'm':
            ract->setKeyGen(0);
            break;

        case 's':
        {
            OSG::UInt32 uiSId = 
                OSG::SimpleSHLChunk  ::getStaticClassId() & 0x000003FF;
            OSG::UInt32 uiTId = 
                OSG::TextureBaseChunk::getStaticClassId() & 0x000003FF;
            OSG::UInt32 uiMId = 
                OSG::MaterialChunk   ::getStaticClassId() & 0x000003FF;


            OSG::UInt32 uiKeyGen = (uiSId) | (uiTId << 10) | (uiMId << 20);

            ract->setKeyGen(uiKeyGen);
        }
        break;

        case 'g':
            bGLFinish = !bGLFinish;
            ract->setUseGLFinish(bGLFinish);
            //act->setUseGLFinish(bGLFinish);
            std::cerr << "Set use gl finish to: " << bGLFinish << std::endl;
            break;
    }
}

// change the geometry created with makePlaneGeo into quad with center origin 
in plane given by (dirx, diry)
// edge length is 2*size
void changePlaneGeo (OSG::GeometryUnrecPtr geo,
                     OSG::Real32 size, 
                     OSG::Pnt3f origin,
                     OSG::Vec3f dirx,
                     OSG::Vec3f diry) 
{
  //geo->removeFromProperties (OSG::Geometry::PositionsIndex);
  //geo->removeFromProperties (OSG::Geometry::NormalsIndex);

    OSG::GeoPnt3fPropertyUnrecPtr  pnts  = OSG::GeoPnt3fProperty ::create();
    OSG::GeoVec3fPropertyUnrecPtr  norms = OSG::GeoVec3fProperty ::create();
    geo->setPositions(pnts);
    geo->setNormals  (norms);

    OSG::GeoPnt3fProperty::StoredFieldType *p  = pnts ->editFieldPtr();
    OSG::GeoVec3fProperty::StoredFieldType *n  = norms->editFieldPtr();

    p->push_back(origin - size*dirx - size*diry);
    p->push_back(origin - size*dirx + size*diry);
    p->push_back(origin + size*dirx - size*diry);
    p->push_back(origin + size*dirx + size*diry);
    OSG::Vec3f normal = dirx.cross(diry);
    n->push_back(normal);
    n->push_back(normal);
    n->push_back(normal);
    n->push_back(normal);
}

// load sky-box imitation; uses 
skyFront.jpg/skyBack.jpg/skyLeft.jpg/skyRight.jpg/skyTop.jpg/skyBottom.jpg
OSG::NodeUnrecPtr loadBackground (void)
{
    OSG::ImageUnrecPtr           imgFront  = 
OSG::ImageFileHandler::the()->read("skyFront.jpg");
    OSG::TextureObjChunkUnrecPtr texFront  = OSG::TextureObjChunk::create();
    texFront->setImage(imgFront);

    OSG::ImageUnrecPtr           imgBack   = 
OSG::ImageFileHandler::the()->read("skyBack.jpg");
    OSG::TextureObjChunkUnrecPtr texBack   = OSG::TextureObjChunk::create();
    texBack->setImage(imgBack);

    OSG::ImageUnrecPtr           imgLeft   = 
OSG::ImageFileHandler::the()->read("skyLeft.jpg");
    OSG::TextureObjChunkUnrecPtr texLeft   = OSG::TextureObjChunk::create();
    texLeft->setImage(imgLeft);

    OSG::ImageUnrecPtr           imgRight  = 
OSG::ImageFileHandler::the()->read("skyRight.jpg");
    OSG::TextureObjChunkUnrecPtr texRight  = OSG::TextureObjChunk::create();
    texRight->setImage(imgRight);

    OSG::ImageUnrecPtr           imgTop    = 
OSG::ImageFileHandler::the()->read("skyTop.jpg");
    OSG::TextureObjChunkUnrecPtr texTop    = OSG::TextureObjChunk::create();
    texTop->setImage(imgTop);

    OSG::ImageUnrecPtr           imgBottom = 
OSG::ImageFileHandler::the()->read("skyBottom.jpg");
    OSG::TextureObjChunkUnrecPtr texBottom = OSG::TextureObjChunk::create();
    texBottom->setImage(imgBottom);

    // create box geometry
    //OSG::GroupUnrecPtr sky = OSG::makeCoredNode<OSG::Group>();
    OSG::GeometryUnrecPtr left =  OSG::makePlaneGeo(2.0f*skySize,
                                              2.0f*skySize,
                                              1, 1);
    OSG::GeometryUnrecPtr right =  OSG::makePlaneGeo(2.0f*skySize,
                                              2.0f*skySize,
                                              1, 1);
    OSG::GeometryUnrecPtr front =  OSG::makePlaneGeo(2.0f*skySize,
                                               2.0f*skySize,
                                               1, 1);
    OSG::GeometryUnrecPtr back =  OSG::makePlaneGeo(2.0f*skySize,
                                              2.0f*skySize,
                                              1, 1);
    OSG::GeometryUnrecPtr top =  OSG::makePlaneGeo(2.0f*skySize,
                                             2.0f*skySize,
                                             1, 1);
    OSG::GeometryUnrecPtr bottom =  OSG::makePlaneGeo(2.0f*skySize,
                                                2.0f*skySize,
                                                1, 1);
    changePlaneGeo(left, skySize, 
                   OSG::Pnt3f(+skySize, 0.0f, 0.0f),
                   OSG::Vec3f(0.0f, -1.0f, 0.0f), OSG::Vec3f(0.0f, 0.0f, 1.0f));
    changePlaneGeo(right, skySize, 
                   OSG::Pnt3f(-skySize, 0.0f, 0.0f),
                   OSG::Vec3f(0.0f, 1.0f, 0.0f), OSG::Vec3f(0.0f, 0.0f, 1.0f));
    changePlaneGeo(front, skySize, 
                   OSG::Pnt3f(0.0f, +skySize, 0.0f),
                   OSG::Vec3f(1.0f, 0.0f, 0.0f), OSG::Vec3f(0.0f, 0.0f, 1.0f));
    changePlaneGeo(back, skySize, 
                   OSG::Pnt3f(0.0f, -skySize, 0.0f),
                   OSG::Vec3f(-1.0f, 0.0f, 0.0f), OSG::Vec3f(0.0f, 0.0f, 1.0f));
    changePlaneGeo(top, skySize, 
                   OSG::Pnt3f(0.0f, 0.0f, +skySize),
                   OSG::Vec3f( 1.0f, 0.0f, 0.0f), OSG::Vec3f(0.0f, -1.0f, 
0.0f));
    changePlaneGeo(bottom, skySize, 
                   OSG::Pnt3f(0.0f, 0.0f, -skySize),
                   OSG::Vec3f(-1.0f, 0.0f, 0.0f), OSG::Vec3f(0.0f, -1.0f, 
0.0f));

    OSG::FieldContainerUnrecPtr mat = OSG::getDefaultMaterial()->shallowCopy();
    OSG::ChunkMaterial*   leftChunk = 
dynamic_cast<OSG::ChunkMaterial*>(mat.get());
    left->setMaterial(leftChunk);
    leftChunk->addChunk(texLeft);
    mat = OSG::getDefaultMaterial()->shallowCopy();
    OSG::ChunkMaterial* rightChunk  = 
dynamic_cast<OSG::ChunkMaterial*>(mat.get());
    right->setMaterial(rightChunk);
    rightChunk->addChunk(texRight);
    mat = OSG::getDefaultMaterial()->shallowCopy();
    OSG::ChunkMaterial* frontChunk  = 
dynamic_cast<OSG::ChunkMaterial*>(mat.get());
    front->setMaterial(frontChunk);
    frontChunk->addChunk(texFront);
    mat = OSG::getDefaultMaterial()->shallowCopy();
    OSG::ChunkMaterial* backChunk   = 
dynamic_cast<OSG::ChunkMaterial*>(mat.get());
    back->setMaterial(backChunk);
    backChunk->addChunk(texBack);
    mat = OSG::getDefaultMaterial()->shallowCopy();
    OSG::ChunkMaterial* topChunk    = 
dynamic_cast<OSG::ChunkMaterial*>(mat.get());
    top->setMaterial(topChunk);
    topChunk->addChunk(texTop);
    mat = OSG::getDefaultMaterial()->shallowCopy();
    OSG::ChunkMaterial* bottomChunk = 
dynamic_cast<OSG::ChunkMaterial*>(mat.get());
    bottom->setMaterial(bottomChunk);
    bottomChunk->addChunk(texBottom);

    OSG::NodeUnrecPtr sky = OSG::makeCoredNode<OSG::Group>();
    sky->addChild(makeNodeFor(left));
    sky->addChild(makeNodeFor(right));
    sky->addChild(makeNodeFor(front));
    sky->addChild(makeNodeFor(back));
    sky->addChild(makeNodeFor(top));
    sky->addChild(makeNodeFor(bottom));

    return sky;
}

void makeCurrent (int w)
{
   if (w < 0) {
      wglMakeCurrent(NULL, NULL);
      return;
   } 
   // make window w>0 current
   if (!wglMakeCurrent(hDC, hRC)) {
      FWARNING(("TiledSupport::makeCurrent: Can't Activate GL Context for 
window!\n"));
   }
   //FWARNING(("current DC=%p, current RC=%p\n", wglGetCurrentDC(), 
wglGetCurrentContext()));
}
void swapBuffers (int w)
{
   if (w < 0) {
      return;
   }
   if (!SwapBuffers(hDC)) {
      FWARNING(("TiledSupport::swapBuffers: Can't swap buffers for window!\n"));
   }
}
void killGLWindow (int w)
{
   FWARNING(("TiledSupport::killGLWindow\n"));
   if (!wglMakeCurrent(NULL,NULL)) {                                    // Are 
We Able To Release The DC And RC Contexts?
     FWARNING(("TiledSupport::killGLWindow: Release Of DC And RC Failed!\n"));
   }
   if (hRC) {                                                                   
                // Do We Have A Rendering Context?
      if (!wglDeleteContext(hRC)) {                                             
// Are We Able To Delete The RC?
        FWARNING(("TiledSupport::killGLWindow: Release Rendering Context 
Failed!\n"));
      }
      hRC = NULL;                                                               
                // Set RC To NULL
   }

   if (hDC) {
      if (!ReleaseDC(hWnd, hDC)) {                                      // Are 
We Able To Release The DC
        FWARNING(("TiledSupport::killGLWindow: Release Device Context 
Failed!\n"));
      }
      hDC = NULL;                                                               
// Set DC To NULL
   }

   if (hWnd) { 
      if (!DestroyWindow(hWnd)) {                                       // Are 
We Able To Destroy The Window?
        FWARNING(("TiledSupport::killGLWindow: Could Not Release hWnd!"));
      }
      hWnd = NULL;                                                      // Set 
hWnd To NULL
   }
}

// function executed within the thread
void ThreadProc (void* )
{
   std::cout << "enter ThreadProc" << std::endl;

   makeCurrent(0);
   while (true) {
     win2->render(ract);
     swapBuffers(0);
   }
}

// create OpenGL window
bool createWindow ()
{
   if (hInstance == NULL) { // register window class
     hInstance      = GetModuleHandle(NULL);                    // Grab An 
Instance For Our Window
     WNDCLASS  wc;                                              // Windows 
Class Structure
     wc.style       = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;       // Redraw On 
Size, And Own DC For Window.
     wc.lpfnWndProc   = (WNDPROC)DefWindowProc;                 // WndProc 
Handles Messages
     wc.cbClsExtra    = 0;                                      // No Extra 
Window Data
     wc.cbWndExtra    = 0;                                      // No Extra 
Window Data
     wc.hInstance   = hInstance;                                // Set The 
Instance
     wc.hIcon       = LoadIcon(NULL, IDI_WINLOGO);              // Load The 
Default Icon
     wc.hCursor     = LoadCursor(NULL, IDC_ARROW);              // Load The 
Arrow Pointer
     wc.hbrBackground = NULL;                                   // No 
Background Required For GL
     wc.lpszMenuName  = NULL;                                   // We Don't 
Want A Menu
     wc.lpszClassName = "OpenSG Tile";                          // Set The 
Class Name
     
     if (!RegisterClass(&wc)) { // Attempt To Register The Window Class
       FWARNING(("TiledSupport::createWindows: Failed To Register The Window 
Class!\n"));
       return false;  
     }
   }

   RECT mClientRect;
   mClientRect.left   = 10;
   mClientRect.top    = 10; 
   mClientRect.right  = mClientRect.left + win_width;
   mClientRect.bottom = mClientRect.top  + win_height;

   DWORD dwStyle   = WS_OVERLAPPEDWINDOW;                               // 
Windows Style
   DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;                // 
Window Extended Style
   //AdjustWindowRectEx(&mClientRect, dwStyle, FALSE, dwExStyle);       // 
Adjust WindowRect To True Size Including Decorations

   GLuint PixelFormat; // Holds The Results After Searching For A Match

   // open one window
   FWARNING(("TiledSupport::createWindows: open window\n"));
   // Create The Window
   hWnd = CreateWindowEx(dwExStyle,                     // Extended Style For 
The Window
                            "OpenSG Tile",              // Class Name
                            "Tiles",                    // Window Title
                            dwStyle |                   // Defined Window Style
                            WS_CLIPSIBLINGS |           // Required Window Style
                            WS_CLIPCHILDREN,            // Required Window Style
                            mClientRect.left,
                            mClientRect.top,    // Window Position
                            win_width,          // Calculate Window Width
                            win_height,         // Calculate Window Height
                            NULL,                       // No Parent Window
                            NULL,                       // No Menu
                            hInstance,                  // Instance
                            NULL);
   if (!hWnd) {                 // Pass this-Pointer To WM_CREATE
       killGLWindow(0); // Reset The Display
       FWARNING(("TiledSupport::createWindows: Window Creation Error!\n"));
       return false;    
   }

   ShowWindow(hWnd, SW_SHOW); // Show The Window
   //SetForegroundWindow(hWnd); // Slightly Higher Priority
   //ResizeGLScene(width, height); // Set Up Our Perspective GL Screen

   hDC = GetDC(hWnd);
   if (hDC == 0) {                                                      // Did 
We Get A Device Context?
       killGLWindow(0);                                                         
// Reset The Display
       FWARNING(("TiledSupport::createWindows: Can't Create A GL Device 
Context!\n"));
       return false;    
   }

   static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),  //  
size of this pfd  
                                        1,                     // version 
number  
                                        PFD_DRAW_TO_WINDOW |   // support 
window  
                                        PFD_SUPPORT_OPENGL |   // support 
OpenGL  
                                        PFD_DOUBLEBUFFER,      // double 
buffered  
                                        PFD_TYPE_RGBA,         // RGBA type  
                                        24,                    // 24-bit color 
depth  
                                        0, 0, 0, 0, 0, 0,      // color bits 
ignored  
                                        0,                     // no alpha 
buffer  
                                        0,                     // shift bit 
ignored  
                                        0,                     // no 
accumulation buffer  
                                        0, 0, 0, 0,            // accum bits 
ignored  
                                        32,                    // 32-bit 
z-buffer      
                                        0,                     // no stencil 
buffer  
                                        0,                     // no auxiliary 
buffer  
                                        PFD_MAIN_PLANE,        // main layer  
                                        0,                     // reserved  
                                        0, 0, 0                // layer masks 
ignored  
   }; 
   PixelFormat = ChoosePixelFormat(hDC, (const PIXELFORMATDESCRIPTOR*)&pfd);
   if (PixelFormat == 0) { 
      // Did Windows Find A Matching Pixel Format?
      killGLWindow(0); // Reset The Display
      FWARNING(("TiledSupport::createWindows: Can't Find A Suitable 
PixelFormat!\n"));
      return false;     
   }

   if (!SetPixelFormat(hDC, PixelFormat, (const PIXELFORMATDESCRIPTOR*)&pfd)) { 
      // Are We Able To Set The Pixel Format?   
      killGLWindow(0); // Reset The Display
      FWARNING(("TiledSupport::createWindows: Can't Set The PixelFormat!\n"));
      return false;     
   }   
   ShowWindow(hWnd, SW_SHOW); // Show The Window
   hRC = wglCreateContext(hDC);
   if (hRC == 0) { 
      // Are We Able To Get A Rendering Context?
      killGLWindow(0); // Reset The Display
      FWARNING(("TiledSupport::createWindows: Can't Create A GL Rendering 
Context!\n"));
      return false;     
   }
   makeCurrent(0);
}

int main(int argc, char **argv)
{
    OSG::osgInit(argc,argv);
    // GLUT init
    glutInit           (&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

    glutInitWindowSize (500, 500);
    winId = glutCreateWindow("OpenSG");

    glutReshapeFunc (NULL);
    glutDisplayFunc (display);
    glutIdleFunc    (display);
    glutMouseFunc   (mouse);
    glutMotionFunc  (motion);
    glutKeyboardFunc(keyboard);

    win = OSG::GLUTWindow::create();
    win->setGlutId(winId);
    win->init();
    win->resize(500, 500);

    // create OSG objects
    createWindow();
    // create OSG objects
    win2 = OSG::WIN32Window::create();
    win2->editSFHwnd() ->setValue(hWnd);
    win2->editSFHdc()  ->setValue(hDC);
    win2->editSFHglrc()->setValue(hRC);
    ract = OSG::RenderAction::create();
    ract->setVolumeDrawing(true);
    win2->init();
    // very important for the size of viewports
    win2->resize(win_width, win_height);

    // very important: a context can only be current on one thread
    makeCurrent(-1);

    // create the scene
    OSG::NodeUnrecPtr scene = OSG::makeCoredNode<OSG::Group>();

#if 1
    std::cout << "load background" << std::endl;
    OSG::NodeRecPtr box = loadBackground();
    scene->addChild(box);
    std::cout << "done." << std::endl;
#endif
    scene->addChild(OSG::makeTorus(1.0f, 2.0f, 5, 5));

    // create the SimpleSceneManager helper
    mgr = new OSG::SimpleSceneManager;
    // create the window and initial camera/viewport
    mgr->setWindow(win );
    // tell the manager what to manage
    mgr->setRoot  (scene);

    // create shared OSG elements
    OSG::SolidBackgroundRecPtr bg = OSG::SolidBackground::create();
    bg->setColor(OSG::Color3f(0.0f, 0.0f, 0.0f));

    OSG::CameraUnrecPtr   cam  = mgr->getCamera();
    OSG::NodeUnrecPtr     root = mgr->getInternalRoot(); 
    OSG::ViewportRecPtr   np = OSG::Viewport::create();
    np->setCamera    (cam);
    np->setRoot      (root);
    np->setSize      (0, 0, 1, 1);
    np->setBackground(bg);
    //np->addForeground(fg);
    win2->addPort(np);

    OSG::Thread::getCurrentChangeList()->commitChanges();
    // show the whole scene
    mgr->showAll();

    // instead start a new thread which runs the loop
    OSG::WindowDrawThread::ObjTransitPtr thread = 
OSG::WindowDrawThread::get("render", 0);
    thread->runFunction(::ThreadProc, // thread function
                        1,            // aspect id
                        NULL);        // thread argument

    // GLUT main loop
    glutMainLoop ();

    return 0;
}

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to