opengl glTexParameteri

时间:2011-04-16 18:09:28

标签: android opengl-es draw textures

如何设置opengl以正确使用glTextParameteriv。下面的代码在模拟器中工作,但不是我的htc欲望与cyanogen mod 7.也许有人可以用他自己的手机尝试?

public class GLView extends GLSurfaceView implements GLSurfaceView.Renderer {

public GLView(Context context) {
    super(context);
    setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
    setRenderer(this);
}

int textureID;

@Override
public void onDrawFrame(GL10 gl) {
    gl.glMatrixMode(GL10.GL_MODELVIEW); 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID);        
    ((GL11Ext)gl).glDrawTexfOES(10, 10, 0, 100, 100);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Bitmap bitmap;
    int[] textures;
    InputStream is;

    is = getResources().openRawResource(R.drawable.skater_idle_roll);

    try {
        BitmapFactory.Options sBitmapOptions  = new BitmapFactory.Options();
        // Set our bitmaps to 16-bit, 565 format.
        sBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
        bitmap = BitmapFactory.decodeStream(is, null, sBitmapOptions);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            // Ignore.
        }
    }

    //gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
    gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
    gl.glShadeModel(GL10.GL_FLAT);

    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glDisable(GL10.GL_DITHER);
    gl.glDisable(GL10.GL_LIGHTING);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000);

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    textures = new int[1];
    gl.glGenTextures(1, textures, 0);
    textureID = textures[0];

    int[] crop = new int[4];

    crop[0] = 0;
    crop[1] = bitmap.getHeight();
    crop[2] = bitmap.getWidth();
    crop[3] = -bitmap.getHeight();

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);        

    // here EXCEPTION is thrown
    ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, crop, 0); 
}

}

DDMS Ausgabe:

04-19 20:24:23.225:ERROR / AndroidRuntime(2524):致命异常:GLThread 10 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):android.opengl.GLException:值无效 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):在android.opengl.GLErrorWrapper.checkError(GLErrorWrapper.java:62) 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):在android.opengl.GLErrorWrapper.glTexParameteriv(GLErrorWrapper.java:803) 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):在android.opengl.GLLogWrapper.glTexParameteriv(GLLogWrapper.java:2512) 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):at dk.opengltest.GLView.onSurfaceCreated(GLView.java:93) 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):在android.opengl.GLSurfaceView $ GLThread.guardedRun(GLSurfaceView.java:1348) 04-19 20:24:23.225:ERROR / AndroidRuntime(2524):在android.opengl.GLSurfaceView $ GLThread.run(GLSurfaceView.java:1118)

glDebugFlags处于活动状态。副本岛使用相同的技术绘制作品,所以我想我只是缺少一些东西,但我不知道是什么......

1 个答案:

答案 0 :(得分:1)

我知道我的三星手机处理的纹理与我的Nexus手机不同。我必须确保我的纹理是2的精确幂才能使它正常工作。

查看纹理的分辨率,并将其更改为2,4,8,16,32,64,128,256 ......等等