Pyglet在AMD HD4250上运行不正常

2024-03-29 07:49:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用pyglet构建一个python程序。源代码可以在任何计算机上运行,除了我的笔记本电脑。我的笔记本电脑也是唯一一个有AMD显卡的:HD4250。它的Xubuntu 13.04AMD64,图形驱动程序是X11开源驱动程序。它看起来是这样的: enter image description here

当在构造器中添加一个clear语句时,屏幕得到了正确的构建,但是速度非常慢。它最多每30秒刷新2次,几乎不响应任何输入。我该怎么解决这个问题?在

Pop>看起来OpenGL不是问题:当使用Qt OpenGL(C++)时,根本没有问题。在

一些(希望相关)代码:

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

Tags: selffieldsizegetwindowsidepygletcenter
1条回答
网友
1楼 · 发布于 2024-03-29 07:49:49

以下代码生成什么:
(它本身并不局限于某个帧缓冲区,因此它可能会产生更好的输出)

#!/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()

您可以尝试强制使用特定的绘图方法,例如:

^{pr2}$

以及

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

相关问题 更多 >