示例#1
0
    def load(self, filepath):
        ilib = img_lib_t()
        rc = img_lib_attach(byref(ilib))
        if rc: raise RuntimeError(rc)

        try:
            img = img_t()

            # 24-bits/pixel BGRA format, little-endian
            img.format = IMG_FMT_RGBA8888
            img.flags |= IMG_FORMAT

            rc = img_load_file(ilib, ascii_bytes(filepath), None, byref(img))
            if rc: raise RuntimeError(rc)
            #~ print('img is %d x %d x %d' % (img.w, img.h, IMG_FMT_BPP(img.format)))

            self.img = img
            self.width = img.w
            self.height = img.h

            size = img.access.direct.stride * img.h
            self.data = (c_char * size).from_address(
                addressof(img.access.direct.data.contents))

        finally:
            img_lib_detach(ilib)
示例#2
0
    def __init__(self, source, stype=None):
        if source.endswith('.vert') or source.endswith('.frag'):
            text = self.load(source)
            stype = GL_VERTEX_SHADER if source.endswith('.vert') else GL_FRAGMENT_SHADER

        else:
            text = ascii_bytes(source)
            if stype is None:
                # try to auto-detect
                if 'gl_Frag' in source:
                    stype = GL_FRAGMENT_SHADER
                else:
                    stype = GL_VERTEX_SHADER

        self.create(stype, text)
示例#3
0
    def __init__(self, source, stype=None):
        if source.endswith('.vert') or source.endswith('.frag'):
            text = self.load(source)
            stype = GL_VERTEX_SHADER if source.endswith(
                '.vert') else GL_FRAGMENT_SHADER

        else:
            text = ascii_bytes(source)
            if stype is None:
                # try to auto-detect
                if 'gl_Frag' in source:
                    stype = GL_FRAGMENT_SHADER
                else:
                    stype = GL_VERTEX_SHADER

        self.create(stype, text)