Jogl2不会接受jogl 1.0代码 – GL_LIGHTING和GL_LIGHT_MODEL_AMBIENT无法parsing或不是字段?

我试图在jogl 2.0上第一次运行我的代码(到现在为止我使用了jogl 1.0),但是Eclipse几乎抛出了每一个我都有“无法parsing或者不是字段”的消息。

jogl 2.0库中的文件是:

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 

代码非常简单:

 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; } 

而当我尝试编译它,这里有一些问题, 简短的版本

 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 

和更多…这是长版本

 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 

那么,这里有什么问题? 我添加了所有相关的jar子,但仍然没有在jogl 1.0中工作,仍然工作在jogl 2.0。 为什么?

非常感激

jogl 2.0已经添加了configuration文件,这对于支持基于OpenGL的新着色器来说非常重要。 基础GL类只包含在所有OpenGLconfiguration文件中仍然通用的function。 http://jogamp.org/jogl/doc/Overview-OpenGL-Evolution-And-JOGL.html

要修复您的代码,您首先需要请求一个固定function兼容的configuration文件。 这是在GLCapabilities构造函数的jogl 2中完成的:

示例1请求与固定function使用兼容的configuration文件:

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

示例2要求使用可编程管线使用与桌面OpenGL 2和移动OpenGL ES 2设备兼容的configuration文件:

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

在GLEventListener函数中,您现在需要根据所选configuration文件明确获取匹配function的GL对象。

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

gl现在将解决您的应用程序的所有缺less的方法。