Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to run my code on jogl 2.0 , for the first time (until now I worked with jogl 1.0) however Eclipse throws to almost every that I have a "cannot be resolved or is not a field" message .

The files that are in the library of the jogl 2.0 are :

gluegen-rt.jar
jogl-all.jar
gluegen-rt.dll
joal.dll
jocl.dll
jogl_cg.dll
jogl_desktop.dll
jogl_mobile.dll
nativewindow_awt.dll
nativewindow_win32.dll
newt.dll

And the code is pretty simple :

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import javax.swing.JFrame;
import com.jogamp.opengl.util.Animator;



public class Practice10IlluminateSphere extends JFrame implements KeyListener{

    private static float deltaZ=0;


    float t=0;

    public static void main(String[] args) {
        Practice10IlluminateSphere frame=new Practice10IlluminateSphere();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    public Practice10IlluminateSphere(){
        setSize(600,600);
        setTitle("Hello Universe");

        GraphicListener listener=new GraphicListener();
        GLCanvas canvas = new GLCanvas(new GLCapabilities());
        canvas.addGLEventListener(listener);
        getContentPane().add(canvas);

        Animator animator = new Animator(canvas);
        animator.start();

        addKeyListener(this);
    }

    public class GraphicListener implements GLEventListener{


        public void display(GLAutoDrawable arg0) {

            GL gl=arg0.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);


            gl.glEnable(GL.GL_DEPTH_TEST);
            gl.glCullFace(GL.GL_FRONT); 
            gl.glEnable(GL.GL_CULL_FACE);
            gl.glFrontFace(GL.GL_CCW);


            GLU glu=new GLU();
            GLUquadric quadric=glu.gluNewQuadric();
            glu.gluQuadricNormals(quadric, GL.GL_TRUE);

            gl.glLoadIdentity();
            gl.glTranslatef(-0.5f,0,0);

                gl.glColor3f(0.7f,1,0.7f);
                glu.gluSphere(quadric, 0.5f, 90, 90);

            gl.glLoadIdentity();
            gl.glTranslatef(0.5f,0,deltaZ);

                gl.glColor3f(1,0.7f,0.7f);
                glu.gluSphere(quadric, 0.4f, 90, 90);


            t+=0.05f;
            float position3[]= {(float)(Math.cos(t)),-1.0f,0,1};
            gl.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, position3, 0);

        }

        public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {

        }

        public void init(GLAutoDrawable arg0) {

            GL gl=arg0.getGL();
            gl.glEnable(GL.GL_LIGHTING);

            float ambient[]= {0.2f,0.2f,0.2f,1};
            gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT , ambient,0);

            gl.glEnable(GL.GL_LIGHT2);
            float position3[]= {1.0f,0.0f,0.0f,1};
            gl.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, position3, 0);
            float intensity3[]= {1,1,0,1};
            gl.glLightfv(GL.GL_LIGHT2, GL.GL_DIFFUSE, intensity3, 0);
            gl.glLightf(GL.GL_LIGHT2,GL.GL_LINEAR_ATTENUATION,0.9f);
            gl.glLightf(GL.GL_LIGHT2,GL.GL_CONSTANT_ATTENUATION,0.9f);
            gl.glLightf(GL.GL_LIGHT2,GL.GL_QUADRATIC_ATTENUATION,0.9f);

            gl.glEnable(GL.GL_LIGHT3);
            float position4[]= {1.0f,1.0f,1.0f,1};
            gl.glLightfv(GL.GL_LIGHT3, GL.GL_POSITION, position4, 0);
            float intensity4[]= {1,1,0,1};
            gl.glLightfv(GL.GL_LIGHT3, GL.GL_DIFFUSE, intensity4, 0);
            float dir4[]= {-1.0f,-1.0f,-1.0f,1};
            gl.glLightfv(GL.GL_LIGHT3, GL.GL_SPOT_DIRECTION, dir4, 0);
            gl.glLightf(GL.GL_LIGHT3, GL.GL_SPOT_CUTOFF, 50);
            gl.glLightf(GL.GL_LIGHT3, GL.GL_SPOT_EXPONENT, 50);


//          gl.glEnable(GL.GL_COLOR_MATERIAL);
//          gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
            float specColor[]= {1,1,1,1};
            gl.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR, specColor,0);
            gl.glMaterialf(GL.GL_FRONT_AND_BACK,GL.GL_SHININESS, 80);
            GL.gl_
        }

        public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {

        }
    }

    public void keyPressed(KeyEvent arg0) {
        if(arg0.getKeyCode()==KeyEvent.VK_A){
            deltaZ+=0.05;
        }
        if(arg0.getKeyCode()==KeyEvent.VK_B){
            deltaZ-=0.05;
        }
    }

    public void keyReleased(KeyEvent arg0) {

    }

    public void keyTyped(KeyEvent arg0) {

    }


    static final long serialVersionUID=100;
}

And when I try the compile it , here are some of the problems , the short version :

GL_DIFFUSE cannot be resolved or is not a field 

GL_LIGHT0 cannot be resolved or is not a field  

The method glVertex3f(int, float, int) is undefined for the type GL

The method glEnd() is undefined for the type GL

GL_LIGHTING cannot be resolved or is not a field

GL_LIGHT0 cannot be resolved or is not a field

GL_LIGHT1 cannot be resolved or is not a field

and more ... here is the long version :

Description Resource    Path    Location    Type
The method glLoadIdentity() is undefined for the type GL    Practice10IlluminateSphere.java /TESTING_opengl/src line 83 Java Problem
The type Practice10IlluminateSphere.GraphicListener must implement the inherited abstract method GLEventListener.dispose(GLAutoDrawable)    Practice10IlluminateSphere.java /TESTING_opengl/src line 64 Java Problem
The method glColor3f(float, int, float) is undefined for the type GL    Practice10IlluminateSphere.java /TESTING_opengl/src line 86 Java Problem
The method glTranslatef(float, int, int) is undefined for the type GL   Practice10IlluminateSphere.java /TESTING_opengl/src line 84 Java Problem
The method glTranslatef(float, int, float) is undefined for the type GL Practice10IlluminateSphere.java /TESTING_opengl/src line 90 Java Problem
The method glLoadIdentity() is undefined for the type GL    Practice10IlluminateSphere.java /TESTING_opengl/src line 89 Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 98 Java Problem
The method glColor3f(int, float, float) is undefined for the type GL    Practice10IlluminateSphere.java /TESTING_opengl/src line 92 Java Problem
GL_LIGHTING cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 109    Java Problem
GL_POSITION cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 98 Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 114    Java Problem
GL_LIGHT_MODEL_AMBIENT cannot be resolved or is not a field Practice10IlluminateSphere.java /TESTING_opengl/src line 112    Java Problem
GL_POSITION cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 116    Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 116    Java Problem
GL_DIFFUSE cannot be resolved or is not a field Practice10IlluminateSphere.java /TESTING_opengl/src line 118    Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 118    Java Problem
The method glVertex3f(float, int, float) is undefined for the type GL   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 105    Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 119    Java Problem
The method glVertex3f(int, int, int) is undefined for the type GL   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 104    Java Problem
GL_LINEAR_ATTENUATION cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 119    Java Problem
The method glNormal3f(int, int, int) is undefined for the type GL   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 103    Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 120    Java Problem
The method glBegin(int) is undefined for the type GL    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 101    Java Problem
GL_CONSTANT_ATTENUATION cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 120    Java Problem
The method glColor3f(int, int, int) is undefined for the type GL    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 100    Java Problem
GL_LIGHT2 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 121    Java Problem
The method glTranslatef(float, float, float) is undefined for the type GL   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 98 Java Problem
GL_QUADRATIC_ATTENUATION cannot be resolved or is not a field   Practice10IlluminateSphere.java /TESTING_opengl/src line 121    Java Problem
The method glLoadIdentity() is undefined for the type GL    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 97 Java Problem
GL_LIGHT3 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 123    Java Problem
The type Practice11IlluminateGeometry.GraphicListener must implement the inherited abstract method GLEventListener.dispose(GLAutoDrawable)  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 83 Java Problem
GL_LIGHT3 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 125    Java Problem
Animator cannot be resolved to a type   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 77 Java Problem
GL_POSITION cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 125    Java Problem
Animator cannot be resolved to a type   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 77 Java Problem
GL_LIGHT3 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 127    Java Problem
The constructor GLCapabilities() is undefined   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 73 Java Problem
GL_DIFFUSE cannot be resolved or is not a field Practice10IlluminateSphere.java /TESTING_opengl/src line 127    Java Problem
GLCanvas cannot be resolved to a type   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 73 Java Problem
GL_LIGHT3 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 129    Java Problem
GLCanvas cannot be resolved to a type   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 73 Java Problem
GL_SPOT_DIRECTION cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 129    Java Problem
The import com.sun.opengl cannot be resolved    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 31 Java Problem
GL_LIGHT3 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 130    Java Problem
The import javax.media.opengl.GLCanvas cannot be resolved   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 26 Java Problem
GL_SPOT_CUTOFF cannot be resolved or is not a field Practice10IlluminateSphere.java /TESTING_opengl/src line 130    Java Problem
GL_LIGHT3 cannot be resolved or is not a field  Practice10IlluminateSphere.java /TESTING_opengl/src line 131    Java Problem
Syntax error, insert "AssignmentOperator Expression" to complete Expression Practice10IlluminateSphere.java /TESTING_opengl/src line 139    Java Problem
GL_SHININESS cannot be resolved or is not a field   Practice10IlluminateSphere.java /TESTING_opengl/src line 138    Java Problem
GL_SPECULAR cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 137    Java Problem
GL_SPOT_EXPONENT cannot be resolved or is not a field   Practice10IlluminateSphere.java /TESTING_opengl/src line 131    Java Problem
gl_ cannot be resolved or is not a field    Practice10IlluminateSphere.java /TESTING_opengl/src line 139    Java Problem
Syntax error, insert ";" to complete Statement  Practice10IlluminateSphere.java /TESTING_opengl/src line 139    Java Problem
GL_POSITION cannot be resolved or is not a field    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 128    Java Problem
GL_LIGHT0 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 130    Java Problem
GL_DIFFUSE cannot be resolved or is not a field Practice11IlluminateGeometry.java   /TESTING_opengl/src line 130    Java Problem
GL_LIGHT1 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 132    Java Problem
GL_LIGHT1 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 134    Java Problem
GL_POSITION cannot be resolved or is not a field    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 134    Java Problem
GL_LIGHT1 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 136    Java Problem
GL_DIFFUSE cannot be resolved or is not a field Practice11IlluminateGeometry.java   /TESTING_opengl/src line 136    Java Problem
The method glVertex3f(int, float, int) is undefined for the type GL Practice11IlluminateGeometry.java   /TESTING_opengl/src line 106    Java Problem
The method glVertex3f(float, float, float) is undefined for the type GL Practice11IlluminateGeometry.java   /TESTING_opengl/src line 107    Java Problem
The method glVertex3f(float, float, int) is undefined for the type GL   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 108    Java Problem
The method glEnd() is undefined for the type GL Practice11IlluminateGeometry.java   /TESTING_opengl/src line 110    Java Problem
GL_LIGHTING cannot be resolved or is not a field    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 121    Java Problem
GL_LIGHT_MODEL_AMBIENT cannot be resolved or is not a field Practice11IlluminateGeometry.java   /TESTING_opengl/src line 124    Java Problem
GL_LIGHT0 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 126    Java Problem
GL_LIGHT0 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 128    Java Problem
GL_SPECULAR cannot be resolved or is not a field    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 138    Java Problem
The constructor GLCapabilities() is undefined   Practice10IlluminateSphere.java /TESTING_opengl/src line 54 Java Problem
GL_LIGHT1 cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 138    Java Problem
GL_AMBIENT_AND_DIFFUSE cannot be resolved or is not a field Practice11IlluminateGeometry.java   /TESTING_opengl/src line 142    Java Problem
GL_COLOR_MATERIAL cannot be resolved or is not a field  Practice11IlluminateGeometry.java   /TESTING_opengl/src line 141    Java Problem
GL_SHININESS cannot be resolved or is not a field   Practice11IlluminateGeometry.java   /TESTING_opengl/src line 145    Java Problem
GL_SPECULAR cannot be resolved or is not a field    Practice11IlluminateGeometry.java   /TESTING_opengl/src line 144    Java Problem

So, what's wrong here ? I added all the relevant jars but still nothing that worked in jogl 1.0 , still works on jogl 2.0 . Why ?

Much appreciated

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

jogl 2.0 have added profiles, this is important in order to support the new shader only based OpenGL contexts. The base GL class only contain functionality that is still common across all OpenGL profiles. http://jogamp.org/jogl/doc/Overview-OpenGL-Evolution-And-JOGL.html

To fix your code you first need to request a fixed function compatible profile. This is done in jogl 2 at the GLCapabilities constructor:

Example 1 to request a profile that is compatible with fixed functionality use:

GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));

Example 2 to request a profile that is compatible with both desktop OpenGL 2 and mobile OpenGL ES 2 devices using the programmable pipeline use:

GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2ES2));

Inside the GLEventListener functions you now need to specifically get the GL object that match functionality according to the profile you selected.

public class GraphicListener implements GLEventListener{
    public void display(GLAutoDrawable arg0) {
        GL2 gl=arg0.getGL().getGL2();

gl will now resolve all the missing methods for your application.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.