public void generateMipMaps(ByteBuffer data, int width, int height, boolean test)
	{
		ByteBuffer mipData = data;

		for (int level = test ? 0 : 1; level <= 4; level++)
		{
			int parWidth = width >> level - 1;
			int mipWidth = width >> level;
			int mipHeight = height >> level;

			if(mipWidth <= 0 || mipHeight <= 0)
			{
				break;
			}

			ByteBuffer mipData1 = BufferUtils.createByteBuffer(data.capacity());

			mipData1.clear();

			for (int mipX = 0; mipX < mipWidth; mipX++)
			{
				for (int mipY = 0; mipY < mipHeight; mipY++)
				{
					int p1 = mipData.getInt((mipX * 2 + 0 + (mipY * 2 + 0) * parWidth) * 4);
					int p2 = mipData.getInt((mipX * 2 + 1 + (mipY * 2 + 0) * parWidth) * 4);
					int p3 = mipData.getInt((mipX * 2 + 1 + (mipY * 2 + 1) * parWidth) * 4);
					int p4 = mipData.getInt((mipX * 2 + 0 + (mipY * 2 + 1) * parWidth) * 4);

					int pixel = b(b(p1, p2), b(p3, p4));

					mipData1.putInt((mipX + mipY * mipWidth) * 4, pixel);
				}
			}

			GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, GL11.GL_RGBA, mipWidth, mipHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, mipData1);
			GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.1F * level); // Create transparency for each level.

			mipData = mipData1;
		}
	}