What controls which interface GLAutoDrawable.getGL() returns?

只愿长相守 提交于 2019-12-12 04:37:24

问题


In trying to work through tutorials on JOGL, I run into trouble when entering this part of the code:

@Override
public void display(GLAutoDrawable glad) {
    GL gl = glad.getGL();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glBegin(GL.GL_TRIANGLES);

This doesn't compile because glBegin is not a method in GL even though the online tutorials use it that way. By digging around in the JOGL javadoc I found that I could get the tutorial to work by doing this:

    GL2 gl = (GL2) glad.getGL();

Then all the methods are there. My questions are:

  1. Can I expect a different interface to be returned by getGL on different platforms? This is on MacOS 10.9. What controls what version of the interface is used?
  2. Since it appears that the tutorials are out of date, did this work under a different version of OpenGL?

回答1:


Your question is very similar to Can't find GL.glColor3f in JOGL?. The reason why you were not able to use glBegin without casting to GL2 is because glBegin (and many other functions) were deprecated in OpenGL 3. This is known as immediate mode where you specify vertices between glBegin and glEnd. In OpenGL 3 and higher the way to draw primitives is by storing the vertices in a buffer and drawing with glDrawArrays or glDrawElements. You will get different versions of OpenGL on different platforms and different computers. It depends on what version of OpenGL is supported on that computer. Newer computers with newer graphics cards will be able to support the latest version of OpenGL while older computers might be stuck on an older OpenGL version.




回答2:


Please look at our Java documentation and our overview of OpenGL evolution. The GL interface you get depends on the GLProfile you use and the GL interface your machine supports. It doesn't depend on your operating system but rather on what is supported by your graphics card. All methods were in GL in JOGL 1 whereas there are several GL interfaces and implementations in JOGL 2. user3256930's answer is incomplete. A desktop machine can support both OpenGL (backward and forward compatible profiles) and OpenGL ES. Then, there are at least 3 GL implementations that you can get and it depends on your profile, you can call GLProfile.getMaxFixedFunc(boolean), GLProfile.getMaxProgrammable(boolean), getDefault(), ...

As glBegin is only in the fixed pipeline and not in OpenGL ES, you'll get it only if the GL interface you get is GL2 or another interface that extends it, for example GL4bc (bc = backward compatible).

Please rather post your questions specific to JOGL on our official forum.



来源:https://stackoverflow.com/questions/25850368/what-controls-which-interface-glautodrawable-getgl-returns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!