Android OpenGL 某些纹理未加载/重新加载
我似乎有一个奇怪的问题,在一部手机上,两个纹理根本无法加载,因为它们显示为白色矩形,但是,它们都加载在我的手机上。另一个问题是,恢复游戏后会显示加载屏幕,第一次应用程序暂停时效果很好,但第二次恢复后,纹理不会加载到我的手机上......但是加载屏幕正在加载的纹理都会出现美好的。
所有纹理都是 2 的幂,大小为 024x1024...总共大约有 20 个纹理。
导致该问题类型的原因可能有哪些?
这是重新加载的代码...
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated(gl, config);
if(firstTimeCreate) {
load(); //load settings
Assets.Load(this);
firstTimeCreate = false;
} else {
//When screen is resumed....
Assets.ReloadLoadingScreen();
}
这就是所有内容的所在,这是加载方法...
GL10 gl = glGraphics.getGL();
int[] textureIds = new int[1];
gl.glGenTextures(1, textureIds, 0);
textureId = textureIds[0];
InputStream in = null;
try {
in = fileIO.readAsset(fileName);
Bitmap bitmap = BitmapFactory.decodeStream(in);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
setFilters(GL10.GL_LINEAR , GL10.GL_LINEAR);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
width = bitmap.getWidth();
height = bitmap.getHeight();
bitmap.recycle();
} catch(IOException e) {
throw new RuntimeException("Couldn't load texture '" + fileName +"'", e);
} finally {
if(in != null)
try { in.close(); } catch (IOException e) { }
}
和绑定方法...
public void bind() {
GL10 gl = glGraphics.getGL();
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
}
不认为上面有什么问题,但也许有?
I seem to have a bit of a strange problem, on one phone two textures dont load up at all as they appear as white rectangles, however, they both load on my phone. Another issue is that upon resuming the game a loading screen shows, this works great the first time the app is paused, but after a second resume the texture doesnt load on my phone...however the textures that the loading screen is loading all appear fine.
All textures are by a power of 2 and are 024x1024...there are around 20 textures in total.
What reasons could there be for the type of issue?
Here is the code for reloading...
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated(gl, config);
if(firstTimeCreate) {
load(); //load settings
Assets.Load(this);
firstTimeCreate = false;
} else {
//When screen is resumed....
Assets.ReloadLoadingScreen();
}
That is where everything is this is the load method...
GL10 gl = glGraphics.getGL();
int[] textureIds = new int[1];
gl.glGenTextures(1, textureIds, 0);
textureId = textureIds[0];
InputStream in = null;
try {
in = fileIO.readAsset(fileName);
Bitmap bitmap = BitmapFactory.decodeStream(in);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
setFilters(GL10.GL_LINEAR , GL10.GL_LINEAR);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
width = bitmap.getWidth();
height = bitmap.getHeight();
bitmap.recycle();
} catch(IOException e) {
throw new RuntimeException("Couldn't load texture '" + fileName +"'", e);
} finally {
if(in != null)
try { in.close(); } catch (IOException e) { }
}
and the bind method...
public void bind() {
GL10 gl = glGraphics.getGL();
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
}
Dont think anything is wrong with the above but maybe there is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为我们需要更多细节来正确地为您指明正确的方向。不幸的是,有很多因素可能导致此问题。
您是否正在onSurfaceCreated加载纹理?当您暂停应用程序并恢复时,这些纹理需要在 OpenGL 中重新绑定。
另外,如果您使用Eclipse,LogCat窗口中是否有任何错误?
您可能想要做的一件事是启用 OpenGL 调试标志以进行测试。您可以在这里找到相关信息:
http://developer.android.com/resources/articles /glsurfaceview.html
I think we would need some more details to properly point you in the right direction. Unfortunately, there are so many things that could be causing this issue.
Are you loading your textures onSurfaceCreated? When you pause the application and resume, these textures need to be re-bound in OpenGL.
Also, are there any errors in the LogCat window if you are using Eclipse?
One thing you may want to do is enable OpenGL debug flags for testing. You can find information on this here:
http://developer.android.com/resources/articles/glsurfaceview.html