@@ -728,10 +728,6 @@ protected void beginRender() {
728728 pclearStencil = clearStencil ;
729729 clearStencil = false ;
730730
731- if (SINGLE_BUFFERED && sketch .frameCount == 1 ) {
732- restoreFirstFrame ();
733- }
734-
735731 if (fboLayerEnabledReq ) {
736732 fboLayerEnabled = true ;
737733 fboLayerEnabledReq = false ;
@@ -779,6 +775,8 @@ protected void beginRender() {
779775 0 , 0 , (int )(scale * graphics .width ), (int )(scale * graphics .height ),
780776 0 , 0 , graphics .width , graphics .height );
781777 }
778+ } else if (SINGLE_BUFFERED && sketch .frameCount == 1 ) {
779+ restoreFirstFrame ();
782780 }
783781 }
784782
@@ -935,6 +933,10 @@ private void createFBOLayer() {
935933 int depthBits = PApplet .min (REQUESTED_DEPTH_BITS , getDepthBits ());
936934 int stencilBits = PApplet .min (REQUESTED_STENCIL_BITS , getStencilBits ());
937935
936+ backTex = 0 ;
937+ frontTex = 1 ;
938+ boolean savedFirstFrame = SINGLE_BUFFERED && sketch .frameCount == 0 && firstFrame != null ;
939+
938940 genTextures (2 , glColorTex );
939941 for (int i = 0 ; i < 2 ; i ++) {
940942 bindTexture (TEXTURE_2D , glColorTex .get (i ));
@@ -944,13 +946,17 @@ private void createFBOLayer() {
944946 texParameteri (TEXTURE_2D , TEXTURE_WRAP_T , CLAMP_TO_EDGE );
945947 texImage2D (TEXTURE_2D , 0 , RGBA , fboWidth , fboHeight , 0 ,
946948 RGBA , UNSIGNED_BYTE , null );
947- initTexture (TEXTURE_2D , RGBA , fboWidth , fboHeight , graphics .backgroundColor );
949+ if (i == frontTex && savedFirstFrame ) {
950+ // Copy first frame to front texture (will be drawn as background in next frame)
951+ texSubImage2D (TEXTURE_2D , 0 , 0 , 0 , graphics .width , graphics .height ,
952+ RGBA , UNSIGNED_BYTE , firstFrame );
953+ } else {
954+ // Intitialize texture with background color
955+ initTexture (TEXTURE_2D , RGBA , fboWidth , fboHeight , graphics .backgroundColor );
956+ }
948957 }
949958 bindTexture (TEXTURE_2D , 0 );
950959
951- backTex = 0 ;
952- frontTex = 1 ;
953-
954960 genFramebuffers (1 , glColorFbo );
955961 bindFramebufferImpl (FRAMEBUFFER , glColorFbo .get (0 ));
956962 framebufferTexture2D (FRAMEBUFFER , COLOR_ATTACHMENT0 , TEXTURE_2D ,
0 commit comments