How can I mask textures (meaning that when a texture contains a certain color, that color is completely transparent) in LWJGL without manually creating a black/white texture for each texture that I'm going to use?
LWJGL is driving me completely crazy in that regard. I'm using slicks TextureLoader and Texture classes to load a PNG file, but since I have no way of manipulating the actual texture data inside those classes (texture.getTextureData() only returns copies of the values and additionally the data returned is always 65543 something entries long, which is ridiculous for a 100x100 texture), I can't manually set the alpha of pixels to 0.0f which match the color that is to be masked.
Since I don't know how to load PNGs myself, I'm now trying to create the texture manually a second time after loading it with TextureLoader, but I can't even get normal texturing to work manually, lol!:
m_texture = ResourceManager.getTexture(file_location);
//safe the texture ID given by glGenTextures()
m_textureID = GL11.glGenTextures();
//get pixel data out of m_texture
byte pixels = m_texture.getTextureData();
ByteBuffer bb = ByteBuffer.allocate(pixels.length);
IntBuffer ib = bb.asIntBuffer();
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, m_texture.getTextureWidth(),
m_texture.getTextureHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, ib);
This block always throws an exception which says that the remaining buffer contains 0 elements.
This is my sprite drawing function btw, it works flawlessly if I just m_texture.bind() instead of manually binding my texture:
public void draw()
GL11.glTranslatef(m_position.x+(m_size.x/2.0f), m_position.y+(m_size.y/2.0f), 0.0f);
GL11.glRotatef(m_angle, 0.0f, 0.0f,1.0f);
I'm coming from C++ and wanted to code a little 2D engine in Java, but it's driving me nuts.
Can I even create a new manual texture this way? Or how could I go about "auto-texture-masking" while still using Texture and TextureLoader?