Skip to content

[p5.js 2.0 Bug Report]: ortho() doesn't reset after a pop() on framebuffers #8321

@davepagurek

Description

@davepagurek

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

All (1.x and 2.x)

Web browser and version

All

Operating system

All

Steps to reproduce this

Steps:

  1. Create a framebuffer
  2. In fbo.draw() callback:
  3. push(), apply an ortho() camera, and draw something
  4. pop() so the camera should be reset, then draw something else
  5. Draw that to the main canvas

After the pop, the outlines are kinda messed up:

Image

When doing the same thing to the main canvas, with push/pop instead of fbo.draw, the ortho() gets correctly reset:

Image

Snippet:

let drawToFBO = true

let fbo
function setup() {
  createCanvas(400, 400, WEBGL);
  setAttributes({ antialias: true })
  fbo = createFramebuffer()
}

function draw() {
  background(220);
  imageMode(CENTER)
  
  if (drawToFBO) fbo.begin()
  push()
  ortho()
  translate(0, -100)
  for (let i = -3; i <= 3; i++) {
    push()
    translate(i * 50, 0)
    box(40)
    pop()
  }
  pop()

  
  push()
  translate(0, 100)
  for (let i = -3; i <= 3; i++) {
    push()
    translate(i * 50, 0)
    box(40)
    pop()
  }
  pop()
  
  if (drawToFBO) {
    fbo.end()
    image(fbo, 0, 0)
  }
}

Live: https://editor.p5js.org/davepagurek/sketches/_h8ZxlaP9

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions