Anyone have any ideas?
This is what Im working on so far. I have used the exmaple linked in the above
post.
I create a layered window:
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
DetectMemoryLeaks();
MSG msg = { 0 };
WNDCLASSEX wcl = { 0 };
wcl.cbSize = sizeof(wcl);
wcl.style = CS_HREDRAW | CS_VREDRAW;
wcl.lpfnWndProc = WindowProc;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hInstance = hInstance;
wcl.hIcon = LoadIcon(0, IDI_APPLICATION);
wcl.hCursor = LoadCursor(0, IDC_ARROW);
wcl.hbrBackground = 0;
wcl.lpszMenuName = 0;
wcl.lpszClassName = _T("GLLayeredWindowClass");
wcl.hIconSm = 0;
if (!RegisterClassEx(&wcl))
return 0;
g_hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST,
wcl.lpszClassName,
_T("GL Layered Window Demo"), WS_POPUP, 0, 0, IMAGE_WIDTH,
IMAGE_HEIGHT, 0, 0, wcl.hInstance, 0);
if (g_hWnd)
{
if (Init())
{
ShowWindow(g_hWnd, nShowCmd);
UpdateWindow(g_hWnd);
while (true)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
DrawFrame();
}
}
}
Cleanup();
UnregisterClass(wcl.lpszClassName, hInstance);
}
return (int)(msg.wParam);
}
Then I establish the osg reference object for my scene in the WindProc:
Code:
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static TCHAR szBuffer[32] = { 0 };
switch (msg)
{
case WM_CREATE:
{
osg::ref_ptr<osg::Referenced> windata =
new osgViewer::GraphicsWindowWin32::WindowData(hWnd);
osg::ref_ptr<osg::GraphicsContext::Traits> traits =
new osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = 800;
traits->height = 600;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->pbuffer = true;
traits->inheritedWindowData = windata;
osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits.get()
);
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc);
camera->setViewport(
new osg::Viewport(0, 0, traits->width, traits->height));
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
camera->setClearColor(osg::Vec4f(0.0f, 0.0f, 0.0f, 0.0f));
camera->setProjectionMatrixAsPerspective(
30.0f, (double)traits->width / (double)traits
->height, 1.0, 1000.0);
g_viewer = new osgViewer::Viewer;
g_viewer->setCamera(camera.get());
g_viewer->setSceneData(osgDB::readNodeFile("cessna.osg"));
g_viewer->setKeyEventSetsDone(0);
g_viewer->setCameraManipulator(
new osgGA::TrackballManipulator);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
{
SendMessage(hWnd, WM_CLOSE, 0, 0);
return 0;
}
break;
case WM_NCHITTEST:
return HTCAPTION; // allows dragging of the window
case WM_TIMER:
_stprintf(szBuffer, _TEXT("%d FPS"), g_frames);
SetWindowText(hWnd, szBuffer);
g_frames = 0;
return 0;
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
Then in the msg loop in WinMain
Draw frame is called and it looks like this:
Code:
void DrawFrame()
{
g_viewer->frame();
// At this stage the pbuffer will contain our scene. Now we make a
system
// memory copy of the pbuffer.
CopyPBufferToImage();
// Then we pre-multiply each pixel with its alpha component. This is how
// the layered windows API expects images containing alpha information.
ImagePreMultAlpha(&g_scene);
// Finally we update our layered window with our scene.
RedrawLayeredWindow();
// Since we're doing off-screen rendering the frame rate will be
// independent of the video display's refresh rate.
g_frames++;
}
He has his own code to establish OpenGL and set up pbuffers. But OSG offers
pbuffers, so Im thinking I should be able to draw to the pbuffer, then follow
his order of things where we do pre multiplication of each pixel with alpha.
Then call g_viewer->frame() after that maybe and use his g_frames++ to help the
refresh rate. Im just lacking the knowledge I need to implement the
pbuffer.... or well at least that as a starting point.
Any one who can guide me in the right direction? Or tell me Im going in the
completely wrong one?
Thanks!!
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60720#60720
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org