我一直在試圖加載一個bmp圖片作爲我的程序紋理使用IOStream
類擴展DataInputStream
讀取基於紋理的代碼照片上的像素用於C++加載程序代碼:JOGL紋理加載
//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或文件系統。你能詳細解釋一下嗎? – 2010-01-21 18:16:30
在一個文件系統我創建了一個包「數據」,並添加到它的照片 但改變加載程序代碼後,它的工作原理和加載完美的紋理「我試圖打印圖片的信息,它的工作原理」.. ..但是當它來綁定紋理沒有發生任何事情時,它繪製了一個白色的方塊! – Nour 2010-01-22 09:01:40
嗨,你解決了嗎? – elect 2015-08-07 13:31:20