简体   繁体   English

Pyglet在AMD HD4250上无法正常运行

[英]Pyglet not running properly on AMD HD4250

I am building an python program using pyglet. 我正在使用pyglet构建python程序。 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. 我的笔记本电脑也是唯一一款带有AMD显卡的笔记本电脑:HD4250。 Its Xubuntu 13.04 AMD64, and the graphics drivers are the X11 Open Source ones. 它的Xubuntu 13.04 AMD64和图形驱动程序是X11开源的。 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. 每30秒最多刷新2次,几乎不响应任何输入。 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. 似乎OpenGL并不是问题所在:使用Qt OpenGL(也为C ++)时,根本没有这样的问题。

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)))

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM