mirror of
https://github.com/processing/processing4.git
synced 2026-04-22 20:24:45 +02:00
Added Earth2 example, renamed OPENGL2 to OPENGL in all examples
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// available in OPENGL2.
|
||||
// Images by Kevin Bjorke.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
PImage pic1, pic2;
|
||||
int selMode = REPLACE;
|
||||
@@ -11,7 +11,7 @@ String name = "replace";
|
||||
int picAlpha = 255;
|
||||
|
||||
void setup() {
|
||||
size(800, 480, OPENGL2);
|
||||
size(800, 480, OPENGL);
|
||||
|
||||
PFont font = createFont(PFont.list()[0], 20);
|
||||
textFont(font, 20);
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// Simple example showing a lit rotating cube. The projection
|
||||
// is set to orthographic if the mouse is pressed.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
float spin = 0.0;
|
||||
|
||||
void setup() {
|
||||
size(400, 400, OPENGL2);
|
||||
size(400, 400, OPENGL);
|
||||
|
||||
noStroke();
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
// be later organized in a tree structure to apply geometrical
|
||||
// transformations to different levels of the tree.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
PShape3D object;
|
||||
PShape group1, group2, group3;
|
||||
|
||||
void setup() {
|
||||
size(600, 600, OPENGL2);
|
||||
size(600, 600, OPENGL);
|
||||
noStroke();
|
||||
|
||||
// We record all the geometry in object.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// Click on the screen to enable/disable drawing with the recorded
|
||||
// shape.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
PShape globe;
|
||||
PImage texmap;
|
||||
@@ -29,7 +29,7 @@ int SINCOS_LENGTH = (int)(360.0f / SINCOS_PRECISION);
|
||||
boolean usingPShape = false;
|
||||
|
||||
public void setup() {
|
||||
size(600, 600, OPENGL2);
|
||||
size(600, 600, OPENGL);
|
||||
|
||||
PFont font = createFont(PFont.list()[0], 12);
|
||||
textFont(font, 12);
|
||||
|
||||
262
java/libraries/opengl/examples/Earth2/Earth2.pde
Normal file
262
java/libraries/opengl/examples/Earth2/Earth2.pde
Normal file
@@ -0,0 +1,262 @@
|
||||
// Earth
|
||||
// by Mike 'Flux' Chang (cleaned up by Aaron Koblin).
|
||||
// Based on code by Toxi.
|
||||
// OPENGL port by Andres Colubri
|
||||
//
|
||||
// This example shows the shape recording functionality in OPENGL/P3D,
|
||||
// using the object-oriented mode, where the drawing calls are methods
|
||||
// in the PShape3D object.
|
||||
|
||||
import processing.opengl.*;
|
||||
|
||||
PShape3D globe;
|
||||
PImage texmap;
|
||||
|
||||
int sDetail = 200; // Sphere detail setting
|
||||
float rotationY = 0;
|
||||
float globeRadius = 450;
|
||||
float pushBack = 0;
|
||||
|
||||
float[] cx, cz, sphereX, sphereY, sphereZ;
|
||||
float sinLUT[];
|
||||
float cosLUT[];
|
||||
float SINCOS_PRECISION = 0.5f;
|
||||
int SINCOS_LENGTH = (int)(360.0f / SINCOS_PRECISION);
|
||||
|
||||
boolean usingPShape = false;
|
||||
|
||||
public void setup() {
|
||||
size(600, 600, OPENGL);
|
||||
|
||||
PFont font = createFont(PFont.list()[0], 12);
|
||||
textFont(font, 12);
|
||||
|
||||
texmap = loadImage("world32k.jpg");
|
||||
initializeSphere(sDetail);
|
||||
|
||||
autoNormal(false);
|
||||
noStroke();
|
||||
|
||||
// Everything that is drawn between beginRecord/endRecord
|
||||
// is saved into the PShape3D object.
|
||||
// Drawing the PShape3D object is much faster than redrawing
|
||||
// all the geometry again in the draw() function.
|
||||
globe = new PShape3D(this);
|
||||
globe.beginRecord();
|
||||
recTexSphere(globe, globeRadius, texmap);
|
||||
globe.endRecord();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
renderGlobe();
|
||||
|
||||
fill(255);
|
||||
if (usingPShape) {
|
||||
text("With PShape3D. FPS: " + frameRate, 10, height - 30);
|
||||
} else {
|
||||
text("Without PShape3D. FPS: " + frameRate, 10, height - 30);
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
usingPShape = !usingPShape;
|
||||
}
|
||||
|
||||
public void renderGlobe() {
|
||||
pushMatrix();
|
||||
translate(width/2.0f, height/2.0f, pushBack);
|
||||
lights();
|
||||
|
||||
pushMatrix();
|
||||
|
||||
rotateY(rotationY);
|
||||
|
||||
if (usingPShape) {
|
||||
shape(globe);
|
||||
} else {
|
||||
drawTexSphere(globeRadius, texmap);
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
popMatrix();
|
||||
|
||||
rotationY += 0.01;
|
||||
}
|
||||
|
||||
public void initializeSphere(int res) {
|
||||
sinLUT = new float[SINCOS_LENGTH];
|
||||
cosLUT = new float[SINCOS_LENGTH];
|
||||
|
||||
for (int i = 0; i < SINCOS_LENGTH; i++) {
|
||||
sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION);
|
||||
cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION);
|
||||
}
|
||||
|
||||
float delta = (float)SINCOS_LENGTH/res;
|
||||
float[] cx = new float[res];
|
||||
float[] cz = new float[res];
|
||||
|
||||
// Calc unit circle in XZ plane
|
||||
for (int i = 0; i < res; i++) {
|
||||
cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH];
|
||||
cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH];
|
||||
}
|
||||
|
||||
// Computing vertexlist vertexlist starts at south pole
|
||||
int vertCount = res * (res-1) + 2;
|
||||
int currVert = 0;
|
||||
|
||||
// Re-init arrays to store vertices
|
||||
sphereX = new float[vertCount];
|
||||
sphereY = new float[vertCount];
|
||||
sphereZ = new float[vertCount];
|
||||
float angle_step = (SINCOS_LENGTH*0.5f)/res;
|
||||
float angle = angle_step;
|
||||
|
||||
// Step along Y axis
|
||||
for (int i = 1; i < res; i++) {
|
||||
float curradius = sinLUT[(int) angle % SINCOS_LENGTH];
|
||||
float currY = -cosLUT[(int) angle % SINCOS_LENGTH];
|
||||
for (int j = 0; j < res; j++) {
|
||||
sphereX[currVert] = cx[j] * curradius;
|
||||
sphereY[currVert] = currY;
|
||||
sphereZ[currVert++] = cz[j] * curradius;
|
||||
}
|
||||
angle += angle_step;
|
||||
}
|
||||
sDetail = res;
|
||||
}
|
||||
|
||||
// Generic routine to draw textured sphere
|
||||
void drawTexSphere(float r, PImage t) {
|
||||
int v1,v11,v2;
|
||||
r = (r + 240 ) * 0.33;
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
texture(t);
|
||||
float iu=(float)(t.width-1)/(sDetail);
|
||||
float iv=(float)(t.height-1)/(sDetail);
|
||||
float u=0,v=iv;
|
||||
for (int i = 0; i < sDetail; i++) {
|
||||
normal(0, -1, 0);
|
||||
vertex(0, -r, 0,u,0);
|
||||
normal(sphereX[i], sphereY[i], sphereZ[i]);
|
||||
vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v);
|
||||
u+=iu;
|
||||
}
|
||||
vertex(0, -r, 0,u,0);
|
||||
normal(sphereX[0], sphereY[0], sphereZ[0]);
|
||||
vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v);
|
||||
endShape();
|
||||
|
||||
// Middle rings
|
||||
int voff = 0;
|
||||
for(int i = 2; i < sDetail; i++) {
|
||||
v1=v11=voff;
|
||||
voff += sDetail;
|
||||
v2=voff;
|
||||
u=0;
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
texture(t);
|
||||
for (int j = 0; j < sDetail; j++) {
|
||||
normal(sphereX[v1], sphereY[v1], sphereZ[v1]);
|
||||
vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v);
|
||||
normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
|
||||
vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv);
|
||||
u+=iu;
|
||||
}
|
||||
|
||||
// Close each ring
|
||||
v1=v11;
|
||||
v2=voff;
|
||||
normal(sphereX[v1], sphereY[v1], sphereZ[v1]);
|
||||
vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v);
|
||||
normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
|
||||
vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv);
|
||||
endShape();
|
||||
v+=iv;
|
||||
}
|
||||
u=0;
|
||||
|
||||
// Add the northern cap
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
texture(t);
|
||||
for (int i = 0; i < sDetail; i++) {
|
||||
v2 = voff + i;
|
||||
normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
|
||||
vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v);
|
||||
normal(0, 1, 0);
|
||||
vertex(0, r, 0, u, v+iv);
|
||||
u+=iu;
|
||||
}
|
||||
normal(sphereX[voff], sphereY[voff], sphereZ[voff]);
|
||||
vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v);
|
||||
|
||||
endShape();
|
||||
}
|
||||
|
||||
void recTexSphere(PShape3D obj, float r, PImage t) {
|
||||
int v1,v11,v2;
|
||||
r = (r + 240 ) * 0.33;
|
||||
obj.beginShape(TRIANGLE_STRIP);
|
||||
obj.texture(t);
|
||||
float iu=(float)(t.width-1)/(sDetail);
|
||||
float iv=(float)(t.height-1)/(sDetail);
|
||||
float u=0,v=iv;
|
||||
for (int i = 0; i < sDetail; i++) {
|
||||
obj.normal(0, -1, 0);
|
||||
obj.vertex(0, -r, 0,u,0);
|
||||
obj.normal(sphereX[i], sphereY[i], sphereZ[i]);
|
||||
obj.vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v);
|
||||
u+=iu;
|
||||
}
|
||||
obj.vertex(0, -r, 0,u,0);
|
||||
obj.normal(sphereX[0], sphereY[0], sphereZ[0]);
|
||||
obj.vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v);
|
||||
obj.endShape();
|
||||
|
||||
// Middle rings
|
||||
int voff = 0;
|
||||
for(int i = 2; i < sDetail; i++) {
|
||||
v1=v11=voff;
|
||||
voff += sDetail;
|
||||
v2=voff;
|
||||
u=0;
|
||||
obj.beginShape(TRIANGLE_STRIP);
|
||||
obj.texture(t);
|
||||
for (int j = 0; j < sDetail; j++) {
|
||||
normal(sphereX[v1], sphereY[v1], sphereZ[v1]);
|
||||
obj.vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v);
|
||||
obj.normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
|
||||
obj.vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv);
|
||||
u+=iu;
|
||||
}
|
||||
|
||||
// Close each ring
|
||||
v1=v11;
|
||||
v2=voff;
|
||||
obj.normal(sphereX[v1], sphereY[v1], sphereZ[v1]);
|
||||
obj.vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v);
|
||||
obj.normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
|
||||
obj.vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv);
|
||||
obj.endShape();
|
||||
v+=iv;
|
||||
}
|
||||
u=0;
|
||||
|
||||
// Add the northern cap
|
||||
obj.beginShape(TRIANGLE_STRIP);
|
||||
obj.texture(t);
|
||||
for (int i = 0; i < sDetail; i++) {
|
||||
v2 = voff + i;
|
||||
obj.normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
|
||||
obj.vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v);
|
||||
obj.normal(0, 1, 0);
|
||||
obj.vertex(0, r, 0, u, v+iv);
|
||||
u+=iu;
|
||||
}
|
||||
obj.normal(sphereX[voff], sphereY[voff], sphereZ[voff]);
|
||||
obj.vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v);
|
||||
|
||||
obj.endShape();
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Using push() and pop() to define the curves of the lines of type.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
Line ln;
|
||||
Line lns[];
|
||||
@@ -14,7 +14,7 @@ String words[] = {
|
||||
};
|
||||
|
||||
void setup() {
|
||||
size(800, 480, OPENGL2);
|
||||
size(800, 480, OPENGL);
|
||||
|
||||
// Array of line objects
|
||||
lns = new Line[8];
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Ported from NeHe tutorial 8:
|
||||
// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
import javax.media.opengl.*;
|
||||
import java.nio.*;
|
||||
@@ -52,7 +52,7 @@ float ySpeed = 0.2f;
|
||||
GLUgl2 glu;
|
||||
|
||||
void setup() {
|
||||
size(400, 400, OPENGL2);
|
||||
size(400, 400, OPENGL);
|
||||
// orientation(PORTRAIT);
|
||||
|
||||
glu = new GLUgl2();
|
||||
@@ -86,7 +86,7 @@ void setup() {
|
||||
lightDifBfr = FloatBuffer.wrap(lightDif);
|
||||
lightPosBfr = FloatBuffer.wrap(lightPos);
|
||||
|
||||
PGraphicsOpenGL2 pgl = (PGraphicsOpenGL2)g;
|
||||
PGraphicsOpenGL pgl = (PGraphicsOpenGL)g;
|
||||
GL gl = pgl.beginGL();
|
||||
|
||||
Texture teximage = null;
|
||||
@@ -134,7 +134,7 @@ void setup() {
|
||||
public void draw() {
|
||||
background(0);
|
||||
|
||||
PGraphicsOpenGL2 pgl = (PGraphicsOpenGL2)g;
|
||||
PGraphicsOpenGL pgl = (PGraphicsOpenGL)g;
|
||||
GL gl = pgl.beginGL();
|
||||
|
||||
pgl.gl2f.glShadeModel(GL2.GL_SMOOTH);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import com.sun.opengl.util.BufferUtil;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.PixelGrabber;
|
||||
@@ -36,7 +35,8 @@ Texture readPixels(BufferedImage img, boolean storeAlphaChannel) {
|
||||
}
|
||||
|
||||
int bytesPerPixel = storeAlphaChannel ? 4 : 3;
|
||||
ByteBuffer unpackedPixels = BufferUtil.newByteBuffer(packedPixels.length * bytesPerPixel);
|
||||
//ByteBuffer unpackedPixels = BufferUtil.newByteBuffer(packedPixels.length * bytesPerPixel);
|
||||
ByteBuffer unpackedPixels = ByteBuffer.allocate(packedPixels.length * bytesPerPixel);
|
||||
|
||||
for (int row = img.getHeight() - 1; row >= 0; row--) {
|
||||
for (int col = 0; col < img.getWidth(); col++) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Sun and mercury textures from http://planetpixelemporium.com
|
||||
// Star field picture from http://www.galacticimages.com/
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
PImage starfield;
|
||||
|
||||
@@ -21,7 +21,7 @@ PShape planet2;
|
||||
PImage surftex2;
|
||||
|
||||
void setup() {
|
||||
size(800, 480, OPENGL2);
|
||||
size(800, 480, OPENGL);
|
||||
|
||||
starfield = loadImage("starfield.jpg");
|
||||
suntex = loadImage("sun.jpg");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// from a file in PDB format (http://www.pdb.org/) and displays
|
||||
// the structure using a ribbon representation.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
String pdbFile = "4HHB.pdb"; // PDB file to read
|
||||
//String pdbFile = "2POR.pdb";
|
||||
@@ -24,7 +24,7 @@ ArrayList models;
|
||||
Arcball arcball;
|
||||
|
||||
void setup() {
|
||||
size(800, 600, OPENGL2);
|
||||
size(800, 600, OPENGL);
|
||||
|
||||
arcball = new Arcball(width/2, height/2, 600);
|
||||
readPDB(pdbFile);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// the PShape3D class to create a particle system.
|
||||
// Rocket model from http://keleb.free.fr/codecorner/models-en.htm
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
PShape3D rocket;
|
||||
PShape3D particles;
|
||||
@@ -19,7 +19,7 @@ float timeInc = 0.03;
|
||||
PVector axis, pos, vel;
|
||||
|
||||
void setup() {
|
||||
size(800, 600, OPENGL2);
|
||||
size(800, 600, OPENGL);
|
||||
//orientation(PORTRAIT);
|
||||
|
||||
rocket = (PShape3D)loadShape("rocket.obj");
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// the same surface but without the texture, and the
|
||||
// offscreen texture with the particle system.
|
||||
|
||||
import processing.opengl2.*;
|
||||
import processing.opengl.*;
|
||||
|
||||
PGraphics pg;
|
||||
PShape trefoil;
|
||||
@@ -14,7 +14,7 @@ PShape3D particles;
|
||||
int mode = 0;
|
||||
|
||||
void setup() {
|
||||
size(280, 400, OPENGL2);
|
||||
size(280, 400, OPENGL);
|
||||
|
||||
PFont font = createFont(PFont.list()[0], 18);
|
||||
textFont(font, 18);
|
||||
@@ -23,7 +23,7 @@ void setup() {
|
||||
noStroke();
|
||||
|
||||
// Creating offscreen surface for 3D rendering.
|
||||
pg = createGraphics(32, 512, OPENGL2);
|
||||
pg = createGraphics(32, 512, OPENGL);
|
||||
|
||||
// Initializing particle system
|
||||
PShape3D.Parameters params = PShape3D.newParameters(POINT_SPRITES, STREAM);
|
||||
|
||||
Reference in New Issue
Block a user