# Sketch stuck in WEBGL mode and cannot switch back to P2D mode

**URL:** https://discourse.processing.org/t/sketch-stuck-in-webgl-mode-and-cannot-switch-back-to-p2d-mode/32048
**Category:** Coding Questions
**Created:** [September 1, 2021, 8:50am UTC](https://discourse.processing.org/t/sketch-stuck-in-webgl-mode-and-cannot-switch-back-to-p2d-mode/32048 "2021-09-01T08:50:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![salmans911](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@salmans911](https://discourse.processing.org/u/salmans911)
#### Post date: [September 1, 2021, 8:50am UTC](https://discourse.processing.org/t/sketch-stuck-in-webgl-mode-and-cannot-switch-back-to-p2d-mode/32048/1 "2021-09-01T08:50:20Z")

</div>

Hello everyone, how do I programmatically switch the sketch from WEBGL mode back to P2D mode, it switches fine from P2D mode to WEBGL mode, but not back. I tried manually changing \_renderer with the P2D Object, but it still doesn’t work. Could anyone point me on what I need to do?

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [September 1, 2021, 2:08pm UTC](https://discourse.processing.org/t/sketch-stuck-in-webgl-mode-and-cannot-switch-back-to-p2d-mode/32048/2 "2021-09-01T14:08:30Z")

</div>

Hi,

Why do you want two switch from WEBGL to P2D? What is your use case?

One solution is to create to buffers with [`createGraphics()`](https://p5js.org/reference/#/p5/createGraphics) with different renderers (`P2D` and `WEBGL`) and switch between the two:

```auto
let graphics1, graphics2;
let firstCanvas = true;

function setup() {
  createCanvas(400, 400);
  
  // Create the two graphics
  graphics1 = createGraphics(width, height, P2D);
  graphics2 = createGraphics(width, height, WEBGL);
  
  // Draw on P2D
  graphics1.fill(255, 0, 0);
  graphics1.circle(width / 2, height / 2, 100);
  
  // Draw on WEBGL
  graphics2.sphere(100);
}

function draw() {
  background(220);
  
  // Display one buffer or the other
  if (firstCanvas) {
    image(graphics1, 0, 0);
  } else {
    image(graphics2, 0, 0);
  }
}

// Switch buffers when clicking with the mouse
function mousePressed() {
  firstCanvas = !firstCanvas;
}

```
