【发布时间】:2012-04-25 05:56:47
【问题描述】:
我最近开发了一个动态壁纸应用程序。在那我发现我的安卓动态壁纸有一个奇怪的问题。我使用我的 HTC Wildfire S、三星 Galaxy 标签、摩托罗拉 Droid Millstone、三星 Galaxy pop 来测试我的壁纸和模拟器,一切正常,但在三星手机上(三星 Galaxy S II 和三星 Galaxy Player 有症状)初始启动时屏幕保持黑色。但是一旦我们移动到设置屏幕并返回预览它的工作正常。在对这些手机进行一些调试后,我发现壁纸正确加载,但纹理不只是显示出来。我尝试搜索该问题,但没有发现任何有用的信息。
我从本机代码中绑定纹理。在那使用 OPEN GL 库绑定壁纸。我的 opengl 库启动如下
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textureConverted);
glBindTexture(GL_TEXTURE_2D,textureConverted);
//...and bind it to our array
__android_log_print(ANDROID_LOG_DEBUG,
"NDK initOpenGL()",
"binded texture"
);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
//GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
//GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, /* target */
0, /* level */
GL_RGBA, /* internal format */
textureWidth, /* width */
textureHeight, /* height */
0, /* border */
GL_RGBA, /* format */
GL_UNSIGNED_BYTE,/* type */
NULL);
//setup simple shading
glShadeModel(GL_FLAT);
//check_gl_error("glShademo_comdel");
glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
在我的drawFunction中
glClear(GL_COLOR_BUFFER_BIT);
int max;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
__android_log_print(ANDROID_LOG_DEBUG,
"NDK drawFrame()",
"GL_MAX_TEXTURE_SIZE: %d",
max);
glBindTexture(GL_TEXTURE_2D,textureConverted);
int rect[4] = {0, textureHeight, textureWidth, nTextureHeight};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
glTexSubImage2D(GL_TEXTURE_2D, /* target */
0, /* level */
0, /* xoffset */
0, /* yoffset */
textureWidth,
textureHeight,
GL_RGBA, /* format */
GL_UNSIGNED_BYTE, /* type */
pFrameConverted->data[0]);
glDrawTexiOES(0, 0, 0, drawWidth, drawHeight); //drawWidth is th screenwidth and drawheight is the screenheight
为什么这不适用于三星手机?
【问题讨论】:
-
将 glGetError 放入代码中,看看它是否命中任何东西。您可能会超过 GL_MAX_TEXTURE_SIZE,但不能确定。
-
我尝试在我的代码中使用 glGetError() 函数。它总是返回 0。所以我认为那里没有问题。
-
你需要给我们更多细节:textureWidth和textureHeight的值是多少。向我们展示加载纹理位图的代码和使用 glTexSubmage 的代码..
-
@Renard 现在您可以获得我的代码中使用的 glTexSubmage 的详细信息。 textureWidth 和 textureHeight 的值是 256*256, 512*512..
-
您的代码乍一看还不错。您是否尝试过使用 GLSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);?
标签: android opengl-es live-wallpaper samsung-mobile