Hi Elhanan, It is unclear to me whether you are trying to build a 32 or 64-bit application in Win7x64. My C#/OSG application runs fine on Win7x64 using similar initialization code, however it is built as a x86/Win32 application. My C++/CLI project is set to the Win32 platform, and in all my C# applications I changed the platform target from the default "Any CPU" to x86. I have not tried getting this code to work in a x64 application.
Kind regards, Ruben -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Elhanan Ilani Sent: zondag 15 juli 2012 15:08 To: [email protected] Subject: [osg-users] OSG and .NET in Windows 7 x64 Hi, I'm trying to embed an OSG control inside a Windows Forms c# application. I'm using the following code: Code: // get the window handle(HWND) out of the rendering label HWND mHwnd=(HWND)m_renderingLabel->Handle.ToInt64(); // get the dimensions of the window handle RECT rect; GetWindowRect(mHwnd, &rect); // WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(mHwnd); // create osg's graphics context traits osg::ref_ptr<osg::GraphicsContext::Traits> traits=new osg::GraphicsContext::Traits; // set location and size of the window traits->x = 0; traits->y = 0; traits->width = rect.right - rect.left; traits->height = rect.bottom - rect.top; windowDecoration = false; traits->doubleBuffer = true; sharedContext = 0; inheritedWindowData = traits->windata; pbuffer = false; // We must set the pixelformat before we can create the OSG Rendering Surface PIXELFORMATDESCRIPTOR pixelFormat = { sizeof(PIXELFORMATDESCRIPTOR), // Specifies the size of this data structure. This value should be set to sizeof(PIXELFORMATDESCRIPTOR). 1, //Specifies the version of this data structure. This value should be set to 1. PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, // A set of bit flags that specify properties of the pixel buffer PFD_TYPE_RGBA, //Specifies the type of pixel data. PFD_TYPE_RGBA or PFD_TYPE_COLORINDEX 24, // Specifies the number of color bitplanes in each color buffer. For RGBA pixel types, it is the size of the color buffer, excluding the alpha bitplanes 0, // cRedBits Specifies the number of red bitplanes in each RGBA color buffer. 0, // cRedShift Specifies the shift count for red bitplanes in each RGBA color buffer. 0,0,// cGreenBits, cGreenShift 0,0,// cBlueBits , cBlueShift 0,0,// cAlphaBits, cAlphaShift 0, // cAccumBits Specifies the total number of bitplanes in the accumulation buffer. 0, // cAccumRedBits Specifies the number of red bitplanes in the accumulation buffer. 0,0,0,//cAccumGreenBits ,cAccumBlueBits ,cAccumAlphaBits 24,// cDepthBits Specifies the depth of the depth (z-axis) buffer. 0, // cStencilBits Specifies the depth of the stencil buffer. 0, // cAuxBuffers Specifies the number of auxiliary buffers. Auxiliary buffers are not supported. PFD_MAIN_PLANE, // iLayerType Ignored. Earlier implementations of OpenGL used this member, but it is no longer used. 0, // bReserved Specifies the number of overlay and underlay planes. Bits 0 through 3 specify up to 15 overlay planes and bits 4 through 7 specify up to 15 underlay planes 0, // dwLayerMask Ignored. Earlier implementations of OpenGL used this member, but it is no longer used. 0, // dwVisibleMask Specifies the transparent color or index of an underlay plane. When the pixel type is RGBA, dwVisibleMask is a transparent RGB color value 0 // dwDamageMask Ignored. Earlier implementations of OpenGL used this member, but it is no longer used. }; // Retrieves a device context for the client area. (ATL) HDC hdc = ::GetDC(mHwnd); if (hdc==0) { // Destroys the window associated with the CWindow object and sets m_hWnd to NULL. ::DestroyWindow(mHwnd); return ; } // The ChoosePixelFormat OpenGL function attempts to match an appropriate pixel format supported by a device context to a given pixel format specification. int pixelFormatIndex = ::ChoosePixelFormat(hdc, &pixelFormat); if (pixelFormatIndex==0) { // (MFC)Releases the display device context of a container of a windowless control, freeing the device context for use by other applications ::ReleaseDC(mHwnd, hdc); ::DestroyWindow(mHwnd); return ; } // The SetPixelFormat OpenGL function sets the pixel format of the specified device context to the format specified by the iPixelFormat index. if (!::SetPixelFormat(hdc, pixelFormatIndex, &pixelFormat)) { ::ReleaseDC(mHwnd, hdc); ::DestroyWindow(mHwnd); return ; } // back to open scene graph... // create graphics context osg::ref_ptr<osg::GraphicsContext> gc=osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera=new osg::Camera; camera->setGraphicsContext(gc.get()); camera->setViewport(new camera->osg::Viewport(0,0,traits->width,traits->height)); camera->setDrawBuffer(GL_BACK); camera->setReadBuffer(GL_BACK); // Create the viewer and attach the camera to it m_osgViewer=new osgViewer::Viewer; m_osgViewer->addSlave(camera.get()); m_osgViewer->setDone(true); It works without any problems on windows XP x86 and Windows 7 x86 but when I switch to Windows 7 x64 the code isn't working anymore. On the call to get to osg::GraphicsContext::createGraphicsContext(traits.get()) I get NULL and the output shows: Error: [Screen #0] GraphicsWindowWin32::setPixelFormat() - No matching pixel format found based on traits specified. Again, this only happens on windows 7 x64. I hope someone can help me. ... Thank you! Cheers, Elhanan ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=48850#48850 _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/emaildisclaimer _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

