Just started, need some pointers! (and now also a glTexImage2D problem)

Hello everyone!

I’ve just started working with jogl, and it looks very interresting! But I find it very difficult to find good tutorials and/or articles about the topic!
I would really appreciate if anyone could give me some pointers for where to read :slight_smile:

I’ve been spending some time with lesson07 from NeHe now, but I can’t manage to get the code to compile. My problem is
that I have to spend much time finding replacements for “outdated code”.

The only thing I can’t find a sollution for is this:

public void init(GLAutoDrawable drawable) {
		this.gl = drawable.getGL();
		this.glu = drawable.getGLU();  // <-- This is my problem!! I can't find out how to "getGLU()"  ???

Thanks a lot!

IIRC GLU was turned into an independant class in JOGL.

If you’re working in a proper IDE, type GLU and [ctrl]+[space] and it will find the class for you.

Thanks a lot! That seemed to work :slight_smile:

But I still have some trouble.

I got this exception:

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0
	at com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes(BufferFactory.java:274)
	at com.sun.opengl.impl.GLImpl.glTexImage2D(GLImpl.java:21147)
	at GLWindow.makeRGBTexture(GLWindow.java:329)
	at GLWindow.init(GLWindow.java:135)
	at com.sun.opengl.impl.GLDrawableHelper.init(GLDrawableHelper.java:72)
	at javax.media.opengl.GLCanvas$InitAction.run(GLCanvas.java:271)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:189)
	at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:265)
	at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
	at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
	at sun.awt.RepaintArea.paintComponent(Unknown Source)
	at sun.awt.RepaintArea.paint(Unknown Source)
	at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Here is the method that throws the exeption


private void makeRGBTexture(GL gl, GLU glu, BufferedImage img, int target, boolean mipmapped)
	{
		ByteBuffer dest = null;
		switch(img.getType())
		{
		case BufferedImage.TYPE_3BYTE_BGR:
		case BufferedImage.TYPE_CUSTOM:
		{
			byte[] data = ((DataBufferByte)img.getRaster().getDataBuffer()).getData();
			dest = ByteBuffer.allocateDirect(data.length);
			dest.order(ByteOrder.nativeOrder());
			dest.put(data, 0, data.length);
			break;
		}
		case BufferedImage.TYPE_INT_RGB:
		{
			int[] data = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
			dest = ByteBuffer.allocateDirect(data.length * BufferUtil.SIZEOF_INT);
			dest.order(ByteOrder.nativeOrder());
			dest.asIntBuffer().put(data, 0, data.length);
			break;
		}
		default:
			throw new RuntimeException("Unsupported image type " + img.getType());
		}
		if(mipmapped)
		{
			glu.gluBuild2DMipmaps(target, GL.GL_RGB8, img.getWidth(), img.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
		}
		else
		{
                        // THIS IS WHERE IT CRASHES!
			gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);


		}
	}

dest.asIntBuffer().put(data, 0, data.length);

rewind/flip your buffers

the bytes between POS and LIM are sent (in this case, it turned out to be 0)

Thanks! That made it :slight_smile:

But now my screen is all black, but I guess it’s just a newbie-error ::slight_smile:

I placed a JOptionPane.showMessageDialog() in the KeyPressed event, and when this dialog shows, the texuteredbox
appears, but when I click “OK” it goes back in black.

Heres the entire class sourcecode --> http://java.pastebin.com/910407

Does [data/crate.png] have POT-dimensions ?

I don’t know what you mean with POT, but the size is 256x256.

But I don’t think the textures are the problem, because when the MessageDialog appears, I can see the the box WITH textures.
Actually, I would guess It’s a problem with flipping the screen, cause If I press the MessageDialog button again, it goes back in black.

err. nvm

Err…the reason it toggled visibility could be because the key I had placed the MessageDialog on also toggled light ;D

Sorry…

But still…in the C++ version of this tutorial, it is visible all the time, but it get more brighter when light is turned on.
Shouldn’t this also be the case here?

Edit: yes it should! I’d just forgotten to flip my FloatBuffers that positions, and set up the ambient/diffuse values for the light!

Once again…sorry :-\

Don´t say sorry.

Sometimes we win, sometimes we learn

These are Java ports of the NeHe OpenGL tutorials
These tutorials were written using the JSR-231 api (javax.media.opengl).

http://pepijn.fab4.be/?page_id=34