A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
This is achieved by creating a separate sketch-window class so that sketch doesn't have to inherit from gl-window. That way, the slots of sketch can be initialized BEFORE the window gets created, and the window can be assigned the correct dimensions from the start, avoiding a resize.
Implementation notes:
Since there may be a circular dependency between the sketch slots and the SDL2 window (specifically: trying to create textures during slot initialization would break because the OpenGL context of the window is not available yet), we have to delay their initialization. My approach is to create a skeleton image object, save a lambda that will do the OpenGL parts of image creation and update the imageobject, and then call all the lambdas after the window has been created.
For backward compatibility with sketches that handle input via the kit.sdl2 methods, we have to forward those method calls to the sketch object.
For some reason, the call to (gl:clear-color 0.0 1.0 0.0 1.0) in initialize-gl started taking effect after the refactoring, and the background colour of sketches with (copy-pixels t) suddenly became green if they didn't call background anywhere (they had a black background before - I'm not sure why!). So I just changed it to (gl:clear-color 0.0 0.0 0.0 1.0) for backward compatibility.
Various parts of the code, as well as debugging help, were contributed by @Gleefre :)
An attempt to fix the first render being lost due to window resizing (see: https://github.com/vydd/sketch/issues/69).
This is achieved by creating a separate
sketch-window
class so thatsketch
doesn't have to inherit fromgl-window
. That way, the slots ofsketch
can be initialized BEFORE the window gets created, and the window can be assigned the correct dimensions from the start, avoiding a resize.Implementation notes:
image
object, save a lambda that will do the OpenGL parts of image creation and update theimage
object, and then call all the lambdas after the window has been created.kit.sdl2
methods, we have to forward those method calls to thesketch
object.(gl:clear-color 0.0 1.0 0.0 1.0)
ininitialize-gl
started taking effect after the refactoring, and the background colour of sketches with(copy-pixels t)
suddenly became green if they didn't callbackground
anywhere (they had a black background before - I'm not sure why!). So I just changed it to(gl:clear-color 0.0 0.0 0.0 1.0)
for backward compatibility.Various parts of the code, as well as debugging help, were contributed by @Gleefre :)