OpenGL 3.1-4.1 新功能和弃用功能
我使用 OpenGL 已经大约一年了,并且学到了很多东西。不幸的是,我了解到它的方式是旧的 3.x 之前的方式,意味着立即模式、默认着色器、矩阵堆栈等。通过查看 OpenGL 规范,我或多或少知道从那时到现在发生了什么变化。我并不完全理解一些新的做事方式。
根据我的理解,他们摆脱了矩阵堆栈,这意味着您必须跟踪自己的变换矩阵,这看起来并不太复杂。他们还摆脱了即时模式,这意味着您现在需要使用 VBO 或 VAO(永远不知道哪一个,也许两者都......)来发送像素/法线/纹理等。着色器程序的信息。我不太明白这些对象的工作方式,我认为你需要将所有信息放入其中,并提供某种偏移量来显示像素、法线和纹理坐标之间的分隔符。有人可以简要解释一下这实际上是如何工作的(或者给我发送一个解释它的链接)吗?我尝试了维基百科并谷歌搜索,但发现自己仍然不太理解它们。
我想更多了解的另一点是着色器,因为我从未使用过它们。我不会问如何对它们进行编码或其他任何事情,只是需要在那里输入什么以及 opengl 仍然可以为您做什么。更具体地说,您需要在着色器中做什么才能获得基本的渲染程序?我知道您需要进行所有照明计算并使用矩阵来计算真实的顶点位置。但是opengl是否仍然处理背面剔除、线条裁剪、多边形填充和其他较低级别的问题,或者您是否必须自己将它们编码到着色器中(或者它们甚至不属于着色器)?
I've been working with OpenGL for about a year now, and have learned a lot of stuff. Unfortunatly the way I learned it was the old pre 3.x way, meaning immediate mode, default shaders, matrix stacks, etc. I more or less have an idea of what has changed from then to now by looking at the OpenGL specs, however I don't totally understand some of the new ways to do things.
From my understanding they got rid of matrix stacks, meaning you have to keep track of your own transformation matrices, which doesn't seem too complicated. They also got rid of immediate mode, meaning you now need to use VBOs or VAOs (never know which one, maybe both..) to send the pixel/normal/texture,etc. information to the shader program. I don't really get the way these objects works, I think you need to put all the info into them, and provide an ofset of some sort to show the separators between pixel,normal and texture coordinates. Could someone briefly explain how this actually works (or send me a link which explains it)? I tried wikipedia and googling it, but found myself still not quite understanding them.
Another point I would like to know more about are shaders, as I've never used them. I'm not going to ask how to code them or anything, just what needs to go in there and what opengl still does for you. More specifically, what would you need to do in the shaders to get a basic rendering program? I know you need to do all the ligthing calculations and use your matrices to calculate the real vertex position. But does opengl still take care of backface culling, line clipping, polygon filling and other lower level issues, or do you have to code them yourslef into the shaders (or don't they even belong in the shaders)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于立即模式已被弃用,因此执行“Hello Triangle”应用程序会涉及更多一些。这里有一个关于现代 OpenGL 的很好的教程:
http://arcsynthesis.org/gltut/
你应该阅读它彻底。请记住,它不使用 VAO,因此您必须随后在其他地方阅读它。 VAO 不会改变太多东西,因此您不必忘记从提到的教程中学到的东西来使用它们。
关于你的第二个问题...你的顶点着色器将由 OpenGL 对每个顶点执行。您的工作是计算顶点的最终位置并准备要发送到片段着色器的数据(如法线、光照数据...),给定顶点的属性和您发送到着色器的其他数据(制服 - 您将阅读有关教程中)。片段着色器将按片段执行,并且在片段着色器中您将计算每个片段的最终颜色。
您可以在这里看到:
http://www.opengl.org/sdk/docs/man4/< /a>
像 glPolygonMode 和 glCullFace 这样的东西仍然存在。
Since immediate mode is deprecated doing a "hello triangle" application is a bit more involved. There is a good tutorial on modern OpenGL here:
http://arcsynthesis.org/gltut/
You should read it thoroughly. Bear in mind that it doesn't use VAOs so you'll have to read about it somewhere else afterwards. VAOs don't change things much so you won't have to unlearn things from mentioned tutorial to use them.
And about your second question... Your vertex shader will be executed by OpenGL for every vertex. Your job is to calculate final position of the vertex and prepare data (like normals, light data...) to be sent to fragment shader, given the attributes of vertex and other data you send to shader (uniforms - you'll read about it in tutorial). Fragment shader will be executed per fragment and in fragment shader you are calculating the final color of each fragment.
You can see here:
http://www.opengl.org/sdk/docs/man4/
that things like, glPolygonMode and glCullFace are still there.