Pyglet not running properly on AMD HD4250

走远了吗. 提交于 2019-12-11 18:57:39

问题


I am building an python program using pyglet. The source code runs just fine on any computer exept for my laptop. My Laptop is also the only one with a AMD graphics card: the HD4250. Its Xubuntu 13.04 AMD64, and the graphics drivers are the X11 Open Source ones. This is how it looks:

When adding a clear statement in the constructor the screen gets build properly, but then is incredebly slow. It will refresh at max 2 times per 30 seconds and barely respond to any input. How can I fix this?

It does not seem that OpenGL is the problem: when using Qt OpenGL (C++ also) there are no problems like this at all.

Some (hopefully relevant) code:

def draw(self):
        pyglet.text.Label('Start Screen',
                          font_name='Arial',
                          font_size=16,
                          x=self.window.get_size()[0]/2, y=self.window.get_size()[1]-20,
                          anchor_x='center', anchor_y='center').draw()

        pyglet.text.Label('This side is looking at the enemy',
                          font_name='Arial',
                          font_size=16,
                          x=self.window.get_size()[0]/2, y=self.window.get_size()[1]-60,
                          anchor_x='center', anchor_y='center').draw()

        pyglet.text.Label(self.bottumText,
                          font_name='Arial',
                          font_size=16,
                          x=self.window.get_size()[0]/2, y=20,
                          anchor_x='center', anchor_y='center').draw()

        for y in range(0, len(self.fields)):
            for field in self.fields[y]:

                if (field.selected):
                    glColor3f(self.color[0], self.color[1], self.color[2])
                    # glColor3f(1, 0, 1)
                else:
                    glColor3f(1, 1, 1)

                # Draw center
                # self.drawCircle(field.x, field.y, 5, [1, 1, 1])

                # # Draw top side
                pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', 
                    (field.x + field.size, field.y + field.size, 
                    field.x - field.size, field.y + field.size)))

                # Draw down side
                pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', 
                    (field.x + field.size, field.y - field.size, 
                    field.x - field.size, field.y - field.size)))

                # Draw left side
                pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', 
                    (field.x - field.size, field.y - field.size,
                    field.x - field.size, field.y + field.size)))

                # Draw right side
                pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', 
                    (field.x + field.size, field.y - field.size,
                    field.x + field.size, field.y + field.size)))

回答1:


What does the following code produce:
(It's not limited to a certain frame buffer per se so it might produce better output)

#!/usr/bin/python
import pyglet
from time import time, sleep

class Window(pyglet.window.Window):
    def __init__(self, refreshrate):
        super(Window, self).__init__(vsync = False)
        self.frames = 0
        self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255))
        self.last = time()
        self.alive = 1
        self.refreshrate = refreshrate
        self.click = None
        self.drag = False

    def on_draw(self):
        self.render()

    def on_mouse_press(self, x, y, button, modifiers):
        self.click = x,y

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if self.click:
            self.drag = True
            print 'Drag offset:',(dx,dy)

    def on_mouse_release(self, x, y, button, modifiers):
        if not self.drag and self.click:
            print 'You clicked here', self.click, 'Relese point:',(x,y)
        else:
            print 'You draged from', self.click, 'to:',(x,y)
        self.click = None
        self.drag = False

    def render(self):
        self.clear()
        if time() - self.last >= 1:
            self.framerate.text = str(self.frames)
            self.frames = 0
            self.last = time()
        else:
            self.frames += 1
        self.framerate.draw()
        self.flip()

    def on_close(self):
        self.alive = 0

    def run(self):
        while self.alive:
            self.render()
            # ----> Note: <----
            #  Without self.dispatc_events() the screen will freeze
            #  due to the fact that i don't call pyglet.app.run(),
            #  because i like to have the control when and what locks
            #  the application, since pyglet.app.run() is a locking call.
            event = self.dispatch_events()
            sleep(1.0/self.refreshrate)

win = Window(23) # set the fps
win.run()

You could try to force specific drawing methods that might work with the open driver you're using, stuff like:

glEnable(GL_TEXTURE_2D)

and

glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glBegin(GL_TRIANGLES)
glVertex2f(0, 0)
glVertex2f(window.width, 0)
glVertex2f(window.width, window.height)
glEnd()


来源:https://stackoverflow.com/questions/16548833/pyglet-not-running-properly-on-amd-hd4250

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!