Hello Guest

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

  • 3 Replies
  • 7409 Views
[SOLVED] GLU.gluProject ??????
« on: December 10, 2010, 01:21:32 »
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:
Code: [Select]
       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:

Code: [Select]
Viewport: 0, 0, -2147352576, -536805376
Even stranger:
Code: [Select]
       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:

Code: [Select]
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
« Last Edit: December 10, 2010, 07:19:31 by wondersonic »
S.

Re: GLU.gluProject ??????
« Reply #1 on: December 10, 2010, 01:41:45 »
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:

Code: [Select]
      //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

Re: GLU.gluProject ??????
« Reply #2 on: December 10, 2010, 01:45:42 »
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.

Re: GLU.gluProject ??????
« Reply #3 on: December 10, 2010, 07:19:14 »
Thanks to both of you!
S.