Code in Texturing.java:
texture = TextureReader.readTexture( filename );---- down in stack (readTexture):
BufferedImage bufferedImage = ImageIO.read(ResourceRetriever.getResourceAsStream(resourceName)); return readPixels(bufferedImage, storeAlphaChannel);---- down in stack (readPixels):
PixelGrabber pixelgrabber =
new PixelGrabber(img, 0, 0, img.getWidth(), img.getHeight(),
packedPixels, 0, img.getWidth());
int bytesPerPixel = storeAlphaChannel ? 4 : 3;
ByteBuffer unpackedPixels = BufferUtil.newByteBuffer(packedPixels.length * bytesPerPixel);
for (int row = img.getHeight() - 1; row >= 0; row--) {
for (int col = 0; col < img.getWidth(); col++) {
int packedPixel = packedPixels[row * img.getWidth() + col];
unpackedPixels.put((byte) ((packedPixel >> 16) & 0xFF));
unpackedPixels.put((byte) ((packedPixel >> 8) & 0xFF));
unpackedPixels.put((byte) ((packedPixel >> 0) & 0xFF));
if (storeAlphaChannel) {
unpackedPixels.put((byte) ((packedPixel >> 24) & 0xFF));
}
}
}
unpackedPixels.flip();
return new Texture(unpackedPixels, img.getWidth(), img.getHeight());
The number of texels for both the width and height of a texture image, not including the optional border, must be a power of 2. If your original image does not have dimensions that fit that limitation, you can use the OpenGL Utility Library routine gluScaleImage() to alter the size of your textures.
The framebuffer itself can also be used as a source for texture data. glCopyTexImage2D() reads a rectangle of pixels from the framebuffer and uses it for a new texture.