PDA

View Full Version : Merging OpenInventor-OpenGL with SoCamera



Louis-Charles Dumais
11-09-2004, 11:43 AM
Hi,

I`m having technical problems merging OpenGL and Open Inventor and I'm asking for help to solve the problem. I could give a small paypal gift to the person solving the “equation”. What I'm trying to do is to use OpenGL and OpenInventor in the same GL context and using the same camera for OpenGL and OpenInventor. This camera is the SoCamera from the OpenInventor package. This mean something like this:

void draw(){
drawTheInventorStuff();
drawTheOpenGLStuff();
}

The problem is that I cant get the same exact visualization coordinates for OpenGL and OpenInventor with the SoCamera and I dont know why. I have been reading a lot on the SoCamera and looking at the source code to finally isolate what I think are the two functions needed for my task : SbViewVolume::getMatrix() and SbViewVolume::getMatrices( sbMatrixAffine , sbMatrixProjection) . Basically, at the moment, what I do is to take the SbViewVolume from the camera and getMatrix:

SbViewVolume cameraSbViewVolume;
cameraSbViewVolume = camera->getViewVolume();
sbMatrixCamera= cameraSbViewVolume.getMatrix();//working

then I use

glMatrixMode(GL_PROJECTION);
glLoadIdentity ();
glMultMatrixf(sbMatrixCamera[0]);

before drawing my GL stuff to get the same camera view than in my OpenInventor rendering pipeline. Its working for the exception of an annoying perspective problem or Viewport Ratio problem and I dont know how to solve it. I invite you to take a look at the problem by looking at a small video you can find at:
http://www.netchilds.com/Louis/test.mpeg

(If everything worked correctly, you could see only one plane and one 6 DOF mechanism but its not the case. You will notice I have the same problem with perpective and ortho camera.)

If you know how to solve the problem, what matrix or GL call I should be using please message me todumais01@gmc.ulaval.ca . I'm including the code below I'm using in the video to give you a better idea of my problem.

Thank you for your help,
Louis-Charles Dumais

The Drawing loop of the gl windows:

void Fl_Inventor_Window::draw()
{

adjustCameraClippingPlanes();

scenemanager->render();
glDraw();
glFlush();
}

and my glDraw command:

void Fl_Inventor_Window::glDraw(){

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

SbViewVolume cameraSbViewVolume;
cameraSbViewVolume = camera->getViewVolume();
SbMatrix sbMatrixCamera;
sbMatrixCamera= cameraSbViewVolume.getMatrix();

glMultMatrixf(sbMatrixCamera[0]);

glEnable(GL_DEPTH_TEST);

//start of dump lightning
GLfloat LightAmbient[]= { 0.75f, 0.75f, 0.75f, 1.0f };
//GLfloat LightAmbient[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightDiffuse1[]= { 0.0f, 1.0f, 0.0f, 1.0f };
GLfloat LightDiffuse2[]= { 1.0f, 0.0f, 0.0f, 1.0f };
GLfloat LightPosition1[]= { 1.0f, 0.0f,0.0f, 1.0f };
GLfloat LightPosition2[]= { -1.0f, 0.0f,0.0f, 1.0f };
//GLfloat LightPosition[]= { -1.0f, 0.0f, 0.0f, 1.0f };
//GLfloat LightPosition1[]= {tempSbVec3fPos[0], tempSbVec3fPos[1],tempSbVec3fPos[2],1.0f};
//GLfloat LightPosition2[]= {tempSbVec3fPos[0], -tempSbVec3fPos[1],tempSbVec3fPos[2],1.0f};
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //
glLightfv(GL_LIGHT3, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT3, GL_DIFFUSE, LightDiffuse1);
glLightfv(GL_LIGHT3, GL_POSITION,LightPosition1);
glEnable(GL_LIGHT3);

glLightfv(GL_LIGHT4, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT4, GL_DIFFUSE, LightDiffuse2);
glLightfv(GL_LIGHT4, GL_POSITION,LightPosition2);
glEnable(GL_LIGHT4);
//end of dump lightning

glDisable(GL_LIGHTING);
//the multicolor quad
glBegin(GL_QUADS);
glColor3f(0.05f,0.0f,0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);

glColor3f(-0.5f,1.0f,0.0f);
glVertex3f(0.05f,0.0f, 0.0f);

glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 0.05f,0.0f, 0.10f);

glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 0.0f,0.0f, 0.10f);
glEnd();

//the pink quad
glColor3f(1.0f,0.0f,1.0f);
glBegin(GL_QUADS);
glVertex3f( 0.1f,0.1f, 0.0f);
glVertex3f( -0.1f,0.1f, 0.0f);
glVertex3f( -0.1f,-0.1f, 0.0f);
glVertex3f( 0.1f,-0.1f, 0.0f);
glEnd();

//now redrawing the openinventor object to show the difference
if( sceneRoot ) {
sceneRoot->removeChild(camera);
}

SbViewportRegion myViewport(w(), h());
SoGLRenderAction myRenderAction(myViewport);
myRenderAction.apply(sceneRoot);

if( camera ) {
sceneRoot->insertChild(camera, 1);
}

}

Louis-Charles Dumais
11-10-2004, 04:59 AM
Thank you for your help! The problem has been solved.

The solution was to use:
cameraSbViewVolume = camera->getViewVolume((GLfloat)w()/(GLfloat)h());

instead of
cameraSbViewVolume = camera->getViewVolume();