def test_render_front(self): soya.set_root_widget(self.blue_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)), (0, 0, 255)) soya.set_root_widget(self.red_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(255, 0, 0))
def render(self): if self.active: self.scene.begin_round() self.scene.advance_time(1.0) self.scene.begin_round() self.scene.advance_time(1.0) self.scene.begin_round() self.scene.advance_time(1.0) self.scene.begin_round() self.scene.advance_time(1.0) self.scene.begin_round() self.scene.advance_time(1.0) soya.render()
def test_render_back_read(self): """Test that rendering made without switching back buffer are accessible with screenshot""" # Screenshot in front buffer soya.set_root_widget(self.blue_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255)) # Screenshot in back buffer soya.set_root_widget(self.red_camera) soya.render(swap_buffer=False) screenshot = soya.screenshot(use_back_buffer=True) self.assertEquals(screenshot.getpixel((0,0)),(255, 0, 0))
def test_render_does_not_alter(self): """Test that rendering in the back buffer doesn't alter the front one.""" # Screenshot in front buffer soya.set_root_widget(self.blue_camera) soya.render() # Screenshot in back buffer soya.set_root_widget(self.red_camera) soya.render(swap_buffer=False) # Front buffer didn't changed screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255)) # Everything still work fine soya.set_root_widget(self.blue_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255))
sword3 = soya.Body(scene, sword_model) sword3.x = 1.0 sword3.y = -1.0 sword3.rotate_y( 90.0) sword3.rotate_z(-90.0) # Creates a light and a camera. light = soya.Light(scene) light.set_xyz(0.5, 0.0, 2.0) camera = soya.Camera(scene) camera.z = 2.0 soya.set_root_widget(camera) soya.render() # Basic No-op shader that render textures and colors : shader_code = """!!ARBfp1.0 TEMP color; TEX color, fragment.texcoord[0], texture[0], 2D; MUL result.color, color, fragment.color; END """ # Magic effect shader : shader_code = """!!ARBfp1.0
for event in soya.MAIN_LOOP.events: if event[0] == soya.sdlconst.MOUSEMOTION: self.mouse_pos = camera.coord2d_to_3d(event[1], event[2], -15.0) self.move(self.mouse_pos) green = soya.Material(); green.diffuse = (0.0, 1.0, 0.0, 1.0) Cursor(scene, soya.cube.Cube(None, green).to_model()) # Adds a light. light = soya.Light(scene) light.set_xyz(0.0, 0.2, 1.0) # Creates a camera. camera = soya.Camera(scene) camera.set_xyz(0.0, 0.0, 4.0) camera.fov = 100.0 soya.set_root_widget(camera) # Main loop try: soya.MainLoop(scene).main_loop() except: soya.render(); soya.screenshot().resize((320, 240)).save(os.path.join(os.path.dirname(sys.argv[0]), "results", os.path.basename(sys.argv[0])[:-3] + ".jpeg"))
def render(self): if self.active: soya.render()