2012-07-04 41 views
0

我有我的渲染器下面的代碼:爲什麼OpenGL在某些手機上運行,​​而不是在其他手機上運行?

package hello.project; 

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

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

public class HelloOpenGLES10Renderer implements Renderer { 

    private Square  square; 
    private Square2  square2; 
    private Square3  square3; 
    private SquareAccesories  squareAcc; 
    private SquareEyes  squareEyes; 
    private SquareLips  squareLips; 
    private SquarePants  squarePants; 
    private SquareShoes  squareShoes; 
    private Context  context; 
    //public static int w,h; 


    /** Constructor to set the handed over context */ 
    public HelloOpenGLES10Renderer(Context context) { 
     this.square  = new Square(); 
     this.square2  = new Square2(); 
     this.square3  = new Square3(); 
     this.squareAcc  = new SquareAccesories(); 
     this.squareEyes  = new SquareEyes(); 
     this.squareLips  = new SquareLips(); 
     this.squarePants  = new SquarePants(); 
     this.squareShoes  = new SquareShoes(); 
     this.context=context; 
    } 

    public void onDrawFrame(GL10 gl) { 

     if (Project.ifDraw){ 
      Square.loadGLTexture(gl, this.context,Square.getSex()); 
      Square2.loadGLTexture(gl, this.context,Square2.getHair()); 
      Square3.loadGLTexture(gl, this.context,Square3.getDress()); 
      SquareAccesories.loadGLTexture(gl, this.context,SquareAccesories.getAcc()); 
      SquareEyes.loadGLTexture(gl, this.context,SquareEyes.getEyes()); 
      SquareLips.loadGLTexture(gl, this.context,SquareLips.getLips()); 
      SquarePants.loadGLTexture(gl, this.context,SquarePants.getPants()); 
      SquareShoes.loadGLTexture(gl, this.context,SquareShoes.getShoes()); 
      Project.ifDraw=false; 
     } 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 
     //GLU.gluPerspective(gl, 45.0f, (float)w/(float)h, 0.1f, 100.0f); 
     GLU.gluLookAt(gl, 0, 1, 5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); 
     gl.glColor4f(1.0f, 1.0f, 1.0f, 2.0f); 
     square.draw(gl); 
     square2.draw(gl); 
     square3.draw(gl); 
     squareEyes.draw(gl); 
     squareAcc.draw(gl); 
     squareLips.draw(gl); 
     squareShoes.draw(gl); 
     squarePants.draw(gl); 

     /*// clear Screen and Depth Buffer 
     Square.loadGLTexture(gl, this.context,Square.getSex()); 
     Square2.loadGLTexture(gl, this.context,Square2.getHair()); 
     gl.glColor4f(1.0f, 1.0f, 1.0f, 2.0f); 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

     // Reset the Modelview Matrix 
     gl.glLoadIdentity(); 
     // GLU.gluLookAt(gl, 0, 0, 0, 0, 0, 0, 0, 0, 0); 
     // Drawing 
     gl.glTranslatef(0.0f, 0.0f, -5.0f); // move 5 units INTO the screen 
     square.draw(gl); 
     square2.draw(gl);*/ 
    } 

    public void onSurfaceChanged(GL10 gl, int width, int height) { 
     if(height == 0) {      //Prevent A Divide By Zero By 
      height = 1;       //Making Height Equal One 
     } 

     //w=width; 
     //h=height; 
     //Square.loadGLTexture(gl, this.context,Square.getSex()); 
     //Square2.loadGLTexture(gl, this.context,Square2.getHair()); 
     gl.glViewport(0, 0, width, height);  //Reset The Current Viewport 
     gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix 
     gl.glLoadIdentity();     //Reset The Projection Matrix 

     //Calculate The Aspect Ratio Of The Window 
     GLU.gluPerspective(gl, 45.0f, (float)width/(float)height, 0.1f, 100.0f); 

     gl.glMatrixMode(GL10.GL_MODELVIEW);  //Select The Modelview Matrix 
     gl.glLoadIdentity();     //Reset The Mode lview Matrix 
    } 

    public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     // Load the texture for the square 
     gl.glEnable(GL10.GL_BLEND); 
     gl.glEnable(GL10.GL_TEXTURE_2D); 
     gl.glShadeModel(GL10.GL_FLAT); //Enable Smooth Shading 
     //gl.glEnable(GL10.GL_ALPHA_TEST); 
     gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
     //gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 
     //Square.loadGLTexture(gl, this.context,Square.getSex()); 
     //Square2.loadGLTexture(gl, this.context,Square2.getHair()); 
     //Square3.loadGLTexture(gl, this.context,Square3.getDress()); 
     //SquareAccesories.loadGLTexture(gl, this.context,SquareAccesories.getAcc()); 
     //SquareEyes.loadGLTexture(gl, this.context,SquareEyes.getEyes()); 
     //SquareLips.loadGLTexture(gl, this.context,SquareLips.getLips()); 
     //SquarePants.loadGLTexture(gl, this.context,SquarePants.getPants()); 
     //SquareShoes.loadGLTexture(gl, this.context,SquareShoes.getShoes()); 
     //gl.glAlphaFunc(GL10.GL_GREATER, 0.5f); 

     gl.glDisable(GL10.GL_DEPTH_TEST); 

     gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black Background 
     gl.glClearDepthf(1.0f);  //Depth Buffer Setup 
     gl.glDepthFunc(GL10.GL_NEVER); //The Type Of Depth Testing To Do 

     //Really Nice Perspective Calculations 
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 
    } 
} 

在模擬器上,它可以完美運行。我使用Xperia Play進行調試,並在HTC xplorer和Galaxy Nexus上試用了它,並且工作正常。 2天我在三星Galaxy和HTC手機上試了一下,但SurfaceView沒有顯示任何內容,它是空白的,任何ideeas爲什麼會發生這種情況?

+0

不知道爲什麼這不適合你,但你不應該在繪製方法中加載紋理。在開始繪製和重新使用它們之前預加載它們,這會很好地加快速度。 – Joru

回答

1

使圖片尺寸冪爲2並知道它的工作

相關問題