def useTexture(tex_id, shader_program, name='texture', tex_pos=None): if tex_pos is None: tex_pos = 0 if tex_id is not None: ES.glActiveTexture(positions[tex_pos]) ES.glBindTexture(ES.GL_TEXTURE_2D, tex_id) shader_program.uniform1i(name, tex_pos)
def loadTexture(pathOrURL, tex_pos=None): if tex_pos is None: tex_pos = 0 ES.glActiveTexture(positions[tex_pos]) r = pathOrURL d = Image.open(r) d.load() # d.show() width, height = d.width, d.height b = list(d.getdata()) t = (ctypes.c_ubyte * len(b * len(b[0]))) pt = t() print len(b) for (i,p) in enumerate(b): if not len(p) == len(pt[i*len(b[0]):i*len(b[0])+len(b[0])]): print len(p), len(pt[i*len(b[0]):i*len(b[0])+len(b[0])]) print p pt[i*len(b[0]):i*len(b[0])+len(b[0])] = p[:] tex_id = ES.GLuint() ES.glGenTextures(1, ctypes.byref(tex_id), param0_t=ctypes.POINTER(ES.GLuint)) ES.glBindTexture(ES.GL_TEXTURE_2D, tex_id) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_WRAP_S, ES.GL_REPEAT) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_WRAP_T, ES.GL_REPEAT) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_MAG_FILTER, ES.GL_LINEAR) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_MIN_FILTER, ES.GL_LINEAR) ES.glGenerateMipmapOES(ES.GL_TEXTURE_2D) ES.glTexImage2D(ES.GL_TEXTURE_2D, 0, ES.GL_RGBA, width, height, 0, ES.GL_RGBA, ES.GL_UNSIGNED_BYTE, byref(pt)) del pt return tex_id
def loadTexture(pathOrURL, tex_pos=None): if tex_pos is None: tex_pos = 0 ES.glActiveTexture(positions[tex_pos]) r = pathOrURL d = Image.open(r) d.load() # d.show() width, height = d.width, d.height b = list(d.getdata()) t = (ctypes.c_ubyte * len(b * len(b[0]))) pt = t() print len(b) for (i, p) in enumerate(b): if not len(p) == len(pt[i * len(b[0]):i * len(b[0]) + len(b[0])]): print len(p), len(pt[i * len(b[0]):i * len(b[0]) + len(b[0])]) print p pt[i * len(b[0]):i * len(b[0]) + len(b[0])] = p[:] tex_id = ES.GLuint() ES.glGenTextures(1, ctypes.byref(tex_id), param0_t=ctypes.POINTER(ES.GLuint)) ES.glBindTexture(ES.GL_TEXTURE_2D, tex_id) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_WRAP_S, ES.GL_REPEAT) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_WRAP_T, ES.GL_REPEAT) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_MAG_FILTER, ES.GL_LINEAR) ES.glTexParameteri(ES.GL_TEXTURE_2D, ES.GL_TEXTURE_MIN_FILTER, ES.GL_LINEAR) ES.glGenerateMipmapOES(ES.GL_TEXTURE_2D) ES.glTexImage2D(ES.GL_TEXTURE_2D, 0, ES.GL_RGBA, width, height, 0, ES.GL_RGBA, ES.GL_UNSIGNED_BYTE, byref(pt)) del pt return tex_id