我正在使用openGL ES 2.0创建一个活壁纸。这个应用程序在我的nexus中运行得很好,但是它没有在Nexus中显示任何东西。
到目前为止我已经测试过的东西:
checkGlError方法,我发现它没有问题地传递onSurfaceCreated和onSurfaceChanged。如果在onDrawFrame()方法.的第一行中调用该方法,则该方法将引发异常。
checkGlError代码如下:
private void checkGlError(String op) {
int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
Log.e(TAG, op + ": glError " + error);
throw new RuntimeException(op + ": glError " + error);
}
}我注意到错误发生在两个设备中,但它在nexus S中看起来很关键,而在nexus one中绘制得很好。我的猜测是,着色器没有被正确编译,并且存在一个问题。
你知道附件S和附件1之间的其他不相容之处吗?有办法调试着色器的代码吗?
发布于 2011-09-22 17:44:57
最后,我的问题与this question有关。
当从资源读取时,Android调整了我的纹理大小。我解决了它从原始文件夹读取纹理的问题:
public void loadBitmap(int resourceId) {
textureId = resourceId;
/* Get the texture */
InputStream is = mContext.getResources().openRawResource(textureId);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
} finally {
try {
is.close();
} catch (IOException e) {
// Ignore.
}
}
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Buffer data = ByteBuffer.allocateDirect(width * height * 4);
bitmap.copyPixelsToBuffer(data);
data.position(0);
// Bind the texture object
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(0));
...
// OpenGL stuff
...
}发布于 2011-07-25 16:45:48
你知道附件S和附件1之间的其他不兼容吗?
这不是我所知道的,虽然OpenGL的ES驱动程序在不同的电话中也有不同的可能性。
有一种调试着色器代码的方法吗?
我自己还没有尝试过着色器,但是,我可以通过在我的GLSurfaceView上进行调试来检查常规的翻译、旋转等等。
尝试在您的GLSurfaceView上设置以下内容,并检查是否能够看到LogCat中的更改:
mGLSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR
| GLSurfaceView.DEBUG_LOG_GL_CALLS);https://stackoverflow.com/questions/6818362
复制相似问题