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) {
	for(int y = 0; y < height; y++) {
		int curColor = lerpColor(col1, col2, map(y, 0, height, 0, 1));
		line(0, y, width, y);
public void draw() {
	if(isLoaded) {
		translate(-width/2, -height/2);
		gradient(sky.dayColor, sky.sunsetColor);
  pgl = (PJOGL) beginPGL();
  perspective(radians(90), (float)width/(float)height, 0.01f, 1000000f);
	  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);

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.