示例#1
0
    def test_texture_raw(self, painter):
        material = Material()
        import os

        texture = self.renderer.new_texture(
            gl.Surface(Path(os.path.join(os.path.dirname(__file__), "material_test.bmp")))
        )
        texture.generate_mipmap()
        texture.mag_filter(gl.TextureFilter.linear)
        texture.min_filter_bilinear(gl.TextureFilter.linear)
        material.add_texture(
            texture,
            gl.TextureType.ambient,
            gl.TextureMapping.uv,
            gl.StackOperation.add,
            gl.TextureMapMode.wrap,
            gl.BlendMode.basic,
        )
        cube_view = self.cube.drawable(self.renderer)
        painter.state.look_at(gl.vec3f(0, 0.8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0))
        painter.state.perspective(angle.deg(35), 200 / 200, 0.005, 30.0)
        painter.state.rotate(angle.deg(42), gl.vec3f(1, 1, 0))
        self.deg += 1
        with painter.bind([material.bindable(self.renderer)]):
            painter.draw([cube_view])
示例#2
0
 def test_yaw(self):
     c = Camera()
     c.yaw = angle.deg(90)
     self.assertAlmostEqual(c.yaw.degree, 90, .2)
     c.yaw = angle.deg(-90)
     self.assertEqual(c.yaw.degree, 0)
     c.yaw = angle.deg(12)
     self.assertAlmostEqual(c.yaw.degree, 12, .2)
示例#3
0
 def test_roll(self):
     c = Camera()
     c.roll = angle.deg(90)
     self.assertAlmostEqual(c.roll.degree, 90, 1e-5)
     c.roll = angle.deg(-90)
     self.assertEqual(c.roll.degree, 0)
     c.roll = angle.deg(12)
     self.assertAlmostEqual(c.roll.degree, 12, 1e-5)
示例#4
0
 def test_pitch(self):
     c = Camera()
     c.pitch = angle.deg(90)
     self.assertEqual(c.pitch.degree, 90)
     c.pitch = angle.deg(-90)
     self.assertEqual(c.pitch.degree, 0)
     c.pitch = angle.deg(12)
     self.assertAlmostEqual(c.pitch.degree, 12, 1e-5)
示例#5
0
 def test_cube(self, painter):
     material = Material()
     material.add_color(
         gl.ShaderParameterType.vec3,
         StackOperation.add
     )
     cube_view = self.cube.drawable(self.renderer)
     painter.state.look_at(
         gl.vec3f(0, .8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0)
     )
     painter.state.perspective(
         angle.deg(35), 200 / 200, 0.005, 30.0
     )
     painter.state.rotate(angle.deg(32), gl.vec3f(0, 1, 0))
     with painter.bind([material.bindable(self.renderer)]):
         painter.draw([cube_view])
示例#6
0
    def test_no_copy(self):
        self.assertIs(self.s, self.s.scale(1,2,3))
        self.assertIs(self.s, self.s.translate(1,2,3))
        self.assertIs(self.s, self.s.rotate(angle.deg(0), gl.vec3f(1,2,3)))
        self.assertIs(self.s, self.s.look_at(
            gl.vec3f(0,0,0), gl.vec3f(1,2,3), gl.vec3f(0, 1, 0)
        ))
        self.assertIs(self.s, self.s.perspective(angle.deg(45), 1, 31, 32))
        self.assertIs(self.s, self.s.ortho(0, 0, 200, 200))

        self.assertIs(
            self.s,
            self.s.scale(1,2,3).translate(1,2,3).rotate(
                angle.deg(0), gl.vec3f(1,2,3)
            ).look_at(
                gl.vec3f(0,0,0), gl.vec3f(1,2,3), gl.vec3f(0, 1, 0)
            ).perspective(angle.deg(45), 1, 31, 32).ortho(0, 0, 200, 200)
        )
示例#7
0
    def test_texture(self, painter):
        material = Material()
        material.add_color(gl.ShaderParameterType.vec3, gl.StackOperation.add)
        import os

        material.add_texture(
            os.path.join(os.path.dirname(__file__), "material_test.bmp"),
            gl.TextureType.ambient,
            gl.TextureMapping.uv,
            gl.StackOperation.add,
            gl.TextureMapMode.wrap,
            gl.BlendMode.basic,
        )
        cube_view = self.cube.drawable(self.renderer)
        painter.state.look_at(gl.vec3f(0, 0.8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0))
        painter.state.perspective(angle.deg(35), 200 / 200, 0.005, 30.0)
        painter.state.rotate(angle.deg(42), gl.vec3f(1, 1, 0))
        self.deg += 1
        with painter.bind([material.bindable(self.renderer)]):
            painter.draw([cube_view])
示例#8
0
 def test_render_color0(self, painter):
     material = Material()
     material.add_color(
         gl.ShaderParameterType.vec3,
         StackOperation.add
     )
     painter.state.translate(100, 100, 0)
     painter.state.scale(100, 100, 0)
     painter.state.rotate(angle.deg(20), gl.vec3f(1, 1, 0))
     cube_view = self.cube.drawable(self.renderer)
     with painter.bind([material.bindable(self.renderer)]):
         painter.draw([cube_view])
示例#9
0
    def test_sphere(self, painter):
        s = scene.from_string("s 0 0 0 1", "nff")
        self.assertIsNotNone(s)
        self.assertEqual(len(s.meshes), 1)
        self.assertEqual(len(s.materials), 1)
        mesh = s.meshes[0]
        mat = s.materials[0]
        self.assertIsNotNone(mesh)
        self.assertIsNotNone(mat)
        mat.ambient = gl.Color3f("white")

        painter.state.look_at(gl.vec3f(0, 0.8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0))
        painter.state.perspective(angle.deg(45), 200 / 200, 0.005, 30.0)
        with painter.bind([mat.bindable(self.renderer)]):
            painter.draw([mesh.drawable(self.renderer)])
示例#10
0
    def test_perspective(self):
        m = gl.mat4f(self.s.model)
        v = gl.mat4f(self.s.view)
        p = gl.mat4f(self.s.projection)
        mvp = gl.mat4f(self.s.mvp)

        self.assertEqual(m, self.s.model)
        self.assertEqual(v, self.s.view)
        self.assertEqual(p, self.s.projection)
        self.assertEqual(mvp, self.s.mvp)

        self.s.perspective(angle.deg(45), 1, 0.1, 300)

        self.assertEqual(m, self.s.model)
        self.assertEqual(v, self.s.view)
        self.assertNotEqual(p, self.s.projection)
        self.assertNotEqual(mvp, self.s.mvp)
示例#11
0
 def test_update_ambiant(self, painter):
     material = Material()
     material.ambiant = gl.col3f(1,0,0)
     mesh = gl.Spheref(gl.vec3f(0), 1).drawable(self.renderer)
     painter.state.look_at(
         gl.vec3f(0, .8, 10), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0)
     )
     painter.state.perspective(
         angle.deg(35), 200 / 200, 0.005, 30.0
     )
     bindable = material.bindable(self.renderer)
     s = painter.push_state()
     s.translate(1, 0, 0)
     with painter.bind([bindable]):
         painter.draw([mesh])
     painter.pop_state()
     s = painter.push_state()
     s.translate(-1, 0, 0)
     material.ambiant = gl.col3f(0, 1, 1)
     with painter.bind([bindable]):
         painter.draw([mesh])
示例#12
0
    def test_sphere_light(self, painter):
        s = scene.from_string("s 0 0 0 1", "nff")
        self.assertIsNotNone(s)
        self.assertEqual(len(s.meshes), 1)
        self.assertEqual(len(s.materials), 1)
        mesh = s.meshes[0]
        mat = s.materials[0]
        self.assertIsNotNone(mesh)
        self.assertIsNotNone(mat)
        mat.ambient = gl.Color3f("#222")
        mat.shading_model = gl.material.ShadingModel.gouraud
        mat.diffuse = gl.Color3f("white")
        mat.specular = gl.Color3f("white")
        mat.shininess = 3

        painter.state.look_at(gl.vec3f(0, 0.8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0))
        painter.state.perspective(angle.deg(45), 200 / 200, 0.005, 30.0)
        light = self.renderer.new_light(
            gl.PointLightInfo(gl.vec3f(5, -1, 0), gl.Color3f("black"), gl.Color3f("#0f0f0f"))
        )
        with painter.bind([light, mat.bindable(self.renderer)]):
            painter.draw([mesh.drawable(self.renderer)])
示例#13
0
 def test_look_at_identity(self):
     c = Camera()
     c.look_at(c.front)
     self.assertEqual(c.yaw, angle.deg(0))
     self.assertEqual(c.roll, angle.rad(0))
     self.assertEqual(c.pitch, angle.rad(0))
示例#14
0
 def test_frustum(self):
     c = Camera()
     c.init_frustum(angle.deg(30), 1, 10, 20)
     self.assertTrue(c.has_frustum)
     f = c.frustum