Hello. I'm encountering some errors trying to create a 512 x 512 texture and filling it with an empty byte buffer. Java throws an error saying that it expects a texture resolution of 1024 x 1024.
java.lang.IllegalArgumentException: Number of remaining buffer elements is 262144, must be at least 1048576
Any idea what it could be?
Jeremy
HEre's the code
bb = createTextureBB(320);
int dimension = (int) Math.sqrt(bb.limit());
myTextureHandle = makeTexture(bb, dimension, dimension);
public static ByteBuffer createTextureBB(int size) {
int power = 1;
int powSize = 2;
while (size > powSize){
powSize = (int) (Math.pow((double) 2,(double) power));
power++;
}
size = powSize;
System.out.println("size "+size);
byte[] bytearray = new byte[(powSize*powSize)];
for (int i = 0; i< (powSize*powSize); i++){
bytearray =00000000;
}
ByteBuffer bb = ByteBuffer.allocateDirect(bytearray.length * SIZE_BYTE).order(ByteOrder.nativeOrder());
bb.put(bytearray).flip();
return bb;
}
public static int makeTexture(ByteBuffer pixels, int w, int h)
{
// get a new empty texture
int textureHandle = allocateTexture();
// 'select' the new texture by it's handle
GL11.glBindTexture(GL11.GL_TEXTURE_2D,textureHandle);
// set texture parameters:
// how to wrap texture
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
// how to scale up texture
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); //GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); //GL11.GL_NEAREST);
// Create the texture from pixels
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, // type of texture we're creating
0, // level-of-detail: use 0
GL11.GL_RGBA, // texture pixel format
w, h, // width and height of texture image (powers of 2)
0, // widtt of the border (either 0 or 1, use 0)
GL11.GL_RGBA, // image pixel format
GL11.GL_UNSIGNED_BYTE, // image pixel data type
pixels // image pixel data
);
return textureHandle;
}