How to use the pyglet.image function in pyglet

To help you get started, weā€™ve selected a few pyglet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyglet / pyglet / tests / interactive / graphics / test_multitexture.py View on Github external
def render(self):
        # Enable blending
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        # Enable transparency
        gl.glEnable(gl.GL_ALPHA_TEST)
        gl.glAlphaFunc(gl.GL_GREATER, .1)

        # Load textures
        self.texture = pyglet.image.TextureGrid(
                pyglet.image.ImageGrid(
                    pyglet.image.load(
                        self.test_data.get_file('images', 'multitexture.png')), 1, 4))
        self.background = pyglet.image.load(
                self.test_data.get_file('images', 'grey_background.png')).get_texture()

        # Create vertex list showing the multi texture
        self.vertex_list = pyglet.graphics.vertex_list(4,
                ('v2f', (32, 332, 64, 332, 64, 364, 32, 364)),
                ('0t3f', self.texture[1].tex_coords),
                ('1t3f', self.texture[2].tex_coords),
                ('2t3f', self.texture[3].tex_coords))
github pyglet / pyglet / tests / base / interactive.py View on Github external
def _check_screenshot(self, screenshot_name):
        session_file_name = self._get_screenshot_session_file_name(screenshot_name)
        committed_file_name = self._get_screenshot_committed_file_name(screenshot_name)

        assert os.path.isfile(session_file_name)
        if os.path.isfile(committed_file_name):
            committed_image = pyglet.image.load(committed_file_name)
            session_image = pyglet.image.load(session_file_name)
            self.assert_image_equal(committed_image, session_image)
        else:
            assert self.allow_missing_screenshots
            warnings.warn('No committed reference screenshot available.')
github pyglet / pyglet / tests / unit / media / test_sources.py View on Github external
def test_get_animation_no_video(self):
        source = Source()
        animation = source.get_animation()

        self.assertIsNotNone(animation)
        self.assertIsInstance(animation, pyglet.image.Animation)
        self.assertEqual(len(animation.frames), 0)
github pyglet / pyglet / tests / interactive / image / CHECKERBOARD.py View on Github external
def test_main(self):
        width, height = 200, 200
        self.window = w = Window(width, height, visible=False)
        w.push_handlers(self)

        self.texture = image.create(32, 32, image.CheckerImagePattern()).texture

        w.set_visible()
        while not (w.has_exit or self.has_exit):
            w.dispatch_events()
        w.close()
github neozhaoliang / pywonderland / src / uniform-tilings / example_wythoff_shader_animation.py View on Github external
caption="Wythoff Explorer",
                                      resizable=True,
                                      visible=False,
                                      vsync=False)
        self._start_time = time.clock()
        self._last = self._now = self._start_time
        self._frame_count = 0  # count number of frames rendered so far
        self.shaderA = Shader(["./glsl/wythoff.vert"], ["./glsl/common.frag",
                                                        "./glsl/BufferA.frag"])

        self.shaderB = Shader(["./glsl/wythoff.vert"], ["./glsl/common.frag",
                                                        "./glsl/main.frag"])

        self.font_texture = create_image_texture(FONT_TEXTURE)
        self.noise_texture = create_image_texture(NOISE_TEXTURE)
        self.iChannel0 = pyglet.image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height,
                                                              gl.GL_RGBA32F_ARB)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(self.iChannel0.target, self.iChannel0.id)
        gl.glActiveTexture(gl.GL_TEXTURE1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.font_texture)
        gl.glActiveTexture(gl.GL_TEXTURE2)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.noise_texture)

        with FrameBuffer() as self.bufferA:
            self.bufferA.attach_texture(self.iChannel0)

        # initialize the shaders
        with self.shaderA:
            self.shaderA.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderA.uniformf("iResolution", width, height, 0.0)
            self.shaderA.uniformf("iTime", 0.0)
github psychopy / psychopy / psychopy / visual.py View on Github external
self.winHandle.on_key_press = psychopy.event._onPygletKey
        self.winHandle.on_mouse_press = psychopy.event._onPygletMousePress
        self.winHandle.on_mouse_release = psychopy.event._onPygletMouseRelease
        self.winHandle.on_mouse_scroll = psychopy.event._onPygletMouseWheel
        if not self.allowGUI: 
            #make mouse invisible. Could go further and make it 'exclusive' (but need to alter x,y handling then)
            self.winHandle._mouse_visible=False
        self.winHandle.on_resize = self.onResize
        if self.pos is None:
            #work out where the centre should be
            self.pos = [ (thisScreen.width-self.size[0])/2 , (thisScreen.height-self.size[1])/2 ]
        self.winHandle.set_location(self.pos[0]+thisScreen.x, self.pos[1]+thisScreen.y)#add the necessary amount for second screen
        
        try: #to load an icon for the window
            iconFile = os.path.join(psychopy.__path__[0], 'psychopy.png')
            icon = pyglet.image.load(filename=iconFile)
            self.winHandle.set_icon(icon)
        except: pass#doesn't matter
github sympy / sympy / sympy / plotting / pyglet / media / gst_openal.py View on Github external
def _get_texture(self):
        self._wait_frame_format()
        if not self._texture:
            glEnable(GL_TEXTURE_2D)
            texture = image.Texture.create_for_size(GL_TEXTURE_2D,
                self.width, self.height, GL_RGB)
            if texture.width != self.width or texture.height != self.height:
                self._texture = texture.get_region(
                    0, 0, self.width, self.height)
            else:
                self._texture = texture

            # Flip texture coords (good enough for simple apps).
            bl, br, tr, tl = self._texture.tex_coords
            self._texture.tex_coords = tl, tr, br, bl
        return self._texture
    texture = property(_get_texture)
github 01AutoMonkey / open.gl-tutorials-to-pyglet / 5-1-Depth_and_Stencils-Cube.py View on Github external
glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 3 * sizeof(GLfloat))

texAttrib = glGetAttribLocation(shaderProgram, "texcoord")
glEnableVertexAttribArray(texAttrib)
glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 6 * sizeof(GLfloat))


# Load textures
textures = [0] * 2
textures_ctype = (GLuint * len(textures))(*textures)
glGenTextures(2, textures_ctype)

glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, textures_ctype[0])

image = pyglet.image.load("sample.png")
width, height = image.width, image.height
image = image.get_data('RGB', width * 3)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image)

glUniform1i(glGetUniformLocation(shaderProgram, "texKitten"), 0)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

glActiveTexture(GL_TEXTURE1)
glBindTexture(GL_TEXTURE_2D, textures_ctype[1])

image = pyglet.image.load("sample2.png")
width, height = image.width, image.height
github pyglet / pyglet / pyglet / resource.py View on Github external
# Large images are not placed in an atlas
        max_texture_size = pyglet.image.get_max_texture_size()
        max_size = min(2048, max_texture_size)
        if width > max_size or height > max_size:
            return None

        # Group images with small height separately to larger height
        # (as the allocator can't stack within a single row).
        bin_size = 1
        if height > max_size / 4:
            bin_size = 2

        try:
            texture_bin = self._texture_atlas_bins[bin_size]
        except KeyError:
            texture_bin = pyglet.image.atlas.TextureBin(border=True)
            self._texture_atlas_bins[bin_size] = texture_bin

        return texture_bin
github mikedh / trimesh / trimesh / viewer / windowed.py View on Github external
def save_image(self, file_obj):
        """
        Save the current color buffer to a file object
        in PNG format.

        Parameters
        -------------
        file_obj: file name, or file- like object
        """
        manager = pyglet.image.get_buffer_manager()
        colorbuffer = manager.get_color_buffer()

        # if passed a string save by name
        if hasattr(file_obj, 'write'):
            colorbuffer.save(file=file_obj)
        else:
            colorbuffer.save(filename=file_obj)