GSDP:GAM100/CProcessing/readFrameBufferAdvanced()

From Inside
Jump to: navigation, search

readFrameBufferAdvanced()

Description

Returns a PImage of a section of the last frame's frame buffer (what was drawn to the screen). Using readFrameBufferAdvanced() lets you set a few flags that are described below.

Parameters

readFrameBuffer(int x, int y, int w, int h, bool copyPixelData, bool usePixelPerfectFiltering)

  • x - (int) X coordinate of the top left corner of the pixel to start from.
  • y - (int) Y coordinate of the top left corner of the pixel to start from.
  • w - (int) Width of the sub image in pixels.
  • h - (int) Height of the sub image in pixels.
  • copyPixelData - (bool) Copies the pixel data of the image so it can be manipulated later.
  • usePixelPerfectFiltering - (bool) Turns off bilinear smoothing for images, good for pixel art.

Example

PImage jImage;
int x_size, y_size;

void init()
{
  jImage = loadImage("./Assets/justin1.png");

  x_size = imageWidth(jImage);
  y_size = imageHeight(jImage);
}

PImage frameBuffer;
PImage frameBufferTinted;

void update()
{
  if(frameBuffer)
    freeImage(&frameBuffer);
  if (frameBufferTinted)
    freeImage(&frameBufferTinted);

  // Read in the frame buffer
  frameBuffer = readFrameBufferAdvanced(0, 0, canvasWidth, canvasHeight, true, false);
  
  // Choose a random tint color
  PColor rTint = color(randomRangeInt(0, 255), randomRangeInt(0, 255), randomRangeInt(0, 255), 255);

  // Tint the read in frame buffer
  frameBufferTinted = imageCreateTint(frameBuffer, rTint);

  // Draw to the screen
  // WARNING: Causes flashing colors
  background(color(255, 255, 255, 255));
  image(frameBufferTinted, mouseX, mouseY, (float)canvasWidth / 2.0f, (float)canvasHeight / 2.0f, 255);
  image(jImage, (float)canvasWidth / 2.0f, (float)canvasHeight / 2.0f, (float)x_size, (float)y_size, 255);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>