@@ -504,8 +504,7 @@ protected void initSurface(int antialias) {
504504 canvas = new Canvas ();
505505 canvas .setFocusable (true );
506506 canvas .requestFocus ();
507- canvas .setBackground (Color .BLACK );
508- canvas .setForeground (Color .BLACK );
507+ canvas .setBackground (new Color (pg .backgroundColor , true ));
509508 canvas .setBounds (0 , 0 , pg .parent .width , pg .parent .height );
510509
511510 pg .parent .setLayout (new BorderLayout ());
@@ -516,9 +515,14 @@ protected void initSurface(int antialias) {
516515 request_depth_bits ,
517516 request_stencil_bits , 1 );
518517 Display .setDisplayMode (new DisplayMode (pg .parent .width , pg .parent .height ));
518+ int argb = pg .backgroundColor ;
519+ float r = ((argb >> 16 ) & 0xff ) / 255.0f ;
520+ float g = ((argb >> 8 ) & 0xff ) / 255.0f ;
521+ float b = ((argb ) & 0xff ) / 255.0f ;
522+ Display .setInitialBackground (r , g , b );
519523 Display .setParent (canvas );
520524 Display .create (format );
521- Display .setVSyncEnabled (true );
525+ Display .setVSyncEnabled (true );
522526 } catch (LWJGLException e ) {
523527 e .printStackTrace ();
524528 }
@@ -587,7 +591,7 @@ protected void update() {
587591 texParameteri (TEXTURE_2D , TEXTURE_WRAP_T , CLAMP_TO_EDGE );
588592 texImage2D (TEXTURE_2D , 0 , RGBA , fboWidth , fboHeight , 0 ,
589593 RGBA , UNSIGNED_BYTE , null );
590- initTexture (TEXTURE_2D , RGBA , fboWidth , fboHeight );
594+ initTexture (TEXTURE_2D , RGBA , fboWidth , fboHeight , pg . backgroundColor );
591595 }
592596 bindTexture (TEXTURE_2D , 0 );
593597
@@ -682,8 +686,13 @@ protected void update() {
682686
683687 // Clear all buffers.
684688 clearDepth (1 );
685- clearStencil (0 );
686- clearColor (0 , 0 , 0 , 0 );
689+ clearStencil (0 );
690+ int argb = pg .backgroundColor ;
691+ float a = ((argb >> 24 ) & 0xff ) / 255.0f ;
692+ float r = ((argb >> 16 ) & 0xff ) / 255.0f ;
693+ float g = ((argb >> 8 ) & 0xff ) / 255.0f ;
694+ float b = ((argb ) & 0xff ) / 255.0f ;
695+ clearColor (r , g , b , a );
687696 clear (DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT );
688697
689698 bindFramebuffer (FRAMEBUFFER , 0 );
@@ -873,7 +882,12 @@ protected void beginDraw(boolean clear0) {
873882
874883 if (firstFrame ) {
875884 // No need to draw back color buffer because we are in the first frame.
876- clearColor (0 , 0 , 0 , 0 );
885+ int argb = pg .backgroundColor ;
886+ float a = ((argb >> 24 ) & 0xff ) / 255.0f ;
887+ float r = ((argb >> 16 ) & 0xff ) / 255.0f ;
888+ float g = ((argb >> 8 ) & 0xff ) / 255.0f ;
889+ float b = ((argb ) & 0xff ) / 255.0f ;
890+ clearColor (r , g , b , a );
877891 clear (COLOR_BUFFER_BIT );
878892 } else if (!clear0 ) {
879893 // Render previous back texture (now is the front) as background,
@@ -1791,7 +1805,17 @@ protected boolean textureIsBound(int target, int id) {
17911805
17921806
17931807 protected void initTexture (int target , int format , int width , int height ) {
1808+ initTexture (target , format , width , height , 0 );
1809+ }
1810+
1811+
1812+ protected void initTexture (int target , int format , int width , int height ,
1813+ int initColor ) {
1814+ int [] glcolor = new int [16 * 16 ];
1815+ Arrays .fill (glcolor , javaToNativeARGB (initColor ));
17941816 IntBuffer texels = PGL .allocateDirectIntBuffer (16 * 16 );
1817+ texels .put (glcolor );
1818+ texels .rewind ();
17951819 for (int y = 0 ; y < height ; y += 16 ) {
17961820 int h = PApplet .min (16 , height - y );
17971821 for (int x = 0 ; x < width ; x += 16 ) {
0 commit comments