Ciao 访客, welcome back to old school! :p
public class PGraphicsOpenGL extends PGraphics { // JOGL2 objects: /** * How the P3D renderer handles the different OpenGL profiles? Basically, * P3D has two pipeline modes: fixed or programmable. In the fixed mode, * only the gl and gl2f objects are available. The gl2f object contains the * intersection between OpenGL 2.x desktop and OpenGL 1.1 embedded, and in this * way it ensures the functionality parity between the P3D render (PC/MAC) * and A3D (Android) in the fixed pipeline mode. * In the programmable mode, there further options: GL2, GL3 and GL4. * GL2 corresponds to the basic programmable profile that results from the common * functionality between OpenGL 3.0 desktop and OpenGL 2.0 embedded. As said just * before, since P3D and A3D aim at feature parity as much as possible, this is * the only programmable-pipeline GL object that the P3D renderer uses. * The gl3 and gl4 objects will be available when the pipeline mode is PROG_GL3 or * PROG_GL4, respectively. Although P3D doens't make any use of these objects, * they are part of the API nonetheless for users (or libraries) requiring advanced * functionality introduced with OpenGL 3 or OpenGL 4. * By default, P3D tries to auto-select the pipeline mode by with the following * priority order: PROG_GL4, PROG_GL3, PROG_GL2, FIXED. In all the programmable modes, * the gl2p object is always available. This auto-selection can be optionally * overridden when creating the renderer object, so that a specific mode is set. * Note that the programmable mode uses the non-backward compatible GL objects * (GL3, GL4, and not GL3bc, GL4bc) so no fixed mode calls are possible under this mode. */ /** Pipeline mode: FIXED, PROG_GL2, PROG_GL3 or PROG_GL4 */ public int pipeline; /** Basic GL functionality, common to all profiles */ public GL gl; public GL2 gl2; /** Advanced GL functionality (usually, things available as extensions in JOGL1). * This profile is the intersection between GL 2.0 and GL 3.0 */ public GL2GL3 gl2x; /** Fixed GL pipeline, with the functionality common to the GL2 desktop and GLES 1.1 profiles */ public GL2ES1 gl2f; /** Basic programmable GL pipeline: intersection of desktop GL3, GL2 and embedded ES2 profile */ public GL2ES2 gl2p; /** GL3 programmable pipeline, not backwards compatible with GL2 fixed */ public GL3 gl3p; /** GL4 programmable pipeline, not backwards compatible with GL2 fixed */ public GL4 gl4p;
import javax.media.opengl.GL;//基础GL,对所有类型通用import javax.media.opengl.GL2;//基础GL,对所有类型通用import javax.media.opengl.GL2ES1;//固定管线的GL2,GL2+GLES1.1import javax.media.opengl.GL2ES2;//可编程管线的GL2,GL3+GL2+GLES2import javax.media.opengl.GL2GL3;import javax.media.opengl.GL3;//可编程管线的GL3,与固定管线的GL2不兼容import javax.media.opengl.GL4;//可编程管线的GL4,与固定管线的GL2不兼容
public GL gl; public GL2 gl2; public GL2GL3 gl2x; public GL2ES1 gl2f; public GL2ES2 gl2p; public GL3 gl3p; public GL4 gl4p;
public PShape createShape(int type) { PShape3D shape = null; if (type == PShape.GROUP) { shape = new PShape3D(parent, PShape.GROUP); } else if (type == POINTS) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(POINTS); } else if (type == LINES) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(LINES); } else if (type == TRIANGLES) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(TRIANGLES); } else if (type == TRIANGLE_FAN) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(TRIANGLE_FAN); } else if (type == TRIANGLE_STRIP) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(TRIANGLE_STRIP); } else if (type == QUADS) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(QUADS); } else if (type == QUAD_STRIP) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(QUAD_STRIP); } else if (type == POLYGON) { shape = new PShape3D(parent, PShape.GEOMETRY); shape.setKind(POLYGON); } return shape; }
import processing.opengl.*;size(800, 600, P3D);fill(255,0,0);ellipse(100,100,100,100);
import processing.opengl.*;size(800, 600, P3D);PShape obj = createShape(ELLIPSE, 100, 100, 100, 100); obj.fill(255,0,0);shape(obj);
PShape system;//一个PShape即一组元素 void setup() { size(500, 500, P3D); system = createShape(PShape.GROUP);//注意参数为PShape.GROUP for (int i = 0; i < 10; i++) { PShape pt = createShape(POINT);//创建子元素,为一个点 pt.strokeWeight(20);//一个很粗壮的点 pt.stroke(random(255), random(255), random(255));//随机颜色 pt.vertex(random(width), random(height));//随机位置 system.addShape(pt);//将这个粗壮的点添加进system中 pt.end(); }} public void draw () { background(255); shape(system);//绘制粒子系统 int n_particles = system.getChildCount();//得到子节点的数量 for (int i = 0; i <n_particles; i++) { PShape pt = system.getChild(i);//遍历每个子节点 pt.translate(random(-5, 5), random(-5, 5), random(-5, 5));//进行偏移 }}
无意发现新开的这个版没有Thank You 功能哎。