Set gradient background in a 3d sketch

Hello everyone,
I am trying to make a 3d game in processing, but I want to set a gradient as a background. In order to do this, I made a function that creates a linear gradient and just draws it onto the screen in 2d before rendering the 3d geometry. However, despite drawing the gradient before rendering the geometry, it covers up all of the 3d geometry, making the screen a blank gradient.

public void gradient(int col1, int col2) {
	pushStyle();
	for(int y = 0; y < height; y++) {
		int curColor = lerpColor(col1, col2, map(y, 0, height, 0, 1));
		stroke(curColor);
		line(0, y, width, y);
	}
	popStyle();
}
public void draw() {
	if(isLoaded) {
		pushMatrix();
		resetMatrix();
		ortho();
		translate(-width/2, -height/2);
		gradient(sky.dayColor, sky.sunsetColor);
		popMatrix();
  noCursor();
  pgl = (PJOGL) beginPGL();
  pgl.frontFace(PGL.CCW);
  perspective(radians(90), (float)width/(float)height, 0.01f, 1000000f);
  pgl.enable(PGL.CULL_FACE);
	  for(int i = 0; i < wid; i++) {
		  for(int j = 0; j < len; j++) {
			  chunks.get(new PVector(i, 0, j)).render(this);
		  }
	  }
	  for(int i = 0; i < wid; i++) {
		  for(int j = 0; j < len; j++) {
			  chunks.get(new PVector(i, 0, j)).render2(this);
		  }
	  }
  pgl.disable(PGL.CULL_FACE);
endPGL();
  }
}

I tried using PGraphics and also setting it as the background via the background() function, but this didn’t work. The only solution that worked for me was drawing to a pgraphics variable and then using get() to save the image, then set that as the background, but this cuts my FPS from a stable 60 FPS to 5-11.

It turns out that all I had to do was add a parameter specifying which PGraphics object to draw to and render that before the 2d geometry. Making another pgraphics object to render to doesn’t work, but it you use getGraphics() to draw to, then it works.