Null all over the place..

Hi everyone… Can somebody help me?

Im trying to find 3d coord on mouse click event.
And i’m getting a weird error… viewport, mvmatrix, projmatrix are null after those callings…

int viewPort[] = null;
double mvMatrix[] = null;
double projMatrix[] = null;
double objX[] = null;
double objY[] = null;
double objZ[] = null;

gl.glGetIntegerv( GL_VIEWPORT, viewPort );
gl.glGetDoublev( GL_MODELVIEW_MATRIX, mvMatrix );
gl.glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );
float realY = viewPort[3] - (int)evt.getY() - 1;
glu.gluUnProject( (double)evt.getX(), (double)realY, (double)0.0, mvMatrix, projMatrix, viewPort, objX, objY, objZ );

by the way… this code only run when mouse click event is found. and I’m using gluLookAt.

Why is that null?

and im working with java(jbuilderX)
thank you thank you aaaaand thank you

Hi !

Because you set it yo NULL…

int viewPort[] = null;

You create a pointer and initialize it to NULL, you need some place to store the data also, like:

int viewPort[ 4];

And it would work much better, you might want to get your hands on some C tutorial or book and have a look, I think that would make your life much simpler, it is tricky to try to learn both C and OpenGL at the same time.


No. No. I know a bit of C. But I wanna do this at java.

And yes. I’m initializing the variables with null, but the getDoublev method should filled with some value, huh?

Hi !

No, glGetDoublev will put the data in the data area the specified pointer points to, but in your case you just create a pointer, you do not allocate any memory, it is as if you would do this in java:

private int[] myarray = null;
private void test()
myarray[ 0] = 1;
myarray[ 1] = 2;

Here you have the same problem, myarray is just a pointer to an object, but it contains null, it does not point to any valid data…


I thought glgetDoubleV, get the data from the first parameter…

Sooooo… What can i do ?

PS: do you have a msn, icq ?

Hi !

Sorry, I missed that it was Java code in the first answer, something like the code below should work I think.

I am not sure about gluUnproject though, it look’s a bit weird, in Java I would assume you would use an array of 3 doubles for the x,y,z parameters.

double mvMatrix = new double[ 16];
int viewPort[] = new int[ 4];
double mvMatrix[] = new double[ 16];
double projMatrix[] = new double[ 16];
double objX[] = new double[ 1];
double objY[] = new double[ 1];
double objZ[] = new double[ 1];
gl.glGetIntegerv( GL_VIEWPORT, viewPort);
gl.glGetDoublev( GL_MODELVIEW_MATRIX, mvMatrix);
gl.glGetDoublev( GL_PROJECTION_MATRIX, projMatrix);
float realY = viewPort[3] - (int)evt.getY() - 1;
glu.gluUnProject( (double)evt.getX(), (double)realY, (double)0.0, mvMatrix, projMatrix, viewPort, objX, objY, objZ );