添加“java.io.IOException”时遇到的困难;“玩家”;纹理进入屏幕
我从Player类加载“Player.png”文件时遇到了这个奇怪的错误 我知道我的代码组织非常草率,我使用的方法非常糟糕。一半的代码是从教程中借来的 两个类要做的是创建一个屏幕,屏幕上有绿色的瓷砖,填充一个“玩家”精灵,它可以用W、a、S、D键左右、上下移动 错误: java.io.IOException:尝试为当前硬件将纹理分配给big 位于org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:293) 位于org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231) 在 org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:184) 位于org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64) 位于org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24) 在test.PlayerClass.render处(PlayerClass.java:69) 在test.Main.render处(Main.java:110) 在test.Main.run(Main.java:82) at test.Main.Main(Main.java:27) 主类添加“java.io.IOException”时遇到的困难;“玩家”;纹理进入屏幕,java,opengl,lwjgl,slick2d,Java,Opengl,Lwjgl,Slick2d,我从Player类加载“Player.png”文件时遇到了这个奇怪的错误 我知道我的代码组织非常草率,我使用的方法非常糟糕。一半的代码是从教程中借来的 两个类要做的是创建一个屏幕,屏幕上有绿色的瓷砖,填充一个“玩家”精灵,它可以用W、a、S、D键左右、上下移动 错误: java.io.IOException:尝试为当前硬件将纹理分配给big 位于org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoa
public class Main{
private static boolean running = true;
public static final int WIDTH = 1024;
public static final int HEIGHT = 768;
private static Texture tile;
static PlayerClass playerClass = new PlayerClass(100, 100, 32, 32);
public static void main(String[] args){
Main main = new Main();
main.run();
}
//Initialize Method
public static void init(int width, int height ) throws LWJGLException
{
DisplayMode[] m = Display.getAvailableDisplayModes();
for(DisplayMode mode : m)
{
if(mode.getWidth() == 1024 && mode.getHeight() == 768 && mode.getBitsPerPixel() == 32)
{
Display.setDisplayMode(mode);
}
}
Display.setTitle("Game");
Display.setVSyncEnabled(true);
Display.sync(100);
Display.create();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), 0, -1, 1 );
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.2f);
GL11.glEnable(GL11.GL_TEXTURE_2D);
try {
tile = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("RPG/tile.png"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void run()
{
try {
init(1024, 768);
} catch (LWJGLException e) {
e.printStackTrace();
}
while(running)
{
Display.update();
drawTiled(WIDTH, HEIGHT);
input();
update();
render();
}
cleanup();
}
public static void input()
{
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
{
running = false;
}
playerClass.input();
}
public static void update()
{
}
public static void render()
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glLoadIdentity();
try {
playerClass.render();
} catch (IOException e) {
e.printStackTrace();
}
Display.update();
}
public static void cleanup()
{
Display.destroy();
}
public void drawTiled(int screenWidth, int screenHeight) {
Color.white.bind();
tile.bind();
int numberPerRow = screenWidth / tile.getTextureWidth();
int numberOfRows = screenHeight / tile.getTextureHeight();
GL11.glBegin(GL11.GL_QUADS);
for (int j = 0; j < numberOfRows; j++) {
//System.out.print("{");
for (int i = 0; i < numberPerRow; i++)
{
//top left
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(tile.getTextureWidth() * i, tile.getTextureHeight() * j);
//top right
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(tile.getTextureWidth() * (i + 1), tile.getTextureHeight() * j);
//bottom right
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(tile.getTextureWidth() * (i + 1), tile.getTextureHeight() * (j + 1));
//bottom left
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(tile.getTextureWidth() * i, tile.getTextureHeight() * (j + 1));
}
}
}
}
运行以下命令:
System.out.println(GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE));
它将告诉您图形卡允许的最大纹理大小。确保图形卡可以处理您尝试使用的纹理大小。根据错误,它无法运行。运行以下命令:
System.out.println(GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE));
它将告诉您图形卡允许的最大纹理大小。确保图形卡可以处理您尝试使用的纹理大小。根据错误,它不能。瓷砖有多大。png-最大纹理大小可能会因您的卡而异,我认为还有其他一些因素。您的文件可能在此维度之外 Cody的答案为您提供了获得卡的最大纹理大小的方法。如果您正在编写一个供其他人使用的游戏,您可能希望将该代码集成到您的游戏代码中,使其能够根据所运行的卡的功能加载不同的分辨率纹理,或者只需找到一个适用于您想要支持的任何卡的默认值,并将其用于所有安装 下面是一些额外的阅读资料,将解释有关此问题的更多信息、有关此问题的一些历史记录,以及您可能会发现有用的更多技术信息: