Skip to content

Instantly share code, notes, and snippets.

@hansent
Created May 26, 2011 05:40
Show Gist options
  • Select an option

  • Save hansent/992613 to your computer and use it in GitHub Desktop.

Select an option

Save hansent/992613 to your computer and use it in GitHub Desktop.
from glob import glob
import kivy
kivy.require('1.0.0')
from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.cache import Cache
from kivy.clock import Clock
Cache.register('kv.texture', timeout=5)
def print_cache(*args):
Cache.print_usage()
class MyApp(App):
def next_image(self):
for i in range(10):
src = self.file_list.pop(0)
self.image.source = src
self.file_list.append(src)
#print self.image.texture
#gc.collect()
def build(self):
self.file_list = glob('cache/products/1280*')
self.image = Image()
self.button1 = Button(text='Hello World')
self.button = Button(text='Load Image', on_press=self.next_image)
layout = BoxLayout()
layout.add_widget(self.button1)
layout.add_widget(self.button)
Clock.schedule_interval(print_cache, 1)
return layout
if __name__ in ('__android__', '__main__'):
MyApp().run()
@hansent
Copy link
Author

hansent commented May 26, 2011

ok, allocate memory for initial texture

cdef int glfmt = _color_fmt_to_gl(colorfmt)
cdef int datasize = texture_width \* texture_height \* \
        _gl_format_size(glfmt) \* _buffer_type_to_gl_size(bufferfmt)
#cdef void *data = NULL
#cdef int dataerr = 0
with nogil:
    #data = calloc(1, datasize)
    #if data != NULL:
    glTexImage2D(target, 0, glfmt, texture_width, texture_height, 0,
                     glfmt, glbufferfmt, NULL)
    glFlush()
    #free(data)
    #data = NULL
    if mipmap:
        glGenerateMipmap(target)
    #else:
    #    dataerr = 1

#if dataerr:
#    raise Exception('Unable to allocate memory for texture (size is %s)' %
#                    datasize)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment