简体   繁体   English

Android OpenGL应用程序第二次启动时显示白屏

[英]Android OpenGL app display white screen when launch the second time

My game displays texture correctly in the first launch, then I exit and launch it again and display nothing but white screen. 我的游戏在第一次启动时正确显示纹理,然后退出并再次启动它,只显示白色屏幕。 I think there are some problems with texture loading and android activity life-cycle such as clean up things when pause or destroy. 我认为纹理加载和android活动生命周期存在一些问题,例如在暂停或破坏时清理东西。 The funny thing is it only display white screen when i run it, but display perfectly well when i debug. 有趣的是它在运行时只显示白屏,但是在调试时显示得很好。 Please give me some of your advice, thank you. 请给我您的一些建议,谢谢。

My experience so far: 到目前为止的经验:

  • Create your textures in power of two and make sure you scale and clip them to the right ratio when you draw. 以2的幂次创建纹理,并确保在绘制时按比例缩放和裁剪它们。
  • Don't stick to RBGA_8888 when you can do ALPHA_8 (text rendering) 当您可以执行ALPHA_8(文本渲染)时,请勿坚持使用RBGA_8888
  • Do whatever you can do in OnSurfaceCreated before you get called in OnSurfaceDraw 在OnSurfaceDraw中被调用之前,请执行在OnSurfaceCreated中可以做的一切
  • Avoid the GL11 context cast. 避免GL11上下文强制转换。 Some things won't work eg glColor4ub will compile but not work. 有些事情不起作用,例如glColor4ub可以编译但不起作用。
  • Balance your calls of enable and disable for each component draw your call into your scene graph. 平衡每个组件的启用和禁用调用,将您的调用绘制到场景图中。
  • Pre-allocate your nio buffers 预分配您的Nio缓冲区
  • Use DrawElements but for the simplest shapes of one vertice 使用DrawElements,但要获得一个顶点的最简单形状
  • Test on as many devices as you can. 在尽可能多的设备上进行测试。 Just don't settle for the emulator eg non power of twos work on emulator but not on the phone. 只是不要满足于仿真器,例如,不能在仿真器上使用合二为一的功能,而不能在电话上使用。
  • If you can then use the on demand drawing. 如果可以,则可以使用按需工程图。
  • Use the trick of putting a wait in the onTouchEvent call for 20ms and a notify in your onDraw to reduce the deluge of motion events you have to process. 使用这样的技巧:在onTouchEvent调用中等待20毫秒,然后在onDraw中发出通知,以减少必须处理的运动事件。 You can bypass onTouchEven and use a lower call to save some cycles as well. 您可以绕过onTouchEven并使用较低的调用来节省一些周期。
  • Use texture atlas as much as you can eg to draw score and text or animations 尽可能多地使用纹理图集,例如绘制乐谱和文本或动画
  • Disable the fancy rendering options (DITHER_TEST etc...) Unless you crave a realistic rendering on textures. 除非您想在纹理上实现逼真的渲染,否则请禁用奇特的渲染选项(DITHER_TEST等...)。
  • If you draw in 2D, then disable the DEPTH_TEST 如果以2D绘制,则禁用DEPTH_TEST
  • Don't forget the Bitmap.recycle() call when you are done binding your textures. 完成绑定纹理后,请不要忘记Bitmap.recycle()调用。
  • Avoid Object creation destruction (PointF Rect) in your rendering routines. 避免在渲染例程中破坏对象创建(PointF Rect)。 GC calls will slow down your frame rate. GC调用会降低您的帧速率。
  • Preload your textures extensively. 大量预加载纹理。 don't wait until you draw at the last minute to bind your textures. 不要等到最后一刻绘制以绑定纹理。 The lag is noticable if you do so it's better at app start up time. 如果您这样做的话,延迟会很明显,这样可以在应用启动时更好。

You should use the onPause and onResume methods, if its not solving the problem I will add more suggestions. 您应该使用onPause和onResume方法,如果不能解决问题,我会添加更多建议。 I had the same problem a few months ago. 几个月前我遇到了同样的问题。

@Override
protected void onPause() {
    super.onPause();

    mGLView.onPause();
}

@Override
protected void onResume() {
    super.onResume();

    mGLView.onResume();
}

Ok then maybe: 好吧,也许吧:

public void onSurfaceChanged(GL10 gl, int w, int h) {
    gl.glViewport(0, 0, w, h);
}

Are you reloading the textures in onSurfaceCreated() or in another place? 您是在onSurfaceCreated()还是在其他地方重新加载纹理? You'll want to have that stuff in onSurfaceCreated(). 您将需要在onSurfaceCreated()中拥有这些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM