gpt4 book ai didi

java - 16x16 纹理太大,Java openGL

转载 作者:行者123 更新时间:2023-11-29 05:49:34 25 4
gpt4 key购买 nike

我正在制作基于图 block 的游戏,图 block 的纹理为 16x16。每当我尝试加载纹理以便渲染它时,我收到此错误:

java.io.IOException: Attempt to allocate a texture to big for the current hardware
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:292)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:184)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
at main.Tile.loadTexture(Tile.java:124)
at main.Draw.drawMap(Draw.java:282)
at main.Draw.render(Draw.java:324)
at main.LaunchWindow.main(LaunchWindow.java:65)
Exception in thread "main" java.lang.NullPointerException
at main.Draw.drawMap(Draw.java:284)
at main.Draw.render(Draw.java:324)
at main.LaunchWindow.main(LaunchWindow.java:65)

现在,我知道我的 GPU 可以处理它,因为它是一张 1G​​B 的卡。

我跑了

GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE)

得到16384。

这是加载纹理的代码:

public void loadTexture(String a){
try {
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(a));
System.out.println(texture.getTextureRef());

} catch (IOException e) {
e.printStackTrace();
}
}

以及需要渲染时调用的代码:

public void drawMap(Map b){
Color.white.bind();
glBegin(GL_QUADS);

b.divideMap(10);
Tile[][] t = b.makeMap(b.getK());

for(int y = 0; y < b.tiles.length; y++){
for(int x = 0; x < b.tiles[y].length; x++){
Texture a;
t[y][x].loadTexture(t[y][x].getLocation());
a = t[y][x].getTexture();
System.out.println(a.getTextureRef());
a.bind();
glTexCoord2f(0,0);
glVertex2f(x,y);
glTexCoord2f(1,0);
glVertex2f(x + a.getWidth(), y);
glTexCoord2f(1,1);
glVertex2f(x + a.getWidth(), y + a.getHeight());
glTexCoord2f(0,1);
glVertex2f(x, y + a.getHeight());
}
}

glEnd();
}

最佳答案

不知道框架,但从代码中我看到你在每一帧加载所有纹理并且从不释放它们。几帧后,您的内存不足。

关于java - 16x16 纹理太大,Java openGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14449513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com