Thanks a lot ,I already do these in a update callback. But blink continue
exist.
This is my code:
ResultCode ExpCntl::startPaint(HINSTANCE hinstance)
{
ResultCode rslt = SUCCESS;
DWORD paintThreadID;
HANDLE paintThreadHandle;
paintThreadHandle = CreateThread(NULL, 0, PaintThread, &hinstance, NULL,
&paintThreadID);
CloseHandle(paintThreadHandle);
//rslt = PaintThread(&hinstance);
SleepEx(100, false);
return rslt;
}
DWORD WINAPI PaintThread(LPVOID lpData)
{
g_var.threadcount ++;
HINSTANCE hInstPaint = *static_cast<HINSTANCE*>(lpData);
WNDCLASS wndClassPaint;
// register back ground window class
wndClassPaint.style = 0;
wndClassPaint.lpfnWndProc = PaintWinProc;
wndClassPaint.cbClsExtra = 0;
wndClassPaint.cbWndExtra = 0;
wndClassPaint.hInstance = hInstPaint;
wndClassPaint.hIcon = NULL; // no icon
wndClassPaint.hCursor = NULL; // no cursor
wndClassPaint.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // black
background
wndClassPaint.lpszMenuName = NULL;
wndClassPaint.lpszClassName = L"dpesbackground";
//////
// CoInitialize(NULL);
// IMyButtonPtr temp;
// CoCreateInstance(__uuidof(MyButton), NULL, CLSCTX_ALL, __uuidof(IMyButton),
// (void**)&temp);
// CoCreateInstance(__uuidof(ControlManager), NULL, CLSCTX_ALL,
// __uuidof(IControlManager), (void**)&pControlManager);
if (!RegisterClass(&wndClassPaint))
{ // fail to register the window class
//goto over;
g_var.threadcount --;
//GdiplusShutdown(gdiplusToken);
//CoUninitialize();
return 0;
}
// create back ground window
HWND hWndPaint;
hWndPaint = CreateWindow(
L"dpesbackground", // window class name
L"", // window caption
0, // window style
0, // initial x position
0, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstPaint, // program instance handle
NULL); // creation parameters
if (!hWndPaint)
{ // fail to create window
//goto over;
g_var.threadcount --;
//GdiplusShutdown(gdiplusToken);
CoUninitialize();
return 0;
}
// hide the caption of back ground window
DWORD dwStyle = GetWindowLong(hWndPaint, GWL_STYLE);
dwStyle &= ~(WS_CAPTION);
SetWindowLong(hWndPaint, GWL_STYLE, dwStyle);
// show the back ground window
ShowWindow(hWndPaint, SW_MAXIMIZE);
UpdateWindow(hWndPaint);
//ShowCursor(false);
////////////////////////////////这段是加载hook动态库并安装钩子
typedef BOOL (*InstallHook)();
typedef BOOL (*UnHook)();
InstallHook ProcInstallHook = NULL;
UnHook ProcUnHook = NULL;
HINSTANCE hInstLib = NULL;
hInstLib = LoadLibraryA("hook.dll");
if (hInstLib == NULL)
{
MessageBoxA(NULL, "没有打开hook.dll", "提醒", MB_OK);
return 0;
}
ProcInstallHook = (InstallHook) GetProcAddress(hInstLib,"InstallHook");
if (ProcInstallHook != NULL)
{
ProcInstallHook();
}
////////////////////////////////加载hook结束
/*GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);*/
osgViewer::Viewer viewer; //场景
// Local Variable to hold window size data
RECT rect;
// Get the current window size
::GetWindowRect(hWndPaint, &rect);
//全局变量来保存viewer窗口的大小属性
{
_osgviewer_rect().bottom = rect.bottom ;
_osgviewer_rect().left = rect.left;
_osgviewer_rect().right = rect.right;
_osgviewer_rect().top = rect.top;
_osgviewer_rect().viewer_background_color = osg::Vec4(0,0,0,1);
_osgviewer_rect().clicked_editbox = NULL;
}
// Init the GraphicsContext Traits
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
// Init the Windata Variable that holds the handle for the Window to
display OSG in.
osg::ref_ptr<osg::Referenced> windata = new
osgViewer::GraphicsWindowWin32::WindowData(hWndPaint);
// Setup the traits parameters
traits->x = 0;
traits->y = 0;
traits->width = rect.right - rect.left;
traits->height = rect.bottom - rect.top;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->setInheritedWindowPixelFormat = true;
traits->inheritedWindowData = windata;
// Create the Graphics Context
osg::GraphicsContext* gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
// Assign Graphics Context to the Camera
viewer.getCamera()->setGraphicsContext(gc);
// Set the viewport for the Camera
viewer.getCamera()->setClearColor(_osgviewer_rect().viewer_background_color);
viewer.getCamera()->setViewport(new osg::Viewport(traits->x, traits->y,
traits->width, traits->height));
//osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Switch> root = new osg::Switch;
//root->addChild(new osg::Node());
viewer.setSceneData(root.get()); //设置场景根节点
////关闭自动计算远近裁减面
//viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
////设置裁减区域
double clip_width = rect.right - rect.left;
double clip_height = rect.bottom - rect.top;
//viewer.getCamera()->setProjectionMatrixAsFrustum(-clip_width/2,clip_width/2,-clip_height/2,clip_height/2,1,100);
viewer.getCamera()->setProjectionMatrixAsOrtho(-clip_width/2,clip_width/2,-clip_height/2,clip_height/2,-100,100);
//添加事件响应处理
// create a tracball manipulator to move the camera around in response to
keyboard/mouse events
//viewer.setCameraManipulator( new osgGA::TrackballManipulator );
//osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new
osgGA::StateSetManipulator(viewer.getCamera()->getStateSet());
//viewer.addEventHandler(statesetManipulator.get());
viewer.addEventHandler(new DPES_OpenGL::PickHandler());
//viewer.addEventHandler(new osgGA::StateSetManipulator );
viewer.setKeyEventSetsDone(0);
//viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
//viewer.realize();
//viewer.getCamera()->setProjectionMatrixAsPerspective(60,1,1,100);
//
////设置视点让模型处于近裁减面
//osg::Vec3 eye,center,up;
//viewer.getCamera()->getViewMatrixAsLookAt(eye,center,up);
////viewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3(0,0,radius+1),osg::Vec3(0,0,radius),up);
//int a = viewer.getThreadingModel();
//root->setUpdateCallback(new
/*osg::Switch *switchNode = new osg::Switch;
switchNode->addChild(root);
switchNode->setAllChildrenOff();
*/
MSG msg;
root->setUpdateCallback(new rootCallback(hWndPaint,&viewer) );
while(!viewer.done())
{
if (PeekMessage(&msg,NULL,0,0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(!viewer.getSceneData())
break;
viewer.frame();
}
g_var.threadcount --;
//////////// //卸载钩子释放动态库
ProcUnHook = (UnHook) GetProcAddress(hInstLib,"UnHook");
if (ProcUnHook != NULL)
{
ProcUnHook();
}
FreeLibrary(hInstLib);
return 0;
//over:
// g_var.threadcount --;
// GdiplusShutdown(gdiplusToken);
// CoUninitialize();
// return 0;
}
Best regards.
YangXiao.
Wang Rui <[EMAIL PROTECTED]> 写道:
Hi,
I suggest do these in a update callback, or set the threading model to
SingleThreaded (but not efficiently), because it very dangerous add/remove
children in the main loop when multi-thread rendering. You are so lucy not to
crash here. :)
Wang Rui
Thanks Wang Rui
in PaintThreadProc I do
{
root->addchild();
or root->removeChild();
.....
}
YangXiao.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
---------------------------------
雅虎邮箱,您的终生邮箱!_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org