Skip to content Skip to sidebar Skip to footer

Pyglet Script Works In Windows But Not In Osx

I am working in a pyglet script which displays an animation, it works as expected in Windows, but when I execute it in osx I only get a blank screen. I know it works because I've

Solution 1:

This is a (working) example code where flip is utilized:

import pyglet
from pyglet.gl import *
from math import radians, cos, sin, degrees, atan2
from time import time
from os.path import abspath

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
pyglet.options['audio'] = ('alsa', 'openal', 'silent')
key = pyglet.window.key

classBasicObject(pyglet.sprite.Sprite):
    def__init__(*args, **dictWars):
        iftype(args) == tupleandlen(args) == 2andlen(dictWars) == 0andtype(args[1]) == dict:
            args, dictWars = args

        self = args[0]
        self.name = args[1]
        self.render = True
        self.anchor = 'center'

        self.last_update = time()

        self.texture = pyglet.image.load(abspath(dictWars['texture']))
        super(BasicObject, self).__init__(self.texture)

        self.x, self.y = 0, 0
        self.rotation = 0if'x'in dictWars:
            self.x = dictWars['x']
        if'y'in dictWars:
            self.y = dictWars['y']

    defswap_image(self, image, filePath=True):
        if filePath:
            self.texture = pyglet.image.load(abspath(image))
        else:
            self.texture = image
        self.image = self.texture

    defdraw_line(self, xy, dxy, color=(0.2, 0.2, 0.2, 1)):
        glColor4f(color[0], color[1], color[2], color[3])
        glBegin(GL_LINES)
        glVertex2f(xy[0], xy[1])
        glVertex2f(dxy[0], dxy[1])
        glEnd()

    defrotate(self, deg):
        self.image.anchor_x = self.image.width / 2
        self.image.anchor_y = self.image.height / 2
        self.rotation = self.rotation+deg
        if self.anchor != 'center':
            self.image.anchor_x = 0
            self.image.anchor_y = 0defclick(self):
        print('Clicked:',self.name)

    defwork(self, *args):
        if time() - self.last_update > 0.1:
            self.rotate(10)

    defclick_check(self, x, y):
        if x > self.x and x < (self.x + self.width):
            if y > self.y and y < (self.y + self.height):
                return self

    def_draw(self):
        self.work()
        # self.draw_line((x,y), (dx, dy))
        self.draw()

classGUI(pyglet.window.Window):
    def__init__(self):
        super(GUI, self).__init__(640,340, caption='My app')
        self.alive = True
        self.keys_down = {}

        self.myImage = BasicObject('TestImage', texture='/path/to/texture.png')

    defrender(self, *args):
        pyglet.gl.glClearColor(1, 1, 1, 1)
        self.clear()
        # .. This is where you draw your objects, for instance
        self.myImage._draw()
        self.flip()

    defon_draw(self):
        self.render()

    defon_close(self):
        self.alive = Falsedefon_key_press(self, symbol, modkey):
        self.keys_down[symbol] = time()

    defon_key_release(self, symbol, modkey):
        if symbol in self.keys_down:
            del(self.keys_down[symbol])

    defon_mouse_release(self, x, y, button, modifiers):
        passdefon_mouse_press(self, x, y, button, modifiers):
        print(button,'pressed',(x,y))


    defon_mouse_motion(self, x, y, dx, dy):
        passdefon_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        passdefrun(self):
        while self.alive:
            event = self.dispatch_events()

            for symbol in self.keys_down:
                if symbol == key.ESCAPE:
                    self.alive = Nonebreakelif symbol == key.LEFT:
                    pass#Arrowkey Leftelif symbol == key.RIGHT:
                    pass#Arrowkey Rightelif symbol == key.UP:
                    pass#Arrowkey Upelif symbol == key.DOWN:
                    pass#Arrowkey Downelif symbol == 65515:
                    pass# Win keyelse:
                    print(symbol)
            self.render()


if __name__ == '__main__':
    x = GUI()
    pyglet.clock.set_fps_limit(120)
    x.run()

This is also the code i use in all my projects, something that's been evolving to fit my needs but also something that's proved to be working in most scenarios.

Post a Comment for "Pyglet Script Works In Windows But Not In Osx"