OpenGL 已弃用的函数以及 gluPerspective 和 Transform

发布于 2024-12-13 04:00:36 字数 1482 浏览 3 评论 0原文

我是 OpenGL 新手,仍在尝试基本形状。我有时会发现许多函数,例如 glEnd 等,OpenGL 3+ 文档中未提及这些函数。它们被其他功能取代了吗?或者我必须手动编写它们? 是否有使用 OpenGL 3+ 的在线教程?

至于“ gluPerspective”,我读到它没有在 Opengl 3+ 中使用。它不应该是 GLUT 中的一个单独的函数吗?它与 OpenGL 3+ 有什么关系?最后,Transform( Width, Height ); 是什么意思?做? (我在下载的一些示例代码中找到了它,但在 GLUT 或 OpenGL 中找不到它)。

这是代码:

GLvoid Transform(GLfloat Width, GLfloat Height)
{
  glViewport(00, 00, Width, Height);              /* Set the viewport */
  glMatrixMode(GL_PROJECTION);                  /* Select the projection matrix */
  glLoadIdentity();             /* Reset The Projection Matrix */
  gluPerspective(20.0,Width/Height,0.1,100.0);  /* Calculate The Aspect Ratio Of The Window */
  glMatrixMode(GL_MODELVIEW);                   /* Switch back to the modelview matrix */
}


/* A general OpenGL initialization function.  Sets all of the initial parameters. */
GLvoid InitGL(GLfloat Width, GLfloat Height)    
{
  glClearColor(0.0, 0.0, 0.0, 0.0);     /* This Will Clear The Background Color To Black */
  glLineWidth(2.0);                             /* Add line width,   ditto */
  Transform( Width, Height );                   /* Perform the transformation */
}

/* The function called when our window is resized  */
GLvoid ReSizeGLScene(GLint Width, GLint Height)
{
  if (Height==0)    Height=1;                   /* Sanity checks */
  if (Width==0)      Width=1;
  Transform( Width, Height );                   /* Perform the transformation */
}

I am new to OpenGL and I am still experimenting with basic shapes. I sometimes find many functions like glEnd and many more, that are not mentioned in the OpenGL 3+ documentation. Were they replaced by other functions? Or do I have to write them manually?
Is there a tutorial online that uses OpenGL 3+?

As for " gluPerspective" I have read that it isn't used in Opengl 3+. Isn't it supposed to be a separate function in GLUT? what does it has to do with OpenGL 3+? Last, what does Transform( Width, Height ); do? (I found it in some sample code I downloaded, and I can't find it in GLUT or OpenGL).

here is the code:

GLvoid Transform(GLfloat Width, GLfloat Height)
{
  glViewport(00, 00, Width, Height);              /* Set the viewport */
  glMatrixMode(GL_PROJECTION);                  /* Select the projection matrix */
  glLoadIdentity();             /* Reset The Projection Matrix */
  gluPerspective(20.0,Width/Height,0.1,100.0);  /* Calculate The Aspect Ratio Of The Window */
  glMatrixMode(GL_MODELVIEW);                   /* Switch back to the modelview matrix */
}


/* A general OpenGL initialization function.  Sets all of the initial parameters. */
GLvoid InitGL(GLfloat Width, GLfloat Height)    
{
  glClearColor(0.0, 0.0, 0.0, 0.0);     /* This Will Clear The Background Color To Black */
  glLineWidth(2.0);                             /* Add line width,   ditto */
  Transform( Width, Height );                   /* Perform the transformation */
}

/* The function called when our window is resized  */
GLvoid ReSizeGLScene(GLint Width, GLint Height)
{
  if (Height==0)    Height=1;                   /* Sanity checks */
  if (Width==0)      Width=1;
  Transform( Width, Height );                   /* Perform the transformation */
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

于我来说 2024-12-20 04:00:36

我有时会发现许多函数,例如 glEnd 等,这些函数在 OpenGL 3+ 文档中没有提及。它们被其他功能取代了吗?

它们已被完全删除,因为它们的工作方式不能很好地反映现代图形系统在硬件和软件方面的工作方式。 glBegin(…) 和 glEnd() 形成了所谓的立即模式的环境:每次调用都会引发一个操作。这反映了大约 20 年前早期图形系统的构建方式。

如今,人们准备一批数据,将它们传输到 GPU 内存,并通过一次绘图调用触发批量绘图。 OpenGL 通过顶点数组和顶点缓冲对象 (VBO) 来实现这一点。顶点数组自 OpenGL-1.1(1996)以来就已经存在,并且 VBO API 是建立在顶点数组之上的,因此对于任何合理的程序,都可以轻松添加 VBO 支持。

或者我必须手动编写它们?是否有使用 OpenGL 3+ 的在线教程?

这取决于所讨论的功能。例如,整个纹理环境、组合器已被删除。就像矩阵操作功能和整个灯光界面一样。

他们所做的和配置的现在是通过着色器和制服来完成的。有人可能会说,既然您需要提供着色器,那么您就应该自己实现这一点。您很快就会发现,通常编写着色器比摆弄大量 OpenGL 参数设置调用更容易、更简洁。此外,一旦您取得了足够的进展,您就几乎不会错过矩阵操作函数。每个处理 3D 图形的严肃应用程序都会维护变换矩阵本身;无论是为了增强灵活性还是仅仅因为其他地方也需要这些矩阵,例如一些物理模拟。

至于“gluPerspective”,我读到它在 Opengl 3+ 中没有使用。它不应该是 GLUT 中的一个单独的函数吗?它与 OpenGL 3+ 有什么关系?最后,Transform( Width, Height ); 是什么意思?做? (我在下载的一些示例代码中找到了它,但在 GLUT 或 OpenGL 中找不到它)。

gluPerspective 是 GLU 的一部分。 GLU 是 OpenGL 实用函数的配套库,过去随 OpenGL-1.1 一起提供。然而它不是 OpenGL 规范的一部分并且完全可选。

过剩又是另一回事了。它是一个简单的框架,用于快速设置 OpenGL 窗口和上下文,并提供一些简约的输入 API。它也不再被积极维护。我个人建议不要使用它。如果必须使用 GLUT API,请使用 FreeGLUT。或者更好的是,根本不要过多,使用 Qt、GTK 等工具包或 GLFW 或 SDL 等框架。

I sometimes find many functions like glEnd and many more, that are not mentioned in the OpenGL 3+ documentation. Were they replaced by other functions?

They have been completely removed, since their workings doesn't reflect well with how modern graphics systems work on both the hardware and the software side. glBegin(…) and glEnd() form the surroundings of the so called immediate mode: Every call causes an operation. This reflects how early graphics systems were built, some 20 years ago.

Today one prepares batches of data, transfers them to GPU memory and triggers batch drawings with a single drawing call. OpenGL does this through vertex arrays and vertex buffer objects (VBOs). Vertex arrays have been around since OpenGL-1.1 (1996), and the VBO API is founded on vertex arrays, so for any reasonable program VBO support was added easily.

Or do I have to write them manually? Is there a tutorial online that uses OpenGL 3+?

It depends on the function in question. For example the whole texture environment, combiners have been removed. Just like the matrix manipulation functions and the whole lighting interface.

What they did and configured is now done through shaders and uniforms. Since you're expected to supply shaders one might say, you're expected to implement this yourself. OTOH you'll quickly find out, that often writing a shader is easier and more concise, than fiddling with large numbers of OpenGL parameter setting calls. Also once you've progressed far enough you'll hardly miss the matrix manipulation functions. Every serious application dealing with 3D graphics maintains the transformation matrices itself; be it for enhanced flexibilty or simply because those matrices are required in other places, too, e.g. some physics simulation.

As for " gluPerspective" I have read that it isn't used in Opengl 3+. Isn't it supposed to be a separate function in GLUT? what does it has to do with OpenGL 3+? Last, what does Transform( Width, Height ); do? (I found it in some sample code I downloaded, and I can't find it in GLUT or OpenGL).

gluPerspective is part of GLU. GLU is a companion library of OpenGL Utility functions, that used to ship with OpenGL-1.1. However it is not part of the OpenGL specification and completely optional.

GLUT is something else again. It's a simplicistic framework for quick and dirty setup of a OpenGL window and context, offering some minimalistic input API. Also it's no longer actively maintained. Personally I recommend not using it. If you must use a GLUT API, use FreeGLUT. Or better yet, don't GLUT at all, use a toolkit like Qt, GTK or a framework like GLFW or SDL.

过潦 2024-12-20 04:00:36

它们被其他功能取代了吗?

不。

或者我必须手动编写它们吗?

对于旧式即时模式几何提交,您必须制作自己的类似作品。 矩阵堆栈有一个替代品

是否有使用 OpenGL 3+ 的在线教程?

至少一个< /a>.

Were they replaced by other functions?

No.

Or do I have to write them manually?

For old-style immediate-mode geometry submission you'll have to make your own work-alike. The matrix stack has a replacement.

Is there a tutorial online that uses OpenGL 3+?

At least one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文