Ranger, I’ve thought about that, but since I have so many non-standard textures I fear the memory increase would be drastic and I want to avoid that if possible.
Ihkbob, I’ve been using TextureRenderer and am trying to migrate to using my own texture support using VBOs and GLSL. I’ve been using GL_TEXTURE_2D, and for my simple tests everything looks fine, but for my more complex ones the text looks “scrunched” and some of the colors look slightly odd.
I’m using a BufferedImage.TYPE_4BYTE_ABGR and doing the following with it to create a texture:
if ((image.getType() != BufferedImage.TYPE_4BYTE_ABGR) && (image.getType() != BufferedImage.TYPE_3BYTE_BGR) && (image.getType() != BufferedImage.TYPE_CUSTOM)) {
throw new RuntimeException("Unhandled BufferedImage format. Use 4BYTE_ABGR or 3BYTE_BGR. Type: " + image.getType());
}
boolean alpha = image.getColorModel().hasAlpha();
int byteCount = alpha ? 4 : 3;
byte[] data = new byte[width * byteCount];
WritableRaster raster = image.getRaster();
ByteBuffer pixels = ByteBuffer.allocateDirect((width * height) * byteCount);
pixels.order(ByteOrder.nativeOrder());
for (int i = 0; i < height; i++) {
raster.getDataElements(x, y + i, width, 1, data);
pixels.put(data);
}
pixels.flip();
int[] id = new int[] {textureId};
if (textureId == -1) {
gl.glGenTextures(1, id, 0);
}
gl.glBindTexture(GL.GL_TEXTURE_2D, id[0]);
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);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, alpha ? GL.GL_RGBA : GL.GL_RGB, width, height, 0, alpha ? GL.GL_RGBA : GL.GL_RGB, GL.GL_UNSIGNED_BYTE, pixels);
I’m trying to make this as efficient as possible by not doing any data conversion before pushing the data to the texture and this seems to work…for the most part. :o