Some more information reply to here.
2009/4/16 Terry Braun <...>
Hi, a couple of questions - how are you converting numbers back and
forth between the javascript and java?
I didn't do any type conversion manually and just let Rhino engine do
it for me.
Have you tested the conversion to make sure it is done well?
I didn't test the correctness of Rhino's auto conversion between Java
and javascript because the sample just work well in my computer at
office. It just fail in some computer, ie. my computer at home.
Is the error always the same?
Yes.
Do you have some sample code that will show what you are doing?
Yes, my sample is here. Which required JOGL library to work.
/*
* OpenGL Hello world
*/
print("Hello OpenGL in SWT/JOGL!");
var opengl = JavaImporter(
org.eclipse.swt,
org.eclipse.swt.widgets,
org.eclipse.swt.events,
org.eclipse.swt.layout,
org.eclipse.swt.graphics,
org.eclipse.swt.opengl,
javax.media.opengl.GL,
javax.media.opengl.GLContext,
javax.media.opengl.GLDrawableFactory,
javax.media.opengl.glu);
with(opengl) {
var display = Display.getDefault();
var resize = function(canvas) {
canvas.setCurrent();
context.makeCurrent();
var rect = canvas.getClientArea();
var width = rect.width;
var height = Math.max(rect.height, 1);
GL.glViewport(0, 0, width, height);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
var aspect = width / height;
glu.gluPerspective(45, aspect, 0, 400);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
context.release();
}
var drawTorus = function(r, R, nsides, rings) {
var ringDelta = 2.0 * Math.PI / rings;
var sideDelta = 2.0 * Math.PI / nsides;
var theta = 0.0;
var cosTheta = 1.0;
var sinTheta = 0.0;
for (var i = rings - 1; i >= 0; i--) {
var theta1 = theta + ringDelta;
var cosTheta1 = Math.cos(theta1);
var sinTheta1 = Math.sin(theta1);
GL.glBegin(GL.GL_QUAD_STRIP);
var phi = 0.0;
for (var j = nsides; j >= 0; j--) {
phi += sideDelta;
var cosPhi = Math.cos(phi);
var sinPhi = Math.sin(phi);
var dist = R + r * cosPhi;
GL.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 *
cosPhi, sinPhi);
GL.glVertex3f(cosTheta1 * dist, -sinTheta1 *
dist, r * sinPhi);
GL.glNormal3f(cosTheta * cosPhi, -sinTheta *
cosPhi, sinPhi);
GL.glVertex3f(cosTheta * dist, -sinTheta *
dist, r * sinPhi);
}
GL.glEnd();
theta = theta1;
cosTheta = cosTheta1;
sinTheta = sinTheta1;
}
}
var shell = new Shell(display);
shell.setLayout(new FillLayout());
var data = new GLData();
data.doubleBuffer = true;
var canvas = new GLCanvas(shell, SWT.NO_BACKGROUND, data);
canvas.setCurrent();
var context = GLDrawableFactory.getFactory
().createExternalGLContext();
var GL = context.getGL();
var glu = new GLU();
canvas.addControlListener(new ControlAdapter({
controlResized: function(e) {
resize(canvas);
}
}));
context.makeCurrent();
GL.glClearColor(1.0, 1.0, 1.0, 1.0);
GL.glColor3f(1.0, 0.0, 0.0);
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
GL.glClearDepth(1.0);
GL.glLineWidth(2);
GL.glEnable(GL.GL_DEPTH_TEST);
context.release();
shell.setText("Javascript OpenGL in SWT/JOGL");
shell.setSize(640, 480);
shell.open();
var rot = 0;
display.asyncExec(new java.lang.Runnable({
run: function() {
if (!canvas.isDisposed()) {
canvas.setCurrent();
context.makeCurrent();
GL.glClear(GL.GL_COLOR_BUFFER_BIT |
GL.GL_DEPTH_BUFFER_BIT);
GL.glClearColor(.3, .5, .8, 1.0);
GL.glLoadIdentity();
GL.glTranslatef(0.0, 0.0, -10.0);
var frot = rot;
GL.glRotatef(0.15 * rot, 2.0 * frot,
10.0 * frot, 1.0);
GL.glRotatef(0.3 * rot, 3.0 * frot, 1.0
* frot, 1.0);
rot++;
GL.glPolygonMode(GL.GL_FRONT_AND_BACK,
GL.GL_LINE);
GL.glColor3f(0.9, 0.9, 0.9);
drawTorus(1, 1.9 + Math.sin(0.004 *
frot), 15, 15);
canvas.swapBuffers();
context.release();
display.asyncExec(this);
//canvas.getDisplay().timerExec(10,
this);
}
}
}));
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Have you tested using just Java, to isolate the problem?
Yes. My code comes from SWT OpenGL samples here
http://www.eclipse.org/swt/opengl/
the JOGL one (Snippet 209).
It works fine in both machine.
And I also try the Snippet 174 for eclipse OpenGL binding.
Rhino version here:
/*
* OpenGL Hello world
*/
print("Hello OpenGL in SWT/OGL!");
var opengl = JavaImporter(
org.eclipse.swt,
org.eclipse.swt.widgets,
org.eclipse.swt.events,
org.eclipse.swt.layout,
org.eclipse.swt.graphics,
org.eclipse.swt.opengl,
org.eclipse.opengl);
with(opengl) {
var display = Display.getDefault();
var init = function(canvas) {
canvas.setCurrent();
resize(canvas);
GL.glClearColor(1.0, 1.0, 1.0, 1.0);
GL.glColor3f(.0, .0, .0);
GL.glClearDepth(1.0);
GL.glLineWidth(2);
GL.glEnable(GL.GL_DEPTH_TEST);
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
var render = function() {
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glLoadIdentity();
GL.glTranslatef(0, 0, -6);
GL.glBegin(GL.GL_QUADS);
GL.glVertex3f(-1, 1, 0);
GL.glVertex3f(1, 1, 0);
GL.glVertex3f(1, -1, 0);
GL.glVertex3f(-1, -1, 0);
GL.glEnd();
}
var resize = function(canvas) {
canvas.setCurrent();
var rect = canvas.getClientArea();
var width = rect.width;
var height = Math.max(rect.height, 1);
GL.glViewport(0, 0, width, height);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
var aspect = width / height;
GLU.gluPerspective(45, aspect, 0, 400);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
}
var drawTorus = function(r, R, nsides, rings) {
var ringDelta = 2.0 * Math.PI / rings;
var sideDelta = 2.0 * Math.PI / nsides;
var theta = 0.0;
var cosTheta = 1.0
var sinTheta = 0.0;
for (var i = rings - 1; i >= 0; i--) {
var theta1 = theta + ringDelta;
var cosTheta1 = Math.cos(theta1);
var sinTheta1 = Math.sin(theta1);
GL.glBegin(GL.GL_QUAD_STRIP);
var phi = 0.0;
for (var j = nsides; j >= 0; j--) {
phi += sideDelta;
var cosPhi = Math.cos(phi);
var sinPhi = Math.sin(phi);
var dist = R + r * cosPhi;
GL.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 *
cosPhi, sinPhi);
GL.glVertex3f(cosTheta1 * dist, -sinTheta1 *
dist, r * sinPhi);
GL.glNormal3f(cosTheta * cosPhi, -sinTheta *
cosPhi, sinPhi);
GL.glVertex3f(cosTheta * dist, -sinTheta *
dist, r * sinPhi);
}
GL.glEnd();
theta = theta1;
cosTheta = cosTheta1;
sinTheta = sinTheta1;
}
}
var shell = new Shell(display);
shell.setLayout(new FillLayout());
var data = new GLData();
data.doubleBuffer = true;
var canvas = new GLCanvas(shell, SWT.NONE, data);
canvas.addControlListener(new ControlAdapter({
controlResized: function(e) {
resize(canvas);
}
}));
init(canvas);
var rot = 0;
display.asyncExec(new java.lang.Runnable({
run: function() {
if (canvas.isDisposed()) return;
if (!canvas.isDisposed()) {
canvas.setCurrent();
GL.glClear(GL.GL_COLOR_BUFFER_BIT |
GL.GL_DEPTH_BUFFER_BIT);
GL.glClearColor(.3, .5, .8, 1.0);
GL.glLoadIdentity();
GL.glTranslatef(0.0, 0.0, -10.0);
var frot = rot;
GL.glRotatef(0.15 * rot, 2.0 * frot,
10.0 * frot, 1.0);
GL.glRotatef(0.3 * rot, 3.0 * frot, 1.0
* frot, 1.0);
rot++;
GL.glPolygonMode(GL.GL_FRONT_AND_BACK,
GL.GL_LINE);
GL.glColor3f(0.9, 0.9, 0.9);
drawTorus(1, 1.9 + Math.sin(0.004 *
frot), 15, 15);
canvas.swapBuffers();
display.asyncExec(this);
//canvas.getDisplay().timerExec(10,
this);
}
}
}));
shell.setText("Javascript OpenGL in SWT/OGL");
shell.setSize(640, 480);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
They behave the same. The behavior is quite stable, some machine
always work, otherwise always fail.
It's hard to believe the script behaves differently in JVMs from
different machines.
All execute with JDK/JRE 1.6.0_* and rhino1_7R2
org.mozilla.javascript.tools.shell.Main
Maybe someone can help you, but you might need to provide more
information.
Thanks for your willing to help. Do tell me if anyone need any
information about this issue. :)
Terry
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino