try {
System.out.println(new File(filename).exists());
bi = ImageIO.read(new File(filename));
int height = bi.getHeight();
int width = bi.getWidth();
int[] raw_pixels = bi.getRGB(0, 0, width, height, null, 0, width);
ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4);
for(int i = 0; i < height; i++){
for (int j = 0; j < width; j++){
int pixel = raw_pixels[i * height + j];
pixels.put( (byte) ((pixel >> 16) & 0xff) );
pixels.put( (byte) ((pixel >> 8) & 0xff) );
pixels.put( (byte) (pixel & 0xff) );
pixels.put( (byte) ((pixel >> 24) & 0xff) );
}
}
pixels.flip();
id = glGenTextures();
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
} catch (IOException e) {
printStackTrace();
}
我不知道为什么,但ImageIO.read()只是停止了程序,除非我发表评论,否则它不会读取它。它打印为true所以我知道路径有效,但ImageIO只是打破了。
编辑:当我说停止时我的意思是JVM没有运行下一行,如果我在调试模式下暂停它,它就停止了。
native void load(String name, boolean isBuiltin);
是抽象类ClassLoader上的第1736行 它停留在线上几个小时,它不会继续
编辑2:如果我只是在没有glfw的情况下运行该类,我会收到此错误
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fff8ae6aa07, pid=4914, tid=0x0000000000001c03
#
# JRE version: Java(TM) SE Runtime Environment (8.0_144-b01) (build 1.8.0_144-b01)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.144-b01 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libGL.dylib+0x1a07] glGetError+0xd
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# [path to project]/hs_err_pid4914.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#