[SOLVED] GLU.gluProject ??????

Started by wondersonic, December 10, 2010, 01:21:32

Previous topic - Next topic

wondersonic

Hi all,
I'm trying to use this method but without success, can anyone help me to figure out what's wrong?

First why do the following method returns something weird?

Following is my code:
       IntBuffer viewport = ByteBuffer.allocateDirect(Integer.SIZE * 4).asIntBuffer();
        GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
        System.out.println("Viewport: " + viewport.get(0) + ", " + viewport.get(1) + ", " + viewport.get(2) + ", " + viewport.get(3));


Output:

Viewport: 0, 0, -2147352576, -536805376


Even stranger:
       GL11.glViewport(0, 0, 640, 480);
        IntBuffer viewport = ByteBuffer.allocateDirect(Integer.SIZE * 4).asIntBuffer();
        GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
        System.out.println("Viewport: " + viewport.get(0) + ", " + viewport.get(1) + ", " + viewport.get(2) + ", " + viewport.get(3));


Output:

Viewport: 0, 0, -2147352576, -536805376


So until I get it to work, I'm not sure I'll be able to invoke GLU.gluProject??

Regards,
WS
S.

jediTofu

I'm not sure why the values are like that, but it doesn't look like you're allocating the buffer correctly.
Luckily, I used gluProject fairly recently; here's the copy & paste of the code that worked for me:

      //Triangle points
      FloatBuffer pos1 = BufferUtils.createFloatBuffer(3);
      FloatBuffer pos2 = BufferUtils.createFloatBuffer(3);
      FloatBuffer pos3 = BufferUtils.createFloatBuffer(3);

      FloatBuffer model = BufferUtils.createFloatBuffer(16);
      FloatBuffer proj  = BufferUtils.createFloatBuffer(16);
      IntBuffer   view  = BufferUtils.createIntBuffer(16);

      glGetFloat(GL_MODELVIEW_MATRIX,model);
      glGetFloat(GL_PROJECTION_MATRIX,proj);
      glGetInteger(GL_VIEWPORT,view);

      gluProject(-50,-50,0,model,proj,view,pos1);
      gluProject( 50,-50,0,model,proj,view,pos2);
      gluProject(  0, 50,0,model,proj,view,pos3);

      pos1.get(0); //x
      pos1.get(1); //y
      pos1.get(2); //z

      pos2.get(0); //x
      pos2.get(1); //y
      pos2.get(2); //z

      pos3.get(0); //x
      pos3.get(1); //y
      pos3.get(2); //z

cool story, bro

Matthias

ByteBuffer.allocateDirect() returns a ByteBuffer with BIG_ENDIAN byte order: http://download.oracle.com/javase/6/docs/api/java/nio/ByteBuffer.html

You either need to set it to native byte order or simply use BufferUtils.createIntBuffer(4) which does all the work for you.

wondersonic

S.