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

Started by Andrew Alfazy, August 02, 2017, 13:49:47

Previous topic - Next topic

Andrew Alfazy

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

quew8

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).


Andrew Alfazy

Thank You For your fast reply I'm Trying it now. :)

quew8

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.

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.

Andrew Alfazy

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!


Andrew Alfazy