OpenGL不建议使用的功能和gluPerspective和Transform [英] OpenGL deprecated functions and gluPerspective and Transform

查看:114
本文介绍了OpenGL不建议使用的功能和gluPerspective和Transform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenGL的新手,我仍在尝试基本形状.有时我会发现很多功能,例如glEnd等等,而这些功能在OpenGL 3+文档中没有提到.他们被其他功能取代了吗?还是我必须手动编写它们? 在线上有使用OpenGL 3+的教程吗?

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+?

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

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

下面是代码:

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 */
}

推荐答案

我有时会找到许多功能,例如glEnd等,而OpenGL 3+文档中没有提到.他们被其他功能取代了吗?

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?

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

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.

今天,人们准备一批数据,将其传输到GPU内存,并通过一次绘图调用触发批处理图形. OpenGL通过顶点数组和顶点缓冲对象(VBO)来完成此操作.自OpenGL-1.1(1996)以来,顶点数组就已经存在,并且VBO API建立在顶点数组上,因此对于任何合理的程序,都容易添加VBO支持.

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.

还是我必须手动编写它们?在线上有使用OpenGL 3+的教程吗?

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.

他们所做的和配置的工作现在通过着色器和统一方式完成.既然您可能会提供一个着色器,那么您应该自己实现. OTOH您会很快发现,与摆弄大量OpenGL参数设置调用相比,经常编写着色器更容易,更简洁.同样,一旦您取得了足够的进步,您将几乎不会错过矩阵处理功能.每个处理3D图形的重要应用程序都自己维护变换矩阵.是为了提高灵活性,还是仅仅因为在其他地方也需要这些矩阵,例如一些物理模拟.

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.

至于"gluPerspective",我已经阅读到它在Opengl 3+中没有使用.它不是应该在GLUT中是一个单独的功能吗?它与OpenGL 3+有什么关系?最后,Transform(Width,Height);做? (我在下载的一些示例代码中找到了它,但在GLUT或OpenGL中找不到它.)

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是GLU的一部分. GLU是OpenGL实用程序功能的随附库,该库随OpenGL-1.1一起提供.但是,它不是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又是另一回事了.这是用于OpenGL窗口和上下文的快速,肮脏设置的简化框架,提供了一些简约的输入API.而且它也不再被积极维护.我个人建议不要使用它.如果必须使用GLUT API,请使用FreeGLUT.或者更好的是,根本不使用GLUT,使用Qt,GTK之类的工具包或GLFW或SDL之类的框架.

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.

这篇关于OpenGL不建议使用的功能和gluPerspective和Transform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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