new light code from simon, and other prep for 82

This commit is contained in:
benfry
2005-04-06 04:47:22 +00:00
parent b26bb61505
commit 3131e83206
17 changed files with 2298 additions and 974 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ public class PdeBase {
// make sure that this is running on java 1.4
if (PApplet.javaVersion < 1.4) {
if (PApplet.javaVersion < 1.4f) {
//System.err.println("no way man");
PdeBase.showError("Need to install Java 1.4",
"This version of Processing requires \n" +
+4 -3
View File
@@ -172,6 +172,7 @@ public class PdeEditor extends JFrame
upper.add(buttons);
header = new PdeEditorHeader(this);
//header.setBorder(null);
upper.add(header);
textarea = new JEditTextArea(new PdeTextAreaDefaults());
@@ -187,6 +188,8 @@ public class PdeEditor extends JFrame
consolePanel.add(status, BorderLayout.NORTH);
console = new PdeEditorConsole(this);
// windows puts an ugly border on this guy
console.setBorder(null);
consolePanel.add(console, BorderLayout.CENTER);
lineStatus = new PdeEditorLineStatus(textarea);
@@ -206,9 +209,7 @@ public class PdeEditor extends JFrame
// to fix ugliness.. normally macosx java 1.3 puts an
// ugly white border around this object, so turn it off.
if (PdeBase.isMacOS()) {
splitPane.setBorder(null);
}
splitPane.setBorder(null);
// the default size on windows is too small and kinda ugly
int dividerSize = PdePreferences.getInteger("editor.divider.size");
+5 -5
View File
@@ -14,12 +14,12 @@ rm -rf processing-*
cp -r ../shared processing
# add the libraries folder with source
cp -r ../../lib processing/libraries
cp -r ../../net ../../lib processing/libraries/
cp -r ../../opengl ../../lib processing/libraries/
cp -r ../../serial ../../lib processing/libraries/
cp -r ../../lib work/libraries
cp -r ../../net work/libraries/
cp -r ../../opengl work/libraries/
cp -r ../../serial work/libraries/
#cp -r ../../video work/libraries/
# doesn't work on linux, don't include it and confuse people
#cp -r ../../video ../../lib processing/libraries/
# new style examples thing ala reas
cd processing
+5
View File
@@ -10,7 +10,12 @@ else
echo Setting up directories to build for linux...
BUILD_PREPROC=true
cp -r ../shared work
cp -r ../../lib work/libraries
cp -r ../../net work/libraries/
cp -r ../../opengl work/libraries/
cp -r ../../serial work/libraries/
cp -r ../../video work/libraries/
cd work
unzip -q examples.zip
+4 -4
View File
@@ -38,10 +38,10 @@ cp -r ../shared processing
# add the libraries folder with source
cp -r ../../lib processing/libraries
cp -r ../../net ../../lib processing/libraries/
cp -r ../../opengl ../../lib processing/libraries/
cp -r ../../serial ../../lib processing/libraries/
cp -r ../../video ../../lib processing/libraries/
cp -r ../../net processing/libraries/
cp -r ../../opengl processing/libraries/
cp -r ../../serial processing/libraries/
cp -r ../../video processing/libraries/
# new style examples thing ala reas
cd processing
+4
View File
@@ -21,6 +21,10 @@ else
cp -r ../shared work
cp -r ../../lib work/libraries
cp -r ../../net work/libraries/
cp -r ../../opengl work/libraries/
cp -r ../../serial work/libraries/
cp -r ../../video work/libraries/
echo Extracting examples...
cd work
+4 -4
View File
@@ -25,10 +25,10 @@ cp -r ../shared processing
# add the libraries folder with source
cp -r ../../lib processing/libraries
cp -r ../../net ../../lib processing/libraries/
cp -r ../../opengl ../../lib processing/libraries/
cp -r ../../serial ../../lib processing/libraries/
cp -r ../../video ../../lib processing/libraries/
cp -r ../../net processing/libraries/
cp -r ../../opengl processing/libraries/
cp -r ../../serial processing/libraries/
cp -r ../../video processing/libraries/
# new style examples thing ala reas
cd processing
+4
View File
@@ -15,6 +15,10 @@ else
# in case one of those little mac poopers show up
cp -r ../../lib work/libraries
cp -r ../../net work/libraries/
cp -r ../../opengl work/libraries/
cp -r ../../serial work/libraries/
cp -r ../../video work/libraries/
echo Extracting examples...
cd work
+193 -14
View File
@@ -49,10 +49,15 @@ public class PApplet extends Applet
/**
* Version of Java that's in use, whether 1.1 or 1.3 or whatever,
* stored as a double.
* stored as a float.
* <P>
* Note that because this is stored as a float, the values may
* not be <EM>exactly</EM> 1.3 or 1.4. Instead, make sure you're
* comparing against 1.3f or 1.4f, which will have the same amount
* of error (i.e. 1.40000001). This could just be a double, but
* since Processing only uses floats, it's safer to do this,
* because there's no good way to specify a double with the preproc.
*/
//public static final double javaVersion =
//new Double(jdkVersionName).doubleValue();
public static final float javaVersion =
new Float(javaVersionName).floatValue();
@@ -129,9 +134,6 @@ public class PApplet extends Applet
public Dimension screen =
Toolkit.getDefaultToolkit().getScreenSize();
//DisplayMode dm = device.getDisplayMode();
//if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) {
/**
* A leech graphics object that is echoing all events.
*/
@@ -368,7 +370,7 @@ public class PApplet extends Applet
public void init() {
// send tab keys through to the PApplet
try {
if (javaVersion >= 1.4) {
if (javaVersion >= 1.4f) {
//setFocusTraversalKeysEnabled(false); // 1.4-only function
Method defocus =
Component.class.getMethod("setFocusTraversalKeysEnabled",
@@ -641,7 +643,7 @@ public class PApplet extends Applet
size(iwidth, iheight, g.getClass().getName());
} else {
if (PApplet.javaVersion >= 1.3) {
if (PApplet.javaVersion >= 1.3f) {
try {
Class c = Class.forName(JAVA2D);
size(iwidth, iheight, JAVA2D);
@@ -680,6 +682,10 @@ public class PApplet extends Applet
}
}
String openglError =
"Before using OpenGL, you must first select " +
"Import Library > opengl from the Sketch menu.";
try {
//if (renderer.equals(OPENGL)) {
//g = new processing.opengl.PGraphicsGL(iwidth, iheight, this);
@@ -720,14 +726,20 @@ public class PApplet extends Applet
} catch (InvocationTargetException ite) {
String msg = ite.getTargetException().getMessage();
if (msg.indexOf("no jogl in java.library.path") != -1) {
throw new RuntimeException("Before using OpenGL, you must " +
"first select Import Library > " +
"opengl from the Sketch menu.");
//System.out.println("ite found: " + ite.getTargetException().getMessage());
throw new RuntimeException(openglError);
} else {
ite.getTargetException().printStackTrace();
}
} catch (ClassNotFoundException cnfe) {
if (cnfe.getMessage().indexOf("processing.opengl.PGraphicsGL") != -1) {
throw new RuntimeException(openglError);
} else {
throw new RuntimeException("You need to use \"Import Library\" " +
"to add " + renderer +
" to your sketch.");
}
} catch (Exception e) {
e.printStackTrace();
die("Could not start because of a problem with size()", e);
@@ -954,6 +966,7 @@ public class PApplet extends Applet
setup();
//System.out.println("done attempting setup");
//System.out.println("out of try");
g.postSetup(); // FIXME
} catch (RuntimeException e) {
//System.out.println("catching a cold " + e.getMessage());
@@ -1702,7 +1715,7 @@ public class PApplet extends Applet
*/
public void cursor(PImage image, int hotspotX, int hotspotY) {
//if (!isOneTwoOrBetter()) {
if (javaVersion < 1.2) {
if (javaVersion < 1.2f) {
System.err.println("Java 1.2 or higher is required to use cursor()");
System.err.println("(You're using version " + javaVersionName + ")");
return;
@@ -2290,7 +2303,7 @@ public class PApplet extends Applet
public PSound loadSound(String filename) {
if (PApplet.javaVersion >= 1.3) {
if (PApplet.javaVersion >= 1.3f) {
return new PSound2(this, openStream(filename));
}
return new PSound(this, openStream(filename));
@@ -4650,6 +4663,9 @@ v PApplet.this.stop();
} else if (param.equals(ARGS_DISPLAY)) {
int deviceIndex = Integer.parseInt(value) - 1;
//DisplayMode dm = device.getDisplayMode();
//if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) {
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice devices[] = environment.getScreenDevices();
@@ -5028,6 +5044,12 @@ v PApplet.this.stop();
}
public void postSetup() {
if (recorder != null) recorder.postSetup();
g.postSetup();
}
public void hint(int which) {
if (recorder != null) recorder.hint(which);
g.hint(which);
@@ -5688,6 +5710,31 @@ v PApplet.this.stop();
}
public void lightDirection(int num, float x, float y, float z) {
if (recorder != null) recorder.lightDirection(num, x, y, z);
g.lightDirection(num, x, y, z);
}
public void lightFalloff(int num, float constant,
float linear, float quadratic) {
if (recorder != null) recorder.lightFalloff(num, constant, linear, quadratic);
g.lightFalloff(num, constant, linear, quadratic);
}
public void lightSpotAngle(int num, float spotAngle) {
if (recorder != null) recorder.lightSpotAngle(num, spotAngle);
g.lightSpotAngle(num, spotAngle);
}
public void lightSpotConcentration(int num, float concentration) {
if (recorder != null) recorder.lightSpotConcentration(num, concentration);
g.lightSpotConcentration(num, concentration);
}
public void colorMode(int mode) {
if (recorder != null) recorder.colorMode(mode);
g.colorMode(mode);
@@ -5786,6 +5833,138 @@ v PApplet.this.stop();
}
public void ambient(int rgb) {
if (recorder != null) recorder.ambient(rgb);
g.ambient(rgb);
}
public void ambient(float gray) {
if (recorder != null) recorder.ambient(gray);
g.ambient(gray);
}
public void ambient(float x, float y, float z) {
if (recorder != null) recorder.ambient(x, y, z);
g.ambient(x, y, z);
}
public void specular(int rgb) {
if (recorder != null) recorder.specular(rgb);
g.specular(rgb);
}
public void specular(float gray) {
if (recorder != null) recorder.specular(gray);
g.specular(gray);
}
public void specular(float gray, float alpha) {
if (recorder != null) recorder.specular(gray, alpha);
g.specular(gray, alpha);
}
public void specular(float x, float y, float z) {
if (recorder != null) recorder.specular(x, y, z);
g.specular(x, y, z);
}
public void specular(float x, float y, float z, float a) {
if (recorder != null) recorder.specular(x, y, z, a);
g.specular(x, y, z, a);
}
public void shininess(float shine) {
if (recorder != null) recorder.shininess(shine);
g.shininess(shine);
}
public void emissive(int rgb) {
if (recorder != null) recorder.emissive(rgb);
g.emissive(rgb);
}
public void emissive(float gray) {
if (recorder != null) recorder.emissive(gray);
g.emissive(gray);
}
public void emissive(float x, float y, float z ) {
if (recorder != null) recorder.emissive(x, y, z);
g.emissive(x, y, z);
}
public int createAmbientLight(int rgb) {
return g.createAmbientLight(rgb);
}
public int createAmbientLight(float gray) {
return g.createAmbientLight(gray);
}
public int createAmbientLight(float lr, float lg, float lb) {
return g.createAmbientLight(lr, lg, lb);
}
public int createDirectionalLight(int rgb, float nx, float ny, float nz) {
return g.createDirectionalLight(rgb, nx, ny, nz);
}
public int createDirectionalLight(float gray, float nx, float ny, float nz) {
return g.createDirectionalLight(gray, nx, ny, nz);
}
public int createDirectionalLight(float lr, float lg, float lb, float nx, float ny, float nz) {
return g.createDirectionalLight(lr, lg, lb, nx, ny, nz);
}
public int createPointLight(int rgb, float x, float y, float z) {
return g.createPointLight(rgb, x, y, z);
}
public int createPointLight(float gray, float x, float y, float z) {
return g.createPointLight(gray, x, y, z);
}
public int createPointLight(float lr, float lg, float lb, float x, float y, float z) {
return g.createPointLight(lr, lg, lb, x, y, z);
}
public int createSpotLight(int rgb, float x, float y, float z, float nx, float ny, float nz, float angle) {
return g.createSpotLight(rgb, x, y, z, nx, ny, nz, angle);
}
public int createSpotLight(float gray, float x, float y, float z, float nx, float ny, float nz, float angle) {
return g.createSpotLight(gray, x, y, z, nx, ny, nz, angle);
}
public int createSpotLight(float lr, float lg, float lb, float x, float y, float z, float nx, float ny, float nz, float angle) {
return g.createSpotLight(lr, lg, lb, x, y, z, nx, ny, nz, angle);
}
public void strokeWeight(float weight) {
if (recorder != null) recorder.strokeWeight(weight);
g.strokeWeight(weight);
+35 -5
View File
@@ -215,10 +215,10 @@ public interface PConstants {
// lighting
static final int DISABLED = 0;
static final int AMBIENT = 1;
static final int DIFFUSE = 2;
static final int SPECULAR = 3;
static final int AMBIENT = 0;
static final int DIRECTIONAL = 1;
static final int POINT = 2;
static final int SPOT = 3;
// net
@@ -329,8 +329,33 @@ public interface PConstants {
static final int VZ = 22;
static final int VW = 23;
static final int VERTEX_FIELD_COUNT = 24;
// Ambient color (usually to be kept the same as diffuse)
// fill(_) sets both ambient and diffuse.
static final int AR = 24;
static final int AG = 25;
static final int AB = 26;
// Diffuse is shared with fill.
static final int DR = 3;
static final int DG = 4;
static final int DB = 5;
static final int DA = 6;
//specular (by default kept white)
static final int SPR = 27;
static final int SPG = 28;
static final int SPB = 29;
//GL doesn't use a separate specular alpha, but we do (we're better)
static final int SPA = 30;
static final int SHINE = 31;
//emissive (by default kept black)
static final int ER = 32;
static final int EG = 33;
static final int EB = 34;
static final int VERTEX_FIELD_COUNT = 35;
// line & triangle fields (note how these overlap)
@@ -344,4 +369,9 @@ public interface PConstants {
static final int LINE_FIELD_COUNT = 5;
static final int TRIANGLE_FIELD_COUNT = 5;
// normal modes for lighting
static final int AUTO_NORMAL = 0; // normal calculated per triangle
static final int MANUAL_SHAPE_NORMAL = 1; // one normal manually specified per shape
static final int MANUAL_VERTEX_NORMAL = 2; // normals specified for each shape vertex
}
+162 -1
View File
@@ -128,7 +128,7 @@ public class PGraphics extends PImage implements PConstants {
// ........................................................
// internal color for setting/calculating
float calcR, calcG, calcB, calcA;
protected float calcR, calcG, calcB, calcA;
int calcRi, calcGi, calcBi, calcAi;
int calcColor;
boolean calcAlpha;
@@ -446,6 +446,12 @@ public class PGraphics extends PImage implements PConstants {
}
/**
* do anything that needs doing after setup before draw
*/
public void postSetup() {
}
//////////////////////////////////////////////////////////////
@@ -2099,6 +2105,27 @@ public class PGraphics extends PImage implements PConstants {
"can only be used with depth()");
}
public void lightDirection(int num, float x, float y, float z) {
throw new RuntimeException("lightDirection() " +
"can only be used with depth()");
}
public void lightFalloff(int num, float constant,
float linear, float quadratic) {
throw new RuntimeException("lightFalloff() " +
"can only be used with depth()");
}
public void lightSpotAngle(int num, float spotAngle) {
throw new RuntimeException("lightSpotAngle() " +
"can only be used with depth()");
}
public void lightSpotConcentration(int num, float concentration) {
throw new RuntimeException("lightSpotConcentration() " +
"can only be used with depth()");
}
//////////////////////////////////////////////////////////////
@@ -2427,6 +2454,140 @@ public class PGraphics extends PImage implements PConstants {
}
//////////////////////////////////////////////////////////////
/*
public void diffuse(int rgb) {
throw new RuntimeException("diffuse() can only be used with depth()");
}
public void diffuse(float gray) {
throw new RuntimeException("diffuse() can only be used with depth()");
}
public void diffuse(float gray, float alpha) {
throw new RuntimeException("diffuse() can only be used with depth()");
}
public void diffuse(float x, float y, float z) {
throw new RuntimeException("diffuse() can only be used with depth()");
}
public void diffuse(float x, float y, float z, float a) {
throw new RuntimeException("diffuse() can only be used with depth()");
}
*/
//////////////////////////////////////////////////////////////
public void ambient(int rgb) {
throw new RuntimeException("ambient() can only be used with depth()");
}
public void ambient(float gray) {
throw new RuntimeException("ambient() can only be used with depth()");
}
public void ambient(float x, float y, float z) {
throw new RuntimeException("ambient() can only be used with depth()");
}
//////////////////////////////////////////////////////////////
public void specular(int rgb) {
throw new RuntimeException("specular() can only be used with depth()");
}
public void specular(float gray) {
throw new RuntimeException("specular() can only be used with depth()");
}
public void specular(float gray, float alpha) {
throw new RuntimeException("specular() can only be used with depth()");
}
public void specular(float x, float y, float z) {
throw new RuntimeException("specular() can only be used with depth()");
}
public void specular(float x, float y, float z, float a) {
throw new RuntimeException("specular() can only be used with depth()");
}
public void shininess(float shine) {
throw new RuntimeException("shininess() can only be used with depth()");
}
//////////////////////////////////////////////////////////////
public void emissive(int rgb) {
throw new RuntimeException("emissive() can only be used with depth()");
}
public void emissive(float gray) {
throw new RuntimeException("emissive() can only be used with depth()");
}
public void emissive(float x, float y, float z ) {
throw new RuntimeException("emissive() can only be used with depth()");
}
//////////////////////////////////////////////////////////////
public int createAmbientLight(int rgb) {
throw new RuntimeException("createAmbientLight() can only be used with depth()");
}
public int createAmbientLight(float gray) {
throw new RuntimeException("createAmbientLight() can only be used with depth()");
}
public int createAmbientLight(float lr, float lg, float lb) {
throw new RuntimeException("createAmbientLight() can only be used with depth()");
}
public int createDirectionalLight(int rgb, float nx, float ny, float nz) {
throw new RuntimeException("createDirectionalLight() can only be used with depth()");
}
public int createDirectionalLight(float gray, float nx, float ny, float nz) {
throw new RuntimeException("createDirectionalLight() can only be used with depth()");
}
public int createDirectionalLight(float lr, float lg, float lb, float nx, float ny, float nz) {
throw new RuntimeException("createDirectionalLight() can only be used with depth()");
}
public int createPointLight(int rgb, float x, float y, float z) {
throw new RuntimeException("createPointLight() can only be used with depth()");
}
public int createPointLight(float gray, float x, float y, float z) {
throw new RuntimeException("createPointLight() can only be used with depth()");
}
public int createPointLight(float lr, float lg, float lb, float x, float y, float z) {
throw new RuntimeException("createPointLight() can only be used with depth()");
}
public int createSpotLight(int rgb, float x, float y, float z, float nx, float ny, float nz, float angle) {
throw new RuntimeException("createSpotLight() can only be used with depth()");
}
public int createSpotLight(float gray, float x, float y, float z, float nx, float ny, float nz, float angle) {
throw new RuntimeException("createSpotLight() can only be used with depth()");
}
public int createSpotLight(float lr, float lg, float lb, float x, float y, float z, float nx, float ny, float nz, float angle) {
throw new RuntimeException("createSpotLight() can only be used with depth()");
}
//////////////////////////////////////////////////////////////
+903 -417
View File
File diff suppressed because it is too large Load Diff
+554 -465
View File
File diff suppressed because it is too large Load Diff
+77
View File
@@ -318,6 +318,14 @@ public interface PMethods {
public void lightDiffuse(int num, float x, float y, float z);
public void lightSpecular(int num, float x, float y, float z);
public void lightDirection(int num, float x, float y, float z);
public void lightFalloff(int num, float constant, float linear, float quadratic);
public void lightSpotAngle(int num, float spotAngle);
public void lightSpotConcentration(int num, float concentration);
//
@@ -497,5 +505,74 @@ public interface PMethods {
*/
public void save(String filename);
public void postSetup();
public void diffuse(int rgb);
public void diffuse(float gray);
public void diffuse(float gray, float alpha);
public void diffuse(float x, float y, float z);
public void diffuse(float x, float y, float z, float a);
//////////////////////////////////////////////////////////////
public void ambient(int rgb);
public void ambient(float gray);
public void ambient(float x, float y, float z);
//////////////////////////////////////////////////////////////
public void specular(int rgb);
public void specular(float gray);
public void specular(float gray, float alpha);
public void specular(float x, float y, float z);
public void specular(float x, float y, float z, float a);
public void shininess(float shine);
public void emissive(int rgb);
public void emissive(float gray);
public void emissive(float x, float y, float z);
//////////////////////////////////////////////////////////////
public int createAmbientLight(int rgb);
public int createAmbientLight(float gray);
public int createAmbientLight(float lr, float lg, float lb);
public int createDirectionalLight(int rgb, float nx, float ny, float nz);
public int createDirectionalLight(float gray, float nx, float ny, float nz);
public int createDirectionalLight(float r, float g, float b, float nx, float ny, float nz);
public int createPointLight(int rgb, float x, float y, float z);
public int createPointLight(float gray, float x, float y, float z);
public int createPointLight(float lr, float lg, float lb, float x, float y, float z);
public int createSpotLight(int rgb, float x, float y, float z, float nx, float ny, float nz, float angle);
public int createSpotLight(float gray, float x, float y, float z, float nx, float ny, float nz, float angle);
public int createSpotLight(float lr, float lg, float lb, float x, float y, float z, float nx, float ny, float nz, float angle);
}
+18 -2
View File
@@ -2,13 +2,29 @@
X make jdkVersion, jdkVersionName, platform, platformName variables
X additional note about screen sizes and displays
X sto instead of stop in present mode
X appears that opengl libraries weren't correctly added in 81?
GraphicsDevice theDevice =
frame.getGraphicsConfiguration().getDevice();
_ why does diffuse just mirror fill()?
X just removed it
tweaking up simong light code
_ remove/rename postSetup() stuff from PGraphics/PApplet
_ what's up with resetLights?
_ angleMode stuff is kinda overkill
_ move dot() to the bottom w/ the other math
_ add PLight object to avoid method overflow
_ preApplyMatrix, invApplyMatrix?
_ applyMatrixPre and applyMatrixIn
_ rotateXInv is ugly..
_ irotateX?, papplyMatrix?
_ angleMode shouldn't be the first param
_ fix the flicker in java2d mode
X is it because the lock was taken off (g) in PApplet?
GraphicsDevice theDevice =
frame.getGraphicsConfiguration().getDevice();
_ don't let users on < 1.3 load JAVA2D, or < 1.4 load OPENGL
_ apply tint() to textures as well
+315 -49
View File
@@ -185,21 +185,33 @@ public class PGraphicsGL extends PGraphics3 {
// this sets up the positions of the two base lights
// not sure if this needs to be enabled in opengl
public void beginFrame() {
super.beginFrame();
//resetMatrix();
//normal(0, 0, 1);
//System.out.println("beginFrame() start error " + PApplet.hex(gl.glGetError()));
report("top beginFrame()");
private void syncMatrices()
{
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadMatrixf(new float[] {
projection.m00, projection.m10, projection.m20, projection.m30,
projection.m01, projection.m11, projection.m21, projection.m31,
projection.m02, projection.m12, projection.m22, projection.m32,
projection.m03, projection.m13, projection.m23, projection.m33
});
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
// gl coordinates are reversed
gl.glTranslatef(0, height, 0);
gl.glScalef(1, -1, 1);
//gl.glPushMatrix();
}
protected void resetLights() {
super.resetLights();
for (int i = 0; i < MAX_LIGHTS; i++) {
lightDisable(i);
}
}
public void beginFrame() {
super.beginFrame();
syncMatrices();
report("top beginFrame()");
// these are necessary for alpha (i.e. fonts) to work
gl.glEnable(GL.GL_BLEND);
@@ -224,9 +236,12 @@ public class PGraphicsGL extends PGraphics3 {
// these tend to make life easier
// (but sometimes at the expense of a little speed)
gl.glEnable(GL.GL_NORMALIZE);
gl.glEnable(GL.GL_AUTO_NORMAL); // I think this is OpenGL 1.2 only
gl.glEnable(GL.GL_RESCALE_NORMAL);
// Not using them right now because we're doing our own lighting.
//gl.glEnable(GL.GL_NORMALIZE);
//gl.glEnable(GL.GL_AUTO_NORMAL); // I think this is OpenGL 1.2 only
//gl.glEnable(GL.GL_RESCALE_NORMAL);
//gl.GlLightModeli(GL.GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
report("bot beginFrame()");
// are there other things to do here?
@@ -254,6 +269,21 @@ public class PGraphicsGL extends PGraphics3 {
report("bot endFrame()");
}
// For now we do our own lighting (so sum the specular and diffuse light colors...)
protected void handle_lighting() {
super.handle_lighting();
for (int i = vertex_start; i < vertex_end; i++) {
float v[] = vertices[i];
v[R] = min(ONE, v[R] + v[SPR]);
v[G] = min(ONE, v[G] + v[SPG]);
v[B] = min(ONE, v[B] + v[SPB]);
}
}
private final float min(float a, float b) {
return (a < b) ? a : b;
}
protected void render_triangles() {
//public void render_triangles() {
@@ -384,14 +414,17 @@ public class PGraphicsGL extends PGraphics3 {
gl.glColor4f(a[R], a[G], a[B], a[A]);
gl.glTexCoord2f(a[U] * uscale, a[V] * vscale);
gl.glNormal3f(a[NX], a[NY], a[NZ]);
gl.glVertex3f(a[VX], a[VY], a[VZ]);
gl.glColor4f(b[R], b[G], b[B], b[A]);
gl.glTexCoord2f(b[U] * uscale, b[V] * vscale);
gl.glNormal3f(b[NX], b[NY], b[NZ]);
gl.glVertex3f(b[VX], b[VY], b[VZ]);
gl.glColor4f(c[R], c[G], c[B], c[A]);
gl.glTexCoord2f(c[U] * uscale, c[V] * vscale);
gl.glNormal3f(c[NX], c[NY], c[NZ]);
gl.glVertex3f(c[VX], c[VY], c[VZ]);
gl.glEnd();
@@ -403,12 +436,15 @@ public class PGraphicsGL extends PGraphics3 {
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor4f(a[R], a[G], a[B], a[A]);
gl.glNormal3f(a[NX], a[NY], a[NZ]);
gl.glVertex3f(a[VX], a[VY], a[VZ]);
gl.glColor4f(b[R], b[G], b[B], b[A]);
gl.glNormal3f(b[NX], b[NY], b[NZ]);
gl.glVertex3f(b[VX], b[VY], b[VZ]);
gl.glColor4f(c[R], c[G], c[B], c[A]);
gl.glNormal3f(c[NX], c[NY], c[NZ]);
gl.glVertex3f(c[VX], c[VY], c[VZ]);
gl.glEnd();
@@ -420,6 +456,7 @@ public class PGraphicsGL extends PGraphics3 {
public void render_lines() {
//System.out.println("into lines error " + PApplet.hex(gl.glGetError()));
int i = 0;
for (int j = 0; j < pathCount; j++) {
//report("render_lines 1");
@@ -432,6 +469,7 @@ public class PGraphicsGL extends PGraphics3 {
float a[] = vertices[lines[i][VERTEX1]];
gl.glColor4f(a[SR], a[SG], a[SB], a[SA]);
gl.glVertex3f(a[VX], a[VY], a[VZ]);
//System.out.println("First point: " + a[VX] +", "+ a[VY] +", "+ a[VZ]);
// on this and subsequent lines, only draw the second point
for (int k = 0; k < pathLength[j]; k++) {
@@ -655,15 +693,19 @@ public class PGraphicsGL extends PGraphics3 {
super.textMode(mode);
}
public void cameraMode(int mode) {
super.cameraMode(mode);
syncMatrices();
}
//////////////////////////////////////////////////////////////
/*
public void endCamera() {
//System.out.println("PGraphicsGL.endCamera() 1");
super.endCamera();
report("begin endCamera");
System.out.println("begin endCamera");
//System.out.println("PGraphicsGL.endCamera() " + width + " " + height);
//System.exit(0);
@@ -674,18 +716,11 @@ public class PGraphicsGL extends PGraphics3 {
//System.out.println("camera should be");
//printCamera();
/*
gl.glLoadMatrixf(new float[] { p00, p01, p02, p03,
p10, p11, p12, p13,
p20, p21, p22, p23,
p30, p31, p32, p33 } );
*/
// opengl matrices are rotated from processing's
gl.glLoadMatrixf(new float[] { p00, p10, p20, p30,
p01, p11, p21, p31,
p02, p12, p22, p32,
p03, p13, p23, p33 } );
gl.glLoadMatrixf(new float[] { projection.m00, projection.m10, projection.m20, projection.m30,
projection.m01, projection.m11, projection.m21, projection.m31,
projection.m02, projection.m12, projection.m22, projection.m32,
projection.m03, projection.m13, projection.m23, projection.m33 } );
//gl.glScalef(1, -1, 1);
//System.out.println("trying " + height);
@@ -697,30 +732,60 @@ public class PGraphicsGL extends PGraphics3 {
gl.glTranslatef(0, height, 0);
gl.glScalef(1, -1, 1);
/*
float proj[] = new float[16];
gl.glGetFloatv(GL.GL_PROJECTION_MATRIX, proj);
//float mod[] = new float[16];
//gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, mod);
for (int i = 0; i < 16; i++) {
if ((i % 4) == 0) System.out.println();
System.out.print(PApplet.nfs(proj[i], 3, 4) + " ");
}
System.out.println();
*/
report("out of endCamera");
}
*/
//////////////////////////////////////////////////////////////
protected int internalCreateAmbientLight(float lr, float lg, float lb) {
int num = super.internalCreateAmbientLight(lr, lg, lb);
lightEnable(num);
glLightAmbient(num);
glLightPosition(num);
glLightFalloff(num);
return num;
}
protected int internalCreateDirectionalLight(float lr, float lg, float lb, float nx, float ny, float nz) {
int num = super.internalCreateDirectionalLight(lr, lg, lb, nx, ny, nz);
lightEnable(num);
glLightNoAmbient(num);
glLightDirection(num);
glLightDiffuse(num);
glLightSpecular(num);
glLightFalloff(num);
return num;
}
protected int internalCreatePointLight(float lr, float lg, float lb, float x, float y, float z) {
int num = super.internalCreatePointLight(lr, lg, lb, x, y, z);
glLightNoAmbient(num);
glLightPosition(num);
glLightDiffuse(num);
glLightSpecular(num);
glLightFalloff(num);
return num;
}
protected int internalCreateSpotLight(float lr, float lg, float lb, float x, float y, float z, float nx, float ny, float nz, float angle) {
int num = super.internalCreateSpotLight(lr, lg, lb, x, y, z, nx, ny, nz, angle);
glLightNoAmbient(num);
glLightPosition(num);
glLightDirection(num);
glLightDiffuse(num);
glLightSpecular(num);
glLightFalloff(num);
glLightSpotAngle(num);
glLightSpotConcentration(num);
return num;
}
// We're not actually turning on GL lights right now
// because our home-grown ones work better for now.
public void lights() {
super.lights();
gl.glEnable(GL.GL_LIGHTING);
//gl.glEnable(GL.GL_LIGHTING);
}
public void noLights() {
@@ -743,37 +808,238 @@ public class PGraphicsGL extends PGraphics3 {
public void lightPosition(int num, float x, float y, float z) {
super.lightPosition(num, x, y, z);
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_POSITION, new float[] { x, y, z });
glLightPosition(num);
}
public void glLightPosition(int num) {
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_POSITION, new float[] { lightX[num], lightY[num], lightZ[num] });
}
public void lightDirection(int num, float x, float y, float z) {
super.lightDirection(num, x, y, z);
glLightDirection(num);
}
public void glLightDirection(int num) {
if (lightType[num] == DIRECTIONAL) {
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_POSITION, new float[] { lightNX[num], lightNY[num], lightNZ[num], 1 });
} else { // Spot light
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_SPOT_DIRECTION, new float[] { lightNX[num], lightNY[num], lightNZ[num] });
}
}
public void lightAmbient(int num, float x, float y, float z) {
super.lightAmbient(num, x, y, z);
glLightAmbient(num);
}
public void glLightNoAmbient(int num) {
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_AMBIENT, new float[] { lightAmbientR[num],
lightAmbientG[num],
lightAmbientB[num] });
GL.GL_AMBIENT, new float[] { 0, 0, 0 });
}
public void glLightAmbient(int num) {
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_AMBIENT, new float[] { lightDiffuseR[num], lightDiffuseG[num], lightDiffuseB[num] });
}
public void lightDiffuse(int num, float x, float y, float z) {
super.lightDiffuse(num, x, y, z);
glLightDiffuse(num);
}
public void glLightDiffuse(int num) {
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_DIFFUSE, new float[] { lightDiffuseR[num],
lightDiffuseG[num],
lightDiffuseB[num] });
}
public void lightSpecular(int num, float x, float y, float z) {
super.lightSpecular(num, x, y, z);
glLightSpecular(num);
}
public void glLightSpecular(int num) {
gl.glLightfv(GL.GL_LIGHT0 + num,
GL.GL_SPECULAR, new float[] { lightSpecularR[num],
lightSpecularG[num],
lightSpecularB[num] });
}
public void lightFalloff(int num, float constant, float linear, float quadratic) {
super.lightFalloff(num, constant, linear, quadratic);
glLightFalloff(num);
}
public void glLightFalloff(int num) {
gl.glLightf(GL.GL_LIGHT0 + num, GL.GL_CONSTANT_ATTENUATION, lightConstantFalloff[num]);
gl.glLightf(GL.GL_LIGHT0 + num, GL.GL_LINEAR_ATTENUATION, lightLinearFalloff[num]);
gl.glLightf(GL.GL_LIGHT0 + num, GL.GL_QUADRATIC_ATTENUATION, lightQuadraticFalloff[num]);
}
public void lightSpotAngle(int num, float spotAngle) {
super.lightSpotAngle(num, spotAngle);
glLightSpotAngle(num);
}
public void glLightSpotAngle(int num) {
gl.glLightf(GL.GL_LIGHT0 + num, GL.GL_SPOT_CUTOFF, lightSpotAngle[num]);
}
public void lightSpotConcentration(int num, float concentration) {
super.lightSpotConcentration(num, concentration);
glLightSpotConcentration(num);
}
public void glLightSpotConcentration(int num) {
gl.glLightf(GL.GL_LIGHT0 + num, GL.GL_SPOT_EXPONENT, lightSpotConcentration[num]);
}
//////////////////////////////////////////////////////////////
/*
public void fill(int rgb) {
super.fill(rgb);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void fill(float gray) {
super.fill(gray);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void fill(float gray, float alpha) {
super.fill(gray, alpha);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void fill(float x, float y, float z) {
super.fill(x, y, z);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void fill(float x, float y, float z, float a) {
super.fill(x, y, z, a);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
*/
protected void calc_fill() {
super.calc_fill();
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE,
new float[] { calcR, calcG, calcB, calcA });
}
/*
public void diffuse(int rgb) {
super.diffuse(rgb);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void diffuse(float gray) {
super.diffuse(gray);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void diffuse(float gray, float alpha) {
super.diffuse(gray, alpha);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void diffuse(float x, float y, float z) {
super.diffuse(x, y, z);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
public void diffuse(float x, float y, float z, float a) {
super.diffuse(x, y, z, a);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, new float[] {calcR, calcG, calcB, calcA});
}
*/
//////////////////////////////////////////////////////////////
public void ambient(int rgb) {
super.ambient(rgb);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, new float[] {calcR, calcG, calcB, calcA});
}
public void ambient(float gray) {
super.ambient(gray);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, new float[] {calcR, calcG, calcB, calcA});
}
public void ambient(float x, float y, float z) {
super.ambient(x, y, z);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, new float[] {calcR, calcG, calcB, calcA});
}
//////////////////////////////////////////////////////////////
public void specular(int rgb) {
super.specular(rgb);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[] {calcR, calcG, calcB, calcA});
}
public void specular(float gray) {
super.specular(gray);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[] {calcR, calcG, calcB, calcA});
}
public void specular(float gray, float alpha) {
super.specular(gray, alpha);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[] {calcR, calcG, calcB, calcA});
}
public void specular(float x, float y, float z) {
super.specular(x, y, z);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[] {calcR, calcG, calcB, calcA});
}
public void specular(float x, float y, float z, float a) {
super.specular(x, y, z, a);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[] {calcR, calcG, calcB, calcA});
}
//////////////////////////////////////////////////////////////
public void emissive(int rgb) {
super.emissive(rgb);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, new float[] {calcR, calcG, calcB, calcA});
}
public void emissive(float gray) {
super.emissive(gray);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, new float[] {calcR, calcG, calcB, calcA});
}
public void emissive(float x, float y, float z) {
super.emissive(x, y, z);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, new float[] {calcR, calcG, calcB, calcA});
}
public void shininess(float shine) {
super.shininess(shine);
gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, shine);
}
//////////////////////////////////////////////////////////////
+10 -4
View File
@@ -1,8 +1,17 @@
0082 pde
X shut off text anti-aliasing in the about box
X implemented ryan alexander's grow box design
o when centering applet on-screen, needs to check for multiple screens
o this is both for PApplet and PdeRuntime
o PApplet screen size constant is no good
X nope, because centers on default screen
_ external apps don't stop at all when 'stop' is hit
_ moving an external window around a lot will halt the parent
_ external apps also seem to not do newlines properly
_ make a linux version of this release
_ need to fix up the make/dist scripts for linux
_ saved window positions.. if displays has changed, becomes a problem
_ record the display that it was on?
@@ -13,10 +22,7 @@ _ make note that changing screen config requires restart of processing
_ static { checkScreens(); }
_ static void PApplet.checkScreens() { }
_ to run explicitly later
_ when centering applet on-screen, needs to check for multiple screens
_ this is both for PApplet and PdeRuntime
_ PApplet screen size constant is no good
_ this seems too complicated.. just make people restart
_ ability to select monitor via preferences panel
_ check current present code with multiple monitors