mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
towards getting opengl to work
This commit is contained in:
@@ -112,6 +112,7 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
//, "2>", "C:\\net2.txt"
|
||||
};
|
||||
//PApplet.printarr(command);
|
||||
//PApplet.println(PApplet.join(command, " "));
|
||||
|
||||
//for (int i = 0; i < command.length; i++) {
|
||||
// System.out.println(i + " = " + command[i]);
|
||||
|
||||
+18
-7
@@ -4,7 +4,7 @@
|
||||
PApplet - applet base class for the bagel engine
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Except where noted, code is written by Ben Fry and
|
||||
Copyright (c) 2004- Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
@@ -4028,6 +4028,7 @@ public class PApplet extends Applet
|
||||
Frame frame = new Frame();
|
||||
frame.setResizable(false); // remove the grow box
|
||||
frame.pack(); // get insets. get more.
|
||||
frame.show(); // gl hack
|
||||
Class c = Class.forName(name);
|
||||
PApplet applet = (PApplet) c.newInstance();
|
||||
|
||||
@@ -4040,9 +4041,13 @@ public class PApplet extends Applet
|
||||
applet.init();
|
||||
applet.start();
|
||||
|
||||
System.out.println("applet inited, started");
|
||||
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
if (external) {
|
||||
System.out.println("applet is external");
|
||||
|
||||
Insets insets = frame.getInsets(); // does pack() first above
|
||||
//System.out.println(insets);
|
||||
|
||||
@@ -4095,6 +4100,8 @@ public class PApplet extends Applet
|
||||
applet.setupExternal(frame);
|
||||
|
||||
} else { // !external
|
||||
System.out.println("applet not external");
|
||||
|
||||
// remove applet name from args passed in
|
||||
applet.args = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, applet.args, 0, args.length - 1);
|
||||
@@ -4112,10 +4119,14 @@ public class PApplet extends Applet
|
||||
}
|
||||
});
|
||||
}
|
||||
System.out.println("showing frame");
|
||||
|
||||
frame.show();
|
||||
System.out.println("applet requesting focus");
|
||||
applet.requestFocus(); // ask for keydowns
|
||||
|
||||
System.out.println("exiting main()");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
@@ -4224,15 +4235,15 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
static public void saveHeaderTIFF(OutputStream output,
|
||||
int width, int height) throws IOException {
|
||||
PGraphics.saveHeaderTIFF(output, width, height);
|
||||
static public void saveHeaderTIF(OutputStream output,
|
||||
int width, int height) throws IOException {
|
||||
PGraphics.saveHeaderTIF(output, width, height);
|
||||
}
|
||||
|
||||
|
||||
static public void saveTIFF(OutputStream output, int pixels[],
|
||||
int width, int height) throws IOException {
|
||||
PGraphics.saveTIFF(output, pixels, width, height);
|
||||
static public void saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height) throws IOException {
|
||||
PGraphics.saveTIF(output, pixels, width, height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+39
-34
@@ -203,8 +203,8 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
|
||||
// perspective setup
|
||||
public float cameraFOV;
|
||||
public float cameraEyeX, cameraEyeY;
|
||||
public float cameraEyeDist, cameraNearDist, cameraFarDist;
|
||||
public float cameraX, cameraY, cameraZ;
|
||||
public float cameraNear, cameraFar;
|
||||
public float cameraAspect;
|
||||
|
||||
public float p00, p01, p02, p03; // projection matrix
|
||||
@@ -332,11 +332,11 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
// introduced new vars for more flexible code
|
||||
static final float sinLUT[], cosLUT[];
|
||||
static final float SINCOS_PRECISION = 0.5f;
|
||||
static final int SINCOS_LENGTH=(int)(360f/SINCOS_PRECISION);
|
||||
static final int SINCOS_LENGTH = (int) (360f / SINCOS_PRECISION);
|
||||
static {
|
||||
sinLUT = new float[SINCOS_LENGTH];
|
||||
cosLUT = new float[SINCOS_LENGTH];
|
||||
for (int i=0; i<SINCOS_LENGTH; i++) {
|
||||
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);
|
||||
}
|
||||
@@ -419,13 +419,28 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
|
||||
// init perspective projection based on new dimensions
|
||||
cameraFOV = 60; // at least for now
|
||||
cameraEyeX = width / 2.0f;
|
||||
cameraEyeY = height / 2.0f;
|
||||
cameraEyeDist = cameraEyeY / ((float) tan(PI * cameraFOV / 360f));
|
||||
cameraNearDist = cameraEyeDist / 10.0f;
|
||||
cameraFarDist = cameraEyeDist * 10.0f;
|
||||
cameraX = width / 2.0f;
|
||||
cameraY = height / 2.0f;
|
||||
cameraZ = cameraY / ((float) tan(PI * cameraFOV / 360f));
|
||||
cameraNear = cameraZ / 10.0f;
|
||||
cameraFar = cameraZ * 10.0f;
|
||||
cameraAspect = (float)width / (float)height;
|
||||
|
||||
// init lights (here instead of allocate b/c needed by opengl)
|
||||
light = new boolean[MAX_LIGHTS];
|
||||
lightX = new float[MAX_LIGHTS];
|
||||
lightY = new float[MAX_LIGHTS];
|
||||
lightZ = new float[MAX_LIGHTS];
|
||||
lightAmbientR = new float[MAX_LIGHTS];
|
||||
lightAmbientG = new float[MAX_LIGHTS];
|
||||
lightAmbientB = new float[MAX_LIGHTS];
|
||||
lightDiffuseR = new float[MAX_LIGHTS];
|
||||
lightDiffuseG = new float[MAX_LIGHTS];
|
||||
lightDiffuseB = new float[MAX_LIGHTS];
|
||||
lightSpecularR = new float[MAX_LIGHTS];
|
||||
lightSpecularG = new float[MAX_LIGHTS];
|
||||
lightSpecularB = new float[MAX_LIGHTS];
|
||||
|
||||
// reset the cameraMode if PERSPECTIVE or ORTHOGRAPHIC
|
||||
// otherwise just hose the user if it's custom
|
||||
if (depth) cameraMode(this.cameraMode);
|
||||
@@ -454,21 +469,6 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
|
||||
line = new PLine(this);
|
||||
triangle = new PTriangle(this);
|
||||
|
||||
// init lights
|
||||
light = new boolean[MAX_LIGHTS];
|
||||
lightX = new float[MAX_LIGHTS];
|
||||
lightY = new float[MAX_LIGHTS];
|
||||
lightZ = new float[MAX_LIGHTS];
|
||||
lightAmbientR = new float[MAX_LIGHTS];
|
||||
lightAmbientG = new float[MAX_LIGHTS];
|
||||
lightAmbientB = new float[MAX_LIGHTS];
|
||||
lightDiffuseR = new float[MAX_LIGHTS];
|
||||
lightDiffuseG = new float[MAX_LIGHTS];
|
||||
lightDiffuseB = new float[MAX_LIGHTS];
|
||||
lightSpecularR = new float[MAX_LIGHTS];
|
||||
lightSpecularG = new float[MAX_LIGHTS];
|
||||
lightSpecularB = new float[MAX_LIGHTS];
|
||||
}
|
||||
|
||||
|
||||
@@ -497,7 +497,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
lightEnable(0);
|
||||
lightAmbient(0, 0, 0, 0);
|
||||
|
||||
light(1, cameraEyeX, cameraEyeY, cameraEyeDist, 255, 255, 255);
|
||||
light(1, cameraX, cameraY, cameraZ, 255, 255, 255);
|
||||
|
||||
textureMode(IMAGE_SPACE);
|
||||
rectMode(CORNER);
|
||||
@@ -536,12 +536,12 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
|
||||
// reset lines
|
||||
lineCount = 0;
|
||||
line.reset();
|
||||
if (line != null) line.reset(); // is this necessary?
|
||||
pathCount = 0;
|
||||
|
||||
// reset triangles
|
||||
triangleCount = 0;
|
||||
triangle.reset();
|
||||
if (triangle != null) triangle.reset(); // necessary?
|
||||
|
||||
// reset textures
|
||||
texture_index = 0;
|
||||
@@ -612,10 +612,10 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
// reset vertex, line and triangle information
|
||||
// every shape is rendered at endShape();
|
||||
vertex_count = 0;
|
||||
line.reset();
|
||||
if (line != null) line.reset(); // necessary?
|
||||
lineCount = 0;
|
||||
pathCount = 0;
|
||||
triangle.reset();
|
||||
if (triangle != null) triangle.reset(); // necessary?
|
||||
triangleCount = 0;
|
||||
}
|
||||
textureImage = null;
|
||||
@@ -1227,6 +1227,10 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
int tex = triangles[i][TEXTURE_INDEX];
|
||||
int index = triangles[i][INDEX];
|
||||
|
||||
System.out.println("A " + a[X] + " " + a[Y] + " " + a[Z]);
|
||||
System.out.println("B " + b[X] + " " + b[Y] + " " + b[Z]);
|
||||
System.out.println("C " + c[X] + " " + c[Y] + " " + c[Z]);
|
||||
|
||||
triangle.reset();
|
||||
|
||||
if (tex > -1 && textures[tex] != null) {
|
||||
@@ -4180,16 +4184,17 @@ public class PGraphics extends PImage implements PMethods, PConstants {
|
||||
* Note that this setting gets nuked if resize() is called.
|
||||
*/
|
||||
public void cameraMode(int mode) {
|
||||
if (cameraMode == PERSPECTIVE) {
|
||||
if (mode == PERSPECTIVE) {
|
||||
System.out.println("setting camera to perspective");
|
||||
beginCamera();
|
||||
resetMatrix();
|
||||
perspective(cameraFOV, cameraAspect, cameraNearDist, cameraFarDist);
|
||||
lookat(cameraEyeX, cameraEyeY, cameraEyeDist,
|
||||
cameraEyeX, cameraEyeY, 0,
|
||||
perspective(cameraFOV, cameraAspect, cameraNear, cameraFar);
|
||||
lookat(cameraX, cameraY, cameraZ,
|
||||
cameraX, cameraY, 0,
|
||||
0, 1, 0);
|
||||
endCamera();
|
||||
|
||||
} else if (cameraMode == ORTHOGRAPHIC) {
|
||||
} else if (mode == ORTHOGRAPHIC) {
|
||||
beginCamera();
|
||||
resetMatrix();
|
||||
ortho(0, width, 0, height, -10, 10);
|
||||
|
||||
+6
-6
@@ -1031,8 +1031,8 @@ public class PImage implements PConstants, Cloneable {
|
||||
1, 23, 0, 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 8, 0, 8
|
||||
};
|
||||
|
||||
static public void saveHeaderTIFF(OutputStream output,
|
||||
int width, int height) throws IOException {
|
||||
static public void saveHeaderTIF(OutputStream output,
|
||||
int width, int height) throws IOException {
|
||||
byte tiff[] = new byte[768];
|
||||
System.arraycopy(tiff_header, 0, tiff, 0, tiff_header.length);
|
||||
|
||||
@@ -1051,9 +1051,9 @@ public class PImage implements PConstants, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
static public void saveTIFF(OutputStream output, int pixels[],
|
||||
int width, int height) throws IOException {
|
||||
saveHeaderTIFF(output, width, height);
|
||||
static public void saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height) throws IOException {
|
||||
saveHeaderTIF(output, width, height);
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
output.write((pixels[i] >> 16) & 0xff);
|
||||
output.write((pixels[i] >> 8) & 0xff);
|
||||
@@ -1125,7 +1125,7 @@ public class PImage implements PConstants, Cloneable {
|
||||
filename += ".tif";
|
||||
}
|
||||
os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
|
||||
saveTIFF(os, pixels, width, height);
|
||||
saveTIF(os, pixels, width, height);
|
||||
}
|
||||
os.flush();
|
||||
os.close();
|
||||
|
||||
+18
-1
@@ -8,6 +8,14 @@ X beginShape() defaults to beginShape(POLYGON)
|
||||
_ needs to be noted for the reference
|
||||
X screenX(x, y) and screenY(x, y) added for noDepth()
|
||||
X add TRIANGLE_FAN
|
||||
X eyeX, eyeY etc have been renamed cameraX/Y/Z, and cameraNear/Far
|
||||
X modify targa and tiff writing routines to break into header writing
|
||||
X writeTIFF, writeHeaderTIFF, writeTGA, writeHeaderTGA
|
||||
|
||||
_ implement size(0, 0) -> just doesn't bother doing a frame.show();
|
||||
_ implement fullscreen().. this takes over the screen as best it can
|
||||
_ really more like present mode..
|
||||
_ that if applet is 500x500, centers on a 800x600 window
|
||||
|
||||
opengl
|
||||
_ cache needs to also make things a power of 2
|
||||
@@ -26,8 +34,17 @@ _ bring screen space and font size settings back in to PGraphics
|
||||
_ causing too much trouble to be stuck down in PFont
|
||||
_ don't allocate zbuffer & stencil until depth() is called
|
||||
|
||||
_ modify targa and tiff writing routines to break into header writing
|
||||
postscript
|
||||
_ how to hook into curve rendering so that curve segments are drawn
|
||||
_ maybe lines are rendered and sorted,
|
||||
_ but they point to an original version of the curve geometry
|
||||
_ that can be re-rendered
|
||||
_ also integrate catmull-rom -> bezier inverse matrices
|
||||
_ even with the general catmull-rom, to render via ai beziers
|
||||
|
||||
libraries could handle a series of events..
|
||||
i.e. a 'completion' event, or 'new data' event
|
||||
these could be registered on obejcts in a general way
|
||||
|
||||
random tasks
|
||||
_ someone to figure out a good model for adaptive sizing of circles
|
||||
|
||||
Reference in New Issue
Block a user