Schmavery / reprocessing

ReasonML graphics library inspired by Processing
https://schmavery.github.io/reprocessing/
MIT License
682 stars 24 forks source link

Stuff that gets drawn during setup flickers #1

Closed Schmavery closed 7 years ago

Schmavery commented 7 years ago

@bsansouci any ideas

example:

open Reprocessing;
open P;
open PUtils;

let setup env => {
  size env 600 600;
  fill env (color 0 255 0);
  rect env 10 10 300 300;
};

let draw user env => {
  fill env (color 255 0 0);
  rect env 100 100 300 300;
  user
};

ReProcessor.run ::setup ::draw ();

Green square flickers and red one doesn't. Are we somehow clearing the screen and redrawing... seems craaazy.

Eh... on web the green doesn't show up at all.

I probably copy pasted the rect code without understanding exactly how it works.

Schmavery commented 7 years ago

This may be solved by running

Gl.readBuffer Constants.GL_BACK;
Gl.drawBuffer Constants.GL_FRONT;
Gl.copyPixels Constants.GL_COLOR

right after setup, which should copy the back buffer to the front buffer. Double buffering is probably what is resulting in the flickering. Unfortunately regl doesn't support these operations yet.

Hard to know if this will affect behaviour on web.

Schmavery commented 7 years ago

Some insight as to the behaviour on web: http://stackoverflow.com/a/11553432

WebGL automatically clears the drawing buffer on each frame unless you tell it not to

This might also be an interesting point regarding parity between native and web default background colour, worth checking out:

Try setting the page CSS background to blue instead of white, does your WebGL canvas still show white, or does it turn blue as well? (In other words, is the white area just a transparent WebGL canvas due to low alpha values?

Schmavery commented 7 years ago

Woooooo