def init(self): # Initialize display global global_init if not global_init: glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_ALPHA) glut.glutCreateWindow(b'fbmatrix') global_init = True if self.preview or self.raw: glut.glutReshapeWindow(512, 512) elif self.emulate: glut.glutReshapeWindow(1024, 512) glut.glutReshapeFunc(lambda w, h: self.reshape(w, h)) glut.glutDisplayFunc(lambda: self.display()) glut.glutKeyboardFunc(lambda k, x, y: self.keyboard(k, x, y)) # Primary offscreen framebuffer self.mainfbo = fbo.FBO(self.columns, 32, mag_filter=gl.GL_NEAREST, min_filter=gl.GL_NEAREST) # Initialize display shader layoutfile = 'layout.json' if self.displaytype == 'ws2811': self.signalgenerator = displays.ws2811.signalgenerator( layoutfile, supersample=self.supersample) self.signalgenerator.setTexture(self.mainfbo.getTexture()) elif self.displaytype == 'hub75e': self.signalgenerator = displays.hub75e.signalgenerator( columns=self.columns, rows=self.rows, supersample=self.supersample, order=self.order, oe=self.oe, extract=self.extract) self.signalgenerator.setTexture(self.mainfbo.getTexture()) # Emulation shader if self.emulate or self.preview: self.texquad = geometry.simple.texquad() self.texquad.setTexture(self.mainfbo.getTexture()) # Tree emulator if self.emulate: self.tree = assembly.tree.tree(layoutfile) self.tree.setTexture(self.mainfbo.getTexture()) # Render glut.glutSetCursor(glut.GLUT_CURSOR_NONE) if not self.raw and not self.preview and not self.emulate: glut.glutFullScreen()
def testFieldFirstOrder(self): self.renderer = fbmatrix.renderer(order='field-first') screen = fbo.FBO(self.width, self.height) with screen: self.renderer.render = lambda: self.testPatternWhite() self.renderer.display() data = gl.glReadPixels(0, 0, 4096, 194, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, None) self.assertFrameData('tst/data/hub75_fieldfirst_32x32_white.txt', data)
def on_draw(self): self.fbo = fbo.FBO(self.game.level.width, self.game.level.height) self.fbo.attach() pyglet.gl.glColor3f(1.0, 0.0, 0.0) # self.clear() pyglet.gl.glClearColor(0.0, 1.0, 1.0, 1.0) pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT) pyglet.gl.glLoadIdentity() self.game.draw() pyglet.gl.glFlush() self.fbo.detach() pyglet.gl.glClearColor(0.0, 0.0, 0.0, 1.0) pyglet.gl.glColor3f(1.0, 1.0, 1.0) pyglet.gl.glLoadIdentity() # Set up xform matrix so level is centered in window. Scale so it # nearly fits: required_pixels = (self.fbo.width, self.fbo.height) x_scale = self.width // required_pixels[0] y_scale = self.height // required_pixels[1] scale = min(x_scale, y_scale) pyglet.gl.glScalef(scale, scale, scale) # Then transform so it's centered offset_x = (self.width - (required_pixels[0] * scale)) // 2 offset_y = (self.height - (required_pixels[1] * scale)) // 2 pyglet.gl.glTranslatef(offset_x // scale, offset_y // scale, 0.0) self.clear() pyglet.gl.glBindTexture(pyglet.gl.GL_TEXTURE_2D, self.fbo.img) pyglet.gl.glEnable(pyglet.gl.GL_TEXTURE_2D) verts = [(0.0, 0.0), (self.fbo.width, 0.0), (self.fbo.width, self.fbo.height), (0.0, self.fbo.height)] tex_coords = [(0.0, 0.0), (self.fbo.width / float(self.fbo.tex_width), 0.0), (self.fbo.width / float(self.fbo.tex_width), self.fbo.height / float(self.fbo.tex_height)), (0.0, self.fbo.height / float(self.fbo.tex_height))] pyglet.gl.glBegin(pyglet.gl.GL_QUADS) for vc, tc in zip(verts, tex_coords): pyglet.gl.glTexCoord2f(*tc) pyglet.gl.glVertex2f(*vc) pyglet.gl.glEnd()
glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutCreateWindow(b'Amazing ws2811 VGA renderer') if args.preview or args.raw: glut.glutReshapeWindow(1500, 300) elif args.emulate: glut.glutReshapeWindow(1000, 500) else: glut.glutReshapeWindow(840, 1000) glut.glutReshapeFunc(reshape) glut.glutDisplayFunc(display) glut.glutKeyboardFunc(keyboard) # Primary offscreen framebuffer mainfbo = fbo.FBO(512, 512) # WS2811 output shader layoutfile = 'layout.json' if args.display == 'ws2811': signalgenerator = geometry.ws2811.signalgenerator(layoutfile) signalgenerator.setTexture(mainfbo.getTexture()) elif args.display == 'hub75e': signalgenerator = geometry.hub75e.signalgenerator() signalgenerator.setTexture(mainfbo.getTexture()) # Emulation shader texquad = geometry.simple.texquad() texquad.setTexture(mainfbo.getTexture())