2013-11-28 72 views
0

我的代碼在這裏我aplication已經開始活動

/** 
* GLExample java 
    */ 
import android.app.Activity; 
    import android.opengl.GLSurfaceView; 
    import android.os.Bundle; 

    /** 
    * @author pream 
    * 
    */ 
    public class GLExample extends Activity{ 



    GLSurfaceView oursurface; 

    /* (non-Javadoc) 
    * @see android.app.Activity#onCreate(android.os.Bundle) 
    */ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 

     oursurface = new GLSurfaceView(this); 

     oursurface.setRenderer(new GLRendererEx()); 

     setContentView(oursurface); 
    } 



    /* (non-Javadoc) 
    * @see android.app.Activity#onPause() 
    */ 
    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 

     oursurface.onPause(); 
    } 




    /* (non-Javadoc) 
    * @see android.app.Activity#onResume() 
    */ 
    @Override 
    protected void onResume() { 
     // TODO Auto-generated method stub 
     super.onResume(); 

     oursurface.onResume(); 
    } 



    } 

    ** 

GLRendererEX ***/

前停止0
package net.sourceforge.users.shafiul; 

    import javax.microedition.khronos.egl.EGLConfig; 
    import javax.microedition.khronos.opengles.GL10; 

    import android.opengl.GLSurfaceView.Renderer; 
    import android.opengl.GLU; 


    public class GLRendererEx implements Renderer { 


    private GLTriangleEx tri; 



    public void GLRendererEx() { 

     tri = new GLTriangleEx(); 



    } 


    public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) { 
     // TODO Auto-generated method stub 

     gl.glDisable(GL10.GL_DITHER);  //boosting performances 
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); 

     gl.glClearColor(.8f, 0f, .2f, 1f);//red,green&blue,alpha for transparency 

     gl.glClearDepthf(1f); 

     //gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    } 

    public void onDrawFrame(GL10 gl) { 

     // TODO Auto-generated method stub 

     gl.glDisable(GL10.GL_DITHER); 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);//masking.handling colour buffer 
     //camera to look into 

     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 

     GLU.gluLookAt(gl, 0, 0, -5, 0, 0, 0, 0, 2, 0); 
     //GLU.gluLookAt(gl, 0, 0, -23, 0, 0, 0, 0, 2, 0); 
     //GLU.gluLookAt(gl, 0, 0, -30, 0, 0, 0, 0, 2, 0); 

     tri.draw(gl); 
    } 

    public void onSurfaceChanged(GL10 gl, int width, int height) { 
     // TODO Auto-generated method stub 


     //viewport settings 

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

     float ratio = (float) width/height; 

     gl.glMatrixMode(GL10.GL_PROJECTION); 
     gl.glLoadIdentity(); 

     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 25);    

    } 


} 

/** 

*

GLTraingle.java

import java.nio.ByteBuffer; 
import java.nio.ByteOrder; 
import java.nio.FloatBuffer; 
import java.nio.ShortBuffer; 

import javax.microedition.khronos.opengles.GL10; 

/** 
* @author pream 
* 
*/ 
public class GLTriangleEx { 

    private float vertices[]={ 

      0f , 1f , //p0 
      1f ,-1f, //p2 
      -1f,-1f //p3 
    }; 

    private FloatBuffer vertBuff; 
    private short[] pIndex = {0,1,2}; 

    private ShortBuffer pBuff; 

    public GLTriangleEx() 
{ 
     ByteBuffer bBuff = ByteBuffer.allocateDirect(vertices.length*4);//how much 
     bBuff.order(ByteOrder.nativeOrder()); 

     vertBuff =bBuff.asFloatBuffer(); 
     vertBuff.put(vertices); 
     vertBuff.position(0); 


     ByteBuffer pbBuff = ByteBuffer.allocateDirect(pIndex.length*2); 

     pbBuff.order(ByteOrder.nativeOrder()); 

     pBuff = pbBuff.asShortBuffer(); 
     pBuff.put(pIndex); 
     pBuff.position(0); 

} 


    public void draw(GL10 gl) { 

     gl.glFrontFace(GL10.GL_CW); //clockwise 
     gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 

     gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertBuff);//size-2d object,type,stride,buffr pointer. 

     gl.glDrawElements(GL10.GL_TRIANGLES, pIndex.length,GL10.GL_UNSIGNED_SHORT, pBuff);// mode,count,type,indices 
     gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 


    } 
} 

這是我的logcat ..please幫我...

11-28 13:56:22.209: D/dalvikvm(855): GC_FOR_ALLOC freed 42K, 4% free 2549K/2640K, paused 74ms, total 78ms 
11-28 13:56:22.219: I/dalvikvm-heap(855): Grow heap (frag case) to 3.451MB for 960016-byte allocation 
11-28 13:56:22.309: D/dalvikvm(855): GC_FOR_ALLOC freed <1K, 3% free 3486K/3580K, paused 85ms, total 85ms 
11-28 13:56:23.049: D/gralloc_goldfish(855): Emulator without GPU emulation detected. 
11-28 13:56:50.079: D/dalvikvm(855): GC_FOR_ALLOC freed 943K, 25% free 3021K/4028K, paused 97ms, total 108ms 
11-28 13:56:50.369: I/Choreographer(855): Skipped 30 frames! The application may be doing too much work on its main thread. 
11-28 13:56:50.619: I/Choreographer(855): Skipped 149 frames! The application may be doing too much work on its main thread. 
11-28 13:56:50.909: I/Choreographer(855): Skipped 63 frames! The application may be doing too much work on its main thread. 
11-28 13:56:51.169: I/Choreographer(855): Skipped 69 frames! The application may be doing too much work on its main thread. 
11-28 13:56:51.649: I/Choreographer(855): Skipped 49 frames! The application may be doing too much work on its main thread. 
11-28 13:56:51.819: I/Choreographer(855): Skipped 48 frames! The application may be doing too much work on its main thread. 
11-28 13:56:51.919: I/Choreographer(855): Skipped 49 frames! The application may be doing too much work on its main thread. 
11-28 13:57:07.889: D/dalvikvm(855): GC_FOR_ALLOC freed 11K, 13% free 3506K/4028K, paused 149ms, total 168ms 
11-28 13:57:08.059: D/dalvikvm(855): GC_FOR_ALLOC freed 444K, 15% free 3463K/4028K, paused 98ms, total 99ms 
11-28 13:57:08.099: I/Choreographer(855): Skipped 298 frames! The application may be doing too much work on its main thread. 
11-28 13:57:08.905: I/Choreographer(855): Skipped 43 frames! The application may be doing too much work on its main thread. 
11-28 13:57:08.999: I/Choreographer(855): Skipped 49 frames! The application may be doing too much work on its main thread. 
11-28 13:57:09.338: I/Choreographer(855): Skipped 44 frames! The application may be doing too much work on its main thread. 
11-28 13:57:09.479: I/Choreographer(855): Skipped 49 frames! The application may be doing too much work on its main thread. 
11-28 13:57:09.599: I/Choreographer(855): Skipped 48 frames! The application may be doing too much work on its main thread. 
11-28 13:57:09.689: I/Choreographer(855): Skipped 49 frames! The application may be doing too much work on its main thread. 
11-28 13:57:10.119: I/Choreographer(855): Skipped 48 frames! The application may be doing too much work on its main thread. 
11-28 13:57:10.209: I/Choreographer(855): Skipped 47 frames! The application may be doing too much work on its main thread. 
11-28 13:57:10.289: I/Choreographer(855): Skipped 48 frames! The application may be doing too much work on its main thread. 
11-28 13:57:11.139: I/Choreographer(855): Skipped 100 frames! The application may be doing too much work on its main thread. 
11-28 13:57:11.159: D/libEGL(855): Emulator without GPU support detected. Fallback to software renderer. 
11-28 13:57:11.239: D/libEGL(855): loaded /system/lib/egl/libGLES_android.so 
11-28 13:57:11.639: W/dalvikvm(855): threadid=11: thread exiting with uncaught exception (group=0x414c4700) 
11-28 13:57:11.639: E/AndroidRuntime(855): FATAL EXCEPTION: GLThread 82 
11-28 13:57:11.639: E/AndroidRuntime(855): java.lang.NullPointerException 
11-28 13:57:11.639: E/AndroidRuntime(855): at net.sourceforge.users.shafiul.GLRendererEx.onDrawFrame(GLRendererEx.java:54) 
11-28 13:57:11.639: E/AndroidRuntime(855): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523) 
11-28 13:57:11.639: E/AndroidRuntime(855): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 
11-28 13:57:13.439: I/Choreographer(855): Skipped 64 frames! The application may be doing too much work on its main thread. 
11-28 13:57:16.929: I/Process(855): Sending signal. PID: 855 SIG: 9 
+0

發佈完整的堆棧跟蹤。 – Subbu

+0

無效的例外 - 行54.我不能幫助,直到你告訴我哪些是在上面的代碼54行,因爲你無法看到這裏,因爲你在ECLIPSE –

+0

請幫助我在這裏新,@Rahul Gupta – user3047137

回答

1

你當您在onDrawFrame(GL10 gl)方法中調用.draw()方法時,10對象似乎爲空。沒有太多的其他可能性,這可能會給你一個空行。

我不知道你的應用程序應該做什麼,但從GLRendererEx類的構造函數中刪除void。構造函數不能返回void

這是你的構造應該是怎樣的樣子:

public GLRendererEx() { 

    tri = new GLTriangleEx(); 

} 

void關鍵字實質上被阻塞你的構造函數被調用,因爲它無法識別爲一個構造函數。 構造函數沒有明確的返回類型(所以沒有void或其他)。

+0

對不起,有任何建議,請 – user3047137

+0

刪除GLRendererEx構造函數中的'void'。我將編輯我的評論並添加正確的構造函數。 –

+0

已經糾正它,對於給您帶來的不便表示歉意..工作..謝謝。保持良好的工作 – user3047137

相關問題