【发布时间】:2020-08-03 02:50:30
【问题描述】:
执行时并非所有行都打印在窗口上。此外,在函数 showScreen 中的 glutSwapBuffers() 之后窗口崩溃。这是一张图片:https://imgur.com/n0oBJx9
w, h, g = 1200, 900, 1
def plot(coordinates, stringa, g, Px, Px1):
x, y = coordinates
while Px >= Px1:
glBegin(GL_LINES)
if stringa[Px] == "A":
glVertex2f(x, y)
glVertex2f(x, y - g)
y -= g
elif stringa[Px] == "B":
glVertex2f(x, y)
glVertex2f(x + g, y)
x += g
elif stringa[Px] == "C":
glVertex2f(x, y)
glVertex2f(x, y + g)
y += g
elif stringa[Px] == "D":
glVertex2f(x, y)
glVertex2f(x - g, y)
x -= g
glEnd()
Px -= 1
def iterate():
glViewport(0, 0, 500, 500)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def showScreen(coordinates, stringa, g, Px, Px1):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
iterate()
glColor3f(1.0, 0.0, 3.0)
plot(coordinates, stringa, g, Px, Px1)
glutSwapBuffers()
time.sleep(5)
glutInit()
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE |GLUT_RGBA)
glutInitWindowSize(w, h)
window = glutCreateWindow("dragon curve in Opengl")
glutDisplayFunc(showScreen([300, 400], stringa, x, len(stringa)-1, 0))
glutIdleFunc(showScreen([300, 400], stringa, x, len(stringa)-1, 0))
end = time.perf_counter()
print(f'Terminated in {round(end - start, 2)} seconds')
glutMainLoop()
我在 glutSwapBuffers() 之后的函数 showScreen 中收到此错误
freeglut (foo): Fatal error in program. NULL display callback not permitted in GLUT 3.0+ or freeglut 2.0.1+
这个错误是什么意思以及如何解决它?
【问题讨论】:
标签: python opengl glut pyopengl