Class PGraphicsOpenGL

All Implemented Interfaces:
Cloneable, PConstants
Direct Known Subclasses:
PGraphics2D, PGraphics3D

public class PGraphicsOpenGL extends PGraphics
OpenGL renderer.
  • Field Details

    • pgl

      public PGL pgl
      Interface between Processing and OpenGL
    • currentPG

      public PGraphicsOpenGL currentPG
      The renderer currently in use.
    • initialized

      public boolean initialized
      Whether the PGraphics object is ready to render or not.
    • npotTexSupported

      public static boolean npotTexSupported
      Extensions used by Processing
    • autoMipmapGenSupported

      public static boolean autoMipmapGenSupported
    • fboMultisampleSupported

      public static boolean fboMultisampleSupported
    • packedDepthStencilSupported

      public static boolean packedDepthStencilSupported
    • anisoSamplingSupported

      public static boolean anisoSamplingSupported
    • blendEqSupported

      public static boolean blendEqSupported
    • readBufferSupported

      public static boolean readBufferSupported
    • drawBufferSupported

      public static boolean drawBufferSupported
    • maxTextureSize

      public static int maxTextureSize
      Some hardware limits
    • maxSamples

      public static int maxSamples
    • maxAnisoAmount

      public static float maxAnisoAmount
    • depthBits

      public static int depthBits
    • stencilBits

      public static int stencilBits
    • OPENGL_VENDOR

      public static String OPENGL_VENDOR
      OpenGL information strings
    • OPENGL_RENDERER

      public static String OPENGL_RENDERER
    • OPENGL_VERSION

      public static String OPENGL_VERSION
    • OPENGL_EXTENSIONS

      public static String OPENGL_EXTENSIONS
    • GLSL_VERSION

      public static String GLSL_VERSION
    • cameraFOV

      public float cameraFOV
      Camera field of view.
    • cameraX

      public float cameraX
      Default position of the camera.
    • cameraY

      public float cameraY
      Default position of the camera.
    • cameraZ

      public float cameraZ
      Default position of the camera.
    • cameraNear

      public float cameraNear
      Distance of the near and far planes.
    • cameraFar

      public float cameraFar
      Distance of the near and far planes.
    • cameraAspect

      public float cameraAspect
      Aspect ratio of camera's view.
    • defCameraFOV

      public float defCameraFOV
      Default camera properties.
    • defCameraX

      public float defCameraX
    • defCameraY

      public float defCameraY
    • defCameraZ

      public float defCameraZ
    • defCameraNear

      public float defCameraNear
    • defCameraFar

      public float defCameraFar
    • defCameraAspect

      public float defCameraAspect
    • projection

      public PMatrix3D projection
    • camera

      public PMatrix3D camera
    • cameraInv

      public PMatrix3D cameraInv
    • modelview

      public PMatrix3D modelview
    • modelviewInv

      public PMatrix3D modelviewInv
    • projmodelview

      public PMatrix3D projmodelview
    • lights

      public boolean lights
    • lightCount

      public int lightCount
    • lightType

      public int[] lightType
      Light types
    • lightPosition

      public float[] lightPosition
      Light positions
    • lightNormal

      public float[] lightNormal
      Light direction (normalized vector)
    • lightAmbient

      public float[] lightAmbient
      Ambient colors for lights.
    • lightDiffuse

      public float[] lightDiffuse
      Diffuse colors for lights.
    • lightSpecular

      public float[] lightSpecular
      Specular colors for lights. Internally these are stored as numbers between 0 and 1.
    • lightFalloffCoefficients

      public float[] lightFalloffCoefficients
      Light falloff
    • lightSpotParameters

      public float[] lightSpotParameters
      Light spot parameters: Cosine of light spot angle and concentration
    • currentLightSpecular

      public float[] currentLightSpecular
      Current specular color for lighting
    • currentLightFalloffConstant

      public float currentLightFalloffConstant
      Current light falloff
    • currentLightFalloffLinear

      public float currentLightFalloffLinear
    • currentLightFalloffQuadratic

      public float currentLightFalloffQuadratic
  • Constructor Details

    • PGraphicsOpenGL

      public PGraphicsOpenGL()
  • Method Details

    • setParent

      public void setParent(PApplet parent)
      Overrides:
      setParent in class PGraphics
    • setPrimary

      public void setPrimary(boolean primary)
      Description copied from class: PGraphics
      Set (or unset) this as the main drawing surface. Meaning that it can safely be set to opaque (and given a default gray background), or anything else that goes along with that.
      Overrides:
      setPrimary in class PGraphics
    • setSize

      public void setSize(int iwidth, int iheight)
      Description copied from class: PGraphics
      The final step in setting up a renderer, set its size of this renderer. This was formerly handled by the constructor, but instead it's been broken out so that setParent/setPrimary/setPath can be handled differently.

      Important: this is ignored by the Methods task because otherwise it will override setSize() in PApplet/Applet/Component, which will 1) not call super.setSize(), and 2) will cause the renderer to be resized from the event thread (EDT), causing a nasty crash as it collides with the animation thread.

      Overrides:
      setSize in class PGraphics
    • dispose

      public void dispose()
      Description copied from class: PGraphics
      Handle any shutdown for this graphics context.

      This is called when a sketch is shut down and this renderer was specified using the size() command, or inside endRecord() and endRaw(), in order to shut things off.

      Overrides:
      dispose in class PGraphics
    • createSurface

      public PSurface createSurface()
      Overrides:
      createSurface in class PGraphics
    • saveImpl

      public boolean saveImpl(String filename)
    • setCache

      public void setCache(PImage image, Object storage)
      Description copied from class: PGraphics
      Store data of some kind for the renderer that requires extra metadata of some kind. Usually this is a renderer-specific representation of the image data, for instance a BufferedImage with tint() settings applied for PGraphicsJava2D, or resized image data and OpenGL texture indices for PGraphicsOpenGL.
      Overrides:
      setCache in class PGraphics
      Parameters:
      image - The image to be stored
      storage - The metadata required by the renderer
    • getCache

      public Object getCache(PImage image)
      Description copied from class: PGraphics
      Get cache storage data for the specified renderer. Because each renderer will cache data in different formats, it's necessary to store cache data keyed by the renderer object. Otherwise, attempting to draw the same image to both a PGraphicsJava2D and a PGraphicsOpenGL will cause errors.
      Overrides:
      getCache in class PGraphics
      Returns:
      metadata stored for the specified renderer
    • removeCache

      public void removeCache(PImage image)
      Description copied from class: PGraphics
      Remove information associated with this renderer from the cache, if any.
      Overrides:
      removeCache in class PGraphics
      Parameters:
      image - The image whose cache data should be removed
    • beginDraw

      public void beginDraw()
      Description copied from class: PGraphics
      Sets the default properties for a PGraphics object. It should be called before anything is drawn into the object.

      Advanced

      When creating your own PGraphics, you should call this before drawing anything.
      Overrides:
      beginDraw in class PGraphics
    • endDraw

      public void endDraw()
      Description copied from class: PGraphics
      Finalizes the rendering of a PGraphics object so that it can be shown on screen.

      Advanced

      When creating your own PGraphics, you should call this when you're finished drawing.

      Overrides:
      endDraw in class PGraphics
    • beginPGL

      public PGL beginPGL()
      Overrides:
      beginPGL in class PGraphics
    • endPGL

      public void endPGL()
      Overrides:
      endPGL in class PGraphics
    • updateProjmodelview

      public void updateProjmodelview()
    • hint

      public void hint(int which)
      Description copied from class: PGraphics
      Set various hints and hacks for the renderer. This is used to handle obscure rendering features that cannot be implemented in a consistent manner across renderers. Many options will often graduate to standard features instead of hints over time.

      hint(ENABLE_OPENGL_4X_SMOOTH)- Enable 4x anti-aliasing for P3D. This can help force anti-aliasing if it has not been enabled by the user. On some graphics cards, this can also be set by the graphics driver's control panel, however not all cards make this available. This hint must be called immediately after the size() command because it resets the renderer, obliterating any settings and anything drawn (and like size(), re-running the code that came before it again).

      hint(DISABLE_OPENGL_2X_SMOOTH) - In Processing 1.0, Processing always enables 2x smoothing when the P3D renderer is used. This hint disables the default 2x smoothing and returns the smoothing behavior found in earlier releases, where smooth() and noSmooth() could be used to enable and disable smoothing, though the quality was inferior.

      hint(ENABLE_NATIVE_FONTS) - Use the native version fonts when they are installed, rather than the bitmapped version from a .vlw file. This is useful with the default (or JAVA2D) renderer setting, as it will improve font rendering speed. This is not enabled by default, because it can be misleading while testing because the type will look great on your machine (because you have the font installed) but lousy on others' machines if the identical font is unavailable. This option can only be set per-sketch, and must be called before any use of textFont().

      hint(DISABLE_DEPTH_TEST) - Disable the zbuffer, allowing you to draw on top of everything at will. When depth testing is disabled, items will be drawn to the screen sequentially, like a painting. This hint is most often used to draw in 3D, then draw in 2D on top of it (for instance, to draw GUI controls in 2D on top of a 3D interface). Starting in release 0149, this will also clear the depth buffer. Restore the default with hint(ENABLE_DEPTH_TEST), but note that with the depth buffer cleared, any 3D drawing that happens later in draw() will ignore existing shapes on the screen.

      hint(ENABLE_DEPTH_SORT) - Enable primitive z-sorting of triangles and lines in P3D and OPENGL. This can slow performance considerably, and the algorithm is not yet perfect. Restore the default with hint(DISABLE_DEPTH_SORT).

      hint(DISABLE_OPENGL_ERROR_REPORT) - Speeds up the P3D renderer setting by not checking for errors while running. Undo with hint(ENABLE_OPENGL_ERROR_REPORT).

      hint(ENABLE_BUFFER_READING) - Depth and stencil buffers in P2D/P3D will be down-sampled to make PGL#readPixels work with multisampling. Enabling this introduces some overhead, so if you experience bad performance, disable multisampling with noSmooth() instead. This hint is not intended to be enabled and disabled repeatedly, so call this once in setup() or after creating your PGraphics2D/3D. You can restore the default with hint(DISABLE_BUFFER_READING) if you don't plan to read depth from this PGraphics anymore.

      hint(ENABLE_KEY_REPEAT) - Auto-repeating key events are discarded by default (works only in P2D/P3D); use this hint to get all the key events (including auto-repeated). Call hint(DISABLE_KEY_REPEAT) to get events only when the key goes physically up or down.

      hint(DISABLE_ASYNC_SAVEFRAME) - P2D/P3D only - save() and saveFrame() will not use separate threads for saving and will block until the image is written to the drive. This was the default behavior in 3.0b7 and before. To enable, call hint(ENABLE_ASYNC_SAVEFRAME).
      Overrides:
      hint in class PGraphics
      Parameters:
      which - name of the hint to be enabled or disabled
      See Also:
    • beginShape

      public void beginShape(int kind)
      Description copied from class: PGraphics
      Using the beginShape() and endShape() functions allow creating more complex forms. beginShape() begins recording vertices for a shape and endShape() stops recording. The value of the kind parameter tells it which types of shapes to create from the provided vertices. With no mode specified, the shape can be any irregular polygon. The parameters available for beginShape() are POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP. After calling the beginShape() function, a series of vertex() commands must follow. To stop drawing the shape, call endShape(). The vertex() function with two parameters specifies a position in 2D and the vertex() function with three parameters specifies a position in 3D. Each shape will be outlined with the current stroke color and filled with the fill color.

      Transformations such as translate(), rotate(), and scale() do not work within beginShape(). It is also not possible to use other shapes, such as ellipse() or rect() within beginShape().

      The P2D and P3D renderers allow stroke() and fill() to be altered on a per-vertex basis, but the default renderer does not. Settings such as strokeWeight(), strokeCap(), and strokeJoin() cannot be changed while inside a beginShape()/endShape() block with any renderer.
      Overrides:
      beginShape in class PGraphics
      Parameters:
      kind - Either POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP
      See Also:
    • endShape

      public void endShape(int mode)
      Description copied from class: PGraphics
      The endShape() function is the companion to beginShape() and may only be called after beginShape(). When endshape() is called, all the image data defined since the previous call to beginShape() is written into the image buffer. The constant CLOSE as the value for the MODE parameter to close the shape (to connect the beginning and the end).
      Overrides:
      endShape in class PGraphics
      Parameters:
      mode - use CLOSE to close the shape
      See Also:
    • textureWrap

      public void textureWrap(int wrap)
      Description copied from class: PGraphics
      Defines if textures repeat or draw once within a texture map. The two parameters are CLAMP (the default behavior) and REPEAT. This function only works with the P2D and P3D renderers.
      Overrides:
      textureWrap in class PGraphics
      Parameters:
      wrap - Either CLAMP (default) or REPEAT
      See Also:
    • textureSampling

      public void textureSampling(int sampling)
    • beginContour

      public void beginContour()
      Description copied from class: PGraphics
      Use the beginContour() and endContour() function to create negative shapes within shapes such as the center of the letter "O". beginContour() begins recording vertices for the shape and endContour() stops recording. The vertices that define a negative shape must "wind" in the opposite direction from the exterior shape. First draw vertices for the exterior shape in clockwise order, then for internal shapes, draw vertices counterclockwise.

      These functions can only be used within a beginShape()/endShape() pair and transformations such as translate(), rotate(), and scale() do not work within a beginContour()/endContour() pair. It is also not possible to use other shapes, such as ellipse() or rect() within.
      Overrides:
      beginContour in class PGraphics
    • endContour

      public void endContour()
      Description copied from class: PGraphics
      Use the beginContour() and endContour() function to create negative shapes within shapes such as the center of the letter "O". beginContour() begins recording vertices for the shape and endContour() stops recording. The vertices that define a negative shape must "wind" in the opposite direction from the exterior shape. First draw vertices for the exterior shape in clockwise order, then for internal shapes, draw vertices counterclockwise.

      These functions can only be used within a beginShape()/endShape() pair and transformations such as translate(), rotate(), and scale() do not work within a beginContour()/endContour() pair. It is also not possible to use other shapes, such as ellipse() or rect() within.
      Overrides:
      endContour in class PGraphics
    • vertex

      public void vertex(float x, float y)
      Overrides:
      vertex in class PGraphics
    • vertex

      public void vertex(float x, float y, float u, float v)
      Overrides:
      vertex in class PGraphics
    • vertex

      public void vertex(float x, float y, float z)
      Overrides:
      vertex in class PGraphics
    • vertex

      public void vertex(float x, float y, float z, float u, float v)
      Description copied from class: PGraphics
      All shapes are constructed by connecting a series of vertices. vertex() is used to specify the vertex coordinates for points, lines, triangles, quads, and polygons. It is used exclusively within the beginShape() and endShape() functions.

      Drawing a vertex in 3D using the z parameter requires the P3D parameter in combination with size, as shown in the above example.

      This function is also used to map a texture onto geometry. The texture() function declares the texture to apply to the geometry and the u and v coordinates set define the mapping of this texture to the form. By default, the coordinates used for u and v are specified in relation to the image's size in pixels, but this relation can be changed with textureMode().
      Overrides:
      vertex in class PGraphics
      Parameters:
      x - x-coordinate of the vertex
      y - y-coordinate of the vertex
      z - z-coordinate of the vertex
      u - horizontal coordinate for the texture mapping
      v - vertical coordinate for the texture mapping
      See Also:
    • attribPosition

      public void attribPosition(String name, float x, float y, float z)
      Overrides:
      attribPosition in class PGraphics
    • attribNormal

      public void attribNormal(String name, float nx, float ny, float nz)
      Overrides:
      attribNormal in class PGraphics
    • attribColor

      public void attribColor(String name, int color)
      Overrides:
      attribColor in class PGraphics
    • attrib

      public void attrib(String name, float... values)
      Overrides:
      attrib in class PGraphics
    • attrib

      public void attrib(String name, int... values)
      Overrides:
      attrib in class PGraphics
    • attrib

      public void attrib(String name, boolean... values)
      Overrides:
      attrib in class PGraphics
    • noClip

      public void noClip()
      Description copied from class: PGraphics
      Disables the clipping previously started by the clip() function.
      Overrides:
      noClip in class PGraphics
    • flush

      public void flush()
      Overrides:
      flush in class PGraphics
    • bezierVertex

      public void bezierVertex(float x2, float y2, float x3, float y3, float x4, float y4)
      Overrides:
      bezierVertex in class PGraphics
    • bezierVertex

      public void bezierVertex(float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)
      Description copied from class: PGraphics
      Specifies vertex coordinates for Bézier curves. Each call to bezierVertex() defines the position of two control points and one anchor point of a Bézier curve, adding a new segment to a line or shape. The first time bezierVertex() is used within a beginShape() call, it must be prefaced with a call to vertex() to set the first anchor point. This function must be used between beginShape() and endShape() and only when there is no MODE parameter specified to beginShape(). Using the 3D version requires rendering with P3D (see the Environment reference for more information).
      Overrides:
      bezierVertex in class PGraphics
      Parameters:
      x2 - the x-coordinate of the 1st control point
      y2 - the y-coordinate of the 1st control point
      z2 - the z-coordinate of the 1st control point
      x3 - the x-coordinate of the 2nd control point
      y3 - the y-coordinate of the 2nd control point
      z3 - the z-coordinate of the 2nd control point
      x4 - the x-coordinate of the anchor point
      y4 - the y-coordinate of the anchor point
      z4 - the z-coordinate of the anchor point
      See Also:
    • quadraticVertex

      public void quadraticVertex(float cx, float cy, float x3, float y3)
      Description copied from class: PGraphics
      Specifies vertex coordinates for quadratic Bézier curves. Each call to quadraticVertex() defines the position of one control point and one anchor point of a Bézier curve, adding a new segment to a line or shape. The first time quadraticVertex() is used within a beginShape() call, it must be prefaced with a call to vertex() to set the first anchor point. This function must be used between beginShape() and endShape() and only when there is no MODE parameter specified to beginShape(). Using the 3D version requires rendering with P3D (see the Environment reference for more information).
      Overrides:
      quadraticVertex in class PGraphics
      Parameters:
      cx - the x-coordinate of the control point
      cy - the y-coordinate of the control point
      x3 - the x-coordinate of the anchor point
      y3 - the y-coordinate of the anchor point
      See Also:
    • quadraticVertex

      public void quadraticVertex(float cx, float cy, float cz, float x3, float y3, float z3)
      Overrides:
      quadraticVertex in class PGraphics
      cz - the z-coordinate of the control point
      z3 - the z-coordinate of the anchor point
    • curveVertex

      public void curveVertex(float x, float y)
      Description copied from class: PGraphics
      Specifies vertex coordinates for curves. This function may only be used between beginShape() and endShape() and only when there is no MODE parameter specified to beginShape(). The first and last points in a series of curveVertex() lines will be used to guide the beginning and end of the curve. A minimum of four points is required to draw a tiny curve between the second and third points. Adding a fifth point with curveVertex() will draw the curve between the second, third, and fourth points. The curveVertex() function is an implementation of Catmull-Rom splines. Using the 3D version requires rendering with P3D (see the Environment reference for more information).
      Overrides:
      curveVertex in class PGraphics
      Parameters:
      x - the x-coordinate of the vertex
      y - the y-coordinate of the vertex
      See Also:
    • curveVertex

      public void curveVertex(float x, float y, float z)
      Overrides:
      curveVertex in class PGraphics
      z - the z-coordinate of the vertex
    • point

      public void point(float x, float y)
      Description copied from class: PGraphics
      Draws a point, a coordinate in space at the dimension of one pixel. The first parameter is the horizontal value for the point, the second value is the vertical value for the point, and the optional third value is the depth value. Drawing this shape in 3D with the z parameter requires the P3D parameter in combination with size() as shown in the above example.

      Use stroke() to set the color of a point().

      Point appears round with the default strokeCap(ROUND) and square with strokeCap(PROJECT). Points are invisible with strokeCap(SQUARE) (no cap).

      Using point() with strokeWeight(1) or smaller may draw nothing to the screen, depending on the graphics settings of the computer. Workarounds include setting the pixel using set() or drawing the point using either circle() or square().
      Overrides:
      point in class PGraphics
      Parameters:
      x - x-coordinate of the point
      y - y-coordinate of the point
      See Also:
    • point

      public void point(float x, float y, float z)
      Overrides:
      point in class PGraphics
      z - z-coordinate of the point
    • line

      public void line(float x1, float y1, float x2, float y2)
      Description copied from class: PGraphics
      Draws a line (a direct path between two points) to the screen. The version of line() with four parameters draws the line in 2D. To color a line, use the stroke() function. A line cannot be filled, therefore the fill() function will not affect the color of a line. 2D lines are drawn with a width of one pixel by default, but this can be changed with the strokeWeight() function. The version with six parameters allows the line to be placed anywhere within XYZ space. Drawing this shape in 3D with the z parameter requires the P3D parameter in combination with size() as shown in the above example.
      Overrides:
      line in class PGraphics
      Parameters:
      x1 - x-coordinate of the first point
      y1 - y-coordinate of the first point
      x2 - x-coordinate of the second point
      y2 - y-coordinate of the second point
      See Also:
    • line

      public void line(float x1, float y1, float z1, float x2, float y2, float z2)
      Overrides:
      line in class PGraphics
      z1 - z-coordinate of the first point
      z2 - z-coordinate of the second point
    • triangle

      public void triangle(float x1, float y1, float x2, float y2, float x3, float y3)
      Description copied from class: PGraphics
      A triangle is a plane created by connecting three points. The first two arguments specify the first point, the middle two arguments specify the second point, and the last two arguments specify the third point.
      Overrides:
      triangle in class PGraphics
      Parameters:
      x1 - x-coordinate of the first point
      y1 - y-coordinate of the first point
      x2 - x-coordinate of the second point
      y2 - y-coordinate of the second point
      x3 - x-coordinate of the third point
      y3 - y-coordinate of the third point
      See Also:
    • quad

      public void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
      Description copied from class: PGraphics
      A quad is a quadrilateral, a four sided polygon. It is similar to a rectangle, but the angles between its edges are not constrained to ninety degrees. The first pair of parameters (x1,y1) sets the first vertex and the subsequent pairs should proceed clockwise or counter-clockwise around the defined shape.
      Overrides:
      quad in class PGraphics
      Parameters:
      x1 - x-coordinate of the first corner
      y1 - y-coordinate of the first corner
      x2 - x-coordinate of the second corner
      y2 - y-coordinate of the second corner
      x3 - x-coordinate of the third corner
      y3 - y-coordinate of the third corner
      x4 - x-coordinate of the fourth corner
      y4 - y-coordinate of the fourth corner
    • ellipseImpl

      public void ellipseImpl(float a, float b, float c, float d)
    • box

      public void box(float w, float h, float d)
      Overrides:
      box in class PGraphics
      Parameters:
      w - dimension of the box in the x-dimension
      h - dimension of the box in the y-dimension
      d - dimension of the box in the z-dimension
    • sphere

      public void sphere(float r)
      Description copied from class: PGraphics
      A sphere is a hollow ball made from tessellated triangles.

      Advanced

      Implementation notes:

      cache all the points of the sphere in a static array top and bottom are just a bunch of triangles that land in the center point

      sphere is a series of concentric circles who radii vary along the shape, based on, err... cos or something

       [toxi 031031] new sphere code. removed all multiplies with
       radius, as scale() will take care of that anyway
      
       [toxi 031223] updated sphere code (removed modulo)
       and introduced sphereAt(x,y,z,r)
       to avoid additional translate()'s on the user/sketch side
      
       [davbol 080801] now using separate sphereDetailU/V
       
      Overrides:
      sphere in class PGraphics
      Parameters:
      r - the radius of the sphere
      See Also:
    • loadShape

      public PShape loadShape(String filename)
      Description copied from class: PGraphics
      Loads geometry into a variable of type PShape. SVG and OBJ files may be loaded. To load correctly, the file must be located in the data directory of the current sketch. In most cases, loadShape() should be used inside setup() because loading shapes inside draw() will reduce the speed of a sketch.

      Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

      If the file is not available or an error occurs, null will be returned and an error message will be printed to the console. The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned is null.
      Overrides:
      loadShape in class PGraphics
      Parameters:
      filename - name of file to load, can be .svg or .obj
      See Also:
    • pushMatrix

      public void pushMatrix()
      Description copied from class: PGraphics
      Pushes the current transformation matrix onto the matrix stack. Understanding pushMatrix() and popMatrix() requires understanding the concept of a matrix stack. The pushMatrix() function saves the current coordinate system to the stack and popMatrix() restores the prior coordinate system. pushMatrix() and popMatrix() are used in conjunction with the other transformation functions and may be embedded to control the scope of the transformations.
      Overrides:
      pushMatrix in class PGraphics
      See Also:
    • popMatrix

      public void popMatrix()
      Description copied from class: PGraphics
      Pops the current transformation matrix off the matrix stack. Understanding pushing and popping requires understanding the concept of a matrix stack. The pushMatrix() function saves the current coordinate system to the stack and popMatrix() restores the prior coordinate system. pushMatrix() and popMatrix() are used in conjunction with the other transformation functions and may be embedded to control the scope of the transformations.
      Overrides:
      popMatrix in class PGraphics
      See Also:
    • translate

      public void translate(float tx, float ty)
      Description copied from class: PGraphics
      Specifies an amount to displace objects within the display window. The x parameter specifies left/right translation, the y parameter specifies up/down translation, and the z parameter specifies translations toward/away from the screen. Using this function with the z parameter requires using P3D as a parameter in combination with size as shown in the above example.

      Transformations are cumulative and apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling translate(50, 0) and then translate(20, 0) is the same as translate(70, 0). If translate() is called within draw(), the transformation is reset when the loop begins again. This function can be further controlled by using pushMatrix() and popMatrix().

      Overrides:
      translate in class PGraphics
      Parameters:
      tx - left/right translation
      ty - up/down translation
      See Also:
    • translate

      public void translate(float tx, float ty, float tz)
      Overrides:
      translate in class PGraphics
      tz - forward/backward translation
    • rotate

      public void rotate(float angle)
      Two dimensional rotation. Same as rotateZ (this is identical to a 3D rotation along the z-axis) but included for clarity -- it'd be weird for people drawing 2D graphics to be using rotateZ. And they might kick our a-- for the confusion.
      Overrides:
      rotate in class PGraphics
      Parameters:
      angle - angle of rotation specified in radians
      See Also:
    • rotateX

      public void rotateX(float angle)
      Description copied from class: PGraphics
      Rotates a shape around the x-axis the amount specified by the angle parameter. Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the radians() function. Objects are always rotated around their relative position to the origin and positive numbers rotate objects in a counterclockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling rotateX(PI/2) and then rotateX(PI/2) is the same as rotateX(PI). If rotateX() is called within the draw(), the transformation is reset when the loop begins again. This function requires using P3D as a third parameter to size() as shown in the example above.
      Overrides:
      rotateX in class PGraphics
      Parameters:
      angle - angle of rotation specified in radians
      See Also:
    • rotateY

      public void rotateY(float angle)
      Description copied from class: PGraphics
      Rotates a shape around the y-axis the amount specified by the angle parameter. Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the radians() function. Objects are always rotated around their relative position to the origin and positive numbers rotate objects in a counterclockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling rotateY(PI/2) and then rotateY(PI/2) is the same as rotateY(PI). If rotateY() is called within the draw(), the transformation is reset when the loop begins again. This function requires using P3D as a third parameter to size() as shown in the examples above.
      Overrides:
      rotateY in class PGraphics
      Parameters:
      angle - angle of rotation specified in radians
      See Also:
    • rotateZ

      public void rotateZ(float angle)
      Description copied from class: PGraphics
      Rotates a shape around the z-axis the amount specified by the angle parameter. Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the radians() function. Objects are always rotated around their relative position to the origin and positive numbers rotate objects in a counterclockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling rotateZ(PI/2) and then rotateZ(PI/2) is the same as rotateZ(PI). If rotateZ() is called within the draw(), the transformation is reset when the loop begins again. This function requires using P3D as a third parameter to size() as shown in the examples above.
      Overrides:
      rotateZ in class PGraphics
      Parameters:
      angle - angle of rotation specified in radians
      See Also:
    • rotate

      public void rotate(float angle, float v0, float v1, float v2)
      Rotate around an arbitrary vector, similar to glRotate(), except that it takes radians (instead of degrees).
      Overrides:
      rotate in class PGraphics
    • scale

      public void scale(float s)
      Same as scale(s, s, s).
      Overrides:
      scale in class PGraphics
      Parameters:
      s - percentage to scale the object
      See Also:
    • scale

      public void scale(float sx, float sy)
      Same as scale(sx, sy, 1).
      Overrides:
      scale in class PGraphics
      Parameters:
      sx - percentage to scale the object in the x-axis
      sy - percentage to scale the object in the y-axis
    • scale

      public void scale(float sx, float sy, float sz)
      Scale in three dimensions.
      Overrides:
      scale in class PGraphics
      sz - percentage to scale the object in the z-axis
    • shearX

      public void shearX(float angle)
      Description copied from class: PGraphics
      Shears a shape around the x-axis the amount specified by the angle parameter. Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the radians() function. Objects are always sheared around their relative position to the origin and positive numbers shear objects in a clockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling shearX(PI/2) and then shearX(PI/2) is the same as shearX(PI). If shearX() is called within the draw(), the transformation is reset when the loop begins again.

      Technically, shearX() multiplies the current transformation matrix by a rotation matrix. This function can be further controlled by the pushMatrix() and popMatrix() functions.
      Overrides:
      shearX in class PGraphics
      Parameters:
      angle - angle of shear specified in radians
      See Also:
    • shearY

      public void shearY(float angle)
      Description copied from class: PGraphics
      Shears a shape around the y-axis the amount specified by the angle parameter. Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the radians() function. Objects are always sheared around their relative position to the origin and positive numbers shear objects in a clockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling shearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If shearY() is called within the draw(), the transformation is reset when the loop begins again.

      Technically, shearY() multiplies the current transformation matrix by a rotation matrix. This function can be further controlled by the pushMatrix() and popMatrix() functions.
      Overrides:
      shearY in class PGraphics
      Parameters:
      angle - angle of shear specified in radians
      See Also:
    • resetMatrix

      public void resetMatrix()
      Description copied from class: PGraphics
      Replaces the current matrix with the identity matrix. The equivalent function in OpenGL is glLoadIdentity().
      Overrides:
      resetMatrix in class PGraphics
      See Also:
    • applyMatrix

      public void applyMatrix(PMatrix2D source)
      Overrides:
      applyMatrix in class PGraphics
    • applyMatrix

      public void applyMatrix(float n00, float n01, float n02, float n10, float n11, float n12)
      Overrides:
      applyMatrix in class PGraphics
      Parameters:
      n00 - numbers which define the 4x4 matrix to be multiplied
      n01 - numbers which define the 4x4 matrix to be multiplied
      n02 - numbers which define the 4x4 matrix to be multiplied
      n10 - numbers which define the 4x4 matrix to be multiplied
      n11 - numbers which define the 4x4 matrix to be multiplied
      n12 - numbers which define the 4x4 matrix to be multiplied
    • applyMatrix

      public void applyMatrix(PMatrix3D source)
      Overrides:
      applyMatrix in class PGraphics
    • applyMatrix

      public void applyMatrix(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
      Apply a 4x4 transformation matrix to the modelview stack.
      Overrides:
      applyMatrix in class PGraphics
      n03 - numbers which define the 4x4 matrix to be multiplied
      n13 - numbers which define the 4x4 matrix to be multiplied
      n20 - numbers which define the 4x4 matrix to be multiplied
      n21 - numbers which define the 4x4 matrix to be multiplied
      n22 - numbers which define the 4x4 matrix to be multiplied
      n23 - numbers which define the 4x4 matrix to be multiplied
      n30 - numbers which define the 4x4 matrix to be multiplied
      n31 - numbers which define the 4x4 matrix to be multiplied
      n32 - numbers which define the 4x4 matrix to be multiplied
      n33 - numbers which define the 4x4 matrix to be multiplied
    • getMatrix

      public PMatrix getMatrix()
      Overrides:
      getMatrix in class PGraphics
    • getMatrix

      public PMatrix3D getMatrix(PMatrix3D target)
      Description copied from class: PGraphics
      Copy the current transformation matrix into the specified target. Pass in null to create a new matrix.
      Overrides:
      getMatrix in class PGraphics
    • setMatrix

      public void setMatrix(PMatrix2D source)
      Description copied from class: PGraphics
      Set the current transformation to the contents of the specified source.
      Overrides:
      setMatrix in class PGraphics
    • setMatrix

      public void setMatrix(PMatrix3D source)
      Set the current transformation to the contents of the specified source.
      Overrides:
      setMatrix in class PGraphics
    • printMatrix

      public void printMatrix()
      Print the current model (or "transformation") matrix.
      Overrides:
      printMatrix in class PGraphics
      See Also:
    • pushProjection

      public void pushProjection()
    • popProjection

      public void popProjection()
    • resetProjection

      public void resetProjection()
    • applyProjection

      public void applyProjection(PMatrix3D mat)
    • applyProjection

      public void applyProjection(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
    • setProjection

      public void setProjection(PMatrix3D mat)
    • beginCamera

      public void beginCamera()
      Set matrix mode to the camera matrix (instead of the current transformation matrix). This means applyMatrix, resetMatrix, etc. will affect the camera.

      Note that the camera matrix is *not* the perspective matrix, it contains the values of the modelview matrix immediatly after the latter was initialized with ortho() or camera(), or the modelview matrix as result of the operations applied between beginCamera()/endCamera().

      beginCamera() specifies that all coordinate transforms until endCamera() should be pre-applied in inverse to the camera transform matrix. Note that this is only challenging when a user specifies an arbitrary matrix with applyMatrix(). Then that matrix will need to be inverted, which may not be possible. But take heart, if a user is applying a non-invertible matrix to the camera transform, then he is clearly up to no good, and we can wash our hands of those bad intentions.

      begin/endCamera clauses do not automatically reset the camera transform matrix. That's because we set up a nice default camera transform in setup(), and we expect it to hold through draw(). So we don't reset the camera transform matrix at the top of draw(). That means that an innocuous-looking clause like

       beginCamera();
       translate(0, 0, 10);
       endCamera();
       
      at the top of draw(), will result in a runaway camera that shoots infinitely out of the screen over time. In order to prevent this, it is necessary to call some function that does a hard reset of the camera transform matrix inside of begin/endCamera. Two options are
       camera(); // sets up the nice default camera transform
       resetMatrix(); // sets up the identity camera transform
       
      So to rotate a camera a constant amount, you might try
       beginCamera();
       camera();
       rotateY(PI / 8);
       endCamera();
       
      Overrides:
      beginCamera in class PGraphics
      See Also:
    • endCamera

      public void endCamera()
      Record the current settings into the camera matrix, and set the matrix mode back to the current transformation matrix.

      Note that this will destroy any settings to scale(), translate(), or whatever, because the final camera matrix will be copied (not multiplied) into the modelview.

      Overrides:
      endCamera in class PGraphics
      See Also:
    • camera

      public void camera()
      Set camera to the default settings.

      Processing camera behavior:

      Camera behavior can be split into two separate components, camera transformation, and projection. The transformation corresponds to the physical location, orientation, and scale of the camera. In a physical camera metaphor, this is what can manipulated by handling the camera body (with the exception of scale, which doesn't really have a physcial analog). The projection corresponds to what can be changed by manipulating the lens.

      We maintain separate matrices to represent the camera transform and projection. An important distinction between the two is that the camera transform should be invertible, where the projection matrix should not, since it serves to map three dimensions to two. It is possible to bake the two matrices into a single one just by multiplying them together, but it isn't a good idea, since lighting, z-ordering, and z-buffering all demand a true camera z coordinate after modelview and camera transforms have been applied but before projection. If the camera transform and projection are combined there is no way to recover a good camera-space z-coordinate from a model coordinate.

      Fortunately, there are no functions that manipulate both camera transformation and projection.

      camera() sets the camera position, orientation, and center of the scene. It replaces the camera transform with a new one.

      The transformation functions are the same ones used to manipulate the modelview matrix (scale, translate, rotate, etc.). But they are bracketed with beginCamera(), endCamera() to indicate that they should apply (in inverse), to the camera transformation matrix.

      Overrides:
      camera in class PGraphics
      See Also:
    • camera

      public void camera(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
      More flexible method for dealing with camera().

      The actual call is like gluLookat. Here's the real skinny on what does what:

       camera(); or
       camera(ex, ey, ez, cx, cy, cz, ux, uy, uz);
       
      do not need to be called from with beginCamera();/endCamera(); That's because they always apply to the camera transformation, and they always totally replace it. That means that any coordinate transforms done before camera(); in draw() will be wiped out. It also means that camera() always operates in untransformed world coordinates. Therefore it is always redundant to call resetMatrix(); before camera(); This isn't technically true of gluLookat, but it's pretty much how it's used.

      Now, beginCamera(); and endCamera(); are useful if you want to move the camera around using transforms like translate(), etc. They will wipe out any coordinate system transforms that occur before them in draw(), but they will not automatically wipe out the camera transform. This means that they should be at the top of draw(). It also means that the following:

       beginCamera();
       rotateY(PI / 8);
       endCamera();
       
      will result in a camera that spins without stopping. If you want to just rotate a small constant amount, try this:
       beginCamera();
       camera(); // sets up the default view
       rotateY(PI / 8);
       endCamera();
       
      That will rotate a little off of the default view. Note that this is entirely equivalent to
       camera(); // sets up the default view
       beginCamera();
       rotateY(PI / 8);
       endCamera();
       
      because camera() doesn't care whether or not it's inside a begin/end clause. Basically it's safe to use camera() or camera(ex, ey, ez, cx, cy, cz, ux, uy, uz) as naked calls because they do all the matrix resetting automatically.
      Overrides:
      camera in class PGraphics
      Parameters:
      eyeX - x-coordinate for the eye
      eyeY - y-coordinate for the eye
      eyeZ - z-coordinate for the eye
      centerX - x-coordinate for the center of the scene
      centerY - y-coordinate for the center of the scene
      centerZ - z-coordinate for the center of the scene
      upX - usually 0.0, 1.0, or -1.0
      upY - usually 0.0, 1.0, or -1.0
      upZ - usually 0.0, 1.0, or -1.0
    • printCamera

      public void printCamera()
      Print the current camera matrix.
      Overrides:
      printCamera in class PGraphics
      See Also:
    • ortho

      public void ortho()
      Calls ortho() with the proper parameters for Processing's standard orthographic projection.
      Overrides:
      ortho in class PGraphics
    • ortho

      public void ortho(float left, float right, float bottom, float top)
      Calls ortho() with the specified size of the viewing volume along the X and Z directions.
      Overrides:
      ortho in class PGraphics
      Parameters:
      left - left plane of the clipping volume
      right - right plane of the clipping volume
      bottom - bottom plane of the clipping volume
      top - top plane of the clipping volume
    • ortho

      public void ortho(float left, float right, float bottom, float top, float near, float far)
      Sets an orthographic projection.
      Overrides:
      ortho in class PGraphics
      near - maximum distance from the origin to the viewer
      far - maximum distance from the origin away from the viewer
    • perspective

      public void perspective()
      Calls perspective() with Processing's standard coordinate projection.

      Projection functions:

      • frustrum()
      • ortho()
      • perspective()
      Each of these three functions completely replaces the projection matrix with a new one. They can be called inside setup(), and their effects will be felt inside draw(). At the top of draw(), the projection matrix is not reset. Therefore the last projection function to be called always dominates. On resize, the default projection is always established, which has perspective.

      This behavior is pretty much familiar from OpenGL, except where functions replace matrices, rather than multiplying against the previous.

      Overrides:
      perspective in class PGraphics
    • perspective

      public void perspective(float fov, float aspect, float zNear, float zFar)
      Similar to gluPerspective(). Implementation based on Mesa's glu.c
      Overrides:
      perspective in class PGraphics
      Parameters:
      fov - field-of-view angle (in radians) for vertical direction
      aspect - ratio of width to height
      zNear - z-position of nearest clipping plane
      zFar - z-position of the farthest clipping plane
    • frustum

      public void frustum(float left, float right, float bottom, float top, float znear, float zfar)
      Same as glFrustum(), except that it wipes out (rather than multiplies against) the current perspective matrix.

      Implementation based on the explanation in the OpenGL blue book.

      Overrides:
      frustum in class PGraphics
      Parameters:
      left - left coordinate of the clipping plane
      right - right coordinate of the clipping plane
      bottom - bottom coordinate of the clipping plane
      top - top coordinate of the clipping plane
      znear - near component of the clipping plane; must be greater than zero
      zfar - far component of the clipping plane; must be greater than the near value
      See Also:
    • printProjection

      public void printProjection()
      Print the current projection matrix.
      Overrides:
      printProjection in class PGraphics
      See Also:
    • screenX

      public float screenX(float x, float y)
      Description copied from class: PGraphics
      Takes a three-dimensional X, Y, Z position and returns the X value for where it will appear on a (two-dimensional) screen.
      Overrides:
      screenX in class PGraphics
      Parameters:
      x - 3D x-coordinate to be mapped
      y - 3D y-coordinate to be mapped
      See Also:
    • screenY

      public float screenY(float x, float y)
      Description copied from class: PGraphics
      Takes a three-dimensional X, Y, Z position and returns the Y value for where it will appear on a (two-dimensional) screen.
      Overrides:
      screenY in class PGraphics
      Parameters:
      x - 3D x-coordinate to be mapped
      y - 3D y-coordinate to be mapped
      See Also:
    • screenX

      public float screenX(float x, float y, float z)
      Overrides:
      screenX in class PGraphics
      z - 3D z-coordinate to be mapped
    • screenY

      public float screenY(float x, float y, float z)
      Overrides:
      screenY in class PGraphics
      z - 3D z-coordinate to be mapped
    • screenZ

      public float screenZ(float x, float y, float z)
      Description copied from class: PGraphics
      Takes a three-dimensional X, Y, Z position and returns the Z value for where it will appear on a (two-dimensional) screen.
      Overrides:
      screenZ in class PGraphics
      Parameters:
      x - 3D x-coordinate to be mapped
      y - 3D y-coordinate to be mapped
      z - 3D z-coordinate to be mapped
      See Also:
    • modelX

      public float modelX(float x, float y, float z)
      Description copied from class: PGraphics
      Returns the three-dimensional X, Y, Z position in model space. This returns the X value for a given coordinate based on the current set of transformations (scale, rotate, translate, etc.) The X value can be used to place an object in space relative to the location of the original point once the transformations are no longer in use.

      In the example, the modelX(), modelY(), and modelZ() functions record the location of a box in space after being placed using a series of translate and rotate commands. After popMatrix() is called, those transformations no longer apply, but the (x, y, z) coordinate returned by the model functions is used to place another box in the same location.
      Overrides:
      modelX in class PGraphics
      Parameters:
      x - 3D x-coordinate to be mapped
      y - 3D y-coordinate to be mapped
      z - 3D z-coordinate to be mapped
      See Also:
    • modelY

      public float modelY(float x, float y, float z)
      Description copied from class: PGraphics
      Returns the three-dimensional X, Y, Z position in model space. This returns the Y value for a given coordinate based on the current set of transformations (scale, rotate, translate, etc.) The Y value can be used to place an object in space relative to the location of the original point once the transformations are no longer in use.

      In the example, the modelX(), modelY(), and modelZ() functions record the location of a box in space after being placed using a series of translate and rotate commands. After popMatrix() is called, those transformations no longer apply, but the (x, y, z) coordinate returned by the model functions is used to place another box in the same location.
      Overrides:
      modelY in class PGraphics
      Parameters:
      x - 3D x-coordinate to be mapped
      y - 3D y-coordinate to be mapped
      z - 3D z-coordinate to be mapped
      See Also:
    • modelZ

      public float modelZ(float x, float y, float z)
      Description copied from class: PGraphics
      Returns the three-dimensional X, Y, Z position in model space. This returns the Z value for a given coordinate based on the current set of transformations (scale, rotate, translate, etc.) The Z value can be used to place an object in space relative to the location of the original point once the transformations are no longer in use.

      In the example, the modelX(), modelY(), and modelZ() functions record the location of a box in space after being placed using a series of translate and rotate commands. After popMatrix() is called, those transformations no longer apply, but the (x, y, z) coordinate returned by the model functions is used to place another box in the same location.
      Overrides:
      modelZ in class PGraphics
      Parameters:
      x - 3D x-coordinate to be mapped
      y - 3D y-coordinate to be mapped
      z - 3D z-coordinate to be mapped
      See Also:
    • popStyle

      public void popStyle()
      Description copied from class: PGraphics
      The pushStyle() function saves the current style settings and popStyle() restores the prior settings; these functions are always used together. They allow you to change the style settings and later return to what you had. When a new style is started with pushStyle(), it builds on the current style information. The pushStyle() and popStyle() functions can be embedded to provide more control (see the second example above for a demonstration.)
      Overrides:
      popStyle in class PGraphics
      See Also:
    • strokeWeight

      public void strokeWeight(float weight)
      Description copied from class: PGraphics
      Sets the width of the stroke used for lines, points, and the border around shapes. All widths are set in units of pixels.

      Using point() with strokeWeight(1) or smaller may draw nothing to the screen, depending on the graphics settings of the computer. Workarounds include setting the pixel using set() or drawing the point using either circle() or square().
      Overrides:
      strokeWeight in class PGraphics
      Parameters:
      weight - the weight (in pixels) of the stroke
      See Also:
    • strokeJoin

      public void strokeJoin(int join)
      Description copied from class: PGraphics
      Sets the style of the joints which connect line segments. These joints are either mitered, beveled, or rounded and specified with the corresponding parameters MITER, BEVEL, and ROUND. The default joint is MITER.
      Overrides:
      strokeJoin in class PGraphics
      Parameters:
      join - either MITER, BEVEL, ROUND
      See Also:
    • strokeCap

      public void strokeCap(int cap)
      Description copied from class: PGraphics
      Sets the style for rendering line endings. These ends are either squared, extended, or rounded, each of which specified with the corresponding parameters: SQUARE, PROJECT, and ROUND. The default cap is ROUND.

      To make point() appear square, use strokeCap(PROJECT). Using strokeCap(SQUARE) (no cap) causes points to become invisible.
      Overrides:
      strokeCap in class PGraphics
      Parameters:
      cap - either SQUARE, PROJECT, or ROUND
      See Also:
    • lights

      public void lights()
      Sets up an ambient and directional light using OpenGL. API taken from PGraphics3D.
       The Lighting Skinny:
       The way lighting works is complicated enough that it's worth
       producing a document to describe it. Lighting calculations proceed
       pretty much exactly as described in the OpenGL red book.
       Light-affecting material properties:
         AMBIENT COLOR
         - multiplies by light's ambient component
         - for believability this should match diffuse color
         DIFFUSE COLOR
         - multiplies by light's diffuse component
         SPECULAR COLOR
         - multiplies by light's specular component
         - usually less colored than diffuse/ambient
         SHININESS
         - the concentration of specular effect
         - this should be set pretty high (20-50) to see really
           noticeable specularity
         EMISSIVE COLOR
         - constant additive color effect
       Light types:
         AMBIENT
         - one color
         - no specular color
         - no direction
         - may have falloff (constant, linear, and quadratic)
         - may have position (which matters in non-constant falloff case)
         - multiplies by a material's ambient reflection
         DIRECTIONAL
         - has diffuse color
         - has specular color
         - has direction
         - no position
         - no falloff
         - multiplies by a material's diffuse and specular reflections
         POINT
         - has diffuse color
         - has specular color
         - has position
         - no direction
         - may have falloff (constant, linear, and quadratic)
         - multiplies by a material's diffuse and specular reflections
         SPOT
         - has diffuse color
         - has specular color
         - has position
         - has direction
         - has cone angle (set to half the total cone angle)
         - has concentration value
         - may have falloff (constant, linear, and quadratic)
         - multiplies by a material's diffuse and specular reflections
       Normal modes:
       All of the primitives (rect, box, sphere, etc.) have their normals
       set nicely. During beginShape/endShape normals can be set by the user.
         AUTO-NORMAL
         - if no normal is set during the shape, we are in auto-normal mode
         - auto-normal calculates one normal per triangle (face-normal mode)
         SHAPE-NORMAL
         - if one normal is set during the shape, it will be used for
           all vertices
         VERTEX-NORMAL
         - if multiple normals are set, each normal applies to
           subsequent vertices
         - (except for the first one, which applies to previous
           and subsequent vertices)
       Efficiency consequences:
         There is a major efficiency consequence of position-dependent
         lighting calculations per vertex. (See below for determining
         whether lighting is vertex position-dependent.) If there is no
         position dependency then the only factors that affect the lighting
         contribution per vertex are its colors and its normal.
         There is a major efficiency win if
         1) lighting is not position dependent
         2) we are in AUTO-NORMAL or SHAPE-NORMAL mode
         because then we can calculate one lighting contribution per shape
         (SHAPE-NORMAL) or per triangle (AUTO-NORMAL) and simply multiply it
         into the vertex colors. The converse is our worst-case performance when
         1) lighting is position dependent
         2) we are in AUTO-NORMAL mode
         because then we must calculate lighting per-face * per-vertex.
         Each vertex has a different lighting contribution per face in
         which it appears. Yuck.
       Determining vertex position dependency:
         If any of the following factors are TRUE then lighting is
         vertex position dependent:
         1) Any lights uses non-constant falloff
         2) There are any point or spot lights
         3) There is a light with specular color AND there is a
            material with specular color
       So worth noting is that default lighting (a no-falloff ambient
       and a directional without specularity) is not position-dependent.
       We should capitalize.
       Simon Greenwold, April 2005
       
      Overrides:
      lights in class PGraphics
      See Also:
    • noLights

      public void noLights()
      Disables lighting.
      Overrides:
      noLights in class PGraphics
      See Also:
    • ambientLight

      public void ambientLight(float r, float g, float b)
      Add an ambient light based on the current color mode.
      Overrides:
      ambientLight in class PGraphics
      Parameters:
      r - red or hue value (depending on current color mode)
      g - green or saturation value (depending on current color mode)
      b - blue or brightness value (depending on current color mode)
      See Also:
    • ambientLight

      public void ambientLight(float r, float g, float b, float x, float y, float z)
      Add an ambient light based on the current color mode. This version includes an (x, y, z) position for situations where the falloff distance is used.
      Overrides:
      ambientLight in class PGraphics
      x - x-coordinate of the light
      y - y-coordinate of the light
      z - z-coordinate of the light
    • directionalLight

      public void directionalLight(float r, float g, float b, float dx, float dy, float dz)
      Description copied from class: PGraphics
      Adds a directional light. Directional light comes from one direction and is stronger when hitting a surface squarely and weaker if it hits at a gentle angle. After hitting a surface, a directional lights scatters in all directions. Lights need to be included in the draw() to remain persistent in a looping program. Placing them in the setup() of a looping program will cause them to only have an effect the first time through the loop. The affect of the v1, v2, and v3 parameters is determined by the current color mode. The nx, ny, and nz parameters specify the direction the light is facing. For example, setting ny to -1 will cause the geometry to be lit from below (the light is facing directly upward).
      Overrides:
      directionalLight in class PGraphics
      Parameters:
      r - red or hue value (depending on current color mode)
      g - green or saturation value (depending on current color mode)
      b - blue or brightness value (depending on current color mode)
      dx - direction along the x-axis
      dy - direction along the y-axis
      dz - direction along the z-axis
      See Also:
    • pointLight

      public void pointLight(float r, float g, float b, float x, float y, float z)
      Description copied from class: PGraphics
      Adds a point light. Lights need to be included in the draw() to remain persistent in a looping program. Placing them in the setup() of a looping program will cause them to only have an effect the first time through the loop. The v1, v2, and v3 parameters are interpreted as either RGB or HSB values, depending on the current color mode. The x, y, and z parameters set the position of the light.
      Overrides:
      pointLight in class PGraphics
      Parameters:
      r - red or hue value (depending on current color mode)
      g - green or saturation value (depending on current color mode)
      b - blue or brightness value (depending on current color mode)
      x - x-coordinate of the light
      y - y-coordinate of the light
      z - z-coordinate of the light
      See Also:
    • spotLight

      public void spotLight(float r, float g, float b, float x, float y, float z, float dx, float dy, float dz, float angle, float concentration)
      Description copied from class: PGraphics
      Adds a spotlight. Lights need to be included in the draw() to remain persistent in a looping program. Placing them in the setup() of a looping program will cause them to only have an effect the first time through the loop. The v1, v2, and v3 parameters are interpreted as either RGB or HSB values, depending on the current color mode. The x, y, and z parameters specify the position of the light and nx, ny, nz specify the direction of light. The angle parameter affects angle of the spotlight cone, while concentration sets the bias of light focusing toward the center of that cone.
      Overrides:
      spotLight in class PGraphics
      Parameters:
      r - red or hue value (depending on current color mode)
      g - green or saturation value (depending on current color mode)
      b - blue or brightness value (depending on current color mode)
      x - x-coordinate of the light
      y - y-coordinate of the light
      z - z-coordinate of the light
      dx - direction along the x-axis
      dy - direction along the y-axis
      dz - direction along the z-axis
      angle - angle of the spotlight cone
      concentration - exponent determining the center bias of the cone
      See Also:
    • lightFalloff

      public void lightFalloff(float constant, float linear, float quadratic)
      Set the light falloff rates for the last light that was created. Default is lightFalloff(1, 0, 0).
      Overrides:
      lightFalloff in class PGraphics
      Parameters:
      constant - constant value or determining falloff
      linear - linear value for determining falloff
      quadratic - quadratic value for determining falloff
      See Also:
    • lightSpecular

      public void lightSpecular(float x, float y, float z)
      Set the specular color of the last light created.
      Overrides:
      lightSpecular in class PGraphics
      Parameters:
      x - red or hue value (depending on current color mode)
      y - green or saturation value (depending on current color mode)
      z - blue or brightness value (depending on current color mode)
      See Also:
    • isGL

      public boolean isGL()
      Description copied from class: PGraphics
      Return true if this renderer uses OpenGL. Defaults to false.
      Overrides:
      isGL in class PGraphics
    • loadPixels

      public void loadPixels()
      Description copied from class: PImage
      Loads the pixel data of the current display window into the pixels[] array. This function must always be called before reading from or writing to pixels[]. Subsequent changes to the display window will not be reflected in pixels until loadPixels() is called again.

      Advanced

      Call this when you want to mess with the pixels[] array.

      For subclasses where the pixels[] buffer isn't set by default, this should copy all data into the pixels[] array

      Overrides:
      loadPixels in class PImage
    • get

      public int get(int x, int y)
      Description copied from class: PImage
      Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Use the x and y parameters to get the value of one pixel. Get a section of the display window by specifying an additional width and height parameter. When getting an image, the x and y parameters define the coordinates for the upper-left corner of the image, regardless of the current imageMode().

      If the pixel requested is outside the image window, black is returned. The numbers returned are scaled according to the current color ranges, but only RGB values are returned by this function. For example, even though you may have drawn a shape with colorMode(HSB), the numbers returned will be in RGB format.

      Getting the color of a single pixel with get(x, y) is easy, but not as fast as grabbing the data directly from pixels[]. The equivalent statement to get(x, y) using pixels[] is pixels[y*width+x]. See the reference for pixels[] for more information.

      Advanced

      Returns an ARGB "color" type (a packed 32-bit int) with the color. If the coordinate is outside the image, zero is returned (black, but completely transparent).

      If the image is in RGB format (i.e. on a PVideo object), the value will get its high bits set, just to avoid cases where they haven't been set already.

      If the image is in ALPHA format, this returns a white with its alpha value set.

      This function is included primarily for beginners. It is quite slow because it has to check to see if the x, y that was provided is inside the bounds, and then has to check to see what image type it is. If you want things to be more efficient, access the pixels[] array directly.

      Overrides:
      get in class PImage
      Parameters:
      x - x-coordinate of the pixel
      y - y-coordinate of the pixel
      See Also:
    • set

      public void set(int x, int y, int argb)
      Description copied from class: PImage
      Changes the color of any pixel or writes an image directly into the display window.

      The x and y parameters specify the pixel to change and the color parameter specifies the color value. The color parameter is affected by the current color mode (the default is RGB values from 0 to 255). When setting an image, the x and y parameters define the coordinates for the upper-left corner of the image, regardless of the current imageMode().

      Setting the color of a single pixel with set(x, y) is easy, but not as fast as putting the data directly into pixels[]. The equivalent statement to set(x, y, #000000) using pixels[] is pixels[y*width+x] = #000000. See the reference for pixels[] for more information.
      Overrides:
      set in class PImage
      Parameters:
      x - x-coordinate of the pixel
      y - y-coordinate of the pixel
      argb - any value of the color datatype
      See Also:
    • loadTexture

      public void loadTexture()
    • updateTexture

      public void updateTexture()
    • updateTexture

      public void updateTexture(int x, int y, int w, int h)
    • updateDisplay

      public void updateDisplay()
    • mask

      public void mask(PImage alpha)
      Description copied from class: PImage
      Masks part of an image from displaying by loading another image and using it as an alpha channel. This mask image should only contain grayscale data, but only the blue color channel is used. The mask image needs to be the same size as the image to which it is applied.

      In addition to using a mask image, an integer array containing the alpha channel data can be specified directly. This method is useful for creating dynamically generated alpha masks. This array must be of the same length as the target image's pixels array and should contain only grayscale data of values between 0-255.

      Advanced

      Set alpha channel for an image. Black colors in the source image will make the destination image completely transparent, and white will make things fully opaque. Gray values will be in-between steps.

      Strictly speaking the "blue" value from the source image is used as the alpha color. For a fully grayscale image, this is correct, but for a color image it's not 100% accurate. For a more accurate conversion, first use filter(GRAY) which will make the image into a "correct" grayscale by performing a proper luminance-based conversion.

      Overrides:
      mask in class PImage
      Parameters:
      alpha - image to use as the mask
    • filter

      public void filter(int kind)
      This is really inefficient and not a good idea in OpenGL. Use get() and set() with a smaller image area, or call the filter on an image instead, and then draw that.
      Overrides:
      filter in class PImage
    • filter

      public void filter(int kind, float param)
      This is really inefficient and not a good idea in OpenGL. Use get() and set() with a smaller image area, or call the filter on an image instead, and then draw that.
      Overrides:
      filter in class PImage
      Parameters:
      kind - Either THRESHOLD, GRAY, OPAQUE, INVERT, POSTERIZE, BLUR, ERODE, or DILATE
      param - unique for each, see above
    • filter

      public void filter(PShader shader)
      Overrides:
      filter in class PGraphics
      Parameters:
      shader - the fragment shader to apply
    • copy

      public void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
      Description copied from class: PImage
      Copies a region of pixels from one image into another. If the source and destination regions aren't the same size, it will automatically resize source pixels to fit the specified target region. No alpha information is used in the process, however if the source image has an alpha channel set, it will be copied as well.

      As of release 0149, this function ignores imageMode().
      Overrides:
      copy in class PImage
      Parameters:
      sx - X coordinate of the source's upper left corner
      sy - Y coordinate of the source's upper left corner
      sw - source image width
      sh - source image height
      dx - X coordinate of the destination's upper left corner
      dy - Y coordinate of the destination's upper left corner
      dw - destination image width
      dh - destination image height
      See Also:
    • copy

      public void copy(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
      Overrides:
      copy in class PImage
      Parameters:
      src - an image variable referring to the source image.
    • getTexture

      public Texture getTexture()
      Not an approved function, this will change or be removed in the future. This utility method returns the texture associated to the renderer's. drawing surface, making sure is updated to reflect the current contents off the screen (or offscreen drawing surface).
    • getTexture

      public Texture getTexture(boolean load)
      Not an approved function either, don't use it.
    • getTexture

      public Texture getTexture(PImage img)
      Not an approved function, this will change or be removed in the future. This utility method returns the texture associated to the image. creating and/or updating it if needed.
      Parameters:
      img - the image to have a texture metadata associated to it
    • getFrameBuffer

      public FrameBuffer getFrameBuffer()
      Not an approved function, test its use in libraries to grab the FB objects for offscreen PGraphics.
    • getFrameBuffer

      public FrameBuffer getFrameBuffer(boolean multi)
    • resize

      public void resize(int wide, int high)
      Description copied from class: PImage
      Resize the image to a new width and height. To make the image scale proportionally, use 0 as the value for the wide or high parameter. For instance, to make the width of an image 150 pixels, and change the height using the same proportion, use resize(150, 0).

      Even though a PGraphics is technically a PImage, it is not possible to rescale the image data found in a PGraphics. (It's simply not possible to do this consistently across renderers: technically infeasible with P3D, or what would it even do with PDF?) If you want to resize PGraphics content, first get a copy of its image data using the get() method, and call resize() on the PImage that is returned.
      Overrides:
      resize in class PImage
      Parameters:
      wide - the resized image width
      high - the resized image height
      See Also:
    • loadShader

      public PShader loadShader(String fragFilename)
      Description copied from class: PGraphics
      Loads a shader into the PShader object. The shader file must be loaded in the sketch's "data" folder/directory to load correctly. Shaders are compatible with the P2D and P3D renderers, but not with the default renderer.

      Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

      If the file is not available or an error occurs, null will be returned and an error message will be printed to the console. The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned is null.
      Overrides:
      loadShader in class PGraphics
      Parameters:
      fragFilename - name of fragment shader file
    • loadShader

      public PShader loadShader(String fragFilename, String vertFilename)
      Overrides:
      loadShader in class PGraphics
      vertFilename - name of vertex shader file
    • shader

      public void shader(PShader shader)
      Description copied from class: PGraphics
      Applies the shader specified by the parameters. It's compatible with the P2D and P3D renderers, but not with the default renderer.
      Overrides:
      shader in class PGraphics
      Parameters:
      shader - name of shader file
    • shader

      public void shader(PShader shader, int kind)
      Overrides:
      shader in class PGraphics
      kind - type of shader, either POINTS, LINES, or TRIANGLES
    • resetShader

      public void resetShader()
      Description copied from class: PGraphics
      Restores the default shaders. Code that runs after resetShader() will not be affected by previously defined shaders.
      Overrides:
      resetShader in class PGraphics
    • resetShader

      public void resetShader(int kind)
      Overrides:
      resetShader in class PGraphics
      Parameters:
      kind - type of shader, either POINTS, LINES, or TRIANGLES