glDrawElements compiler error

I’m getting a complie error when using glDrawElements with an int index array like so:

gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, Indices[0]);

the compiler error is:
The method glDrawElements(int, int, int, boolean[]) in the type GL is not applicable for the arguements (int, int, int, int)
I know the int argument I’ve given is valid, so why the error?
I’ve searched the forum, but only found threads regarding runtime errors, which seem unrelated.
I’m using Eclipse on mac 10.3.4 with the latest jogl beta binaries, but I got the same error when I tested on win 2000.
Has anyone run into this or am I just doing something stupid?
thanks for any replies, rob

[quote]I’m getting a complie error when using glDrawElements with an int index array like so:

gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, Indices[0]);

[/quote]
The only unknown I see there is Indicies[0]. I can’t tell if that’s an array of objects or ints.

ints.

private static int Indices[] = {1, 2, ...}

Then you need to pass in the reference to the array of ints – not the first element of the array.

gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, Indices);

thanks for the reply, however I’m confused how I will make my next call to DrawElements. In C it is:

      glDrawElements(GL_TRIANGLE_STRIP, 80, GL_UNSIGNED_INT, &Indices[0]);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, &Inidices[80]);

How am I supposed to pass in the new position of the indices array for the next call if all I’m passing is an array reference?
My apologies for the newbie question.

I think you want glDrawRangeElements(). It allows you to specify starting and ending offsets. You should probably review the javadoc for the GL Interface as you’ve a better idea of what you’re after than I do.

glDrawRangeElements() don’t specify the tarting and ending offsets in the index array. It specifies the min and max index used in the index array. It’s a hint to the drivers so only a portion of the vertex arrays can be sent to the card.

You wan’t to use a direct java.nio.IntBuffer instead of a int array. That way the index array is stored on the native side of java, wich is the same as if you used c. In Jogl I think you have to slice the buffer to get a subregion. As Jogl don’t respect position and limit. Or am I wrong? I only use LWJGL and there you can set the position and limit on the original buffer.

Anyway you need to read up on java.nio.* And don’t use java arrays with opengl vertex arrays.

Okay, everything makes sense for the most part. I’ve created an IntBuffer to use for my indices. First I tried replacing this gl code:

glDrawElements(GL_TRIANGLE_STRIP, 80, GL_UNSIGNED_INT, &Inidices[0]);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, &Inidices[80]); 

with this java code:

gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, indexBuffer.position(0));
gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 4, GL.GL_UNSIGNED_INT, indexBuffer.position(80)); 

this draws the first call, but not the second. I guess this is what Tom means when he says JOGL doesn’t respect position and limit. fine. so than I tried:

gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, indexBuffer.position(0).slice());
gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 4, GL.GL_UNSIGNED_INT, indexBuffer.position(80).slice()); 

but this gives an error because position returns a Buffer not an IntBuffer and slice is not defined for Buffer. What worked is this:

IntBuffer slc;
indexBuffer.position(0); 
slc = indexBuffer.slice();
gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, slc);
indexBuffer.position(80); 
slc = indexBuffer.slice();
gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 4, GL.GL_UNSIGNED_INT, slc);

I could not figure out how to cast indexBuffer.position().slice() to an IntBuffer. Is there a way to do this all on one line? The reason being I have several lines from several C code opengl files that I need to convert to java using grep and I’m not that good a scripting, so I’m just trying to convert them line for line, rather than turning the 2 lines of code into 6.

Does anybody have any suggestions of a way to do this, or do I have to dust off my perl manual?

thanks for replies, rob

[quote]but this gives an error because position returns a Buffer not an IntBuffer and slice is not defined for Buffer.
[/quote]
position(int) returns a referance to “this” buffer. You can safely cast it back to IntBuffer.

A one line version would be:

gl.glDrawElements(GL.GL_TRIANGLE_STRIP, 80, GL.GL_UNSIGNED_INT, ((IntBuffer)indexBuffer.position(0)).slice());