I have an image, which I'm reading in, to a ByteBuffer, using this method:
public ByteBuffer readData( URL url ) throws Exception
ByteBuffer buf = null;
BufferedImage img = null;
Image src = new ImageIcon( url ).getImage();
img = new BufferedImage( src.getWidth(null), src.getHeight(null), BufferedImage.TYPE_INT_RGB
e( src, 0, 0, null );
int  data = ( (DataBufferInt ) img.getRaster().getDataBuf
buf = ByteBuffer.allocateDirect(
* BufferUtils.SIZEOF_INT );
buf.order( ByteOrder.nativeOrder() );
buf.asIntBuffer().put( data, 0, data.length );
When I map the ByteBuffer (as the data) to some quads, that make up a 3D cube (which is rotating), like so:
Texture img = new Texture(); // Custom class -- very simple though
img.width = 256; // for example
img.height = 256; //
img.data = readData( new File("my_image.jpg").toURL
() ); // the data member is obviously a ByteBuffer instance
glu.gluBuild2DMipmaps( GL.GL_TEXTURE_2D, GL.GL_RGB, img.width, img.height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, img.data );
// Then define the texture coordinates, and render the quads here !
There are no compile-time/run-time errors, a such ... however, the texture being mapped to the cube is not how it is in the file lol. Take a look for yourself:
Here's what the output of my program is currently:
Whereas the texture that I'm loading, and attempting to map to the cube is:
If you look closely enough however, then you can see some very faint detail from the actual proper texture appear on the cube... so it's not a completely random texture...
Can anyone see a problem with my readData() method, perhaps?
By the way, I'm quite confident that this is not a problem with the setup/attributes of the program...
Thanks : )