Hi Mike,
   
     Thanks a lot. I tried a minor trick in PIXELFORMATDESCRIPTOR by setting 
the PFD_DOUBLEBUFFER Flag. This has set the things rolling. Now I have an MFC 
MDI application running with osgViewer::CompositeViewer. Thanks a lot.
   
  Regards
   
  Harash.
  

Harash Sharma <[EMAIL PROTECTED]> wrote:
    Hi Mike,
   
      Thanks. Your suggestion did work. But now there is another problem. The 
window is getting drawn, The window is getting cleared with the specified 
color, the scene is getting loaded. But the window appears blank. I have called 
the osgViewer::CompositeViewer::frame() function in the CView::OnDraw / OnPaint 
functions. 
   
      Just for fun when I changed this to osgViewer::CompositeViewer::run(), I 
found a flickerring image of the loaded scene. I have the feeling that 
somewhere swapBuffers need to be called. Am I right? If yes, then can you guide 
me which function to call for this. 
   
  Thanks
   
  Regards
   
  Harash

"Hartman, Michael W. (MSFC-NNM06AA05Z)[PEOPLETEC]" <[EMAIL PROTECTED]> wrote:
        v\:* {behavior:url(#default#VML);}  o\:* {behavior:url(#default#VML);}  
w\:* {behavior:url(#default#VML);}  .shape {behavior:url(#default#VML);}        
st1\:*{behavior:url(#default#ieooui) }                Harash,
   
  This is from an earlier response that I had written that concerned the same 
problem you are having.   Please give it a try and see if it allows you to 
create the graphics context.  
   
  Thanks,
  Mike Hartman
   
   
  What I have found working with osgViewer and Windows, is that if you are 
assigning OSG to use an existing window/control is that you must set the 
pixelformat for that window/control before OSG can render to it.   I’m not 
familiar with QWidget but it sounds like the same problem.
   
  Below is how I am setting the pixel format for the window that I want OSG to 
render to.
  m_hWnd is the handle to the window/control/QWidget.
   
  //
  // We must set the pixelformat before we can create the OSG Rendering Surface
  //
  PIXELFORMATDESCRIPTOR pixelFormat =
  {
     sizeof(PIXELFORMATDESCRIPTOR),
     1,
     PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
     PFD_TYPE_RGBA,
     24,
     0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0,
     24,
     0,
     0,
     PFD_MAIN_PLANE,
     0,
     0, 0, 0
  };
   
  HDC hdc = ::GetDC(m_hWnd);
  if (hdc==0)
  {
     ::DestroyWindow(m_hWnd);
     return 0;
  }
   
  int pixelFormatIndex = ::ChoosePixelFormat(hdc, &pixelFormat);
  if (pixelFormatIndex==0)
  {
     ::ReleaseDC(m_hWnd, hdc);
     ::DestroyWindow(m_hWnd);
     return 0;
  }
   
  if (!::SetPixelFormat(hdc, pixelFormatIndex, &pixelFormat))
  {
     ::ReleaseDC(m_hWnd, hdc);
     ::DestroyWindow(m_hWnd);
     return 0;
  }
   
   
     

  Michael W Hartman
  Senior Software Engineer    
  Supporting:
  VP33 – Exploration Systems Development Office
  Science & Missions Systems Office
   
  Phone: (256) 544-5250
  Email: [EMAIL PROTECTED]
   

  People-Tec, Inc.
  1900 Golf Rd., Suite A-B
  Huntsville, AL 35802
   
   
   
   
   
   
   
              

 


      
---------------------------------
  
  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Harash Sharma
Sent: Wednesday, May 09, 2007 6:22 AM
To: osg users
Subject: Re: [osg-users] Multiple Camera Support on Windows (MFC)

   
    Hi all,

     

        Thanks to Robert for his help and support. Following his suggestions I 
found the blunder I was making was that somehow I had messed up the library 
versions. The versions I was using did not have the inheritedWindowData member 
in the osg::GraphicsContext::Traits structure. Anyway, I was able to set things 
right on this front by reinstalling OSG1.2 and updating it to 1.9.3 with the 
CMake utility. 

     

       The problem that I am now facing seems beyond me. The 
osg::GraphicsContext is not getting created. I am using the following set of 
statements for the purpose:

     

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;

    
  traits->x = 0;
  traits->y = 0;
  traits->width = Rect.Width();
  traits->height = Rect.Height();

      traits->windowDecoration = false;
  traits->doubleBuffer = true;
  traits->sharedContext = 0;

    
 osg::ref_ptr<osgViewer::GraphicsWindowWin32::WindowData> wdata = new    

                                    osgViewer::GraphicsWindowWin32::WindowData( 
GetSafeHwd() );

    
  traits->inheritedWindowData = wdata.get();

     

      osg::ref_ptr<osg::GraphicsContext> gc =  
osg::GraphicsContext::createGraphicsContext(traits.get());

      

      if ( gc->valid() )  {

          gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
      gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

          m_view->getCamera()->setGraphicsContext(gc.get());

          m_view->getCamera()->setViewport(new osg::Viewport(0,0, 
traits->width, traits->height));
  }

     

      The program compiles properly, but tracing through the program I found 
the GraphicsContext is not getting created. I have confirmed the validity of 
the window Handle m_hWnd. It is not null. I tried another thing, If I comment 
the statement that links the GraphicsContext Traits to the MFC Window :  

                   traits->inheritedWindowData = wdata.get();

    The GraphicsContext gets created. Can anyone tell me what is happening. 

     

    Thanks in advance.

    Regards

     

    Harash.

    
Robert Osfield <[EMAIL PROTECTED]> wrote:

    Hi Harash,
    On 5/8/07, Harash Sharma <[EMAIL PROTECTED]> wrote: 
        As you had suggested, I tried creating the osgViewer::CompositeViewer 
object and to it attached the osgViewer::View. Further, as shown in 
osgMultipleCameras example, the traits structure was filled accordingly. The 
problem I am now facing is how to attach the MFC Window to the GraphicsContext 
/ osgViewer. OSGMFC achieved this by passing the window handle using 
GetSafeHwnd() to Producer::RenderSurface. But I could not locate a mechanism of 
passing any such information to the osgViewer::View or CompositeViewer or 
Viewer. One Win32WindowingSystemInterface class  I could locate, but there too 
I could not find a way out. 


  
I don't have the code to hand, but if your browse through the  osg-users email 
archives for the last week you'll see how to use the 
osg::GraphicsContext::Traits::inheritedWindowData  set to 
osgViewer::GraphicsWindowWin32::WindowData(hwnd)  to tell the viewer to realize 
a window adopting the passed in window.  The approach is roughly the same as 
done in Producer::RenderSurface previous, only the architecture is a bit 
different in osgViewer. 

Robert.



_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
   
    
    
---------------------------------
  
  Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos. 

_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
    
---------------------------------
  Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos. 
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

 
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to