def draw(self, frame):
        # The gneneral plan here is:
        #  1. Get the dots in the range of 0-255.
        #  2. Create a texture with the dots data.
        #  3. Draw the texture, scaled up with nearest-neighbor.
        #  4. Draw a mask over the dots to give them a slightly more realistic look.

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glLoadIdentity()

        # Draw the dots in this color:
        #gl.glColor3f(1.0, 0.5, 0.25)

        gl.glScalef(1, -1, 1)
        gl.glTranslatef(0, -DMD_SIZE[1]*DMD_SCALE, 0)

        #data = frame.get_data_mult()
        
        #this new jk_get_data will read the dots using the dmd function
        #and convert them via the map to rGB.
        data = self.jk_get_data(frame)

        image = pyglet.image.ImageData(DMD_SIZE[0], DMD_SIZE[1], 'RGB', data, pitch=DMD_SIZE[0] * 3)  

        gl.glTexParameteri(image.get_texture().target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        image.blit(0, 0, width=DMD_SIZE[0]*DMD_SCALE, height=DMD_SIZE[1]*DMD_SCALE)

        del image

        gl.glScalef(DMD_SCALE/float(MASK_SIZE), DMD_SCALE/float(MASK_SIZE), 1.0)
        gl.glColor4f(1.0, 1.0, 1.0, 1.0)
        self.mask_texture.blit_tiled(x=0, y=0, z=0, width=DMD_SIZE[0]*MASK_SIZE, height=DMD_SIZE[1]*MASK_SIZE)
Example #2
0
    def draw(self, frame):
        # The gneneral plan here is:
        #  1. Get the dots in the range of 0-255.
        #  2. Create a texture with the dots data.
        #  3. Draw the texture, scaled up with nearest-neighbor.
        #  4. Draw a mask over the dots to give them a slightly more realistic look.

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glLoadIdentity()

        # Draw the dots in this color:
        #gl.glColor3f(1.0, 0.5, 0.25)

        gl.glScalef(1, -1, 1)
        gl.glTranslatef(0, -DMD_SIZE[1] * DMD_SCALE, 0)

        #data = frame.get_data_mult()

        #this new jk_get_data will read the dots using the dmd function
        #and convert them via the map to rGB.
        data = self.jk_get_data(frame)

        image = pyglet.image.ImageData(DMD_SIZE[0],
                                       DMD_SIZE[1],
                                       'RGB',
                                       data,
                                       pitch=DMD_SIZE[0] * 3)

        gl.glTexParameteri(image.get_texture().target,
                           gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        image.blit(0,
                   0,
                   width=DMD_SIZE[0] * DMD_SCALE,
                   height=DMD_SIZE[1] * DMD_SCALE)

        del image

        gl.glScalef(DMD_SCALE / float(MASK_SIZE), DMD_SCALE / float(MASK_SIZE),
                    1.0)
        gl.glColor4f(1.0, 1.0, 1.0, 1.0)
        self.mask_texture.blit_tiled(x=0,
                                     y=0,
                                     z=0,
                                     width=DMD_SIZE[0] * MASK_SIZE,
                                     height=DMD_SIZE[1] * MASK_SIZE)
    def set_state(self):
        glBindTexture(GL_TEXTURE_2D, self.texture.id)

    # No unset_state method required.
    def __eq__(self, other):
        return (self.__class__ is other.__class__
                and self.texture.id == other.texture.id
                and self.texture.target == other.texture.target
                and self.parent == other.parent)

    def __hash__(self):
        return hash((self.texture.id, self.texture.target))


scene_init()
batch = pyglet.graphics.Batch()
dx = dy = dz = 0
image = pyglet.image.load('paperbag.png')

# torus = Torus(batch=batch, group=TextureBindGroup(image.get_texture()))

for m in scene.meshes:  # 导入模型数据
    batch.add(m.vertices.shape[0], GL_TRIANGLES,
              TextureBindGroup(image.get_texture(), TextureEnableGroup()),
              ('v3f/static', m.vertices.reshape(-1).tolist()),
              ('t3f/static', m.texturecoords.reshape(-1).tolist()))
    pass

pyglet.app.run()
Example #4
0
def no_anti_alias(image):
    texture = image.get_texture()
    glBindTexture(texture.target, texture.id)
    glTexParameteri(texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glBindTexture(texture.target, 0)
    return texture