【发布时间】:2010-01-21 12:13:05
【问题描述】:
我一直在尝试加载 bmp 图片以在我的程序中将其用作纹理 我使用 IOStream 类扩展 DataInputStream 以使用此代码基于纹理读取照片上的像素C++ 的加载器代码:
//class Data members
public static int BMPtextures[];
public static int BMPtexCount = 30;
public static int currentTextureID = 0;
//loading methode
static int loadBMPTexture(int index, String fileName, GL gl)
{
try
{
IOStream wdis = new IOStream(fileName);
wdis.skipBytes(18);
int width = wdis.readIntW();
int height = wdis.readIntW();
wdis.skipBytes(28);
byte buf[] = new byte[wdis.available()];
wdis.read(buf);
wdis.close();
gl.glBindTexture(GL.GL_TEXTURE_2D, BMPtextures[index]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, width, height, 0, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, buf);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
currentTextureID = index;
return currentTextureID;
}
catch (IOException ex)
{
// Utils.msgBox("File Error\n" + fileName, "Error", Utils.MSG_WARN);
return -1;
}
}
和 IOStream 代码:
public class IOStream extends DataInputStream {
public IOStream(String file) throws FileNotFoundException {
super(new FileInputStream(file));
}
public short readShortW() throws IOException {
return (short)(readUnsignedByte() + readUnsignedByte() * 256);
}
public int readIntW() throws IOException {
return readShortW() + readShortW() * 256 * 256;
}
void read(Buffer[] buf) {
}
}
和调用:
GTexture.loadBMPTexture(1,"/BasicJOGL/src/basicjogl/data/Font.bmp",gl);
调试后我发现当涉及到这一行时:
IOStream wdis = new IOStream(fileName);
出现IOExeption,这是DispatchException 这是什么意思,我该如何解决?
我尝试过:
- 使用
\和\\和/和// - 改变照片的路径,把
c:\的所有路径都取到photoname.bmp - 使用
1.bmp等数字重命名照片
都没有用。
【问题讨论】:
-
通过阅读这篇文章,我无法判断纹理是位于 jar 中还是位于文件系统中。你能详细说明一下吗?
-
在文件系统中我创建了一个包“数据”并将照片添加到其中但在更改加载器代码后它可以正常工作并完美加载纹理“我试图打印图片的信息和它可以工作“..但是当它绑定纹理时没有发生任何事情它绘制了一个白色正方形!
标签: java loading iostream textures jogl