1 package org.jwz.xscreensaver;
3 import javax.microedition.khronos.egl.EGLConfig;
4 import javax.microedition.khronos.opengles.GL10;
6 import net.rbgrn.android.glwallpaperservice.*;
7 import android.opengl.GLU;
9 import android.content.Context;
10 import android.content.SharedPreferences;
13 // Original code provided by Robert Green
14 // http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers
15 public class ARenderer implements GLWallpaperService.Renderer {
18 boolean secondRun = false;
21 //private static float[] ambientComponent0 = {0.3f, 0.3f, 1.0f, 1.0f};
22 //private static float[] ambientComponent0 = {0.3f, 0.3f, 0.3f, 1.0f};
23 private static float[] ambientComponent0 = {0.5f, 0.5f, 0.5f, 1.0f};
24 private static float[] diffuseComponent0 = {1.0f, 1.0f, 1.0f, 1.0f};
25 private static float[] lightPosition0 = {1f, 1f, -1f, 0f};
27 public void onDrawFrame(GL10 gl) {
32 //gl.glClearColor(0.2f, 0.6f, 0.2f, 1f);
33 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
36 public void onSurfaceChanged(GL10 gl, int width, int height) {
38 gl.glMatrixMode(GL10.GL_PROJECTION);
40 GLU.gluPerspective(gl, 60f, (float)width/(float)height, 1f, 100f);
42 gl.glMatrixMode(GL10.GL_MODELVIEW);
45 gl.glMatrixMode(GL10.GL_MODELVIEW);
46 gl.glTranslatef(0, 0, -5);
47 gl.glRotatef(30f, 1, 0, 0);
49 gl.glEnable(GL10.GL_LIGHTING);
50 gl.glEnable(GL10.GL_RESCALE_NORMAL);
51 gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
52 //Set the color of light bouncing off of surfaces to respect the surface color
53 gl.glEnable(GL10.GL_COLOR_MATERIAL);
55 setupLightSources(gl);
57 // Turn on a global ambient light. The "Cosmic Background Radiation", if you will.
58 //float[] ambientLightRGB = {0.3f, 0.3f, 0.3f, 1.0f};
59 float[] ambientLightRGB = {0.5f, 0.5f, 0.5f, 1.0f};
60 gl.glLightModelfv(GL10.GL_LIGHT_MODEL_AMBIENT, ambientLightRGB, 0);
61 NonSurfaceChanged(width, height);
64 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
69 cn = new CallNative();
72 gl.glEnable(GL10.GL_DEPTH_TEST);
73 gl.glDepthFunc(GL10.GL_LEQUAL);
75 //Turn on culling, so OpenGL only draws one side of the primitives
76 gl.glEnable(GL10.GL_CULL_FACE);
77 //Define the front of a primitive to be the side where the listed vertexes are counterclockwise
78 gl.glFrontFace(GL10.GL_CCW);
79 //Do not draw the backs of primitives
80 gl.glCullFace(GL10.GL_BACK);
84 private void setupLightSources(GL10 gl) {
88 //Enable Light source 0
89 gl.glEnable(GL10.GL_LIGHT0);
91 //Useful part of the Arrays start a 0
92 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, ambientComponent0, 0);
93 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, diffuseComponent0, 0);
95 //Position the light in the scene
96 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPosition0, 0);
100 * Called when the engine is destroyed. Do any necessary clean up because
101 * at this point your renderer instance is now done for.
103 public void release() {
108 public void NonSurfaceCreated() {
112 void NonSurfaceChanged(int w, int h) {
116 cn.nativeResize(w, h);
119 void NonDrawFrame() {
129 System.loadLibrary ("xscreensaver");