def on_frame(self, ftime):
        global start_time
        global data

        self.angle_y = self.angle_y + .5

        self.program1.uniform.eye_matrix.value = transforms.compose(transforms.rotation_degrees(self.angle_z, "z"), 
                transforms.rotation_degrees(self.angle_y, "y"), 
                transforms.rotation_degrees(self.angle_x, "x"),
                transforms.translation(0.0, -0.9, 0.0))

        frame_position = int((pygame.time.get_ticks() - start_time) * 44.1 * 4)

#        print("haow far through ", frame_position/len(data))
#        print("time: ", pygame.time.get_ticks() - start_time)



        scale_factor = 0
        if frame_position + 1000 < len(data):
            for i in range(1,500):
                scale_factor1 = scale_factor + int.from_bytes(data[frame_position+2*i:frame_position+(2*i)+1], byteorder='little', signed=True)**2

            scale_factor1 = scale_factor1 / 500

            self.sound_matrix[self.counter%20] = transforms.stretching(1.0,scale_factor1,1.0)

            self.program1.uniform.point_size.value = float(scale_factor1/4)

            self.counter = self.counter+1

        self.redraw()
Exemple #2
0
    def on_frame(self, ftime):
        global start_time
        global data

        self.angle_y = self.angle_y + .5

        self.program1.uniform.eye_matrix.value = transforms.compose(
            transforms.rotation_degrees(self.angle_z, "z"),
            transforms.rotation_degrees(self.angle_y, "y"),
            transforms.rotation_degrees(self.angle_x, "x"),
            transforms.translation(0.0, -0.9, 0.0))

        frame_position = int((pygame.time.get_ticks() - start_time) * 44.1 * 4)

        #        print("haow far through ", frame_position/len(data))
        #        print("time: ", pygame.time.get_ticks() - start_time)

        scale_factor = 0
        if frame_position + 1000 < len(data):
            for i in range(1, 500):
                scale_factor1 = scale_factor + int.from_bytes(
                    data[frame_position + 2 * i:frame_position + (2 * i) + 1],
                    byteorder='little',
                    signed=True)**2

            scale_factor1 = scale_factor1 / 500

            self.sound_matrix[self.counter % 20] = transforms.stretching(
                1.0, scale_factor1, 1.0)

            self.program1.uniform.point_size.value = float(scale_factor1 / 4)

            self.counter = self.counter + 1

        self.redraw()
Exemple #3
0
    def init(self):

        self.angle = 10
        self.framerate = 20

        self.vertex_shader = glesutils.VertexShader(vertex_glsl)
        self.fragment_shader = glesutils.FragmentShader(fragment_glsl)

        self.program1 = glesutils.Program(self.vertex_shader, self.fragment_shader)
        self.program1.use()

        glClearDepthf(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glFrontFace(GL_CW)

        glClearColor(0.5, 0.5, 0.5, 1)

        self.program1.uniform.light_dir.value = ((0, 1, -1))

        self.verteces_buffer = array_spec.create_buffer(vertex_attrib=vertices)
        for face in faces:
            face["element_buffer"] = glesutils.ElementBuffer(face["vertex_index"])

        self.outer_matrix = transforms.compose(transforms.rotation_degrees(20, "z"), 
                transforms.rotation_degrees(20, "y"), 
                transforms.rotation_degrees(20, "x"),
                transforms.scaling(1.2))

        self.points_matrix = transforms.compose(transforms.stretching(0.1, 1, 1.5),
                             transforms.translation(-0.5, -0.5, -0.5))
    def draw(self):
        #Draw outer lines
        self.program1.uniform.transform_matrix.value = self.outer_matrix
        self.program1.uniform.color.value = (1, 1, 1, 1)
        self.verteces_buffer.draw(elements=self.elements_outer,
                                  mode=GL_LINE_STRIP)
        #Draw points
        self.program1.uniform.transform_matrix.value = self.points_matrix
        self.program1.uniform.color.value = (0, 0, 0, 1)
        self.verteces_buffer.draw(elements=self.elements_points,
                                  mode=GL_POINTS)

        #Draw spinning cube
        rotation_matrix = transforms.compose(
            transforms.rotation_degrees(self.angle, "z"),
            transforms.rotation_degrees(self.angle, "y"),
            transforms.compose(transforms.rotation_degrees(self.angle, "x")))

        self.program1.uniform.transform_matrix.value = rotation_matrix
        self.program1.uniform.color.value = (1, 0, 0, 1)
        self.verteces_buffer.draw(elements=self.elements_face_1,
                                  mode=GL_TRIANGLE_STRIP)
        self.program1.uniform.color.value = (0, 1, 0, 1)
        self.verteces_buffer.draw(elements=self.elements_face_2,
                                  mode=GL_TRIANGLE_STRIP)
        self.program1.uniform.color.value = (0, 0, 1, 1)
        self.verteces_buffer.draw(elements=self.elements_face_3,
                                  mode=GL_TRIANGLE_STRIP)
        self.program1.uniform.color.value = (0, 1, 1, 1)
        self.verteces_buffer.draw(elements=self.elements_face_4,
                                  mode=GL_TRIANGLE_STRIP)
Exemple #5
0
    def draw(self):
        self.program1.uniform.light_position.value = (0,0,-1)
        self.program1.uniform.ambient_light.value = 0.3
   
        rotation_matrix = transforms.compose(transforms.rotation_degrees(self.angle, "z"), 
                transforms.rotation_degrees(self.angle, "y"),
                transforms.compose(transforms.rotation_degrees(self.angle, "x")))
        self.program1.uniform.transform_matrix.value = rotation_matrix

        for face in faces:
            self.program1.uniform.color.value = face["colour"]
            self.program1.uniform.face_normal.value = face["normal"]
            self.verteces_buffer.draw(elements=face["element_buffer"], mode=GL_TRIANGLE_STRIP)
Exemple #6
0
    def init(self):

        self.angle_x = 5
        self.angle_y = 10
        self.angle_z = 5
        self.framerate = 20
        self.counter = 0

        self.vertex_shader = glesutils.VertexShader(vertex_glsl)
        self.fragment_shader = glesutils.FragmentShader(fragment_glsl)

        self.program1 = glesutils.Program(self.vertex_shader,
                                          self.fragment_shader)
        self.program1.use()

        glClearDepthf(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)

        glClearColor(0.0, 0.0, 0.0, 1)

        self.program1.uniform.light_dir.value = ((0, 1, -1))

        self.verteces_buffer = array_spec.create_buffer(vertex_attrib=vertices)
        self.points_buffer = array_spec.create_buffer(
            vertex_attrib=vertices_points)

        self.elements_outer = glesutils.ElementBuffer(indices_outer)
        self.elements_points = glesutils.ElementBuffer(indices_points)

        self.blank_matrix = transforms.translation(0.0, 0.0, 0.0)

        self.position_matrix = []
        for i in range(0, 20):
            self.position_matrix.append(
                transforms.translation((i / 10) - 0.95, 0.0, 0.0))

        self.sound_matrix = []
        for i in range(0, 20):
            self.sound_matrix.append(transforms.translation(0.0, 0.0, 0.0))

        self.program1.uniform.scaling_matrix.value = transforms.scaling(0.1)

        self.program1.uniform.eye_matrix.value = transforms.compose(
            transforms.rotation_degrees(self.angle_z, "z"),
            transforms.rotation_degrees(self.angle_x, "y"),
            transforms.rotation_degrees(self.angle_x, "x"),
            transforms.translation(0.0, -0.9, 0.0))
        self.counter = 0
	def draw(self, ts=None, pos=None):
		ts = ts if ts else self.target_size
		pos = pos if pos else self.pos
		### a scale value of 2 covers whole window
		sx = 2.0
		sy = 2.0

		tx = 0
		ty = 0

		if ts:
			sx *= float(ts[0])/float(self.booth.width)
			sy *= float(ts[1])/float(self.booth.height)

		if pos:
			tx = (2.0*float(pos[0])/float(self.booth.width))-1.0
			ty = (2.0*float(pos[1])/float(self.booth.height))-1.0

		Tm = transforms.translation((-0.5,-0.5,0))
		### correct inverted texture
		R = transforms.rotation_degrees(180, "z")
		### shift texture to center of rotation before rotating
		S = transforms.stretching(sx, sy, 0)
		T = transforms.translation((tx,-ty,0))
		self.booth.mvp_mat.value = T.dot(S).dot(R).dot(Tm)
		#print("Texture size: %dx%d" % (texture_data.width, texture_data.height))
		self.booth.program.use()
		self.texture.bind(self.booth.program.uniform.texture.value)
		self.booth.drawing.draw()
Exemple #8
0
    def draw(self):
        #update uniform
        self.mvp_mat.value = transforms.rotation_degrees(self.angle, "z")

        # draw triangles
        # program must be used
        self.drawing.draw()
    def draw(self, ts=None, pos=None):
        ts = ts if ts else self.target_size
        pos = pos if pos else self.pos
        ### a scale value of 2 covers whole window
        sx = 2.0
        sy = 2.0

        tx = 0
        ty = 0

        if ts:
            sx *= float(ts[0]) / float(self.booth.width)
            sy *= float(ts[1]) / float(self.booth.height)

        if pos:
            tx = (2.0 * float(pos[0]) / float(self.booth.width)) - 1.0
            ty = (2.0 * float(pos[1]) / float(self.booth.height)) - 1.0

        Tm = transforms.translation((-0.5, -0.5, 0))
        ### correct inverted texture
        R = transforms.rotation_degrees(180, "z")
        ### shift texture to center of rotation before rotating
        S = transforms.stretching(sx, sy, 0)
        T = transforms.translation((tx, -ty, 0))
        self.booth.mvp_mat.value = T.dot(S).dot(R).dot(Tm)
        #print("Texture size: %dx%d" % (texture_data.width, texture_data.height))
        self.booth.program.use()
        self.texture.bind(self.booth.program.uniform.texture.value)
        self.booth.drawing.draw()
    def init(self):

        self.angle_x = 5
        self.angle_y = 10
        self.angle_z = 5
        self.framerate = 20
        self.counter = 0

        self.vertex_shader = glesutils.VertexShader(vertex_glsl)
        self.fragment_shader = glesutils.FragmentShader(fragment_glsl)

        self.program1 = glesutils.Program(self.vertex_shader, self.fragment_shader)
        self.program1.use()

        glClearDepthf(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)


        glClearColor(0.0, 0.0, 0.0, 1)

        self.program1.uniform.light_dir.value = ((0, 1, -1))

        self.verteces_buffer = array_spec.create_buffer(vertex_attrib=vertices)
        self.points_buffer = array_spec.create_buffer(vertex_attrib=vertices_points)

        self.elements_outer = glesutils.ElementBuffer(indices_outer)
        self.elements_points = glesutils.ElementBuffer(indices_points)

        self.blank_matrix = transforms.translation(0.0, 0.0, 0.0)

        self.position_matrix = []
        for i in range(0,20):
            self.position_matrix.append(transforms.translation((i/10)-0.95, 0.0, 0.0))

        self.sound_matrix = []
        for i in range(0,20):
            self.sound_matrix.append(transforms.translation(0.0, 0.0, 0.0))

        self.program1.uniform.scaling_matrix.value = transforms.scaling(0.1)

        self.program1.uniform.eye_matrix.value = transforms.compose(transforms.rotation_degrees(self.angle_z, "z"), 
                transforms.rotation_degrees(self.angle_x, "y"), 
                transforms.rotation_degrees(self.angle_x, "x"),
                transforms.translation(0.0, -0.9, 0.0))
        self.counter = 0
Exemple #11
0
    def draw(self, gameWindow):
        self.bindOn(2)
        gameWindow.program.uniform.texture.value = 2
        zoomed = transforms.compose(self.rotoscaleIn, gameWindow.base_matrix)

        gameWindow.program.uniform.alpha.value = self.alpha
        zoomed = transforms.compose(transforms.scaling(self.zoom), zoomed)
        zoomed = transforms.compose(transforms.rotation_degrees(self.rot, "z"),
                                    zoomed)

        zoomed = transforms.compose(self.rotoscaleOut, zoomed)
        gameWindow.mvp_mat.value = zoomed
        gameWindow.drawing.draw()
    def draw(self):
#Draw outer lines
        self.program1.uniform.transform_matrix.value = self.outer_matrix
        self.program1.uniform.color.value = (1, 1, 1, 1)
        self.verteces_buffer.draw(elements=self.elements_outer, mode=GL_LINE_STRIP)
#Draw points
        self.program1.uniform.transform_matrix.value = self.points_matrix
        self.program1.uniform.color.value = (0, 0, 0, 1)
        self.verteces_buffer.draw(elements=self.elements_points, mode=GL_POINTS)    

#Draw spinning cube
        rotation_matrix = transforms.compose(transforms.rotation_degrees(self.angle, "z"), 
                transforms.rotation_degrees(self.angle, "y"),
                transforms.compose(transforms.rotation_degrees(self.angle, "x")))

        self.program1.uniform.transform_matrix.value = rotation_matrix
        self.program1.uniform.color.value = (1, 0, 0, 1)
        self.verteces_buffer.draw(elements=self.elements_face_1, mode=GL_TRIANGLE_STRIP)
        self.program1.uniform.color.value = (0, 1, 0, 1)
        self.verteces_buffer.draw(elements=self.elements_face_2, mode=GL_TRIANGLE_STRIP)
        self.program1.uniform.color.value = (0, 0, 1, 1)
        self.verteces_buffer.draw(elements=self.elements_face_3, mode=GL_TRIANGLE_STRIP)
        self.program1.uniform.color.value = (0, 1, 1, 1)
        self.verteces_buffer.draw(elements=self.elements_face_4, mode=GL_TRIANGLE_STRIP)
Exemple #13
0
    def init(self):
        """All setup which requires the OpenGL context to be active."""
        
        # compile vertex and fragment shaders
        vertex_shader = glesutils.VertexShader(vertex_glsl)
        fragment_shader = glesutils.FragmentShader(fragment_glsl)
        # link them together into a program
        program = glesutils.Program(vertex_shader, fragment_shader)
        # set the background to RGBA = (1, 0, 0, 1) (solid red)
        glClearColor(1, 0, 0, 1)

        # set up pre-multiplied alpha
        glEnable(GL_BLEND)
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)

        # load uniforms
        self.mvp_mat = program.uniform.mvp_mat
        self.mvp_mat.value = transforms.rotation_degrees(self.angle, "z")

        # bind uniform named "texture" to texture unit 1
        # normally, when using only one texture, 0 would be more logical,
        # but this is just for demo purposes
        program.uniform.texture.value = 1 # bind texture to texture unit 1
   
        # data for the three vertices
        positions = ((0, 0), (0, 1), (1, 1), (1, 0))
        elements = (0, 1, 2, 0, 2, 3)
        # create an array buffer from the spec
        # note: all buffer objects are automatically bound on creation
        self.drawing = array_spec.make_drawing(vertex_attrib=positions, elements=elements)

        texture_data = glesutils.TextureData.from_file("apple.png")
        self.texture = glesutils.Texture.from_data(texture_data)
        print("Texture size: %dx%d" % (texture_data.width, texture_data.height))

        # use the program, bind the texture
        program.use()
        self.texture.bind(program.uniform.texture.value)

        # print some OpenGL implementation information
        version = glesutils.get_version()
        for k in version.__dict__:
            print("%s: %s" % (k, getattr(version, k)))
 def draw(self):
     m = transforms.compose(transforms.rotation_degrees(self.angle, "y"), transforms.stretching(-1, 1, 1))
     self.program.uniform.texcoord_mat.value = m[:3,:3]
     self.drawing.draw()
Exemple #15
0
 def draw(self):
     m = transforms.compose(transforms.rotation_degrees(self.angle, "y"), transforms.stretching(-1, 1, 1))
     self.program.uniform.texcoord_mat.value = m[:3,:3]
     self.drawing.draw()
Exemple #16
0
    def init(self):
        """All setup which requires the OpenGL context to be active."""

        self.currentScenario = 0
        self.animation = []
        self.okpressed = 0
        self.kopressed = 0
        self.preload = False

        # compile vertex and fragment shaders
        vertex_shader = glesutils.VertexShader(vertex_glsl)
        fragment_shader = glesutils.FragmentShader(fragment_glsl)
        # link them together into a program
        program = glesutils.Program(vertex_shader, fragment_shader)
        # set the background to RGBA = (1, 0, 0, 1) (solid red)
        glClearColor(1, 0, 0, 0)

        # set up pre-multiplied alpha
        glEnable(GL_BLEND)
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)

        #glDisable(GL_DEPTH_TEST)

        # load uniforms
        self.mvp_mat = program.uniform.mvp_mat
        self.mvp_mat.value = transforms.rotation_degrees(0, "z")

        # bind uniform named "texture" to texture unit 1
        # normally, when using only one texture, 0 would be more logical,
        # but this is just for demo purposes
        program.uniform.texture.value = 0  # bind texture to texture unit 1
        program.uniform.alpha.value = 1.0

        self.actual_w_to_h_ratio = float(self.width) / float(self.height)
        print("WtoH ratio", self.actual_w_to_h_ratio)
        # data for the three vertices
        y_min = 0.70
        positions = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
        elements = (0, 1, 2, 0, 2, 3)
        # create an array buffer from the spec
        # note: all buffer objects are automatically bound on creation
        self.drawing = array_spec.make_drawing(vertex_attrib=positions,
                                               elements=elements)

        # use the program, bind the texture
        program.use()
        self.program = program

        # print some OpenGL implementation information
        version = glesutils.get_version()
        for k in version.__dict__:
            print("%s: %s" % (k, getattr(version, k)))

        self.base_matrix = transforms.scaling(2)
        self.base_matrix = transforms.compose(
            transforms.translation([-1, -1, 0]), self.base_matrix)
        self.base_matrix = transforms.compose(
            transforms.rotation_degrees(180, "z"), self.base_matrix)
        self.translation = transforms.translation([0, 0, 0])
        self.mvp = transforms.compose(self.translation, self.base_matrix)

        #for s in Scenarios:
        #    s.loadTexture()

        print "Before Preloading"
        Scenarios.preload()
        print "Pre-loaded"

        self.fact = Stamp("fact", self)
        self.fiction = Stamp("fiction", self)
        self.currentStamp = None