问题
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