Sign in to follow this  
tinu

multiple viewports and selection

Recommended Posts

Hi, This is a question regarding multiple viewports and selection. Here I use two view ports and draw two spheres in them each. 1)In the first view port I see yellow sphere on the left and the red sphere on the right to it. In the second view port I see red sphere on the left and the yellow sphere on the right to it. Why is this difference wen I use same look at and same objects to draw.... I use the following code: v1.pos.x = 0; v1.pos.y = 493; v1.width = 1024; v1.height = 275; v2.pos.x = 0; v2.pos.y = 0; v2.width = 170; v2.height = 493; glViewport(r.v1.pos.x,r.v1.pos.y,r.v1.width,r.v1.height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (GLfloat) (r.v1.width-r.v1.pos.x)/(GLfloat) r.v1.height-r.v1.pos.y), 1.0f, 200.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,5, 0,0,0, 0,1,0); glPushMatrix(); glColor3f(1,0,0); glutSolidSphere(.1,10,10); glTranslatef(1,0,0); glColor3f(1,1,0); glutSolidSphere(.1,10,10); glPopMatrix(); glViewport(r.v2.pos.x,r.v2.pos.y,r.v2.width,r.v2.height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (GLfloat) (r.v2.width-r.v2.pos.x)/(GLfloat) (r.v2.height-r.v2.pos.y), 1.0f, 200.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,5, 0,0,0, 0,1,0); glPushMatrix(); glColor3f(1,0,0); glutSolidSphere(.1,10,10); glTranslatef(0.3,0,0); glColor3f(1,1,0); glutSolidSphere(.1,10,10); glPopMatrix(); 2)When i use selection to determine picking of objects in a single view port everything works fine. When I use multiple viewports as mentioned above I could not get correct selection. For selection I use the following code: glSelectBuffer(512, buffer); if( ( mouse_x > 170 && mouse_x < 1024 ) && (mouse_y > 275 && mouse_y < 768)) { viewport[0] = r.v3.pos.x; viewport[1] = r.v3.pos.y; viewport[2] = r.v3.width; viewport[3] = r.v3.height; viewport_no = 3; } else if( ( mouse_x > 0 && mouse_x < 1024 ) && (mouse_y > 0 && mouse_y < 275) ) { viewport[0] = r.v1.pos.x; viewport[1] = r.v1.pos.y; viewport[2] = r.v1.width; viewport[3] = r.v1.height; viewport_no = 1; } else { viewport[0] = r.v2.pos.x; viewport[1] = r.v2.pos.y; viewport[2] = r.v2.width; viewport[3] = r.v2.height; viewport_no = 2; } (void) glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix((GLdouble) mouse_x, (GLdouble) (Page_Height - mouse_y),3.0f, 3.0f, viewport); gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 1.0f, 200.0f); glMatrixMode(GL_MODELVIEW); //draw objects glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits = glRenderMode(GL_RENDER); if (hits > 0) { int choose = 0; for (int loop = 0; loop < hits; loop++) choose = buffer[loop*4+3]; } Here selection is improper.objects are drawn at one part of the screen and detected in the selection at some other part of the screen. Where is the problem... Kindly help...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this