Ошибка текстуры GL на некоторых телефонах - PullRequest
3 голосов
/ 07 декабря 2011

Я обнаружил, что на некоторых телефонах некоторые из моих текстур в моем glSurfaceView не загружаются (просто отображаются белым) после некоторого поиска в Google, я установил setDebugFlags (DEBUG_CHECK_ERROR), чтобы получить следующий журнал ошибок, перечисленный ниже.строка 40 в MenuButton.java:

gl.glGenTextures(1, textures, 0);

, где текстура - это мой указатель текстуры, объявленный как:

private int[] textures = new int[1];

Я озадачен, поскольку я видел эту проблему только с Droid Pro ипара других телефонов, и я не уверен, как gl.glGenTextures будет иметь недопустимое значение.Любые мысли будут полезны.

РЕДАКТИРОВАТЬ: код для кнопки меню размещен ниже.

12-06 17:46:31.720: E/AndroidRuntime(2984): android.opengl.GLException: invalid value
12-06 17:46:31.720: E/AndroidRuntime(2984): at android.opengl.GLErrorWrapper.glGenTextures(GLErrorWrapper.java:350)
12-06 17:46:31.720: E/AndroidRuntime(2984): at com.huskybuspurchased.MenuButton.<init>(MenuButton.java:40)
12-06 17:46:31.720: E/AndroidRuntime(2984): at com.huskybuspurchased.CampusMap.onSurfaceCreated(CampusMap.java:112)
12-06 17:46:31.720: E/AndroidRuntime(2984): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
12-06 17:46:31.720: E/AndroidRuntime(2984): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
12-06 17:46:31.728: I/hb(2984): rendering thread paused.

Картинка вопроса: enter image description here

package com.huskybus;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
import android.graphics.Bitmap;
import android.opengl.GLUtils;
import android.util.Log;
import android.view.MotionEvent;

public class MenuButton {
//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[1];
private int width;
private int height;
private float rotation;
public MenuButton(Bitmap graphic,int _rotation,GL10 gl, int _width, int _height) {
    rotation=_rotation;
    width=_width;
    height=_height;

        //Generate one texture pointer...
        gl.glGenTextures(1, textures, 0);
        //...and bind it to our array
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
        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);
        //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, graphic, 0);
        graphic.recycle();

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

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

/**
 * 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.glRotatef(rotation, 0, 0, 1);
    //Draw the vertices as triangles, based on the Index Buffer information
    gl.glDrawElements(GL10.GL_TRIANGLE_FAN, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
    gl.glRotatef(360-rotation, 0, 0, 1);

    // Disable the vertices buffer.
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    //Disable the texture buffer.
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    // Disable face culling.
    gl.glEnable(GL10.GL_CULL_FACE);
}
public boolean amIHit(float[] matrixValues,MotionEvent event) {
    if  (((event.getX())>(0)&&((event.getX()))<5+width)&&((event.getY())>0)&&(event.getY()<width))  {   
        Log.e("sys","hit menu button.");
        return true;
    }
    return false;       
}

}

Ответы [ 2 ]

2 голосов
/ 10 февраля 2012

glSurfaceView выбирает поверхность для рендеринга, и разные устройства Android поддерживают разные поверхности, и, к сожалению, у нас нет общего подмножества, которое поддерживается всеми.поэтому выбор затруднен.
По умолчанию glSurfaceView пытается найти поверхность, близкую к буферу глубины 16 бит.
Так что вам нужно использовать изображение для вашей цели Текстура с буфером глубины 16 бит или, возможно,24 бит.Изображения с большей битовой глубиной могут вызывать проблемы в некоторых устройствах. !!

0 голосов
/ 07 декабря 2011

Вам не обязательно вызывать glGenTextures. Вы можете дать вашим текстурам любое желаемое числовое значение - glGenTextures просто предназначена для удобства получения номера текстуры, который еще не использовался.

...