简体   繁体   English

如何在使用 opengl 时在 pygame 中对图像进行 blit 处理?

[英]How to blit image in pygame while using opengl?

I'm trying to blit my character image using pygame, it works when opengl is not called我正在尝试使用 pygame 对我的角色图像进行 blit,它在未调用 opengl 时有效

pygame.init()
display = pygame.display.set_mode((800, 600))

    def draw(self,display):
        if self.walkCount + 1 >= 30:
            self.walkCount = 0
        if self.left:
            display.blit(walkLeft[self.walkCount // 6], (int(self.x), int(self.y)))
            self.walkCount += 1
        elif self.right:
            display.blit(walkRight[self.walkCount // 6], (int(self.x), int(self.y)))
            self.walkCount += 1
        else:
            display.blit(standing, (int(self.x), int(self.y)))
        pygame.display.flip()
def redraw():
    global WalkCount
    display.fill((0, 0, 0))
    Player1.draw(display)
while True:
    redraw()
pygame.quit()

When opengl is called,当 opengl 被调用时,

display = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF | pygame.OPENGLBLIT)
...
def redraw():
    global WalkCount
    Player1.draw(display)
while True:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    redraw()
pygame.quit()

it doesn't show my character image anymore, how do I fix it?它不再显示我的角色图像,我该如何解决? Am I missing anything?我错过了什么吗?

Am I missing anything?我错过了什么吗?

Yes.是的。 pygame.OPENGLBLIT is obsolete and simply does not work (not sure if it ever worked; I guess not). pygame.OPENGLBLIT已经过时并且根本不起作用(不确定它是否曾经起作用;我猜不是)。

So either use a "regular" display surface or use OpenGL only.因此,要么使用“常规”显示表面,要么仅使用 OpenGL。

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

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