@@ -728,10 +728,6 @@ protected void beginRender() {
728
728
pclearStencil = clearStencil ;
729
729
clearStencil = false ;
730
730
731
- if (SINGLE_BUFFERED && sketch .frameCount == 1 ) {
732
- restoreFirstFrame ();
733
- }
734
-
735
731
if (fboLayerEnabledReq ) {
736
732
fboLayerEnabled = true ;
737
733
fboLayerEnabledReq = false ;
@@ -779,6 +775,8 @@ protected void beginRender() {
779
775
0 , 0 , (int )(scale * graphics .width ), (int )(scale * graphics .height ),
780
776
0 , 0 , graphics .width , graphics .height );
781
777
}
778
+ } else if (SINGLE_BUFFERED && sketch .frameCount == 1 ) {
779
+ restoreFirstFrame ();
782
780
}
783
781
}
784
782
@@ -935,6 +933,10 @@ private void createFBOLayer() {
935
933
int depthBits = PApplet .min (REQUESTED_DEPTH_BITS , getDepthBits ());
936
934
int stencilBits = PApplet .min (REQUESTED_STENCIL_BITS , getStencilBits ());
937
935
936
+ backTex = 0 ;
937
+ frontTex = 1 ;
938
+ boolean savedFirstFrame = SINGLE_BUFFERED && sketch .frameCount == 0 && firstFrame != null ;
939
+
938
940
genTextures (2 , glColorTex );
939
941
for (int i = 0 ; i < 2 ; i ++) {
940
942
bindTexture (TEXTURE_2D , glColorTex .get (i ));
@@ -944,13 +946,17 @@ private void createFBOLayer() {
944
946
texParameteri (TEXTURE_2D , TEXTURE_WRAP_T , CLAMP_TO_EDGE );
945
947
texImage2D (TEXTURE_2D , 0 , RGBA , fboWidth , fboHeight , 0 ,
946
948
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
+ }
948
957
}
949
958
bindTexture (TEXTURE_2D , 0 );
950
959
951
- backTex = 0 ;
952
- frontTex = 1 ;
953
-
954
960
genFramebuffers (1 , glColorFbo );
955
961
bindFramebufferImpl (FRAMEBUFFER , glColorFbo .get (0 ));
956
962
framebufferTexture2D (FRAMEBUFFER , COLOR_ATTACHMENT0 , TEXTURE_2D ,
0 commit comments