pyglet绘图图元GL_POINT。缓冲区问题?

问题描述 投票:1回答:1

[pyglet的入门者。使用pyglet.graphicss.draw()绘制GL_POINT时出现问题。我希望此GL_POINT在下一个像素缓冲区上一个接一个地绘制,但似乎该函数不能保留在下一个像素缓冲区上绘制的最后一个GL_POINT。

import pyglet
from pyglet.gl import *
from pyglet.window import key  # for key input, on_key_press

window = pyglet.window.Window(800, 600)  # create a window object with the resolution of 800x600
window.set_caption('window title')
glClear(GL_COLOR_BUFFER_BIT)
@window.event
def on_key_press(symbol, modifiers):  # keyboard input handler
    if symbol == key.L: # Drawing a center point
        print("DRAWING TEST A POINT (400, 300)")
        pyglet.graphics.draw(
            1, pyglet.gl.GL_POINTS,
            ('v2i', (400, 300))
        )

    elif symbol == key.K: # Drawing a bit further 100 more horizontally from center point
        print("DRAWING TEST A POINT (500, 300)")
        pyglet.graphics.draw(
            1, pyglet.gl.GL_POINTS,
            ('v2i', (500, 300))
        )

pyglet.app.run()

按L会画出一个中心点。

enter image description here

然后按K将从中心点开始水平绘制100,最后一个中心点消失。

enter image description here

错误在哪里?我的代码有问题吗?如果不,我的猜测是,pyglet.graphicss.draw()函数实际上会重绘另一个原始形状吗?我该如何编码才能一个接一个地绘制?

python opengl pyglet
1个回答
1
投票

此问题是由Double buffering引起的。您可以通过将点绘制到两个缓冲区来解决该问题。绘制点两次,并在两者之间交换(flip)之间的OpenGL前后缓冲区。

flip

但是我建议将这些点添加到列表中并绘制列表。例如:]]

pyglet.graphics.draw(
    1, pyglet.gl.GL_POINTS,
    ('v2i', (400, 300))
)
window.flip()
pyglet.graphics.draw(
    1, pyglet.gl.GL_POINTS,
    ('v2i', (400, 300))
)
© www.soinside.com 2019 - 2024. All rights reserved.