Android/Desktop Virtual Resolution. (Same resolution in all devices).

// Example of virtual resolution por Processing 3.0.1.
// Author: Luis lopez martinez - Erkosone. 2016.
int virtualWidth = 320;
int virtualHeight= 200;
PGraphics buffer;
//------------------------------------------------------------------
void settings(){
  size(displayWidth, displayHeight, P3D);
  fullScreen();
}
//------------------------------------------------------------------
void setup(){
  buffer = createGraphics(virtualWidth, virtualHeight, P3D);
}
//------------------------------------------------------------------
void draw(){
  // Start draw in buffer with (320x200) fixed resolution..
  buffer.beginDraw();
  Main();
  buffer.endDraw();
  // End of draw in buffer..

  // Now dump video Buffer on main video..
  beginShape();
  texture(buffer);
  vertex(0,0,                           0,0);
  vertex(displayWidth,0,                virtualWidth,0);
  vertex(displayWidth, displayHeight,   virtualWidth,virtualHeight);
  vertex(0, displayHeight,              0,virtualHeight);
  endShape();
}
//------------------------------------------------------------------
void Main(){
  // Write your program here..
  buffer.background(0);
  buffer.fill(255);
  buffer.textAlign(CENTER);
  buffer.text("VIRTUAL RESOLUTION BY ERKOSONE!", 160, 20);
}

Comments

  • edited February 2016

    displayWidth & displayHeight should only be used as args for size().
    For the rest of the sketch, width & height only, so it respects the actual canvas' dimensions, in case we've chosen another resolution @ size(). :-B

  • edited February 2016

    Given that both virtualWidth & virtualHeight are immutable constants, Java conventions dictate they should be all-caps names separated by underline: VIRTUAL_WIDTH & VIRTUAL_HEIGHT.
    Preferably also tagged as final and even static: ~O)

    static final int VIRTUAL_WIDTH  = 320;
    static final int VIRTUAL_HEIGHT = 200;
    
    PGraphics buffer;
    
    void setup() {
      buffer = createGraphics(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, P3D);
    }
    
Sign In or Register to comment.