Drawing Selection Marquee With Perspective Camera

Hey,

I’m having a problem drawing a marquee selection rectangle in my window. It works if I don’t move the camera, but once I move the camera and try to draw a new marquee(rectangle), it doesn’t work. I think it has to do with matrix transforms…?

This is my setup (snippets of code):

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

glViewport(0,0,x,y)

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45,float(x)/float(y),0.1,1000);

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

to move my camera I use the GL_MODELVIEW matrix

this is driven by mouse events

glTranslatef(0,0,-self.zoom) # zoom in/out
glTranslatef(self.tx,self.ty,0) # move window around geo (… actually it’s moving the geo…)
glRotatef(self.rotx,1,0,0) # rotate view
glRotatef(self.roty,0,1,0)

… now if I use my cursor to generate the marquee window I get the correct result … before I move the camera:

glMatrixMode (GL_PROJECTION)
glPushMatrix()

glLoadIdentity()

viewport = glGetIntegerv(GL_VIEWPORT)
glOrtho(0, viewport[2], viewport[3], 0, 5, -5)

glTranslatef(0,0,0)
glEnable(GL_BLEND)
glColor4f(0.0, 0.0, 0.3, 0.3)
glBegin(GL_QUADS)
glVertex2i(startx, starty)
glVertex2i(endx , starty)
glVertex2i(endx , endy)
glVertex2i(startx, endy)
glEnd()
glLineWidth(2.0)
glColor4f(0.4, 0.4, 0.5, 0.5)
glBegin(GL_LINE_LOOP)
glVertex2i(startx, starty)
glVertex2i(endx , starty)
glVertex2i(endx , endy)
glVertex2i(startx, endy)
glEnd()
glDisable(GL_BLEND)

glMatrixMode (GL_PROJECTION)
glPopMatrix()
glMatrixMode (GL_MODELVIEW)

I switched to the projection matrix so I could draw it in front of the camera. I would imagine with the world moving (using the GL_MODELVIEW matrix), if I drew a new rectangle on the screen , it would show where I made it.

I have updateGL() events set for when I press/drag and release the mouse (and this all works). I also have a ‘if statement’ in my display() routine, to draw the rectangle as well.

Does anyone have an idea why things go out of whack when I move the camera?

Thanks

I got it, if anyone is interested (or if there’s a better way of doing this I’m still open to suggestions)

In my Marquee Cursor Code Section:

glMatrixMode (GL_MODELVIEW) # NEW
glPushMatrix() #NEW

glMatrixMode (GL_PROJECTION)
glPushMatrix()

glLoadIdentity()

viewport = glGetIntegerv(GL_VIEWPORT)
glOrtho(0, viewport[2], viewport[3], 0, 1, -1)

glMatrixMode (GL_MODELVIEW) #NEW
glLoadIdentity() #NEW

… draw rectangle …

glMatrixMode (GL_PROJECTION)
glPopMatrix()

glMatrixMode (GL_MODELVIEW)
glPopMatrix() #NEW