def DrawGLScene(self, *args, **kwargs): glutTimerFunc(self.TimeMS,memberfunctor(self, OpenGL2DSurface.DrawGLScene),0) now=datetime.datetime.now() timediff=now-self.LastRender.pop() self.LastRender.insert(0,now) timediff/=len(self.LastRender) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() nc=1 glScale(64/self.dist,64/self.dist,1) glTranslatef(self.shift.x,self.shift.y,-64) p,s,c,t=self.updater() for i in range(0,len(p)): glTranslatef(p[i][0], p[i][1], 0) glBegin(GL_POLYGON) glColor3f(c[i][0],c[i][1],c[i][2]) r=s[i] for j in range(0,circle_ang): glVertex3f(circle_temp[j].x*r, circle_temp[j].y*r, 0.0) glEnd() if len(t[i])>0: nc+=1 glWindowPos2i(0,self.Height-18*nc) glutBitmapString(OpenGL.GLUT.GLUT_BITMAP_HELVETICA_18,bytes(t[i],'utf-8')) glTranslatef(-p[i][0], -p[i][1], 0) glTranslatef(-self.shift.x,-self.shift.y,64) glColor3f(1,1,1) glWindowPos2i(0,self.Height-18) glutBitmapString(OpenGL.GLUT.GLUT_BITMAP_HELVETICA_18,bytes("%d object @%5.2f FPS" % (len(p),1000000.0/timediff.microseconds),'utf-8')) glutSwapBuffers()
def __init__(self,u): self.window=0 self.updater=u self.dist=64 # for fullhd fullscreen self.shift=Vector2D() self.Width=640 self.Height=480 self.FullScreen=True self.Slow=False self.TimeMS=50 now=datetime.datetime.now() self.LastRender=[now for i in range(0,10)] glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(self.Width, self.Height) glutInitWindowPosition(0, 0) self.window = glutCreateWindow(b"Genesis") #glutDisplayFunc(memberfunctor(self, OpenGL2DSurface.DrawGLScene)) #glutDisplayFunc(foo) glutFullScreen() #glutIdleFunc(memberfunctor(self, OpenGL2DSurface.DrawGLScene)) glutReshapeFunc(memberfunctor(self,OpenGL2DSurface.ReSizeGLScene)) glutKeyboardFunc(memberfunctor(self,OpenGL2DSurface.keyPressed)) InitGL(self.Width, self.Height)
def StartRender(self): glutTimerFunc(self.TimeMS,memberfunctor(self, OpenGL2DSurface.DrawGLScene),0) glutMainLoop()