()
| 111 | |
| 112 | |
| 113 | def test_gl_quad_blit(): |
| 114 | gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) |
| 115 | |
| 116 | quad = Quad(H=HEIGHT, W=WIDTH) |
| 117 | data = np.random.randint(0, 255, (HEIGHT, WIDTH, 4), dtype=np.uint8) |
| 118 | |
| 119 | data[10:20, 10:20] = [255, 0, 0, 255] |
| 120 | data[20:30, 10:20] = [0, 255, 0, 255] |
| 121 | data[10:20, 20:30] = [0, 0, 255, 255] |
| 122 | data[20:30, 20:30] = [255, 255, 255, 255] |
| 123 | data = data[::-1] # flip 0 |
| 124 | data = np.asarray(data, order='C') |
| 125 | |
| 126 | quad.upload_to_texture(data) # upload the pointer |
| 127 | quad.blit() # no camera to render |
| 128 | |
| 129 | # Read result |
| 130 | img_buf = gl.glReadPixels(0, 0, WIDTH, HEIGHT, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE) |
| 131 | img = np.frombuffer(img_buf, np.uint8).reshape(HEIGHT, WIDTH, 4)[::-1] |
| 132 | |
| 133 | img_path = 'test_gl_quad_blit.png' |
| 134 | save_image(img_path, img) |
| 135 | log(f'Quad blit image saved at: {blue(img_path)}') |
| 136 | |
| 137 | assert img[10, 10, :3].argmax() == 0 # red corner |
| 138 | assert img[20, 10, :3].argmax() == 1 # green corner |
| 139 | assert img[10, 20, :3].argmax() == 2 # blue corner |
| 140 | assert all(img[20, 20] == 255) # white corner |
| 141 | |
| 142 | |
| 143 | def test_gl_quad_draw(): |
nothing calls this directly
no test coverage detected