blitting pygame.Surface() onto pygame.OPENGL display

时光毁灭记忆、已成空白 提交于 2021-01-29 03:52:51

问题


How can I blit a pygame.Surface() object onto a pygame.OPENGL display and flip the display?

import pygame

pygame.init()

RES = (640, 480)
display = pygame.display.set_mode(RES, pygame.FULLSCREEN | pygame.OPENGL)

bg_img = pygame.Surface(RES)
bg_img.fill((255, 255, 255))

display.blit(bg_img, (0, 0))
pygame.quit()
sys.exit()

gives me

Traceback (most recent call last):
  File "C:/Game Dev/TESTS/Clock Comparison/opengl_test.py", line 12, in <module>
    display.blit(bg_img, (0, 0))
error: Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)

回答1:


You cannot. To avoid the error, the display surface needs to use the pygame.OPENGLBLIT flag instead of the pygame.OPENGL flag, however after running code like this:

import pygame
import sys

pygame.init()

RES = (640, 480)
display = pygame.display.set_mode(RES, pygame.OPENGLBLIT)

bg_img = pygame.Surface(RES).
bg_img.fill((255, 255, 255))

display.blit(bg_img, (0, 0))
pygame.display.flip()
input()
pygame.quit()
sys.exit()

the display window remains blank.

The pygame documentation lists this flag as:

create an OpenGL rendering context / and use it for blitting. Obsolete.

You will need to find a way to do whatever you were trying in pyOpenGL itself instead.



来源:https://stackoverflow.com/questions/40207529/blitting-pygame-surface-onto-pygame-opengl-display

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