PDA

View Full Version : OpenGL porting to Java(JOGL) and Array References...



bmcclint_gl
05-24-2013, 10:57 AM
OKso I m attempting to learn Java and porting some C++/C# code to Java to start to learn JOGL. I have libraries built for all my objects and types but I am really struggling with the omission of pointers in Java amongst others. I am having trouble trying to determine what JOGL wants when arrays are required by OpenGL from my more complex data structures.

I see that glGetIntegerv(int,int[],int) for example required a third parameter where the third parameter is the index I assume into the array.

int[] viewport = new int[4];
gl.glGetIntegerv(gl.GL_VIEWPORT, viewport); // Fail
gl.glGetIntegerv(gl.GL_VIEWPORT, viewport, 0); // OK

My more complex data structures are compilations of several data structures. None of which are out of the ordinary but I cannot figure out how to pass these complex data structures to the JOGL methods and the compiler messages are vague.

NOTE: I am doing all of this command line as I cannot install an IDE other than Visual Studio where I am located. Im sure Eclipse would help somewhat if I could install.

An example of a call and data type I am attempting to port is glLoadMatrixf(float[]) and my structure is

Matrix4f containing 4 Vector4f for each row; each Vector4f has 4 floats X, Y, Z, W. So Id like to pass to JOGL Matrix.Row0.X. Assuming Java organizes data like C++/C# Id suspect the four Vector4f are contiguous and the four floats are contiguous resulting in 16 contiguous floats. Passing a reference to Row0.X should pass an address of the first byte of the contiguous block of floats.

Im finding that creating a 16 byte float array and passing glLoadMatrixf(m, 0); compiles. Can I even attempt what I am porting or will Java require an entirely different approach?

Any thoughts?

Sample:
Matrix4f proj = Matrix4f.CreateProjection(fovRadians, aspect, near, far);
gl.glLoadMatrixf(proj.Row0.X); // gl is passed in GL2 object

Error:
Cannot find symbol; method glLoadMatrix(float); interface javax.media.opengl.GL2.

JohnBauer
05-29-2013, 10:23 AM
I am using JOGL and all of the array calls typically have a float[] array, int offset or FloatBuffer pattern. Those work fine. For instance:
gl.glLoadMatrixf(float[] m, int m_offset) or gl.glLoadMatrixf(FloatBuffer m). The first call expects a float array of 16 elements or more.

bmcclint_gl
05-29-2013, 01:21 PM
Yeah...what I am learning is my design that works well in C/C++/C# may not work without significant redesign efforts in Java. I may need to decouple things like vectors and matrices and create accessors to get to components that I may need. It will take a little effort on my part to change my brain from an older paradigm to the newer way Java and other languages are moving towards.