aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java2
-rw-r--r--src/newt/classes/jogamp/newt/ScreenImpl.java2
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java28
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidDisplay.java (renamed from src/newt/classes/jogamp/newt/driver/android/Display.java)51
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java133
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java (renamed from src/newt/classes/jogamp/newt/driver/android/Window.java)0
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/MD.java29
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/NEWTSurfaceView.java45
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java56
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/Screen.java59
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/SurfaceCallback.java54
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java12
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/test/GearsGL2ES1.java422
13 files changed, 691 insertions, 202 deletions
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index d98e55bd8..dc07bd180 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -57,7 +57,7 @@ public abstract class DisplayImpl extends Display {
Class displayClass = NewtFactory.getCustomClass(type, "Display");
if(null==displayClass) {
if (NativeWindowFactory.TYPE_ANDROID.equals(type)) {
- displayClass = Class.forName("jogamp.newt.driver.android.Display");
+ displayClass = Class.forName("jogamp.newt.driver.android.AndroidDisplay");
} else if (NativeWindowFactory.TYPE_EGL.equals(type)) {
displayClass = Class.forName("jogamp.newt.driver.kd.KDDisplay");
} else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java
index d1ed10aaf..45899f08d 100644
--- a/src/newt/classes/jogamp/newt/ScreenImpl.java
+++ b/src/newt/classes/jogamp/newt/ScreenImpl.java
@@ -70,7 +70,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
Class screenClass = NewtFactory.getCustomClass(type, "Screen");
if(null==screenClass) {
if (NativeWindowFactory.TYPE_ANDROID.equals(type)) {
- screenClass = Class.forName("jogamp.newt.driver.android.Screen");
+ screenClass = Class.forName("jogamp.newt.driver.android.AndroidScreen");
} else if (NativeWindowFactory.TYPE_EGL.equals(type)) {
screenClass = Class.forName("jogamp.newt.driver.kd.KDScreen");
} else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 71d36e905..e03c4553e 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -141,7 +141,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
Class windowClass = NewtFactory.getCustomClass(type, "Window");
if(null==windowClass) {
if (NativeWindowFactory.TYPE_ANDROID.equals(type)) {
- windowClass = Class.forName("jogamp.newt.driver.android.Window");
+ windowClass = Class.forName("jogamp.newt.driver.android.AndroidWindow");
} else if (NativeWindowFactory.TYPE_EGL.equals(type)) {
windowClass = Class.forName("jogamp.newt.driver.kd.KDWindow");
} else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
@@ -262,12 +262,16 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(screenReferenceAdded) {
throw new InternalError("XXX");
}
- screen.addReference();
- screenReferenceAdded = true;
- createNativeImpl();
+ if(canCreateNativeImpl()) {
+ screen.addReference();
+ screenReferenceAdded = true;
+ createNativeImpl();
+ screen.addScreenModeListener(screenModeListenerImpl);
+ setTitleImpl(title);
+ }
+ // always flag visible,
+ // allowing to retry if visible && 0 == windowHandle
setVisibleImpl(true, x, y, width, height);
- screen.addScreenModeListener(screenModeListenerImpl);
- setTitleImpl(title);
}
} finally {
if(null!=parentWindow) {
@@ -357,6 +361,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// Window: Native implementation
//
+ protected boolean canCreateNativeImpl() {
+ return true; // default: always able to be created
+ }
+
/**
* The native implementation must set the native windowHandle.<br>
*
@@ -595,8 +603,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(0==windowHandle && visible) {
if( 0<width*height ) {
nativeWindowCreated = createNative();
- WindowImpl.this.waitForVisible(visible, true);
- madeVisible = visible;
+ if(nativeWindowCreated) {
+ WindowImpl.this.waitForVisible(visible, true);
+ madeVisible = visible;
+ }
}
} else if(WindowImpl.this.visible != visible) {
if(0 != windowHandle) {
@@ -2077,7 +2087,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// ee.printStackTrace();
}
- if(isNativeValid()) {
+ if(isValid()) {
if(0>width) {
width=this.width;
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/Display.java b/src/newt/classes/jogamp/newt/driver/android/AndroidDisplay.java
index e1944276f..1ba40f189 100644
--- a/src/newt/classes/jogamp/newt/driver/android/Display.java
+++ b/src/newt/classes/jogamp/newt/driver/android/AndroidDisplay.java
@@ -30,19 +30,20 @@ package jogamp.newt.driver.android;
import jogamp.newt.*;
import jogamp.opengl.egl.*;
+
import javax.media.nativewindow.*;
import javax.media.nativewindow.egl.*;
-import android.content.Context;
+import javax.media.opengl.GLException;
-public class Display extends jogamp.newt.DisplayImpl {
+import android.content.Context;
+import android.view.Surface;
- /*package*/ Context appContext;
-
+public class AndroidDisplay extends jogamp.newt.DisplayImpl {
static {
NEWTJNILibLoader.loadNEWT();
- if (!Window.initIDs()) {
- throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs");
+ if (!AndroidWindow.initIDs()) {
+ throw new NativeWindowException("Failed to initialize Android NEWT Windowing library");
}
}
@@ -51,29 +52,47 @@ public class Display extends jogamp.newt.DisplayImpl {
}
- public Display() {
+ public AndroidDisplay() {
}
protected void createNativeImpl() {
- long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight);
- if (handle == EGL.EGL_NO_DISPLAY) {
- throw new NativeWindowException("BC EGL CreateDisplay failed");
+ // EGL Device
+ // final long eglDisplay = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
+ final long eglDisplay = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
+ if (eglDisplay == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("Failed to created EGL default display: error 0x"+Integer.toHexString(EGL.eglGetError()));
+ } else if(DEBUG) {
+ System.err.println("Android Display.createNativeImpl: eglDisplay(EGL_DEFAULT_DISPLAY): 0x"+Long.toHexString(eglDisplay));
+ }
+ if (!EGL.eglInitialize(eglDisplay, null, null)) {
+ throw new GLException("eglInitialize failed eglDisplay 0x"+Long.toHexString(eglDisplay)+", error 0x"+Integer.toHexString(EGL.eglGetError()));
}
- aDevice = new EGLGraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ aDevice = new EGLGraphicsDevice(eglDisplay, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
}
protected void closeNativeImpl() {
if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
- DestroyDisplay(aDevice.getHandle());
+ EGL.eglTerminate(aDevice.getHandle());
}
}
protected void dispatchMessagesNative() {
// n/a .. DispatchMessages();
}
-
- private native long CreateDisplay(int width, int height);
- private native void DestroyDisplay(long dpy);
- private native void DispatchMessages();
+
+ public synchronized boolean setAppContext(Context ctx) {
+ if(null == appContext) {
+ appContext = ctx;
+ return true;
+ } else if(appContext != ctx) {
+ throw new RuntimeException("AppContext already set to "+appContext+", can't override w/ "+ctx);
+ }
+ return false;
+ }
+ public synchronized Context getAppContext() {
+ return appContext;
+ }
+
+ private Context appContext;
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java b/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java
new file mode 100644
index 000000000..34092e885
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package jogamp.newt.driver.android;
+
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.DimensionReadOnly;
+import javax.media.nativewindow.util.SurfaceSize;
+
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.util.MonitorMode;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.util.DisplayMetrics;
+import android.view.Surface;
+import android.view.WindowManager;
+
+public class AndroidScreen extends jogamp.newt.ScreenImpl {
+
+ static {
+ AndroidDisplay.initSingleton();
+ }
+
+ public AndroidScreen() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() { }
+
+ public synchronized boolean setAppContext(Context ctx) {
+ if(!((AndroidDisplay) getDisplay()).setAppContext(ctx)) {
+ return false;
+ }
+ final WindowManager wmgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
+ sm = getScreenMode(wmgr.getDefaultDisplay());
+ setScreenSize(sm.getMonitorMode().getSurfaceSize().getResolution().getWidth(),
+ sm.getMonitorMode().getSurfaceSize().getResolution().getHeight());
+ return true;
+ }
+ public synchronized Context getAppContext() {
+ return ((AndroidDisplay) getDisplay()).getAppContext();
+ }
+
+ protected ScreenMode getCurrentScreenModeImpl() {
+ return sm;
+ }
+
+ ScreenMode sm = null;
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ static DimensionReadOnly getScreenSize(DisplayMetrics outMetrics) {
+ return new Dimension(outMetrics.widthPixels, outMetrics.heightPixels);
+ }
+ static SurfaceSize getSurfaceSize(android.view.Display aDisplay, DimensionReadOnly dim) {
+ int bpp;
+ switch(aDisplay.getPixelFormat()) {
+ case PixelFormat.RGBA_8888: bpp=32; break;
+ case PixelFormat.RGBX_8888: bpp=32; break;
+ case PixelFormat.RGB_888: bpp=24; break;
+ case PixelFormat.RGB_565: bpp=16; break;
+ case PixelFormat.RGBA_5551: bpp=16; break;
+ case PixelFormat.RGBA_4444: bpp=16; break;
+ case PixelFormat.RGB_332: bpp= 8; break;
+ default: bpp=32;
+ }
+ return new SurfaceSize(dim, bpp);
+ }
+ static DimensionReadOnly getScreenSizeMM(DisplayMetrics outMetrics) {
+ final float iw = (float) outMetrics.widthPixels / outMetrics.xdpi;
+ final float ih = (float) outMetrics.heightPixels / outMetrics.xdpi;
+ final float mmpi = 25.4f;
+ return new Dimension((int) ((iw * mmpi)+0.5), (int) ((ih * mmpi)+0.5));
+ }
+ static int getRotation(int androidRotation) {
+ int nrot;
+ switch(androidRotation) {
+ case Surface.ROTATION_270: nrot = ScreenMode.ROTATE_270; break;
+ case Surface.ROTATION_180: nrot = ScreenMode.ROTATE_180; break;
+ case Surface.ROTATION_90: nrot = ScreenMode.ROTATE_90; break;
+ case Surface.ROTATION_0:
+ default: nrot = ScreenMode.ROTATE_0;
+ }
+ return nrot;
+ }
+ static ScreenMode getScreenMode(android.view.Display aDisplay) {
+ final DisplayMetrics outMetrics = new DisplayMetrics();
+ aDisplay.getMetrics(outMetrics);
+
+ final DimensionReadOnly screenSize = getScreenSize(outMetrics);
+ final SurfaceSize surfaceSize = getSurfaceSize(aDisplay, screenSize);
+ final DimensionReadOnly screenSizeMM = getScreenSizeMM(outMetrics);
+ final int refreshRate = (int) aDisplay.getRefreshRate();
+ final MonitorMode mm = new MonitorMode(surfaceSize, screenSizeMM, refreshRate);
+
+ final int rotation = getRotation(aDisplay.getRotation());
+ return new ScreenMode(mm, rotation);
+ }
+
+
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/android/Window.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
index 4d66debef..4d66debef 100644
--- a/src/newt/classes/jogamp/newt/driver/android/Window.java
+++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
diff --git a/src/newt/classes/jogamp/newt/driver/android/MD.java b/src/newt/classes/jogamp/newt/driver/android/MD.java
index 9a2ed9824..06f787233 100644
--- a/src/newt/classes/jogamp/newt/driver/android/MD.java
+++ b/src/newt/classes/jogamp/newt/driver/android/MD.java
@@ -27,6 +27,11 @@
*/
package jogamp.newt.driver.android;
+import java.util.List;
+
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+
import com.jogamp.common.GlueGenVersion;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.VersionUtil;
@@ -36,9 +41,25 @@ public class MD {
public static final String TAG = "JogAmp.NEWT";
public static String getInfo() {
- return VersionUtil.getPlatformInfo()+Platform.NEWLINE+
- GlueGenVersion.getInstance()+Platform.NEWLINE+
- JoglVersion.getInstance()+Platform.NEWLINE+
- Platform.NEWLINE;
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append(VersionUtil.getPlatformInfo()).append(Platform.NEWLINE)
+ .append(GlueGenVersion.getInstance()).append(Platform.NEWLINE)
+ .append(JoglVersion.getInstance()).append(Platform.NEWLINE)
+ .append(Platform.NEWLINE);
+
+ final GLDrawableFactory factory = GLDrawableFactory.getEGLFactory();
+ final List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null);
+ for(int i=0; i<availCaps.size(); i++) {
+ sb.append(availCaps.get(i)).append(Platform.NEWLINE);
+ }
+
+ return sb.toString();
}
+
+ public static void main(String args[]) {
+
+ System.err.println(getInfo());
+ }
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/NEWTSurfaceView.java b/src/newt/classes/jogamp/newt/driver/android/NEWTSurfaceView.java
deleted file mode 100644
index 0a2cfcf05..000000000
--- a/src/newt/classes/jogamp/newt/driver/android/NEWTSurfaceView.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Copyright 2011 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.newt.driver.android;
-
-import android.content.Context;
-import android.view.SurfaceView;
-
-public class NEWTSurfaceView extends SurfaceView {
-
- SurfaceCallback scb;
-
- public NEWTSurfaceView(Context context) {
- super(context);
- scb = new SurfaceCallback();
- this.getHolder().addCallback(scb);
- }
-
- public void doSomething() {
- }
-}
diff --git a/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java b/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java
index b9452e44b..96ca8514f 100644
--- a/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java
+++ b/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java
@@ -27,21 +27,55 @@
*/
package jogamp.newt.driver.android;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.opengl.GLWindow;
+import jogamp.newt.driver.android.test.GearsGL2ES1;
+import com.jogamp.opengl.util.Animator;
+
+import jogamp.newt.driver.android.AndroidWindow;
+
import android.app.Activity;
import android.os.Bundle;
-import android.widget.TextView;
import android.util.Log;
public class NewtVersionActivity extends Activity {
- TextView tv = null;
-
+ AndroidWindow window = null;
+ GLWindow glWindow = null;
+ Animator animator = null;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(MD.TAG, "onCreate - S");
super.onCreate(savedInstanceState);
- tv = new TextView(this);
- tv.setText("need launcher");
- setContentView(tv);
+
+ System.setProperty("nativewindow.debug", "all");
+ System.setProperty("jogl.debug", "all");
+ System.setProperty("newt.debug", "all");
+ System.setProperty("jogamp.debug.JNILibLoader", "true");
+ System.setProperty("jogamp.debug.NativeLibrary", "true");
+ // System.setProperty("jogamp.debug.NativeLibrary.Lookup", "true");
+
+ GLProfile.initSingleton(true);
+
+ GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES1));
+ // caps.setRedBits(5); caps.setGreenBits(6); caps.setBlueBits(5);
+ AndroidDisplay display = (AndroidDisplay) NewtFactory.createDisplay(null);
+ AndroidScreen screen = (AndroidScreen) NewtFactory.createScreen(display, 0);
+ screen.setAppContext(this.getApplicationContext());
+
+ window = (AndroidWindow) NewtFactory.createWindow(new Object[] { this }, screen, caps);
+ setContentView(window.getView());
+
+ glWindow = GLWindow.create(window);
+ glWindow.addGLEventListener(new GearsGL2ES1(1));
+ glWindow.setVisible(true);
+ animator = new Animator(glWindow);
+ animator.setUpdateFPSFrames(1, null);
+
Log.d(MD.TAG, "onCreate - X");
}
@@ -63,6 +97,9 @@ public class NewtVersionActivity extends Activity {
public void onResume() {
Log.d(MD.TAG, "onResume - S");
super.onResume();
+ if(null != animator) {
+ animator.start();
+ }
Log.d(MD.TAG, "onResume - X");
}
@@ -70,6 +107,9 @@ public class NewtVersionActivity extends Activity {
public void onPause() {
Log.d(MD.TAG, "onPause - S");
super.onPause();
+ if(null != animator) {
+ animator.pause();
+ }
Log.d(MD.TAG, "onPause - X");
}
@@ -83,7 +123,9 @@ public class NewtVersionActivity extends Activity {
@Override
public void onDestroy() {
Log.d(MD.TAG, "onDestroy - S");
- super.onDestroy();
+ super.onDestroy();
+ glWindow.destroy();
+ window.destroy();
Log.d(MD.TAG, "onDestroy - X");
}
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/Screen.java b/src/newt/classes/jogamp/newt/driver/android/Screen.java
deleted file mode 100644
index 44c7ca95f..000000000
--- a/src/newt/classes/jogamp/newt/driver/android/Screen.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright 2011 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-
-package jogamp.newt.driver.android;
-
-import javax.media.nativewindow.*;
-import android.content.Context;
-
-public class Screen extends jogamp.newt.ScreenImpl {
-
- static {
- Display.initSingleton();
- }
-
-
- public Screen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- // WINDOW_SERVICEUse with getSystemService(String) to retrieve a WindowManager for accessing
- setScreenSize(fixedWidth, fixedHeight);
- }
-
- protected void closeNativeImpl() { }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- static final int fixedWidth = 1920;
- static final int fixedHeight = 1080;
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/android/SurfaceCallback.java b/src/newt/classes/jogamp/newt/driver/android/SurfaceCallback.java
deleted file mode 100644
index f953fe41d..000000000
--- a/src/newt/classes/jogamp/newt/driver/android/SurfaceCallback.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright 2011 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.newt.driver.android;
-
-import jogamp.common.os.android.MD;
-import android.view.SurfaceHolder;
-import android.view.SurfaceHolder.Callback2;
-import android.util.Log;
-
-public class SurfaceCallback implements Callback2 {
-
- public void surfaceCreated(SurfaceHolder holder) {
- Log.d(MD.TAG, "surfaceCreated");
- }
-
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {
- Log.d(MD.TAG, "surfaceChanged: f "+Integer.toString(format)+", "+width+"x"+height);
- }
-
- public void surfaceDestroyed(SurfaceHolder holder) {
- Log.d(MD.TAG, "surfaceDestroyed");
- }
-
- public void surfaceRedrawNeeded(SurfaceHolder holder) {
- Log.d(MD.TAG, "surfaceRedrawNeeded");
- }
-
-}
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
index ef59cd4ad..75b9f8642 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
@@ -30,7 +30,7 @@ package jogamp.newt.driver.android.event;
import com.jogamp.common.util.IntIntHashMap;
-class AndroidNewtEventFactory {
+public class AndroidNewtEventFactory {
protected static final IntIntHashMap eventTypeANDROID2NEWT;
@@ -56,7 +56,7 @@ class AndroidNewtEventFactory {
eventTypeANDROID2NEWT = map;
}
- public static final int androidKeyCode2Newt(int androidKeyCode) {
+ static final int androidKeyCode2Newt(int androidKeyCode) {
//safest ...but ugly
if (android.view.KeyEvent.KEYCODE_0 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_0;
if (android.view.KeyEvent.KEYCODE_1 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_1;
@@ -100,7 +100,7 @@ class AndroidNewtEventFactory {
return 0;
}
- static final com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) {
int type = eventTypeANDROID2NEWT.get(event.getEventType());
if(0xFFFFFFFF != type) {
return new com.jogamp.newt.event.WindowEvent(type, ((null==newtSource)?null:(Object)newtSource), event.getEventTime());
@@ -108,7 +108,7 @@ class AndroidNewtEventFactory {
return null; // no mapping ..
}
- public static final int androidKeyModifiers2Newt(int androidMods) {
+ static final int androidKeyModifiers2Newt(int androidMods) {
int newtMods = 0;
if ((androidMods & android.view.KeyEvent.META_SYM_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK;
if ((androidMods & android.view.KeyEvent.META_SHIFT_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK;
@@ -117,7 +117,7 @@ class AndroidNewtEventFactory {
return newtMods;
}
- static final com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent event, com.jogamp.newt.Window newtSource) {
int type = eventTypeANDROID2NEWT.get(event.getAction());
if(0xFFFFFFFF != type) {
return new com.jogamp.newt.event.KeyEvent(
@@ -128,7 +128,7 @@ class AndroidNewtEventFactory {
return null;
}
- static final com.jogamp.newt.event.MouseEvent createMouseEvent(android.view.MotionEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.MouseEvent createMouseEvent(android.view.MotionEvent event, com.jogamp.newt.Window newtSource) {
int type = eventTypeANDROID2NEWT.get(event.getAction());
if(0xFFFFFFFF != type) {
int rotation = 0;
diff --git a/src/newt/classes/jogamp/newt/driver/android/test/GearsGL2ES1.java b/src/newt/classes/jogamp/newt/driver/android/test/GearsGL2ES1.java
new file mode 100644
index 000000000..1a4e16112
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/android/test/GearsGL2ES1.java
@@ -0,0 +1,422 @@
+
+package jogamp.newt.driver.android.test;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import com.jogamp.opengl.util.ImmModeSink;
+
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.MouseAdapter;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+
+/**
+ * Gears.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21
+ */
+
+public class GearsGL2ES1 implements GLEventListener {
+ private final float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
+ private final float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
+ private final float green[] = { 0.0f, 0.8f, 0.2f, 0.7f };
+ private final float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
+
+ private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
+ private GearBuffers gear1=null, gear2=null, gear3=null;
+ private float angle = 0.0f;
+ private int swapInterval;
+
+ private int prevMouseX, prevMouseY;
+
+ public GearsGL2ES1(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public GearsGL2ES1() {
+ this.swapInterval = 1;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ System.err.println("Gears: Init: "+drawable);
+ // Use debug pipeline
+ // drawable.setGL(new DebugGL(drawable.getGL()));
+
+ GL _gl = drawable.getGL();
+ // GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl /*, true*/);
+ GL2ES1 gl = _gl.getGL2ES1();
+
+ System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
+ System.err.println("INIT GL IS: " + gl.getClass().getName());
+ System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
+ System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
+ System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
+
+ gl.glLightfv(GL2ES1.GL_LIGHT0, GL2ES1.GL_POSITION, pos, 0);
+ gl.glEnable(GL.GL_CULL_FACE);
+ gl.glEnable(GL2ES1.GL_LIGHTING);
+ gl.glEnable(GL2ES1.GL_LIGHT0);
+ gl.glEnable(GL2ES1.GL_DEPTH_TEST);
+
+ /* make the gears */
+ if(null == gear1) {
+ gear1 = gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
+ System.err.println("gear1 created: "+gear1);
+ } else {
+ System.err.println("gear1 reused: "+gear1);
+ }
+
+ if(null == gear2) {
+ gear2 = gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
+ System.err.println("gear2 created: "+gear2);
+ } else {
+ System.err.println("gear2 reused: "+gear2);
+ }
+
+ if(null == gear3) {
+ gear3 = gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
+ System.err.println("gear3 created: "+gear3);
+ } else {
+ System.err.println("gear3 reused: "+gear3);
+ }
+
+ gl.glEnable(GL2ES1.GL_NORMALIZE);
+
+ // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter());
+ MouseListener gearsMouse = new GearsMouseAdapter();
+ KeyListener gearsKeys = new GearsKeyAdapter();
+
+ if (drawable instanceof Window) {
+ Window window = (Window) drawable;
+ window.addMouseListener(gearsMouse);
+ window.addKeyListener(gearsKeys);
+ } /* else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) drawable;
+ new AWTMouseAdapter(gearsMouse).addTo(comp);
+ new AWTKeyAdapter(gearsKeys).addTo(comp);
+ } */
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height);
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ gl.setSwapInterval(swapInterval);
+
+ float h = (float)height / (float)width;
+
+ gl.glMatrixMode(GL2ES1.GL_PROJECTION);
+
+ gl.glLoadIdentity();
+ gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
+ gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0.0f, 0.0f, -40.0f);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ System.err.println("Gears: Dispose");
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ // Turn the gears' teeth
+ angle += 2.0f;
+
+ // Get the GL corresponding to the drawable we are animating
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ gl.glClear(GL2ES1.GL_COLOR_BUFFER_BIT | GL2ES1.GL_DEPTH_BUFFER_BIT);
+
+ gl.glNormal3f(0.0f, 0.0f, 1.0f);
+
+ // Rotate the entire assembly of gears based on how the user
+ // dragged the mouse around
+ gl.glPushMatrix();
+ gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
+ gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
+ gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
+
+ final boolean disableBufferAfterDraw = true;
+
+ // Place the first gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(-3.0f, -2.0f, 0.0f);
+ gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
+ gl.glMaterialfv(GL2ES1.GL_FRONT_AND_BACK, GL2ES1.GL_AMBIENT_AND_DIFFUSE, red, 0);
+ gear1.draw(gl, disableBufferAfterDraw);
+ gl.glPopMatrix();
+
+ // Place the second gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(3.1f, -2.0f, 0.0f);
+ gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
+ gl.glMaterialfv(GL2ES1.GL_FRONT_AND_BACK, GL2ES1.GL_AMBIENT_AND_DIFFUSE, green, 0);
+ gear2.draw(gl, disableBufferAfterDraw);
+ gl.glPopMatrix();
+
+ // Place the third gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(-3.1f, 4.2f, 0.0f);
+ gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
+ gl.glMaterialfv(GL2ES1.GL_FRONT_AND_BACK, GL2ES1.GL_AMBIENT_AND_DIFFUSE, blue, 0);
+ gear3.draw(gl, disableBufferAfterDraw);
+ gl.glPopMatrix();
+
+ // Remember that every push needs a pop; this one is paired with
+ // rotating the entire gear assembly
+ gl.glPopMatrix();
+ }
+
+ static class GearBuffers {
+ public final ImmModeSink frontFace;
+ public final ImmModeSink frontSide;
+ public final ImmModeSink backFace;
+ public final ImmModeSink backSide;
+ public final ImmModeSink outwardFace;
+ public final ImmModeSink insideRadiusCyl;
+
+ public GearBuffers(
+ ImmModeSink frontFace,
+ ImmModeSink frontSide,
+ ImmModeSink backFace,
+ ImmModeSink backSide,
+ ImmModeSink outwardFace,
+ ImmModeSink insideRadiusCyl) {
+ this.frontFace = frontFace;
+ this.frontSide = frontSide;
+ this.backFace = backFace;
+ this.backSide = backSide;
+ this.outwardFace = outwardFace;
+ this.insideRadiusCyl = insideRadiusCyl;
+ }
+
+ public void draw(GL2ES1 gl, boolean disableBufferAfterDraw) {
+ gl.glShadeModel(GL2ES1.GL_FLAT);
+ frontFace.draw(gl, disableBufferAfterDraw);
+ frontSide.draw(gl, disableBufferAfterDraw);
+ backFace.draw(gl, disableBufferAfterDraw);
+ backSide.draw(gl, disableBufferAfterDraw);
+ outwardFace.draw(gl, disableBufferAfterDraw);
+ gl.glShadeModel(GL2ES1.GL_SMOOTH);
+ insideRadiusCyl.draw(gl, disableBufferAfterDraw);
+ }
+ }
+
+ public static GearBuffers gear(GL2ES1 gl,
+ float inner_radius,
+ float outer_radius,
+ float width,
+ int teeth,
+ float tooth_depth)
+ {
+ final float dz = width * 0.5f;
+ int i;
+ float r0, r1, r2;
+ float angle, da;
+ float u, v, len;
+
+ r0 = inner_radius;
+ r1 = outer_radius - tooth_depth / 2.0f;
+ r2 = outer_radius + tooth_depth / 2.0f;
+
+ da = 2.0f * (float) Math.PI / teeth / 4.0f;
+
+ /* draw front face */
+ ImmModeSink vboFrontFace = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 4*teeth+2,
+ /* vertex */ 3, GL.GL_FLOAT, /* color */ 0, GL.GL_FLOAT,
+ /* normal */ 0, GL.GL_BYTE, /* texture */ 0, GL.GL_FLOAT);
+ vboFrontFace.glBegin(GL.GL_TRIANGLE_STRIP);
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ vboFrontFace.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), dz);
+ vboFrontFace.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), dz);
+ vboFrontFace.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), dz);
+ vboFrontFace.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), dz);
+ }
+ vboFrontFace.glVertex3f(r0 * (float)Math.cos(0f), r0 * (float)Math.sin(0f), dz);
+ vboFrontFace.glVertex3f(r1 * (float)Math.cos(0f), r1 * (float)Math.sin(0f), dz);
+ vboFrontFace.glEnd(gl, false /* immediate */);
+
+ /* draw front sides of teeth */
+ ImmModeSink vboFrontSide = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 6*teeth,
+ /* vertex */ 3, GL.GL_FLOAT, /* color */ 0, GL.GL_FLOAT,
+ /* normal */ 0, GL.GL_FLOAT, /* texture */ 0, GL.GL_FLOAT);
+ vboFrontSide.glBegin(GL.GL_TRIANGLES);
+ for (i = 0; i < teeth; i++) {
+ // QUAD [s0..s3] -> 2x TRIs
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ // s0
+ vboFrontSide.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), dz);
+ // s1
+ vboFrontSide.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), dz);
+ // s2
+ vboFrontSide.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), dz);
+
+ // s0
+ vboFrontSide.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), dz);
+ // s2
+ vboFrontSide.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), dz);
+ // s3
+ vboFrontSide.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), dz);
+ }
+ vboFrontSide.glEnd(gl, false /* immediate */);
+
+ /* draw back face */
+ ImmModeSink vboBackFace = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 4*teeth+2,
+ /* vertex */ 3, GL.GL_FLOAT, /* color */ 0, GL.GL_FLOAT,
+ /* normal */ 0, GL.GL_FLOAT, /* texture */ 0, GL.GL_FLOAT);
+ vboBackFace.glBegin(GL.GL_TRIANGLE_STRIP);
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ vboBackFace.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -dz);
+ vboBackFace.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -dz);
+ vboBackFace.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -dz);
+ vboBackFace.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -dz);
+ }
+ vboBackFace.glVertex3f(r1 * (float)Math.cos(0f), r1 * (float)Math.sin(0f), -dz);
+ vboBackFace.glVertex3f(r0 * (float)Math.cos(0f), r0 * (float)Math.sin(0f), -dz);
+ vboBackFace.glEnd(gl, false /* immediate */);
+
+ /* draw back sides of teeth */
+ ImmModeSink vboBackSide = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 6*teeth,
+ /* vertex */ 3, GL.GL_FLOAT, /* color */ 0, GL.GL_FLOAT,
+ /* normal */ 0, GL.GL_FLOAT, /* texture */ 0, GL.GL_FLOAT);
+ vboBackSide.glBegin(GL.GL_TRIANGLES);
+ for (i = 0; i < teeth; i++) {
+ // QUAD [s0..s3] -> 2x TRIs
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ // s0
+ vboBackSide.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -dz);
+ // s1
+ vboBackSide.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -dz);
+ // s2
+ vboBackSide.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -dz);
+
+ // s0
+ vboBackSide.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -dz);
+ // s2
+ vboBackSide.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -dz);
+ // s3
+ vboBackSide.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -dz);
+ }
+ vboBackSide.glEnd(gl, false /* immediate */);
+
+ /* draw outward faces of teeth */
+ ImmModeSink vboOutwardFace = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 4*4*teeth,
+ /* vertex */ 3, GL.GL_FLOAT, /* color */ 0, GL.GL_FLOAT,
+ /* normal */ 3, GL.GL_FLOAT, /* texture */ 0, GL.GL_FLOAT);
+ vboOutwardFace.glBegin(GL.GL_TRIANGLE_STRIP);
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle);
+ v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle);
+ len = (float)Math.sqrt(u * u + v * v);
+ u /= len;
+ v /= len;
+
+ vboOutwardFace.glNormal3f(v, -u, 0.0f);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), dz);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -dz);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 1 * da), r2 * (float)Math.sin(angle + 1 * da), dz);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 1 * da), r2 * (float)Math.sin(angle + 1 * da), -dz);
+
+ vboOutwardFace.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 1 * da), r2 * (float)Math.sin(angle + 1 * da), dz);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 1 * da), r2 * (float)Math.sin(angle + 1 * da), -dz);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), dz);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -dz);
+
+ u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da);
+ v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da);
+ vboOutwardFace.glNormal3f(v, -u, 0.0f);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), dz);
+ vboOutwardFace.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -dz);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), dz);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -dz);
+
+ vboOutwardFace.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), dz);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -dz);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), dz);
+ vboOutwardFace.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -dz);
+ }
+ vboOutwardFace.glEnd(gl, false /* immediate */);
+
+ /* draw inside radius cylinder */
+ ImmModeSink vboInsideRadiusCyl = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 2*teeth+2,
+ /* vertex */ 3, GL.GL_FLOAT, /* color */ 0, GL.GL_FLOAT,
+ /* normal */ 3, GL.GL_FLOAT, /* texture */ 0, GL.GL_FLOAT);
+ vboInsideRadiusCyl.glBegin(GL.GL_TRIANGLE_STRIP);
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ vboInsideRadiusCyl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f);
+ vboInsideRadiusCyl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -dz);
+ vboInsideRadiusCyl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), dz);
+ }
+ vboInsideRadiusCyl.glNormal3f(-(float)Math.cos(0f), -(float)Math.sin(0f), 0.0f);
+ vboInsideRadiusCyl.glVertex3f(r0 * (float)Math.cos(0f), r0 * (float)Math.sin(0f), -dz);
+ vboInsideRadiusCyl.glVertex3f(r0 * (float)Math.cos(0f), r0 * (float)Math.sin(0f), dz);
+ vboInsideRadiusCyl.glEnd(gl, false /* immediate */);
+ return new GearBuffers(vboFrontFace, vboFrontSide, vboBackFace, vboBackSide, vboOutwardFace, vboInsideRadiusCyl);
+ }
+
+ class GearsKeyAdapter extends KeyAdapter {
+ public void keyPressed(KeyEvent e) {
+ int kc = e.getKeyCode();
+ if(KeyEvent.VK_LEFT == kc) {
+ view_roty -= 1;
+ } else if(KeyEvent.VK_RIGHT == kc) {
+ view_roty += 1;
+ } else if(KeyEvent.VK_UP == kc) {
+ view_rotx -= 1;
+ } else if(KeyEvent.VK_DOWN == kc) {
+ view_rotx += 1;
+ }
+ }
+ }
+
+ class GearsMouseAdapter extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ prevMouseX = e.getX();
+ prevMouseY = e.getY();
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+ int width=0, height=0;
+ Object source = e.getSource();
+ if(source instanceof Window) {
+ Window window = (Window) source;
+ width=window.getWidth();
+ height=window.getHeight();
+ } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) source;
+ width=comp.getWidth();
+ height=comp.getHeight();
+ } else {
+ throw new RuntimeException("Event source neither Window nor Component: "+source);
+ }
+ float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
+ float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
+
+ prevMouseX = x;
+ prevMouseY = y;
+
+ view_rotx += thetaX;
+ view_roty += thetaY;
+ }
+ }
+}