Hi people.
I have I little problem with TextureManager.
TextureManager only works with Images files, not with ByteBuffer.
I need to use TextureManager or something similar to create a texture from a ByteBuffer, because I have my textures on an special package that I read with an special tool (decrypt/unpack/etc…)
I'm need to call a function like this.
protected int createTexture(int width, int height, int type, ByteBuffer byteTexture){
...
}
type is a lwjgl GL11 format like GL11.GL_RGB or GL11.GL_RGBA and byteTexture have the bytes at memory.
My first atent to do this is trying to create the texture "manually", but it doesn't work because I cannot set the file for the image, only the ByteBuffer.
I need to modify the TextureManager or create a TextureMemoryManager for this.
This is my first atempt:
protected int createTexture(int width, int height, int type, ByteBuffer byteTexture) {
int salida=idTextura;
Format formato=Format.Guess;
boolean textureformatknown=true;
switch(type){
//Formatos RGB
case GL11.GL_RGB:
case GL11.GL_RGB8:
formato=Format.RGB8;
break;
case GL11.GL_RGB4:
formato=Format.RGB4;
break;
case GL11.GL_RGB5:
formato=Format.RGB5;
break;
case GL11.GL_RGB5_A1:
formato=Format.RGB5A1;
break;
case GL11.GL_RGB10:
formato=Format.RGB10;
break;
case GL11.GL_RGB10_A2:
formato=Format.RGB10A2;
break;
case GL11.GL_RGB12:
formato=Format.RGB12;
break;
case GL11.GL_RGB16:
formato=Format.RGB16;
break;
//Formatos RGBA
case GL11.GL_RGBA:
case GL11.GL_RGBA8:
formato=Format.RGBA8;
break;
case GL11.GL_RGBA2:
formato=Format.RGBA2;
break;
case GL11.GL_RGBA4:
formato=Format.RGBA4;
break;
case GL11.GL_RGBA12:
formato=Format.RGBA12;
break;
case GL11.GL_RGBA16:
formato=Format.RGBA16;
break;
case GL11.GL_RGBA_MODE:
//Mal royo
System.err.println("Texture Format RGBA_MODE not supported");
textureformatknown=false;
break;
//Formatos comprimidos
case EXTTextureCompressionS3TC.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
formato=Format.RGB_TO_DXT1;
break;
case EXTTextureCompressionS3TC.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
formato=Format.RGBA_TO_DXT1;
break;
case EXTTextureCompressionS3TC.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
formato=Format.RGBA_TO_DXT3;
break;
case EXTTextureCompressionS3TC.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
formato=Format.RGBA_TO_DXT5;
break;
default:
System.err.println("Unknown Texture format: "+type);
textureformatknown=false;
}
if(textureformatknown){
Image imagen= new Image(formato,width,height,byteTexture);
Texture tex = new Texture2D();
tex.setMinificationFilter(MinificationFilter.NearestNeighborNoMipMaps);
tex.setMagnificationFilter(MagnificationFilter.NearestNeighbor);
tex.setImage(imagen);
TextureState ts=game.getDisplay().getRenderer().createTextureState();
ts.setTexture(tex);
System.err.println(tex.getTextureId());
}
return salida;
}