How to change background color of an OpenGL surface?

≯℡__Kan透↙ 提交于 2019-12-25 03:42:35

问题


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:


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.



来源:https://stackoverflow.com/questions/53535984/how-to-change-background-color-of-an-opengl-surface

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