JOGL texture issues

This was working a while back on JOGL.
Ever since I installed the JSR-231 build it causes issues. Is this a known issue?
I’m loading a 32bit PNG.

Here is the result:

Here is my code(just in case)

private ArrayList<Texture> loadedTextures;
	private Texture loadedTexture;
	
	
	public TextureLoader(DataGL glData) {
		loadedTextures = new ArrayList<Texture>();
		
		GL gl = glData.getGL();
		gl.glEnable(GL.GL_TEXTURE_2D);
		gl.glEnable(GL.GL_BLEND);
		gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
	}
	
	
	public Texture loadTexture(DataGL glData, String location)
	{
		GL gl = null;
		Texture tmpTex = null;
		BufferedImage img = null;
		File file = null;
		ByteBuffer imgBuff = null;
		IntBuffer texId = null;
		
		if(isLoaded(location)) {
			tmpTex = loadedTexture;
		}
		else {
			gl = glData.getGL();
			texId = BufferUtils.newIntBuffer(1);
			file = new File(location);
			
			assert file.exists();
			
			try {
				img = ImageIO.read(file);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			byte[] tmpImgBuff = ((DataBufferByte)img.getData().getDataBuffer()).getData();
			int bpp = img.getData().getNumBands();
			imgBuff = BufferUtils.newByteBuffer(tmpImgBuff.length);
			imgBuff.put(tmpImgBuff);
			
			bindTextureToVRAM(gl, imgBuff, texId, img, bpp);
			tmpTex = new Texture(location, texId.get(0), img.getWidth(), img.getHeight());
			
			img.flush();
			imgBuff.clear();
			texId.clear();
		}
		
		return tmpTex;
	}


	private void bindTextureToVRAM(GL gl, ByteBuffer imgBuff, IntBuffer texId, BufferedImage img, int bpp) {		
		gl.glGenTextures(1, texId);
		gl.glBindTexture(GL.GL_TEXTURE_2D, texId.get(0));
		gl.glTexImage2D(
			GL.GL_TEXTURE_2D,
			0,
			bpp != 4 ? GL.GL_RGB8 : GL.GL_RGBA8,
			img.getWidth(),
			img.getHeight(),
			0,
			bpp != 4 ? GL.GL_RGB : GL.GL_RGBA,
			GL.GL_UNSIGNED_BYTE,
			imgBuff
		);
		
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
	}


	private boolean isLoaded(String location) {
		boolean isLoaded = false;
		
		for (Texture tex : loadedTextures) {			
			if(tex.getTextureLocation().equals(location)) {
				loadedTexture = tex.clone();
				isLoaded = true;
				break;
			}
		}
		
		return isLoaded;
	}

You need to rewind your buffer before calling OpenGL (this is new from JSR-231 builds).

               Vincent

Thanks, it’s fixed.
Buffers. Damn!

At least LWJGL throws an exception in that case which would be a GREAT thing if JOGL could check if the buffer was rewound, if not then have it rewind it.


if(buff.position() > 0)
  buff.rewind();

There might be circumstances where you want to avoid exaclty that, maybe you just want the buffer to start somewhere > 0…

One instance would be if your buffer actually represents a sequence of images.

The check you want is not whether or not the buffer is rewound, but rather if the buffer has the expected amount of data remining in it, from the position(). E.g. limit() - position(), otherwise known as remaining().

^^ what he said.

This is what LWJGL does.

Thanks.
Makes sense.

Yes, this is something we need to add to the GlueGen code generator but haven’t had time yet. Hopefully soon.