Hello Guest

[Solved] what is the replace of gluPerspective() in lwjgl 3?

  • 6 Replies
  • 872 Views
I'm moving from lwjgl 2.9 to 3
but gluPerspective has been Removed
How can I make 3d View? ???
note :
my OpenGL is 1.4
« Last Edit: August 02, 2017, 15:07:13 by Andrew Alfazy »

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: what is the replace of gluPerspective() in lwjgl 3?
« Reply #1 on: August 02, 2017, 14:16:52 »
There is no direct equivalent in LWJGL3. GLU was removed from LWJGL since it is designed to work with deprecated features in OpenGL (such as the fixed function pipeline you are using).

However, if you have JOML which optionally comes packaged with LWJGL3 then you can create an appropriate perspective matrix Java side and upload it to OpenGL with glLoadMatrix(). The final code snippet of the section linked here: https://github.com/JOML-CI/JOML#using-with-lwjgl, does almost exactly what you want (it also loads a model-view matrix equivalent to a gluLookAt() call).


Re: what is the replace of gluPerspective() in lwjgl 3?
« Reply #2 on: August 02, 2017, 14:24:20 »
Thank You For your fast reply I'm Trying it now. :)
« Last Edit: August 02, 2017, 14:49:08 by Andrew Alfazy »

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: what is the replace of gluPerspective() in lwjgl 3?
« Reply #3 on: August 02, 2017, 15:07:42 »
No problem. Alternatively you can do what I imagine is exactly what GLU did. It's a simple bit of maths to work out the equivalent parameters for glFrustum(). You can check the documentation or do the geometry yourself. Either way I recon this should perform the same function.

Code: [Select]
public static void gluPerspective(float fovy, float aspect, float near, float far) {
    float bottom = -near * (float) Math.tan(fovy / 2);
    float top = -bottom;
    float left = aspect * bottom;
    float right = -left;
    glFrustum(left, right, bottom, top, near, far);
}

This is probably a simpler method, especially if you're not using JOML already. But using JOML is a step towards not using deprecated features so I would go for my first post.

Re: [Solved] what is the replace of gluPerspective() in lwjgl 3?
« Reply #4 on: August 02, 2017, 15:14:05 »
Thanks Again
"But using JOML is a step towards not using deprecated features so I would go for my first post."
I'm now Learning More about Matrix4f It's look like A power of the camera
Can you Give me Link to good tutorial (No shader plz)
#Sorry for may bad English!

*

Kai

Re: [Solved] what is the replace of gluPerspective() in lwjgl 3?
« Reply #5 on: August 03, 2017, 18:21:17 »
As for migrating from LWJGL 2 to 3, please read this: https://github.com/JOML-CI/JOML/wiki/Migrating-from-LWJGL-2

Re: [Solved] what is the replace of gluPerspective() in lwjgl 3?
« Reply #6 on: August 04, 2017, 20:38:10 »
Thank you kai that's helpful
« Last Edit: December 21, 2017, 11:07:14 by Andrew Alfazy »