我是一位长期读者,第一次发布海报,我最近发现我的Android游戏有一个奇怪的问题。我使用我的HTC Desire Z和模拟器一起测试我的游戏并且一切正常,但我的朋友最近告诉我,在三星手机上(至少Galaxy S2和常规Galaxy有症状)屏幕只是保持白色。在用朋友的手机进行了一些调试后,我发现游戏运行正常,但纹理不仅仅是出现了。我试着搜索这个问题,但没有发现任何有用的东西。
纹理是.png,方形和POT。以下是以位图加载开头的相关代码位:
private boolean LoadTextures(GL10 gl) {
if(DEBUG)
Log.d(TAG, "Loading textures.");
bitmaps[0] = R.raw.game;
bitmaps[1] = R.raw.splash;
bitmaps[2] = R.raw.menu;
bitmaps[3] = R.raw.font01;
bitmaps[4] = R.raw.bg;
bitmaps[5] = R.raw.gameover;
bitmaps[6] = R.raw.helpc;
bitmaps[7] = R.raw.helptag;
gl.glGenTextures(NUM_TEXTURES, textures, 0);
for(int i=0; i<NUM_TEXTURES; i++) {
bitmap = BitmapFactory.decodeResource(context.getResources(), bitmaps[i]);
if(bitmap == null)
{
if(DEBUG)
{
Log.w(TAG, "Bitmap decoding failed, aborting.");
return false;
}
}
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_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);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
return true;
}
我的onSurfaceCreated功能:
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
if(DEBUG)
Log.d(TAG, "GLRenderer: Surface created.");
}
我的onSurfaceChanged功能
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(LoadTextures(gl)) // load textures
{
if(DEBUG)
Log.d(TAG, "Textures loaded succesfully.");
}
else
{
if(DEBUG)
Log.w(TAG, "Texture loading failed.");
}
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glLoadIdentity();
gl.glOrthof(-width/2f, width/2f, -height/2f, height/2f, -1, 1);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glFrontFace(GL10.GL_CCW);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glLoadIdentity();
Log.d(TAG, "Set GL modes succesfully.");
}
OnDrawFrame的相关图纸:
gl.glClearColor(0f, 0f, 0f, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glPushMatrix();
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, i.GetBuffers().GetVertexBuffer());
gl.glTranslatef(i.GetXCoordinate(),i.GetYCoordinate(), i.GetZCoordinate());
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i.GetBuffers().GetTextureId()]);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, i.GetBuffers().GetTextureBuffer());
gl.glDrawElements(GL10.GL_TRIANGLES, i.GetBuffers().GetIndicesCount(),
GL10.GL_UNSIGNED_SHORT, i.GetBuffers().GetIndexBuffer());
gl.glPopMatrix();
有关为何三星手机不起作用的任何提示将不胜感激。