gah, I get a null InputStream
Here's my code (patched up and prolly real ugly) can anyone point me to my mistake? (the path I get in argument is hard-coded, so no problem there)
private final int loadTexture(String path) throws Exception
{
BufferedImage tex = null;
InputStream is = null;
try {
is = Nehe11.class.getResourceAsStream(path);
System.out.println("is=" + is + "\n\n");
tex = (BufferedImage) ImageIO.read(is);
if (tex == null)
{
throw new Exception("Error: Got null from ImageIO.read()");
}
}
catch ( Exception e ) {
throw new Exception("Problem loading bitmap", e);
}
// Create A IntBuffer For Image Address In Memory
IntBuffer buf =
ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
// Extract The Image
tex = ImageIO.read ( is );
// Flip Image
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
// tx.translate(0, -image.getHeight(null));
AffineTransformOp op =
new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
tex = op.filter(tex, null);
// Put Image In Memory
ByteBuffer scratch =
ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight());
byte data[] =
(byte[]) tex.getRaster().getDataElements(
0,
0,
tex.getWidth(),
tex.getHeight(),
null);
scratch.clear();
scratch.put(data);
scratch.rewind();
GL.glGenTextures(buf); // Create Texture In OpenGL
GL.glBindTexture(GL.GL_TEXTURE_2D, buf.get(0));
// Typical Texture Generation Using Data From The Image
// Linear Filtering
GL.glTexParameteri(
GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MIN_FILTER,
GL.GL_LINEAR);
// Linear Filtering
GL.glTexParameteri(
GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MAG_FILTER,
GL.GL_LINEAR);
// Generate The Texture
GL.glTexImage2D(
GL.GL_TEXTURE_2D,
0,
GL.GL_RGB,
tex.getWidth(),
tex.getHeight(),
0,
GL.GL_RGB,
GL.GL_UNSIGNED_BYTE,
scratch);
return buf.get(0); // Return Image Address In Memory
}
Do you guys see anything wrong (with a quick glance?) apart from the newbiness of the code [-(