guys problem is some thing like this which is still there :–
i am rendering a 3D rectangle object which is screen aligned text bounding rect, For rendering this i compute rect coods using gluproject.gluUnproject calls inside the render loop itself. Lets say
if i have global array like this “double boundBox[4][3];” and initialize them only during any mode expect selection mode then the values filled are correct, or else in selection mode I am getting in correct values. I cross checked the order of api calls and every thing seems okie.
Now my application works in this case :
while selection mode dont compute the boundbox rectangles again use already stored previous values.
<u>My render code looks like this.</u>
drawScene(void)
{
glRotatef(m_rAngle,0.0f,1.0f,0.2f);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
GLubyte rasters[24] = {
0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xff, 0xc0, 0xff, 0xc0};
double dModelMatrix[16];
double dProjectionMatrix[16];
int iViewPort[4];
GLdouble dOutX, dOutY, dOutZ;
int ImageWidth,ImageHeight;
ImageWidth=ImageWidth=50;
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glGetDoublev(GL_MODELVIEW_MATRIX,&dModelMatrix[0]);
glGetDoublev(GL_PROJECTION_MATRIX,&dProjectionMatrix[0]);
glGetIntegerv(GL_VIEWPORT,&iViewPort[0]);
if(false == gluProject( 0.0,0.0,0.0,
dModelMatrix,dProjectionMatrix,iViewPort,
&dOutX,&dOutY,&dOutZ))
AfxMessageBox("Failed gluProject");
// now create the bitmap Rec geometry in 3D space.
//if(!initializedArrays)
if(1)
{
if(false == gluUnProject(dOutX+ImageWidth,dOutY,dOutZ,
dModelMatrix,dProjectionMatrix,iViewPort,
&rightBottom[0],&rightBottom[1],&rightBottom[2]))
AfxMessageBox("Failed gluUnProject");
if(false == gluUnProject(dOutX+ImageWidth,dOutY+ImageWidth,dOutZ,
dModelMatrix,dProjectionMatrix,iViewPort,
&rightTop[0],&rightTop[1],&rightTop[2]))
AfxMessageBox("Failed gluUnProject");
if(false == gluUnProject(dOutX,dOutY+ImageWidth,dOutZ,
dModelMatrix,dProjectionMatrix,iViewPort,
&leftTop[0],&leftTop[1],&leftTop[2]))
AfxMessageBox("Failed gluUnProject");
}
glLoadName(DUMMY_OBJECT);
glColor4f(0.8f,0.1f,1.0f,0.5f); // Full Brightness, 50% Alpha ( NEW )
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency Based On Source Alpha Value ( NEW )
glEnable(GL_BLEND);
glBegin(GL_POLYGON);
glVertex3d(0.0,0.0,0.0);
glVertex3d(rightBottom[0],rightBottom[1],rightBottom[2]);
glVertex3d(rightTop[0],rightTop[1],rightTop[2]);
glVertex3d(leftTop[0],leftTop[1],leftTop[2]);
glVertex3d(0.0,0.0,0.0);
glEnd();
glDisable(GL_BLEND);
glColor3f (0.0, 1.0, 1.0);
glRasterPos3f (0,0,0);
glBitmap (ImageWidth, ImageWidth, 0.0, 0.0, 0.0, 0.0, rasters);
glPopMatrix();
glFlush();
}
<u> Here my selection happens while mouse move itself…
This is where i initialize the other things</u>
OnMouseMove(UINT nFlags, CPoint point)
{
m_selEnabled= true;
initializedArrays = true;
renderSceneGraph();
initializedArrays = false;
m_selEnabled= false;
renderSceneGraph();
}
renderSceneGraph(void)
{
HGLRC hglrc = wglGetCurrentContext();
if(hglrc)
{
setVSync(0);
if(m_selEnabled)
{
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0,0,-5000,
0.0,0.0,0.0,
0,0,1);
}
int viewport[4];
if(m_selEnabled)
{
GLErrorCheck();
glGetIntegerv (GL_VIEWPORT, &viewport[0]);
GLErrorCheck();
glSelectBuffer (BUFSIZE, selectBuf);
(void) glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
}
glMatrixMode( GL_PROJECTION );
glPushMatrix ();
glLoadIdentity();
if(m_selEnabled)
{
gluPickMatrix ((GLdouble) m_mouseLoc.x, (GLdouble) (viewport[3] - m_mouseLoc.y),
3.0, 3.0, viewport);
}
glOrtho(-5000,5000,-5000, 5000, -5000, 5000);
glFlush();
// gl initialization required.
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Background
glClearDepth(1.0f); // Depth Buffer Setup
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glPolygonOffset(1.0,1.0);
glEnable(GL_POLYGON_OFFSET_FILL);
glFlush();
}
drawScene();
if(m_selEnabled)
{
GLint hits;
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glFlush();
hits = glRenderMode (GL_RENDER);
}
}
Let me know where i have gone wrong in the above code.
Thank you,
kumar.k