Skip to content
Advertisement

pyglet: on_resize breaks graphics

I’m writing an application with pyglet where all rendered objects are children of the window class. I’m trying to draw a simple rectangle, but using on_resize seems to break everything. There’s no error message, it just doesn’t draw the rectangle.

This is my file structure:

JavaScript

This code doesn’t work, but if I remove the on_resize methods it does:

JavaScript

I would like to be able to keep rendered objects as children of the window class, since that makes running event handlers much easier. Is there any way that I can make this work with the on_resize handler? Any help is appreciated.

EDIT: I tried removing on_resize from the Quad class, and making on_resize do nothing in the Window class. It seems like the existence of the on_resize function is the issue–if on_resize exists, pyglet wont draw the rectangle.

Advertisement

Answer

In the on_resize method add the glViewport function call. And also don’t forget to set up an orthogonal projection. Take a look at my code, it draws a triangle at the center of the screen.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement