简体   繁体   English

为什么OpenGL在某些手机上运行而不在其他手机上运行?

[英]Why does OpenGL run on some phones but not on others?

I have the following code for my Renderer: 我的渲染器具有以下代码:

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); 
    }
}

On the emulator, it works perfect. 在模拟器上,它可以完美运行。 I used an Xperia Play for debugging, and also tried it on an HTC xplorer and Galaxy Nexus, and it worked. 我使用Xperia Play进行调试,并在HTC xplorer和Galaxy Nexus上进行了尝试,并且可以正常工作。 2day i tried it on a Samsung Galaxy and an HTC phone but the SurfaceView did not show nothing, it was blank, any ideeas why this could happen? 2day我在三星银河和HTC手机上尝试过,但是SurfaceView没有显示任何内容,它是空白的,为什么会发生这种情况?

使图片的尺寸为2的幂并知道它是否有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有一个使用NDK的应用程序,当我尝试在某些手机上运行它而在其他手机上运行它时,它可以完美运行 - I have an application, that uses the NDK, and it works perfect when I try to run it on some phones, but not on others 在某些电话上出现NullPointerException,而不是其他电话(相同的API级别) - NullPointerException on some phones, not others (same API level) 为什么 ping 在某些设备上有效,而在其他设备上无效? - Why does ping works on some devices and not others? 为什么某些手机不支持GCM? - Why GCM is not coming on some phones? Android绝对布局在某些手机上看起来不错,但在其他手机上却不行吗? - Android Absolute Layout looks good on some phones but not others? 在联系人上设置 custom_ringtone 适用于某些 android 手机,而不适用于其他手机 - Setting custom_ringtone on contact works on some android phones and not others 为什么这个 GLSL 着色器可以在某些硬件上运行,而在其他硬件上不行? - Why does this GLSL shader works on some hardware but not on others? 某些手机​​上的OpenGL ES 2.0灯光非常暗 - OpenGL ES 2.0 light is very darker on some phones WebView在某些手机上不显示已加载的HTML - WebView does not display loaded Html on some phones 为什么 Android 应用在某些手机上看起来不一样 - Why Android app looks different in some phones
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM