def _platform_free(self): """Frees resources associated with this context.""" if self._context and self._context == osmesa.OSMesaGetCurrentContext(): osmesa.OSMesaMakeCurrent(None, None, GL.GL_FLOAT, 0, 0) osmesa.OSMesaDestroyContext(self._context) self._buffer = None self._context = None
def runglmesa(draw=draw): global ctx if ctx is None: ctx = osmesa.OSMesaCreateContext(osmesa.OSMESA_RGBA, None) buf = arrays.GLubyteArray.zeros((h, w, 4)) assert (osmesa.OSMesaMakeCurrent(ctx, buf, GL_UNSIGNED_BYTE, w, h)) assert (osmesa.OSMesaGetCurrentContext()) initGL() reshape(w, h) display(draw) data = glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE) m = np.frombuffer(data, np.uint8) m = m.reshape(w, h, 4) m = np.flip(m, [0, 1]) return m