I am apparently stumbling across the Java boundaries here and having difficulty with the lack of, or limited understanding or Java, with respect to pointers and type conversions. I have lots of code and objects written in C/C++/C# for OpenGL(Win/Linux/OSX/iOS) and I am attempting to step into the Java realm for OpenGL/Android. I have JOGL working in a command line way with Visual Studio and lots of bat files for the build/jarring/execution of Java files. I have started porting my objects to Java and the way OpenGL works, the API passes lots of pointers around. No big deal but I cannot seem to wrap my head around what Java wants. I am starting to think that the paradigm I have working in the other languages will not translate to Java. I have been tinkering with methods to convert my objects to arrays but to be honest I am thinking there may be performance concerns if I continue down this path. A little code setup/design seems to be in order…sparse to save space but you should get the idea.

Class Vector3f() { float X, Y, Z; }
Class Vector4f() { float X, Y, Z, W; }
Class Matrix4f() { Vector4f Row0, Row1, Row2, Row3; }

I think you can see the idea here…object with variables for access. Matrix4f has vector4 for each row so mat.Row0.X is first element in the matrix.

So I assume that Java when allocating these structures allocates memory in contiguous blocks. Meaning Vector3f has 3 floats, 12 bytes, in a block with X at the first byte of 4 to make up a float. Vector4f similarly and Matrix4f has 4 Vector4f for 16 floats for 64 bytes of contiguous space.

OpenGL has immediate mode calls like the following, glVertex3fv(), glVertex4fv(), glLoadMatrixf() and each of these take a pointer to the first byte in the array of data for the specified data type. In C/C++ I pass things like &vertor.X and C# like ref matrix.Row0.X. I cannot figure out how to ‘cast’ things in Java as to pass the address of the first element of the datatype.

I have tried things like allocate an array of 16 floats in my class and have a method ‘Matrix4f.ToArray(projection, arrayBuffer)’ that copies the matrix to an array. Seem to work and for matrix operations its not that large of an overload. Vertex operations will get heavy. When I finally port display lists, FBOs, VBOs I can’t even think how I am going to pass those large arrays of the above data types around.

So I guess it boils down to this. Am I chasing a design pattern not possible in Java? Is porting from C/C++/C# using a similar model even possible? Will I have to redesign around Java? I suspect others from my background have had the same hurdles to overcome and I’d like to hear some of the experiences. Any online tutorials/lectures on the challenges of pointer based languages to non-pointer languages is greatly appreciated.