hello,
I'm trying to load textures in loop at an average of 1 fps. It
appears every iteration of the loop the image/texture data isn't
being
garbage collected and the script dies within a few minutes of a memory
error. Has anyone else encountered this leak? Is there
a better way to do this? It needs to be scalable so loading all the
images in at the start is not an option.
I've tried to explicitly reassign the self.img variable by setting it
to None and del self.img along with several other attempts. Any
ideas?
thanks, mark
from __future__ import division
from math import pi, sin, cos
from numpy import *
from pyglet import image
from pyglet.gl import *
from pyglet import *
from pyglet import clock
from pyglet import window
from pyglet.window import key
import pyglet
import random
import glob, os, sys
import gc
try:
# Try and create a window with multisampling (antialiasing)
config = Config(sample_buffers=1, samples=4, double_buffer=True,)
#depth_size=16,
w = window.Window(resizable=True, config=config)
except window.NoSuchConfigException:
# Fall back to no multisampling for old hardware
w = window.Window(resizable=True)
def setup():
# One-time GL setup
glClearColor(0, 0, 0, 1)
glDisable(GL_DEPTH_TEST)
glEnable(GL_LIGHT0)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glEnable(player.img.target)
glBindTexture(player.img.target, player.img.id)
@w.event
def on_resize(width, height):
# Override the default on_resize handler to create a 3D projection
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60., float(width) / float(height), .1, 1000.)
glMatrixMode(GL_MODELVIEW)
glClearColor(0, 0, 0, 1)
glDisable(GL_DEPTH_TEST)
glEnable(GL_LIGHT0)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
return pyglet.event.EVENT_HANDLED
pyglet.resource.path = ['images']
pyglet.resource.reindex()
class Player():
def __init__(self):
self.images = ['image.png','image2.png','image3.png']
self.x = 0
self.img = image.load(self.images[0]).get_texture()
def new_img(self,dt):
self.x += 1
self.img = image.load(self.images[self.x%3]).get_texture()
def draw(self):
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glBegin(GL_QUADS)
glTexCoord2f(0,0)
glVertex2f(-1,-1)
glTexCoord2f(0,1)
glVertex2f(-1,1)
glTexCoord2f(1,1)
glVertex2f(1,1)
glTexCoord2f(1,0)
glVertex2f(1,-1)
glEnd()
player = Player()
setup()
pyglet.clock.schedule_interval(player.new_img, 0.001)
@w.event
def on_draw():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0,0,-3)
player.draw()
pyglet.app.run()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---