How to change background color of an OpenGL surfac

2019-08-24 04:11发布

Having

srf = pygame.display.set_mode(viewport, OPENGL | DOUBLEBUF)

and performing

srf.fill([255,255,255])

results in the following error message:

pygame.error: Cannot call on OPENGL Surfaces

How to solve this issue? How can I change the background color?

1条回答
你好瞎i
2楼-- · 2019-08-24 04:38

You have to use the glClearColor function to set the color you want to clear your screen to, and then use glClear to actually clear the screen with the color specified.

E.g. call

glClearColor(0.7, 0, 0, 1)

to set the color to red and then call

glClear(GL_COLOR_BUFFER_BIT)

to clear the screen to this color.

查看更多
登录 后发表回答