Esempio n. 1
0
File: camera.py Progetto: azoon/pymt
    def init_camera(self):
        if not self.capture_device:
            self.capture_device = Device()
            #self.capture_device.setResolution(self.resolution[0], self.resolution[1])

        self.frame_texture  = Texture.create(*self.resolution)
        self.frame_texture.tex_coords = (1,1,0,  0,1,0,  0,0,0, 1,0,0)
Esempio n. 2
0
def label2texture(label):
    vertex_list = label._vertex_lists[0].vertices[:]
    xpos = map(int, vertex_list[::8])
    ypos = map(int, vertex_list[1::8])
    glyphs = label._get_glyphs()

    xstart = xpos[0]
    xend = xpos[-1] + glyphs[-1].width
    width = xend - xstart

    ystart = min(ypos)
    yend = max(y+glyph.height for y, glyph in zip(ypos, glyphs))
    height = yend - ystart

    texture = Texture.create(width, height, gl.GL_ALPHA)

    for glyph, x, y in zip(glyphs, xpos, ypos):
        data = glyph.get_image_data()
        x = x - xstart
        y = height - glyph.height - y + ystart
        texture.blit_into(data, x, y, 0)

    if sys.platform not in ['win32', 'cygwin']:
        texture = texture.get_transform(flip_y=True)

    return texture
Esempio n. 3
0
    def _get_texture(self):
        if self._current_texture:
            return self._current_texture

        texture = Texture.create_for_size(GL_TEXTURE_2D, self.width, self.height)
        glBindTexture(texture.target, texture.id)
        glTexParameteri(texture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

        if not gl_info.have_version(1, 2) or True:
            self.unpack()

        glTexImage2D(
            texture.target,
            texture.level,
            self.format,
            self.width,
            self.height,
            0,
            self.format,
            self.packed_format,
            self.data,
        )

        self._current_texture = texture
        return texture
Esempio n. 4
0
    def __init__(self,
                 width,
                 height,
                 window,
                 num_color_attachments=1,
                 mapping_mode=None,
                 provide_depth=False,
                 provide_stencil=False):
        """"Create an arbitrary layer framebuffer, I'll add stencil and depthbuffers if I ever package this for resuse, in pyweek, those args are pretty much placeholders"""
        if mapping_mode is None:
            mapping_mode = gl.GL_NEAREST
        assert not provide_stencil, 'stencil buffer not implemented'
        assert not provide_depth, 'depth buffer not implemented'
        self.window = window
        self.width = width
        self.height = height
        self.bufferId = gl.GLuint(0)
        self.textureIds = []
        self.buffer_args = []

        #create the vram objects?
        gl.glGenFramebuffers(1, rf(self.bufferId))
        gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.bufferId)

        for bufferIndex in range(num_color_attachments):
            newTex = gl.GLuint(0)
            gl.glGenTextures(1, rf(newTex))
            self.textureIds.append(newTex)
            gl.glBindTexture(gl.GL_TEXTURE_2D, newTex)
            gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGB, width, height, 0,
                            gl.GL_RGB, gl.GL_UNSIGNED_INT, 0)
            gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                               mapping_mode)
            gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                               mapping_mode)
            gl.glFramebufferTexture2D(gl.GL_FRAMEBUFFER,
                                      gl.GL_COLOR_ATTACHMENT0 + bufferIndex,
                                      gl.GL_TEXTURE_2D, newTex, 0)
            self.buffer_args.append(gl.GL_COLOR_ATTACHMENT0 + bufferIndex)
        #assign one of the vram objects to the framebuffer cache?

        if provide_depth:
            self.buffer_args.append(gl.GL_DEPTH_ATTACHMENT)
        if provide_stencil:
            self.buffer_args.append(gl.GL_STENCIL_ATTACHMENT)

        self.buffers_provided = (gl.GLenum *
                                 len(self.buffer_args))(*self.buffer_args)

        gl.glDrawBuffers(len(self.buffer_args), self.buffers_provided)
        self.textures = [
            Texture(self.width, self.height, gl.GL_TEXTURE_2D, texId.value)
            for texId in self.textureIds
        ]

        assert gl.glCheckFramebufferStatus(
            gl.GL_FRAMEBUFFER
        ) == gl.GL_FRAMEBUFFER_COMPLETE, "I don't know why this happened, but at least I can find out"
Esempio n. 5
0
	def takeScreenshot():
		"""
		Takes a screenshot of the current window and returns it.

		@return: screenshot texture.
		"""
		width, height = getWindowUsableSize()
		texture = Texture.create_for_size(GL_TEXTURE_2D, width, height, GL_RGBA)
		texture.blit_into(pyglet.image.get_buffer_manager().get_color_buffer(), 0, 0, 0)
		return texture.get_region(0, 0, width, height)
Esempio n. 6
0
File: camera.py Progetto: azoon/pymt
    def init_camera(self):
        if self.pipeline:
            self.pipeline = None

        GL_CAPS = "video/x-raw-rgb,width=%d,pixel-aspect-ratio=1/1,red_mask=(int)0xff0000,green_mask=(int)0x00ff00,blue_mask=(int)0x0000ff" % (self.resolution[0])
        self.pipeline = gst.parse_launch("%s ! ffmpegcolorspace ! appsink name=camera_sink emit-signals=True caps=%s" % (self.video_src, GL_CAPS) )
        self.camera_sink = self.pipeline.get_by_name('camera_sink')
        self.frame_texture  = Texture.create(*self.resolution)
        self.frame_texture.tex_coords = (1,1,0,  0,1,0,  0,0,0, 1,0,0)

        if self.camera_sink and not self.stopped:
            self.start_capture()
Esempio n. 7
0
 def clear_texture(self):
     w, h = self.size
     n_w = nearest_pow2(w)
     n_h = nearest_pow2(h)
     key = (n_w, n_h)
     tex = self.cache.pop(key, None)
     if tex is None:
         tex = Texture.create(n_w, n_h, GL_RGBA)
         tex.key = key
     tex = tex.get_region(0, 0, w, h)
     self.texture = tex
     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
         GL_COLOR_ATTACHMENT0_EXT, tex.target, tex.id, 0)
Esempio n. 8
0
    def __init__(self, width, height):
        if not gl.gl_info.have_extension('GL_EXT_framebuffer_object'):
            raise Exception('framebuffer object extension not available')

        texture_id = buffer_texture(width, height)
        self.texture = Texture(width, height, gl.GL_TEXTURE_2D, texture_id)

        framebuffer_id = gl.GLuint()
        gl.glGenFramebuffersEXT(1, byref(framebuffer_id))
        self.id = framebuffer_id.value

        with self:
            gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT,
                                         gl.GL_COLOR_ATTACHMENT0_EXT + 0,
                                         gl.GL_TEXTURE_2D, texture_id, 0)
Esempio n. 9
0
 def create_background(self, dim, ix, iy):
     # draw dirt stuff
     freq = 1 / 100
     imgdata = self.perlin.noise2_bytes(ix, iy, freq, 2, dim, 64)
     target = GL_TEXTURE_2D
     gid = GLuint()
     glGenTextures(1, byref(gid))
     glBindTexture(target, gid.value)
     glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
     glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
     glTexImage2D(target, 0, GL_RGBA, dim, dim, 0, GL_RGBA,
                  GL_UNSIGNED_BYTE, imgdata)
     image = Texture(dim, dim, target, gid.value)
     key = 'bg_%d_%d' % (ix, iy)
     self[key] = image
     return key
Esempio n. 10
0
    def _get_texture(self):
        if self._current_texture:
            return self._current_texture

        texture = Texture.create(self.width, self.height, GL_TEXTURE_2D, None)
        glBindTexture(texture.target, texture.id)
        glTexParameteri(texture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

        if not gl_info.have_version(1, 2) or True:
            self.unpack()

        glTexImage2D(texture.target, texture.level, self.format, self.width,
                     self.height, 0, self.format, self.packed_format,
                     self.data)

        self._current_texture = texture
        return texture
Esempio n. 11
0
File: camera.py Progetto: azoon/pymt
    def init_camera(self):
        if not self.capture_device:
            self.capture_device = cvCaptureFromCAM(self.video_src)

        try:
            cvSetCaptureProperty (self.capture_device, CV_CAP_PROP_FRAME_WIDTH,  self.resolution[0])
            cvSetCaptureProperty (self.capture_device, CV_CAP_PROP_FRAME_HEIGHT, self.resolution[1])
            self.frame  = cvQueryFrame( self.capture_device )
            if not int(self.frame.width) == self.resolution[0]:
                raise Exception('Resolution Not supported')
        except:
            w = int(cvGetCaptureProperty (self.capture_device, CV_CAP_PROP_FRAME_WIDTH))
            h = int(cvGetCaptureProperty (self.capture_device, CV_CAP_PROP_FRAME_HEIGHT))
            self.frame  = cvQueryFrame( self.capture_device )
            pymt_logger.warning('Warning: Camera resolution %s not possible!  Defaulting to %s.' % (self.resolution, (w,h)) )
            self._resolution = (w,h)

        self.frame_texture  = Texture.create(*self.resolution)
        self.frame_texture.tex_coords = (1,1,0,  0,1,0,  0,0,0, 1,0,0)
Esempio n. 12
0
def _texture(width, height, use_float=True):
    format = GL_RGBA16F
    if not use_float:
        format = GL_RGBA
    # Returns an empty texture of the given width and height.
    return Texture.create(width, height, internalformat=format)