OpenGL 3.2 核心配置文件指南

发布于 2024-09-24 05:21:58 字数 74 浏览 4 评论 0原文

谁能推荐一个学习 OpenGL 3.2 核心配置文件的指南?

SDK很难读懂,而且我见过的大部分指南都只教授老方法。

Can anyone suggest a guide for learning the OpenGL 3.2 core profile?

The SDK is hard to read, and most of the guides I have seen only taught the old method.

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

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

发布评论

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

评论(1

旧城空念 2024-10-01 05:21:58

我不知道任何好的指南,但我可以为您做一个快速总结,

我假设您已经熟悉着色器、顶点缓冲区等的基础知识。如果您不熟悉,我建议您阅读有关着色器的指南首先,因为所有 OpenGL 3 都基于着色器的使用

初始化时:

  • 使用 glGenBuffersglBindBuffer(GL_ARRAY_BUFFER, bufferID) 和 <创建并填充顶点缓冲区code>glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW)

  • 与索引缓冲区相同,只是使用 GL_ELEMENT_ARRAY_BUFFER 而不是 GL_ARRAY_BUFFER

  • 创建纹理,就像在以前版本的 OpenGL (glGenTextures) 中所做的那样, glBindTexture, glTexImage2D)

  • 使用 glCreateShader 创建着色器,使用 glShaderSource 设置其 GLSL 源代码,并使用 glCompileShader 编译它们;您可以使用 glGetShaderiv(shader, GL_COMPILE_STATUS, &out) 检查它是否成功,并使用 glGetShaderInfoLog

    检索错误消息使用 glCreateShader

  • 创建程序(即一组绑定的着色器) (通常是一个顶点着色器和一个片段着色器)与 glCreateProgram 一起使用,然后使用 glAttachShader 绑定所需的着色器,然后使用 链接 程序代码>glLinkProgram;就像着色器一样,您可以使用 glGetProgramglGetProgramInfoLog

    检查链接是否成功

当您想要绘制时:

  • 使用 glBindBuffer 绑定顶点和索引缓冲区分别带有参数 GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

  • 绑定程序与glUseProgram

  • 现在,对于着色器中的每个变化变量,您必须调用 glVertexAttribPointer ,其语法类似于旧版 glVertexPointerglColorPointer code> 等函数,但其​​第一个参数除外,它是变量的标识符;可以通过在链接程序上调用 glGetAttribLocation 来检索此标识符

  • 对于着色器中的每个统一变量,您必须调用 glUniform ;它的第一个参数是统一变量的位置(也是一种标识符),您可以通过调用glGetUniformLocation来检索该变量(警告:如果您有一个名为“a”的数组,则必须调用function with "a[0]")

  • 对于要绑定的每个纹理,您必须使用GL_TEXTUREi调用glActiveTexture(i对于每个纹理都不同) ,然后glBindTexture,然后将uniform的值设置为i

  • Call glDrawElements

这是你必须做的基本事情。当然还有其他东西,如顶点数组对象、统一缓冲区等,但它们仅用于优化目的

其他领域如剔除、混合、视口等与旧版本的 OpenGL 基本保持相同

我也建议您学习此演示程序(使用顶点数组对象)。最有趣的文件是 main.cpp

希望这可以帮助

I don't know any good guide but I can make you a quick summary

I'll assume that you are already familiar with the basics of shaders, vertex buffers, etc. If you don't, I suggest you read a guide about shaders first instead, because all OpenGL 3 is based on the usage of shaders

On initialisation:

  • Create and fill vertex buffers using glGenBuffers, glBindBuffer(GL_ARRAY_BUFFER, bufferID) and glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW)

  • Same for index buffers, except that you use GL_ELEMENT_ARRAY_BUFFER instead of GL_ARRAY_BUFFER

  • Create textures exactly like you did in previous versions of OpenGL (glGenTextures, glBindTexture, glTexImage2D)

  • Create shaders using glCreateShader, set their GLSL source code using glShaderSource, and compile them with glCompileShader ; you can check if it succeeded with glGetShaderiv(shader, GL_COMPILE_STATUS, &out) and retrieve error messages using glGetShaderInfoLog

  • Create programs (ie. a group of shaders bound together, usually one vertex shader and one fragment shader) with glCreateProgram, then bind the shaders you want using glAttachShader, then link the program using glLinkProgram ; just like shaders you can check linking success with glGetProgram and glGetProgramInfoLog

When you want to draw:

  • Bind the vertex and index buffers using glBindBuffer with arguments GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER respectively

  • Bind the program with glUseProgram

  • Now for each varying variable in your shaders, you have to call glVertexAttribPointer whose syntax is similar to the legacy glVertexPointer, glColorPointer, etc. functions, except for its first parameter which is an identifier for the varying ; this identifier can be retrieved by calling glGetAttribLocation on a linked program

  • For each uniform variable in your shaders, you have to call glUniform ; its first parameter is the location (also a kind of identifier) of the uniform variable, which you can retrieve by calling glGetUniformLocation (warning: if you have an array named "a", you have to call the function with "a[0]")

  • For each texture that you want to bind, you have to call glActiveTexture with GL_TEXTUREi (i being different for each texture), then glBindTexture and then set the value of the uniform to i

  • Call glDrawElements

This is the basic things you have to do. Of course there are other stuff, like vertex array objects, uniform buffers, etc. but they are merely for optimization purposes

Other domains like culling, blending, viewports, etc. remained mostly the same as in older versions of OpenGL

I also suggest you study this demo program (which uses vertex array objects). The most interesting file is main.cpp

Hope this can help

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