1

I've spent the last couple hours searching around the internet trying to figure out how to get a 3d objects position on the screen. One of the most in depth posts I've found is this one, but i still can't manage to get it to work. I'm almost certain it has to do with my lack of understanding of OpenGL/LWJGL.

It seems no matter how much i toy with things i can't get it to spit out anything useful.

This is where i'm at right now

    GL11.glPushAttrib(GL11.GL_TRANSFORM_BIT);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();

    try
    {
        Method setupCameraTransform = EntityRenderer.class.getDeclaredMethod("setupCameraTransform", float.class, int.class);
        setupCameraTransform.setAccessible(true);
        setupCameraTransform.invoke(mc.entityRenderer, event.getPartialTicks(), 0);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    FloatBuffer modelMatrix = BufferUtils.createFloatBuffer(16);
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelMatrix);

    FloatBuffer projMatrix = BufferUtils.createFloatBuffer(16);
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projMatrix);

    IntBuffer viewport = BufferUtils.createIntBuffer(16);
    GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();

    GL11.glPopAttrib();

    FloatBuffer screen2D = BufferUtils.createFloatBuffer(16);
    if(Project.gluProject(242, 76, 25, modelMatrix, projMatrix, viewport, screen2D))
    {
        int[] screen = new int[] {(int)screen2D.get(0), (int)screen2D.get(1)};

        mc.ingameGUI.drawString(mc.fontRenderer, "overlay", screen[0], screen[1], 0xFF00FF00);
    }

A lot of this comes from this thread which seemed very promising, and they claimed to have solved it, but never stated how they did it. I assume the matrices i'm providing to gluProject are not correct. But i'm clueless as to what exactly they need to be.

Any insight on how to accomplish this would be great, thanks!

Fzzy
  • 31
  • 1

0 Answers0