什么控制GLAutoDrawable.getGL()返回哪个接口? [英] What controls which interface GLAutoDrawable.getGL() returns?

查看:129
本文介绍了什么控制GLAutoDrawable.getGL()返回哪个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试遍历JOGL上的教程时,输入代码的这一部分时遇到麻烦:

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

这不会编译,因为 glBegin 不是 GL 中的一种方法,即使在线教程中也是如此.通过深入研究JOGL Javadoc,我发现我可以通过执行以下操作使该教程起作用:

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. 我可以期望 getGL 在不同平台上返回不同的接口吗?这是在MacOS 10.9上.什么控制使用什么版本的界面?
  2. 既然这些教程似乎已经过时了,那么在其他版本的OpenGL上可以正常工作吗?
  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?

推荐答案

您的问题与

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.

这篇关于什么控制GLAutoDrawable.getGL()返回哪个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆