spriteBuffer broken

Bug #1179651 reported by tobs12
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyGL3Display
In Progress
Low
David Griffin

Bug Description

This is an reproducer to create some strange behaviour.
It uses the SpriteFont class from the textexample.
The text rendered before the main loop is fine, the text that is rendered inside is wrong.
It is flickering wrong letters, see screenshot text_bug_screen.png.
Removing the use of spriteBuffer fixes this. So I guess that spriteBuffer is broken.

Here is what I have installed:
Python 2.7.2 on Windows 7 64bit
PyOpenGL-3.0.2.win32, PyOpenGL-accelerate-3.0.2.win32-py2.7
pygame-1.9.1.win32-py2.7
pygl3display r104

---------------------------------------------------------------------------

import sys

from pygl3display import *
configure('pygame')
import random

import pygame

from pygl3display.sprites.pygameimages import PygameSurface
from pygl3display import SpriteBuffer, SpriteGroup, topLeftOffsets, Sprite

class SpriteFont(object):
    def __init__(self, font, size):
        """Prerender the font"""
        chars = ' abcdefghijklmnopqrstuvwxyzQWERTYUIOPASDFGHJKLZXCVBNM,.'
        chars += '/?!"$%^\\\';&*()-_=+1234567890'
        font = pygame.font.Font(pygame.font.match_font(font), size)
        self.fontmap = {}
        self.height = 0
        for char in chars:
            character = font.render(char, True, (255,255,255,255))
            self.height = max((self.height, character.get_height()))
            self.fontmap[char] = (PygameSurface.surfaceify(character),
                                 character.get_width())
        self.spriteBuffer = SpriteBuffer(100)

    def makeString(self, string):
        """Creates a SpriteGroup which renders the string."""
        lines = string.split('\n')
        sprites = []
        ypos = 0
        maxXpos = 0
        for line in lines:
            xpos = 0
            for char in line:
                if char in self.fontmap:
                    if char != ' ':
                        newSprite = self.spriteBuffer.createSprite(self.fontmap[char][0]) # <- removing SpriteBuffer fixes problem
                        newSprite.setOffsets(topLeftOffsets, relative=True)
                        newSprite.setPosition((xpos, ypos))
                        sprites.append(newSprite)
                    xpos += self.fontmap[char][1]
            maxXpos = max(xpos, maxXpos)
            ypos += self.height
        ret = SpriteGroup(sprites)
        return ret

GLCommon.initEnvironment((800,600),fullscreen=False)

font = SpriteFont('dejavu-sans', 20)

text2=font.makeString("Bla")
text2.setPosition((0,30))
text3=font.makeString("ABC")
text3.setPosition((0,60))

while 1:

    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key== pygame.K_ESCAPE:
                sys.exit()
        if event.type == pygame.QUIT:
            sys.exit()

    tick=pygame.time.get_ticks()

    t="%s %i" % ( pygame.display.get_driver(), tick)
    text = font.makeString(t)
    text4 = font.makeString("123456")
    text4.setPosition((0,90))
    GLCommon.doTasks()
---------------------------------------------------------------------------

Revision history for this message
tobs12 (hans1215) wrote :
description: updated
Revision history for this message
David Griffin (habilain) wrote :

SpriteBuffer is one of the things I'm currently looking at. They used to exist because creating sprites was relatively slow - I'm not sure if this is still the case. If it's not, SpriteBuffers will be killed off completely. If making Sprites is still slow, then I will be completely rewriting SpriteBuffers anyway, because at the moment they require a __del__ method which can cause problems for Pythons GC.

This may take a bit longer than the other bugs; I'm currently tight on time due to a car accident that happened a couple of days ago (no injuries, car written off) and dealing with all the problems that caused. Same for the other bug you reported, I'm afraid. But way to go giving PyGL3Display a proper shake-down.

In the meantime, probably the best bet is to not use SpriteBuffers, but just create Sprites directly.

Revision history for this message
tobs12 (hans1215) wrote :

Hello,
sorry to hear from your accident.
This bug (and the other) are not high priority for me.
I just took the example to render text. Not using SpriteBuffers fixes this and is fast enough for me.

Revision history for this message
David Griffin (habilain) wrote :

As part of the current changes, SpriteBuffers will be removed from PyGL3Display. If it is speed effective to do so, a generic Buffer class will replace them. If not, then SpriteBuffers will disappear entirely, leaving users to manage them.

A major part of the reason for killing the current implementation is that the current implementation of SpriteBuffers requires a __del__ method, but __del__ methods cause problems for Pythons GC.

Changed in pygl3display:
status: New → In Progress
importance: Undecided → Low
assignee: nobody → David Griffin (habilain)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.