Hi Janling,
Post by Yanling LiuHi, My program create OpenGL context using Fox::GLCanvas, then I have a
osgUtil::SceneView to handle rendering.
Here is my code for rendering
m_sceneVeiw->update();
m_sceneView->cull();
m_scaneView->draw();
The problem is I cannot get OpenGL projection and modelview matrix using
glGetDoublev(...). All I got is identity matrix for both projection and
modelview.
You can only use glGet* methods from within the current context. Also the
OSG itself manages the projection and model view matrices so these values
will change throught the draw traversal.
I am not quite sure when you are saying the current context. Are you talking
about osg's current context or OpenGL's context? I am sure I have used
glGet* methods in the current OpenGL context. Also I have tried to use
glGet* in osgHud examples like this:
while( !viewer.done() )
{
// wait for all cull and draw threads to complete.
viewer.sync();
// update the scene by traversing it with the the update visitor
which will
// call all node update callbacks and animations.
viewer.update();
double proj[16];
glGetDoublev(GL_PROJECTION_MATRIX, proj);
//after get I output the projection matrix using std::cout
//std::cout<<proj[0]<<" "<<proj[1]<<" ".....
// fire off the cull and draw traversals of the scene.
viewer.frame();
}
Still I can only get identical projection matrix. Don't know how to make
sure current context in such situation.
Post by Yanling Liu1. does osg has any special process/locking about OpenGL projection and
modelview matrix?
No, but OpenGL is state machine, you'll only ever be abe to get the last
values applied to OpenGL using glGet methods, and you can only do it from a
valid graphics context. As a general note, avoid using glGets in OpenGL
application, as it can stall the whole graphics pipeline and kill
performance.
2. Is that safe to use camera projection and modelview matrix of
Post by Yanling LiuosgUtil::SceneView when I need to use OpenGL projection and modelview
matrix?
When and why do you need the projection and modelview matrices?
If you need them from the draw traversal then look no further than the
osg::State object passed into each Drawable::drawImplementation(State&) and
the osg::State object has getProjectionMatrix and getModelViewMatrix()
methods, these just return locally cached OSG matrices, and don't require
any glGet* which is a boon for convinience and performance.
I need to integrate haptic device and Sharp 3D stereo display into my
project. Both of them require OpenGL projection matrix to initialize and
update themselve during rendering. You could see this in following code:
void CCAuxFoxGLWindow::Render(void)
{
osg::Timer_t startTick = osg::Timer::instance()->tick();
if (m_isScannerEnable)
m_pScannerBar->DoRTS();
//here I need to update haptic device workspace using OpenGL proj
matrix.
//code of UpdateCurrentToolOriPos() is at below
if (m_isHapticUsed)
UpdateCurrentToolOriPos();
//m_sceneView is extended from osgUtil::SceneView
m_sceneView->PerformVirtualSurgery();
m_sceneView->UpdateScene();//do update() and cull()
if (m_isHapticUsed)
{
hlBeginFrame();
m_sceneView->draw();
hlEndFrame();
}
else
m_sceneView->draw();
//post processing
if (m_isFrameColorBoost)
FrameColorBoost();
if (m_isSnapShot)
Snapshot();
if (m_isRecordMovie)
RecordMovie();
m_pGLCanvas->swapBuffers();
osg::Timer_t endTick = osg::Timer::instance()->tick();
m_sceneView->UpdateFPS(osg::Timer::instance()->delta_s(startTick,
endTick));
}
// update current tool's orientation and position
void CCAuxFoxGLWindow::UpdateCurrentToolOriPos(void)
{
GLdouble projection[16];
hlMatrixMode(HL_TOUCHWORKSPACE);
hlLoadIdentity();
glGetDoublev(GL_PROJECTION_MATRIX, projection);
// I tried to use camera projection matrix, but still have problem
//
hluFitWorkspace(m_sceneView->getCamera()->getProjectionMatrix().ptr());
hluFitWorkspace(projection);
double position[3];
double rotation[4];
hlGetDoublev(HL_DEVICE_POSITION, position);
hlGetDoublev(HL_DEVICE_ROTATION, rotation);
osg::Vec3f pos(position[0], -position[2], position[1]);
osg::Quat ori(rotation[0], rotation[1], rotation[2], rotation[3]);
m_sceneView->GetVSToolGroup()->TransformCurrentTool(pos, ori);
}
Yanling
Robert.
_______________________________________________
osg-users mailing list
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/