rocking the opengl

This commit is contained in:
benfry
2004-12-10 21:17:18 +00:00
parent e2f4e7be89
commit b7e03430d7
5 changed files with 97 additions and 57 deletions
-1
View File
@@ -189,7 +189,6 @@ rm -rf simong
mkdir -p ../../build/windows/work/libraries/particles/library/
cp library/particles.jar ../../build/windows/work/libraries/particles/library/
exit;
# OPENGL LIBRARY
echo Building OpenGL library...
+23 -5
View File
@@ -110,8 +110,8 @@ public class PApplet extends Applet
//boolean drawMethod;
//boolean loopMethod;
boolean looping;
boolean redraw;
protected boolean looping;
protected boolean redraw;
// true if inside the loop method
//boolean insideLoop;
@@ -145,9 +145,9 @@ public class PApplet extends Applet
static public final int DEFAULT_HEIGHT = 100;
public int width, height;
int libraryCount;
PLibrary libraries[];
boolean libraryCalls[][];
protected int libraryCount;
protected PLibrary libraries[];
protected boolean libraryCalls[][];
//int registeredCount[];
//PLibrary registered[][];
@@ -4224,6 +4224,24 @@ 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 saveTIFF(OutputStream output, int pixels[],
int width, int height) throws IOException {
PGraphics.saveTIFF(output, pixels, width, height);
}
static public void saveTGA(OutputStream output, int pixels[],
int width, int height) throws IOException {
PGraphics.saveTGA(output, pixels, width, height);
}
public void save(String filename) {
g.save(filename);
}
+37 -41
View File
@@ -60,7 +60,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
// needs to happen before background() is called
// and resize.. so it's gotta be outside
boolean hints[] = new boolean[HINT_COUNT];
protected boolean hints[] = new boolean[HINT_COUNT];
// ........................................................
@@ -296,7 +296,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
public PImage textureImage;
static final int DEFAULT_TEXTURES = 3;
PImage textures[] = new PImage[DEFAULT_TEXTURES];
protected PImage textures[] = new PImage[DEFAULT_TEXTURES];
int texture_index;
@@ -537,6 +537,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
// reset lines
lineCount = 0;
line.reset();
pathCount = 0;
// reset triangles
triangleCount = 0;
@@ -561,11 +562,11 @@ public class PGraphics extends PImage implements PMethods, PConstants {
// (but can't return, since needs to update memimgsrc
if (hints[DEPTH_SORT]) {
if (triangleCount > 0) {
//depth_sort_triangles(); // not yet
depth_sort_triangles();
render_triangles();
}
if (lineCount > 0) {
//depth_sort_lines(); // not yet
depth_sort_lines();
render_lines();
}
}
@@ -613,6 +614,7 @@ public class PGraphics extends PImage implements PMethods, PConstants {
vertex_count = 0;
line.reset();
lineCount = 0;
pathCount = 0;
triangle.reset();
triangleCount = 0;
}
@@ -1115,6 +1117,27 @@ public class PGraphics extends PImage implements PMethods, PConstants {
}
// ------------------------------------------------------------------
// 2D or 3D POINTS FROM MODEL (MX, MY, MZ) TO VIEW SPACE (X, Y, Z)
if (depth) {
for (int i = vertex_start; i < vertex_end; i++) {
float vertex[] = vertices[i];
vertex[VX] = m00*vertex[MX] + m01*vertex[MY] + m02*vertex[MZ] + m03;
vertex[VY] = m10*vertex[MX] + m11*vertex[MY] + m12*vertex[MZ] + m13;
vertex[VZ] = m20*vertex[MX] + m21*vertex[MY] + m22*vertex[MZ] + m23;
vertex[VW] = m30*vertex[MX] + m31*vertex[MY] + m32*vertex[MZ] + m33;
}
} else {
// if no depth in use, then the points can be transformed simpler
for (int i = vertex_start; i < vertex_end; i++) {
vertices[i][X] = m00*vertices[i][MX] + m01*vertices[i][MY] + m03;
vertices[i][Y] = m10*vertices[i][MX] + m11*vertices[i][MY] + m13;
}
}
// ------------------------------------------------------------------
// TRANSFORM / LIGHT / CLIP
@@ -1193,8 +1216,8 @@ public class PGraphics extends PImage implements PMethods, PConstants {
}
//protected void depth_sort_triangles() {
//}
protected void depth_sort_triangles() {
}
protected void render_triangles() {
for (int i = 0; i < triangleCount; i ++) {
@@ -1225,8 +1248,8 @@ public class PGraphics extends PImage implements PMethods, PConstants {
}
//protected void depth_sort_lines() {
//}
protected void depth_sort_lines() {
}
public void render_lines() {
for (int i = 0; i < lineCount; i ++) {
@@ -1368,33 +1391,6 @@ public class PGraphics extends PImage implements PMethods, PConstants {
*/
protected void light_and_transform() {
// ------------------------------------------------------------------
// 2D POINTS FROM MODEL (MX, MY, MZ) DIRECTLY TO VIEW SPACE (X, Y, Z)
if (!depth) {
// if no depth in use, then the points can be transformed
for (int i = vertex_start; i < vertex_end; i++) {
vertices[i][X] = m00*vertices[i][MX] + m01*vertices[i][MY] + m03;
vertices[i][Y] = m10*vertices[i][MX] + m11*vertices[i][MY] + m13;
}
}
// ------------------------------------------------------------------
// 3D POINTS FROM MODEL (MX, MY, MZ) TO VIEW SPACE (VX, VY, VZ)
if (depth) {
for (int i = vertex_start; i < vertex_end; i++) {
float vertex[] = vertices[i];
vertex[VX] = m00*vertex[MX] + m01*vertex[MY] + m02*vertex[MZ] + m03;
vertex[VY] = m10*vertex[MX] + m11*vertex[MY] + m12*vertex[MZ] + m13;
vertex[VZ] = m20*vertex[MX] + m21*vertex[MY] + m22*vertex[MZ] + m23;
vertex[VW] = m30*vertex[MX] + m31*vertex[MY] + m32*vertex[MZ] + m33;
}
}
// ------------------------------------------------------------------
// CULLING
@@ -4614,12 +4610,12 @@ public class PGraphics extends PImage implements PMethods, PConstants {
*
* (note: no need for bounds check since it's a 32 bit number)
*/
protected void calc_color_from(int rgb) {
calcColor = rgb;
calcAi = (rgb >> 24) & 0xff;
calcRi = (rgb >> 16) & 0xff;
calcGi = (rgb >> 8) & 0xff;
calcBi = rgb & 0xff;
protected void calc_color_from(int argb) {
calcColor = argb;
calcAi = (argb >> 24) & 0xff;
calcRi = (argb >> 16) & 0xff;
calcGi = (argb >> 8) & 0xff;
calcBi = argb & 0xff;
calcA = (float)calcAi / 255.0f;
calcR = (float)calcRi / 255.0f;
calcG = (float)calcGi / 255.0f;
+25 -10
View File
@@ -456,7 +456,6 @@ public class PImage implements PConstants, Cloneable {
}
/**
* Blend a two colors based on a particular mode.
*/
@@ -926,7 +925,7 @@ public class PImage implements PConstants, Cloneable {
}
private float frac(float x) {
private static float frac(float x) {
return (x - (int) x);
}
@@ -1032,9 +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 void write_tiff(OutputStream output, int pixels[],
int width, int height) throws IOException {
static public void saveHeaderTIFF(OutputStream output,
int width, int height) throws IOException {
byte tiff[] = new byte[768];
System.arraycopy(tiff_header, 0, tiff, 0, tiff_header.length);
@@ -1050,7 +1048,12 @@ public class PImage implements PConstants, Cloneable {
tiff[117] = (byte) ((count) & 0xff);
output.write(tiff);
}
static public void saveTIFF(OutputStream output, int pixels[],
int width, int height) throws IOException {
saveHeaderTIFF(output, width, height);
for (int i = 0; i < pixels.length; i++) {
output.write((pixels[i] >> 16) & 0xff);
output.write((pixels[i] >> 8) & 0xff);
@@ -1067,11 +1070,11 @@ public class PImage implements PConstants, Cloneable {
* [fry 030917]
* Modified to write directly to OutputStream, because of
* memory issues with first making an array of the data.
*
* tga spec: http://organicbit.com/closecombat/formats/tga.html
*/
static void write_targa(OutputStream output, int pixels[],
int width, int height) throws IOException {
static void saveHeaderTGA(OutputStream output,
int width, int height) throws IOException {
byte header[] = new byte[18];
// set header info
@@ -1084,6 +1087,12 @@ public class PImage implements PConstants, Cloneable {
header[17] = 8; // bits per colour component
output.write(header);
}
static public void saveTGA(OutputStream output, int pixels[],
int width, int height) throws IOException {
saveHeaderTGA(output, width, height);
int index = (height-1) * width;
@@ -1107,7 +1116,7 @@ public class PImage implements PConstants, Cloneable {
if (filename.toLowerCase().endsWith(".tga")) {
os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
write_targa(os, pixels, width, height);
saveTGA(os, pixels, width, height);
} else {
if (!filename.toLowerCase().endsWith(".tif") &&
@@ -1116,7 +1125,7 @@ public class PImage implements PConstants, Cloneable {
filename += ".tif";
}
os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
write_tiff(os, pixels, width, height);
saveTIFF(os, pixels, width, height);
}
os.flush();
os.close();
@@ -1127,6 +1136,12 @@ public class PImage implements PConstants, Cloneable {
}
//////////////////////////////////////////////////////////////
// INHERITED BY PGRAPHICS
public void smooth() {
smooth = true;
}
+12
View File
@@ -13,6 +13,10 @@ opengl
_ cache needs to also make things a power of 2
_ if images are already a power of 2, then needn't re-alloc
_ warn people that they should make images be a pow of 2
_ cacheIndex needs to be set to -1 when the image is modified
_ or maybe have a modified() function?
_ lights cannot be enabled/disabled throughout
_ lighting will be based on what's left at endFrame()
_ fonts probably need to be RGBA, not ALPHA style images
_ there's nothing really ALPHA about them?
@@ -22,9 +26,16 @@ _ 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
random tasks
_ someone to figure out a good model for adaptive sizing of circles
_ also goes for arcs, though will be weighted based on arc size
_ figure out why tiff images won't open with after effects
_ open with photoshop, resave, see which tags change
_ particularly of those that are included in the original image
_ perhaps something gets corrected?
_ arc with stroke only draws the arc shape itself
_ may need a 'wedge' function to draw a stroke around the whole thing
@@ -35,6 +46,7 @@ _ image loading bug is huge
_ pmouseX is broken again
_ maintain things a bit different
_ email the beta@ list to see how people are using pmouseX
_ need timer in as part of the api
_ or at least include an example that uses it