Skip to content

Commit 7f365ca

Browse files
Update Glut window to use glutDestroyWindow
Section 3.8 Escape key handling was incorrectly using `sys.exit()` to close the window and will error when attempted to close the process. `glutDestroyWindow` needs to be called instead. Updated example code accordingly.
1 parent 67fb32a commit 7f365ca

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

03-quickstart.rst

+19-13
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,35 @@ package. Here is a minimal setup that should open a window with a black backgrou
200200

201201
.. code:: python
202202
203-
import sys
204203
import OpenGL.GL as gl
205204
import OpenGL.GLUT as glut
206205
206+
window = None
207+
208+
207209
def display():
208210
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
209211
glut.glutSwapBuffers()
210212
211-
def reshape(width,height):
213+
214+
def reshape(width, height):
212215
gl.glViewport(0, 0, width, height)
213216
214-
def keyboard( key, x, y ):
217+
218+
def keyboard(key, x, y):
215219
if key == b'\x1b':
216-
sys.exit( )
217-
218-
glut.glutInit()
219-
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
220-
glut.glutCreateWindow('Hello world!')
221-
glut.glutReshapeWindow(512,512)
222-
glut.glutReshapeFunc(reshape)
223-
glut.glutDisplayFunc(display)
224-
glut.glutKeyboardFunc(keyboard)
225-
glut.glutMainLoop()
220+
glut.glutDestroyWindow(window)
221+
222+
223+
if __name__ == '__main__':
224+
glut.glutInit()
225+
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
226+
window = glut.glutCreateWindow('Hello World')
227+
glut.glutReshapeWindow(512, 512)
228+
glut.glutReshapeFunc(reshape)
229+
glut.glutDisplayFunc(display)
230+
glut.glutKeyboardFunc(keyboard)
231+
glut.glutMainLoop()
226232
227233
.. Note::
228234

0 commit comments

Comments
 (0)