def on_initialize(self, event): # Build cube data V, F, O = cube() vertices = VertexBuffer(V) self.faces = IndexBuffer(F) self.outline = IndexBuffer(O) # Build view, model, projection & normal # -------------------------------------- self.view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) translate(self.view, 0, 0, -5) normal = np.array(np.matrix(np.dot(self.view, model)).I.T) # Build program # -------------------------------------- self.program = Program(vertex, fragment) self.program.bind(vertices) self.program["u_light_position"] = 2, 2, 2 self.program["u_light_intensity"] = 1, 1, 1 self.program["u_model"] = model self.program["u_view"] = self.view self.program["u_normal"] = normal self.phi, self.theta = 0, 0 # OpenGL initalization # -------------------------------------- gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True, polygon_offset=(1, 1), blend_func=('src_alpha', 'one_minus_src_alpha'), line_width=0.75) self.timer.start()
def on_initialize(self, event): # Build cube data V, I, O = cube() vertices = VertexBuffer(V) self.faces = IndexBuffer(I) self.outline = IndexBuffer(O) # Build program # -------------------------------------- self.program = Program(vertex, fragment) self.program.bind(vertices) # Build view, model, projection & normal # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) translate(view, 0, 0, -5) self.program['u_model'] = model self.program['u_view'] = view self.phi, self.theta = 0, 0 # OpenGL initalization # -------------------------------------- gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True, polygon_offset=(1, 1), line_width=0.75, blend_func=('src_alpha', 'one_minus_src_alpha')) self.timer.start()
def on_initialize(self, event): # Build cube data V, I, _ = cube() vertices = VertexBuffer(V) self.indices = IndexBuffer(I) # Build program self.program = Program(vertex, fragment) self.program.bind(vertices) # Build view, model, projection & normal view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) translate(view, 0, 0, -5) self.program['model'] = model self.program['view'] = view self.phi, self.theta = 0, 0 gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True) self.timer.start()
def on_initialize(self, event): # Build cube data # -------------------------------------- vertices, indices, _ = cube() vertices = VertexBuffer(vertices) self.indices = IndexBuffer(indices) # Build program # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) translate(view, 0, 0, -7) self.phi, self.theta = 60, 20 rotate(model, self.theta, 0, 0, 1) rotate(model, self.phi, 0, 1, 0) self.cube = Program(cube_vertex, cube_fragment) self.cube.bind(vertices) self.cube["texture"] = checkerboard() self.cube["texture"].interpolation = 'linear' self.cube['model'] = model self.cube['view'] = view depth = DepthBuffer((512, 512)) color = Texture2D(shape=(512, 512, 3), dtype=np.dtype(np.float32)) self.framebuffer = FrameBuffer(color=color, depth=depth) self.quad = Program(quad_vertex, quad_fragment, count=4) self.quad['texcoord'] = [(0, 0), (0, 1), (1, 0), (1, 1)] self.quad['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)] self.quad['texture'] = color self.quad["texture"].interpolation = 'linear' # OpenGL and Timer initalization # -------------------------------------- set_state(clear_color=(.3, .3, .35, 1), depth_test=True) self.timer = app.Timer(1.0 / 60) self.timer.connect(self.on_timer) self.timer.start() self._set_projection(self.size)
# Glut init # -------------------------------------- glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow("Colored Cube") glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000 / 60, timer, 60) # Build cube data # -------------------------------------- V, I, _ = cube() vertices = VertexBuffer(V) indices = IndexBuffer(I) # Build program # -------------------------------------- program = Program(vertex, fragment) program.bind(vertices) # Build view, model, projection & normal # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -5) program["model"] = model
# Glut init # -------------------------------------- glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('Framebuffer post-processing') glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000 / 60, timer, 60) # Build cube data # -------------------------------------- vertices, indices, _ = cube() vertices = VertexBuffer(vertices) indices = IndexBuffer(indices) # Build program # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -7) phi, theta = 60, 20 rotate(model, theta, 0, 0, 1) rotate(model, phi, 0, 1, 0) cube = Program(cube_vertex, cube_fragment) cube.bind(vertices)
# Glut init # -------------------------------------- glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('Lighted Cube') glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000 / 60, timer, 60) # Build cube data # -------------------------------------- V, F, O = cube() vertices = VertexBuffer(V) faces = IndexBuffer(F) outline = IndexBuffer(O) # Build view, model, projection & normal # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -5) normal = np.array(np.matrix(np.dot(view, model)).I.T) # Build program # -------------------------------------- program = Program(vertex, fragment)
def test_cube(): """Test cube function""" vertices, filled, outline = cube() assert_array_equal(np.arange(len(vertices)), np.unique(filled)) assert_array_equal(np.arange(len(vertices)), np.unique(outline))
# Glut init # -------------------------------------- glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('Colored Cube') glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000 / 60, timer, 60) # Build cube data # -------------------------------------- V, I, _ = cube() vertices = VertexBuffer(V) indices = IndexBuffer(I) # Build program # -------------------------------------- program = Program(vertex, fragment) program.bind(vertices) # Build view, model, projection & normal # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -5) program['model'] = model
# Glut init # -------------------------------------- glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('Rotating Cube') glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000 / 60, timer, 60) # Build cube data # -------------------------------------- V, I, O = cube() vertices = VertexBuffer(V) faces = IndexBuffer(I) outline = IndexBuffer(O) # Build program # -------------------------------------- program = Program(vertex, fragment) program.bind(vertices) # Build view, model, projection & normal # -------------------------------------- view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -5)