Search code examples
javalwjgljogl

I'm trying to use GLU.gluPerspective(), but it's giving me the static reference error


Alright. I'm brand new to OpenGL and the things of the like. I'm using LWJGL 3 and JOGL (for GLU) and I'm at a complete stop in my self-learning process. Right now I'm trying to set up my 3D projection using GLU.gluPerspective(80, 4/3, 0.1, 10000);, but it's giving me Cannot make a static reference to the non-static method gluPerspective(double, double, double, double) from the type GLU - I do know what this means, but I'm not quite sure as to why I'm getting this.

I copied/pasted the sample code from LWJGL 3's page to get most of my code. To draw the cube, I use another bit of code I found online.

The code is fairly long so you can get it at this pastebin link.

A bit of a note for the above, lines 158 through 174 use my custom Player class and Keyboard class, which are minimal and have nothing that affects what I'm doing to get my error within them.

So why would this be giving me that error, despite the fact that I instanciated a new Main()? Am I just a bit rusty on my memory of Java? (the pastebin code is Main.java)


Solution

  • As described in the error message gluPerspective is not a static method of the class GLU, this means you need a GLU object to call it:

    GLU glu = new GLU();
    glu.gluPerspective(80, 4/3, 0.1, 10000);
    

    This is also explained in the JOGL user guide:

    To use the GLU, simply instantiate a GLU object via new GLU() at the beginning of your program. The methods on the GLU object may be called at any point when an OpenGL context is current. Because the GLU implementation is not thread-safe, one GLU object should be created for each GLEventListener or other entity performing OpenGL rendering in a given thread.