开发者

opengles glTexParameteriv

how to setup opengl to use glTextParameteriv correct. The following code works in emulator but not on my htc desire with cyanogen mod 7. Maybe someone can try it with his own phone?

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): FATAL EXCEPTION: GLThread 10 04-19 20:24:23.225: ERROR/AndroidRuntime(2524): android.opengl.GLException: invalid value 04-1开发者_如何学JAVA9 20:24:23.225: ERROR/AndroidRuntime(2524): at android.opengl.GLErrorWrapper.checkError(GLErrorWrapper.java:62) 04-19 20:24:23.225: ERROR/AndroidRuntime(2524): at android.opengl.GLErrorWrapper.glTexParameteriv(GLErrorWrapper.java:803) 04-19 20:24:23.225: ERROR/AndroidRuntime(2524): at 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): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348) 04-19 20:24:23.225: ERROR/AndroidRuntime(2524): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

glDebugFlags are active. Replica Island which uses the same technik to draw works, so i think i am just missing something but i don't know what...


I know that my samsung phone handled textures differently than my Nexus one. I had to make sure that my texture was exact powers of 2 in order for it to work correctly.

See what the resolution of your textures are and change them to either be 2,4,8,16,32,64,128,256...etc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜