def on_resize(self, event, arg=None): if event: w = event.width h = event.height else: if arg: w = arg['w'] h = arg['h'] else: raise Exception dx = w/h glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho( -2 * dx, 2 * dx, -2, 2, -2, 2 )
def render_scene(self): self.rot += 0.5 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotatef(self.rot, 1, 1, 0.5) # Draw a simple cube. glBegin(GL_QUADS) glColor3f(0, 1, 0) glVertex3f(1, 1, -1) glVertex3f(-1, 1, -1) glVertex3f(-1, 1, 1) glVertex3f(1, 1, 1) glColor3f(1, 0.5, 0) glVertex3f(1, -1, 1) glVertex3f(-1, -1, 1) glVertex3f(-1, -1, -1) glVertex3f(1, -1, -1) glColor3f(1, 0, 0) glVertex3f(1, 1, 1) glVertex3f(-1, 1, 1) glVertex3f(-1, -1, 1) glVertex3f(1, -1, 1) glColor3f(1, 1, 0) glVertex3f(1, -1, -1) glVertex3f(-1, -1, -1) glVertex3f(-1, 1, -1) glVertex3f(1, 1, -1) glColor3f(0, 0, 1) glVertex3f(-1, 1, 1) glVertex3f(-1, 1, -1) glVertex3f(-1, -1, -1) glVertex3f(-1, -1, 1) glColor3f(1, 0, 1) glVertex3f(1, 1, -1) glVertex3f(1, 1, 1) glVertex3f(1, -1, 1) glVertex3f(1, -1, -1) glEnd() glFlush()
def render_scene(self): self.rot += .5 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotatef(self.rot, 1, 1, 0.5) # Draw a simple cube. glBegin(GL_QUADS) glColor3f(0, 1, 0) glVertex3f(1, 1, -1) glVertex3f(-1, 1, -1) glVertex3f(-1, 1, 1) glVertex3f(1, 1, 1) glColor3f(1, 0.5, 0) glVertex3f(1, -1, 1) glVertex3f(-1, -1, 1) glVertex3f(-1, -1, -1) glVertex3f(1, -1, -1) glColor3f(1, 0, 0) glVertex3f(1, 1, 1) glVertex3f(-1, 1, 1) glVertex3f(-1, -1, 1) glVertex3f(1, -1, 1) glColor3f(1, 1, 0) glVertex3f(1, -1, -1) glVertex3f(-1, -1, -1) glVertex3f(-1, 1, -1) glVertex3f(1, 1, -1) glColor3f(0, 0, 1) glVertex3f(-1, 1, 1) glVertex3f(-1, 1, -1) glVertex3f(-1, -1, -1) glVertex3f(-1, -1, 1) glColor3f(1, 0, 1) glVertex3f(1, 1, -1) glVertex3f(1, 1, 1) glVertex3f(1, -1, 1) glVertex3f(1, -1, -1) glEnd() glFlush()