def drawFocus(self): glColor4f(0, 0, 0, 0.4) glPushMatrix() glLoadIdentity() glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D(0, self.width, 0, self.height) glLineStipple(1, 0xf0f0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) glVertex2f(1, 0) glVertex2f(self.width, 0) glVertex2f(self.width, self.height - 1) glVertex2f(1, self.height - 1) glEnd() glDisable(GL_LINE_STIPPLE) glPopMatrix() # restore PROJECTION glMatrixMode(GL_MODELVIEW) glPopMatrix()
def set_screen(self): ''' Set ortho projection, showing world space coords 0 <= x < WIDTH, and 0 <= y < HEIGHT. ''' gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluOrtho2D(0, self.width - 1, 0, self.height - 1)
def on_resize(self, width, height): # scale is distance from screen centre to top or bottom, in world coords scale = 110 glMatrixMode(GL_PROJECTION) glLoadIdentity() aspect = width / height gluOrtho2D(-scale * aspect, +scale * aspect, -scale, +scale) return EVENT_HANDLED
def on_resize(self, width, height): # scale is distance from screen centre to top or bottom, in world coords scale = 110 glMatrixMode(GL_PROJECTION) glLoadIdentity() aspect = width / height gluOrtho2D( -scale * aspect, +scale * aspect, -scale, +scale) return EVENT_HANDLED
def set_ortho(self, zoom): ''' Screen's shortest dimension (usually height) will show exactly self.zoom of the world from the center of the screen to each edge, regardless of screen resolution, window size. ''' def ortho_bounds(self, zoom, aspect): left = bottom = -zoom right = top = zoom if self.width > self.height: # landscape mode window bottom /= aspect top /= aspect elif self.width < self.height: # portrait mode window left *= aspect right *= aspect return left, right, bottom, top aspect = self.width / self.height gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluOrtho2D(*ortho_bounds(zoom, aspect))