From 8fac02179d5fb1e07b695341260a36166bd22549 Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 11 Dec 2004 23:36:38 +0000 Subject: [PATCH] towards getting opengl to work --- processing/app/PdeRuntime.java | 1 + processing/core/PApplet.java | 25 ++++++++---- processing/core/PGraphics.java | 73 ++++++++++++++++++---------------- processing/core/PImage.java | 12 +++--- processing/core/todo.txt | 19 ++++++++- 5 files changed, 82 insertions(+), 48 deletions(-) diff --git a/processing/app/PdeRuntime.java b/processing/app/PdeRuntime.java index 2df62b107..16edd8c57 100644 --- a/processing/app/PdeRuntime.java +++ b/processing/app/PdeRuntime.java @@ -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]); diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index a81e35e60..bfab7eac2 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -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); } diff --git a/processing/core/PGraphics.java b/processing/core/PGraphics.java index 8cbd8e2e9..a01db9922 100644 --- a/processing/core/PGraphics.java +++ b/processing/core/PGraphics.java @@ -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 -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); diff --git a/processing/core/PImage.java b/processing/core/PImage.java index d92b8ca1b..9c408bd82 100644 --- a/processing/core/PImage.java +++ b/processing/core/PImage.java @@ -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(); diff --git a/processing/core/todo.txt b/processing/core/todo.txt index b71f2f780..b095eb432 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -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