某些手机​​上无法加载纹理

发布于 2024-12-31 23:09:20 字数 4801 浏览 5 评论 0原文

我有几个用户报告他们的屏幕上出现白色块,我不确定是什么导致了这个问题。它似乎在大多数手机上工作正常,但我不确定问题是什么。 (已知不适用于 Galaxy Nexus 和 Droid Pro,但在我原来的 Droid 上运行良好)。我只是被难住了,下面是我的代码和用户发布的问题的屏幕截图。知道是什么原因造成的吗?它是用 ES 1.1 编写的。未加载的是透明的 png,使用

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

在此处输入图像描述

代码绘制:

 public class MenuButton {
    AssetManager assetManager;
    GL10 gl;
    // Our vertices.

    //Our texture.
    private float texture[] = {
            //Mapping coordinates for the vertices
            0.0f, 1.0f,
            1.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f, 
    };

    // The order we like to connect them.
    private byte indices[] = {0,1,3,2};


    // Our vertex buffer.
    private FloatBuffer vertexBuffer;

    // Our index buffer.
    private ByteBuffer indexBuffer;

    //texture buffer.
    private FloatBuffer textureBuffer;

    //Our texture pointer.
    private int[] textures = new int[3];


    float width;
    float height;
    public MenuButton(Bitmap graphic,GL10 _gl, int _width, int _height) {
        width=_width;
        height=_height;

        float vertices[] = {
                0f, -_width, 0.0f, //LB
                width, -_width, 0.0f,  //RB
                0, 0, 0.0f,  //LT
                _width, 0.0f, 0.0f,   //RT
            };


        gl=_gl;
        ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
        byteBuf.order(ByteOrder.nativeOrder());
        vertexBuffer = byteBuf.asFloatBuffer();
        vertexBuffer.put(vertices);
        vertexBuffer.position(0);

        //
        byteBuf = ByteBuffer.allocateDirect(texture.length * 4);
        byteBuf.order(ByteOrder.nativeOrder());
        textureBuffer = byteBuf.asFloatBuffer();
        textureBuffer.put(texture);
        textureBuffer.position(0);

        //
        indexBuffer = ByteBuffer.allocateDirect(indices.length);
        indexBuffer.put(indices);
        indexBuffer.position(0);    



        loadGLTexture(0, graphic);

    }

    /**
     * This function draws our square on screen.
     * @param gl
     */
    public void draw(GL10 gl) {
        //Bind our only previously generated texture in this case
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

        //Point to our buffers
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

        //Set the face rotation
        gl.glFrontFace(GL10.GL_CCW);

        //Enable the vertex and texture state
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

        gl.glEnable(GL10.GL_CULL_FACE);
        //Draw the vertices as triangles, based on the Index Buffer information
        gl.glDrawElements(GL10.GL_TRIANGLE_FAN, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);

        // Disable the vertices buffer.
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        //Disable the texture buffer.
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    }
    /**
     * Load the textures
     * 
     * @param gl - The GL Context
     * @param context - The Activity context
     */
    public void destroyTexture() {
        gl.glDeleteTextures(3, textures, 0);
    }
    public void loadGLTexture(int graphicsToLoad,Bitmap bitmap) {


        //Generate three texture pointers...
        gl.glGenTextures(3, textures, 0);
        //...and bind it to our array
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
        //Create Nearest Filtered Texture
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();           
    }
    public boolean amIHit(float[] matrixValues,MotionEvent event) {
        Log.e("sys",""+event.getY());

//      if  (((event.getX())>(0)&&((event.getX()))<5+width)&&((event.getY())>0)&&(event.getY()<width))  {   
        if  (((event.getX()>0)&&(event.getX()<5+width))&&((event.getY()>0)&&(event.getY()<5+height)))   {   
            Log.e("sys","hit menu button.");
            return true;
        }
        Log.e("sys","menu button not hit.");
        return false;       
    }


}

I had a couple user report white blocks on their screens, and im unsure whats causing this issue. It seems to work fine on most phones but im unsure what the problem could be. (known to not be working on the Galaxy Nexus and Droid Pro, but works fine on my original Droid). Im just stumped, below is my code and a screenshot the user posted of the issue. Any idea what could be causing this? Its written in ES 1.1. The ones that arent loading are pngs with transparent being draw with

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

enter image description here

code:

 public class MenuButton {
    AssetManager assetManager;
    GL10 gl;
    // Our vertices.

    //Our texture.
    private float texture[] = {
            //Mapping coordinates for the vertices
            0.0f, 1.0f,
            1.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f, 
    };

    // The order we like to connect them.
    private byte indices[] = {0,1,3,2};


    // Our vertex buffer.
    private FloatBuffer vertexBuffer;

    // Our index buffer.
    private ByteBuffer indexBuffer;

    //texture buffer.
    private FloatBuffer textureBuffer;

    //Our texture pointer.
    private int[] textures = new int[3];


    float width;
    float height;
    public MenuButton(Bitmap graphic,GL10 _gl, int _width, int _height) {
        width=_width;
        height=_height;

        float vertices[] = {
                0f, -_width, 0.0f, //LB
                width, -_width, 0.0f,  //RB
                0, 0, 0.0f,  //LT
                _width, 0.0f, 0.0f,   //RT
            };


        gl=_gl;
        ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
        byteBuf.order(ByteOrder.nativeOrder());
        vertexBuffer = byteBuf.asFloatBuffer();
        vertexBuffer.put(vertices);
        vertexBuffer.position(0);

        //
        byteBuf = ByteBuffer.allocateDirect(texture.length * 4);
        byteBuf.order(ByteOrder.nativeOrder());
        textureBuffer = byteBuf.asFloatBuffer();
        textureBuffer.put(texture);
        textureBuffer.position(0);

        //
        indexBuffer = ByteBuffer.allocateDirect(indices.length);
        indexBuffer.put(indices);
        indexBuffer.position(0);    



        loadGLTexture(0, graphic);

    }

    /**
     * This function draws our square on screen.
     * @param gl
     */
    public void draw(GL10 gl) {
        //Bind our only previously generated texture in this case
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

        //Point to our buffers
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

        //Set the face rotation
        gl.glFrontFace(GL10.GL_CCW);

        //Enable the vertex and texture state
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

        gl.glEnable(GL10.GL_CULL_FACE);
        //Draw the vertices as triangles, based on the Index Buffer information
        gl.glDrawElements(GL10.GL_TRIANGLE_FAN, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);

        // Disable the vertices buffer.
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        //Disable the texture buffer.
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    }
    /**
     * Load the textures
     * 
     * @param gl - The GL Context
     * @param context - The Activity context
     */
    public void destroyTexture() {
        gl.glDeleteTextures(3, textures, 0);
    }
    public void loadGLTexture(int graphicsToLoad,Bitmap bitmap) {


        //Generate three texture pointers...
        gl.glGenTextures(3, textures, 0);
        //...and bind it to our array
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
        //Create Nearest Filtered Texture
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();           
    }
    public boolean amIHit(float[] matrixValues,MotionEvent event) {
        Log.e("sys",""+event.getY());

//      if  (((event.getX())>(0)&&((event.getX()))<5+width)&&((event.getY())>0)&&(event.getY()<width))  {   
        if  (((event.getX()>0)&&(event.getX()<5+width))&&((event.getY()>0)&&(event.getY()<5+height)))   {   
            Log.e("sys","hit menu button.");
            return true;
        }
        Log.e("sys","menu button not hit.");
        return false;       
    }


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必了 2025-01-07 23:09:20

查看此链接,以及使用二次方大小位图的重要性:

http://groups.google.com/group/android-developers/browse_thread/thread/2cb496c5da3b6955?pli=1

也许这是根本问题,有些平台(例如您的 Droid)更宽容,而其他平台(例如您用户的 Galaxy Nexus)则不然。

这是另一种可能性:

Android OpenGL ES 1.1 白盒纹理

您必须启用顶点数组和纹理坐标数组并绑定您的
在调用 glDraw...() 函数之前缓冲索引。

Take a look at this link, and the importance of using power-of-two size bitmaps:

http://groups.google.com/group/android-developers/browse_thread/thread/2cb496c5da3b6955?pli=1

Perhaps this is the underlying problem, and some platforms (like your Droid) are more forgiving, and other platforms (like your user's Galaxy Nexus) aren't.

Here is another possibility:

Android OpenGL ES 1.1 white box textures

You must enable vertex array and texture coords array and bind your
buffer indexes before making any calls to your glDraw...() function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文