I'm going to post my entire source code as it stands right now in the
hope that someone with more experience than I can
get me pointed in the right direction. I've been trying lots of
different things. Feel free to use caps lock when expressing
discontent
with my code :')

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.MyLiveWallpaper;



imports are all square. --Not included:

public class MyLiveWallpaper extends GLWallpaperService implements
SensorEventListener  {

    private final Handler mHandler = new Handler();
    SensorManager sm = null;

    private static final String TAG = "Compass";


    private final Paint mPaint = new Paint();
    private float mTouchX = -1;
    private float mTouchY = -1;

    public GLSurfaceView mGLSurfaceView;


    private float mOffset;

    @Override
    public void onCreate() {
        super.onCreate();
        sm = (SensorManager) getSystemService(SENSOR_SERVICE);
        sm.registerListener(this,
sm.getDefaultSensor(Sensor.TYPE_ORIENTATION) ,
SensorManager.SENSOR_DELAY_GAME);
      mGLSurfaceView = new GLSurfaceView(this);
         //Do I need this here?


    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public Engine onCreateEngine() {
        return new GLEngine();
    }
 // THE CLASS BELOW THIS WORKS IN AN ACTIVITY
    public class OpenGLRenderer implements GLSurfaceView.Renderer {
        private Square square;
        private float angle = 45f;
        public OpenGLRenderer() {
                // Initialize our square.
                square = new Square();
        }
        /*
         * (non-Javadoc)
         *
         * @see
         *
android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition
         * .khronos.opengles.GL10,
javax.microedition.khronos.egl.EGLConfig)
         */
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {

                gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

                gl.glShadeModel(GL10.GL_SMOOTH);

                gl.glClearDepthf(1.0f);

                gl.glEnable(GL10.GL_DEPTH_TEST);

                gl.glDepthFunc(GL10.GL_LEQUAL);

                gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

        }

        /*
         * (non-Javadoc)
         *
         * @see
         *
android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.
         * khronos.opengles.GL10)
         */
        public void onDrawFrame(GL10 gl) {

                gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

                gl.glLoadIdentity();

                // Translates 4 units into the screen.
                gl.glTranslatef(0, 0, -4);
                //

                gl.glPushMatrix();
                gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);

                gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f);

                square.draw(gl);
                gl.glPopMatrix();

                angle++;
        }

        /*
         * (non-Javadoc)
         *
         * @see
         *
android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition
         * .khronos.opengles.GL10, int, int)
         */
        public void onSurfaceChanged(GL10 gl, int width, int height) {


                gl.glViewport(0, 0, width, height);

                gl.glMatrixMode(GL10.GL_PROJECTION);

                gl.glLoadIdentity();

                GLU.gluPerspective(gl, 45.0f, (float) width / (float) height,
0.1f,
                                100.0f);

                gl.glMatrixMode(GL10.GL_MODELVIEW);

                gl.glLoadIdentity();
        }
    }

    class CubeEngine extends GLEngine {
         private SurfaceHolder mSurfaceHolder;

        private long mStartTime;
        private float mCenterX;
        private float mCenterY;

        private final Runnable mDrawCube = new Runnable() {
            public void run() {
                drawFrame();
//CHECK OUT drawFrame() --Am I doing things correctly there?

            }
        };
        private boolean mVisible;


        CubeEngine() {


                 mGLSurfaceView = new GLSurfaceView(MyLiveWallpaper.this);
                    //The Line Above this is probably horribly
incorrect.
                 mGLSurfaceView.setRenderer(new OpenGLRenderer());
 
mGLSurfaceView.setRenderMode(RENDERMODE_CONTINUOUSLY);
            //I'm not sure this is the correct place
           //Should this go in OnCreate()?

        }

        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);
            this.mSurfaceHolder = surfaceHolder;

            // By default we don't get touch events, so enable them.
            setTouchEventsEnabled(true);
        }
        @Override
        public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
            super.onSurfaceChanged(holder, format, width, height);


        }

        @Override
        public void onSurfaceCreated(SurfaceHolder holder) {
            super.onSurfaceCreated(holder);

        }

        @Override
        public void onSurfaceDestroyed(SurfaceHolder holder) {
            super.onSurfaceDestroyed(holder);

        }

        @Override
        public void onOffsetsChanged(float xOffset, float yOffset,
                float xStep, float yStep, int xPixels, int yPixels) {

        }

        /*
         * Store the position of the touch event so we can use it for
drawing later
         */

        @Override
        public void onTouchEvent(MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_MOVE) {
                mTouchX = event.getX();
                mTouchY = event.getY();
            } else {
                mTouchX = -1;
                mTouchY = -1;
            }


                super.onTouchEvent(event);
        }

        void drawFrame() {
            final SurfaceHolder holder = getSurfaceHolder();

            Canvas c = null;
            try {
                c = holder.lockCanvas();
                if (c != null) {
                    // draw something

                }
            } finally {
                if (c != null) holder.unlockCanvasAndPost(c);
            }

            // Reschedule the next redraw
            mHandler.removeCallbacks(mDrawCube);
            if (mVisible) {
                mHandler.postDelayed(mDrawCube, 1000 / 25);
            }
        }


        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }

        @Override
        public void onSensorChanged(SensorEvent event) {
                // TODO Auto-generated method stub
                Sensor mySensor = event.sensor;

                mValues[0] = event.values[0];
                mValues[1] = event.values[1];
                mValues[2] = event.values[2];


        }

                }





        Thanks for any analysis!

I'm extending the code found here:
http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers



On Feb 14, 4:19 am, joshbeck <[email protected]> wrote:
> I was afraid you might say that:
> I've gone through and incorporated GLWallpaperService per his
> instructions, but specifically I'm getting hung up here:
> --QUOTE--
> In your GLEngine subclass, instantiate your Renderer, configure it and
> set it using setRenderer(Renderer) and setRenderMode(int).
> --/QUOTE--
> (http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-
> wallpapers)
>
> Logcat is throwing a null pointer exception at line 79 in
> GLWallpaperService.java which reads as follows:
>     ---LOGCAT ERROR--
> @Override
> public void onSurfaceCreated(SurfaceHolder holder) {
> Log.d(TAG, "onSurfaceCreated()");
> mGLThread.surfaceCreated(holder);     <--Right Here Line 79
> super.onSurfaceCreated(holder);}
>
>    ---END LOGCAT ERROR---
>
> The following class works perfectly within an Activity for me:
>                --BEGIN CLASS--
>  public class OpenGLRenderer implements Renderer {
>            //Should it be GLSurfaceView.Renderer? <--
>
>         private Square square;
>         private float angle = 45f;
>         public OpenGLRenderer() {
>
>                 square = new Square();
>                 //I have a square class that defines verts and
> such.
>  }
>
>         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
>                 --Clear the screen and prep it--
>                 }
>
>         public void onDrawFrame(GL10 gl) {
>                 --This function draws and rotates my object--
>         }
> public void onSurfaceChanged(GL10 gl, int width, int height) {
>
>                 --The code I have here also checks out in an Activity--
>         }
>     }
>
>                      ---END CLASS---
>
> -My Initial class extends GLWallpaperService --onCreate() as
> follows:--
>
>   public void onCreate() {
>  GLSurfaceView mGLSurfaceView = new GLSurfaceView(this);
>      //I have a feeling this is misplaced.
>
> }
>
> --My subclass extends GLEngine--
>
> class CubeEngine extends GLEngine {
>         private final Runnable mDrawCube = new Runnable() {
>             public void run() {
>                 //Does Nothing ATM
>             }
>         };
>         private boolean mVisible;
>
>         CubeEngine() {
>             //Blank Constructor
>         }
>
>         @Override
>         public void onCreate(SurfaceHolder surfaceHolder) {
>             super.onCreate(surfaceHolder);
>
>            mGLSurfaceView.setRenderer(new OpenGLRenderer());
>                 //This setRenderer is what I need help with.
>
>             // By default we don't get touch events, so enable them.
>             setTouchEventsEnabled(true);
>         }
>
>                --I don't think I need to override the
>                  things like onSurfaceChanged here, because
>                  I think that my OpenGLRenderer Class
>                  handles that, or at least it should.  --
>
> Thanks for being patient with me. I'll sort it all out in time I'm
> sure.
> Just getting an OpenGL object to work correctly in a regular Activity
> was
> a giant leap!
>
> Josh Beck
> Northeast ISD
> Humble Android Apprentice.
>
> On Feb 14, 3:03 am, Lance Nanek <[email protected]> wrote:
>
>
>
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > On Feb 14, 3:06 am, joshbeck <[email protected]> wrote:
>
> > > Hello all,
>
> > > I can construct an Activity that utilized OpenGL to draw a square, set
> > > properties, and
> > > make it rotate around a fixed point by implementing
> > > android.opengl.GLSurfaceView,Renderer
> > > and configuring:
>
> > > public void onSurfaceCreated(GL10 gl, EGLConfig config) {}
>
> > > public void onDrawFrame(GL10 gl) {}
>
> > > public void onSurfaceChanged(GL10 gl, int width, int height) {}
>
> > > -----Separately----
>
> > > I can construct a live wallpaper by drawing an image (Bitmap) to a
> > > Canvas
> > > as specified at:
>
> > >http://developer.android.com/resources/samples/CubeLiveWallpaper/inde...
>
> > > My Question:
>
> > > I'm trying to figure out how to create a GLSurface and draw to it
> > > within a Live Wallpaper.
> > > I'm all about doing research. So, any advice is appreciated.
>
> > > The Simple Cube wallpaper demo Google provided was VERY helpful.
> > > I think a lot of folks would like to see something along those except
> > > with an OpenGL cube in mind.
>
> > > --Much appreciated. I'm totally new to OpenGL.
>
> > > Josh Beck

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to