OpenGL version to start with (as of late 2014)(开始的 OpenGL 版本(截至 2014 年底))
问题描述
我对 OpenGL 一无所知,但事实证明,我正在做的事情可能需要它(想出这个只是因为我想要一些需要快速绘图的视觉效果 - 硬件加速).
I know nothing about OpenGL, but it turns out it might be needed for something that I'm working on (figured this out simply because I want some visual effects that need fast drawing - hardware accelerated).
所以我非常担心从当前日期开始为哪个版本的 OpenGL 编码?(2014 年 9 月供未来读者使用).
So I'm very much troubled about which version of OpenGL to start coding for as of the current date? (September 2014 for future readers).
到目前为止,我已经读过 OpenGL 3.x 是最可用的(读作:受支持的)版本,即使在非常旧的硬件(即为 Windows XP 设计)上也是如此.但是,如果我为 OpenGL 4.x 开发,我的应用程序会向后兼容 3.x 支持的硬件吗?或者它只是在那里中断并且只能在 4.x(以及未来?)支持的硬件上运行?
As of now, I have read OpenGL 3.x is the most available (read as: supported) version, even on very old hardware (i.e. designed for Windows XP). But, what if I develop for OpenGL 4.x, will my application be backward-compatible with 3.x supported hardware? Or does it just break there and only run on 4.x (and future?) supported hardware?
我对 OpenGL 的使用不是用于视频游戏或任何类似的东西,所以我可能永远不需要高级功能(到目前为止,我无法举出任何例子来说明我可能永远不会使用的东西,我希望有经验的 OpenGL 人会明白我的意思).但是,我认为这不会以任何方式降低所需的驱动程序支持,对吗?
My use of OpenGL is not for a videogame or anything similar so I might never need advanced functionality (as of now I can't name any to give you an example of what I may never use, I hope experienced OpenGL people will understand my point). However, I don't think this is going to lower in any way the driver support required, am I right?
请注意,我可能使用了错误的术语,我想开始学习 OpenGL,这使我无法理解我是否需要 this 或 that 功能和/或可能的要求 - 我需要真正的建议才能开始并找到出路.
Please note that I might have used the wrong terminology and I want to start learning OpenGL which puts me in a position not so good to understand whether I might need this or that feature and/or possible requirements - I am in the need of real advice to get started and figure my way out.
推荐答案
我相信这个答案会跳过许多细节和例外(所以请注意,如果您不同意或有什么要补充的,请发表评论:P), 但是... 每个 OpenGL 版本大多只是添加功能,所以如果您开始使用新功能,它可能会限制您可以在其上运行应用程序的硬件(因此这个问题引起了反对票,而它应该引起解释).
I'm sure this answer skips many many details and exceptions (so take with salt and if you disagree or have something to add, leave a comment :P), but... Each OpenGL version mostly just adds features, so if you start using a new features it might limit the hardware you can run your app on (and so the question attracted a downvote, when instead it should have attracted an explanation).
基本绘图几乎保持不变,有一个很大的例外:所有的东西都是 在版本 3 中已弃用并在 3.1 中删除.
Basic drawing pretty much remains a constant, with one very big exception: all the stuff that was deprecated in version 3 and removed in 3.1.
我们曾经能够做以下事情:
We used to be able to do things like:
glEnable(GL_LIGHTING); //fixed-pipeline lighting. replaced with shaders
glEnable(GL_TEXTURE_2D); //fixed texturing
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); //builtin matrices
glBegin(GL_TRIANGLES); glVertex3f(...) ...; glEnd(); //immediate mode with per-vertex calls
glVertexPointer(..., myArray); glDrawArrays(...); //immediate mode with client side array
但即便如此,我们仍然有 GLSL 着色器和 VBO.有相当多的重叠,GL3 的弃用并没有立即取代一切:
But even then we still had GLSL shaders and VBOs. There's a fair amount of overlap and the GL3 deprecation didn't instantly replace everything:
glBufferData(...); //buffer mesh data to bound VBO
...
glVertexAttribPointer(...); //attach data to myCustomVar (either VBO or immediate mode local array)
...
attribute vec3 myCustomVar;
varying vec3 myVarying;
...
gl_Position = gl_ProjectionMatrix * gl_ModelviewMatrix * gl_Vertex;
...
gl_FragColor = vec4(1, 0, 0, 1);
新,>= GL 3:
新的绘图方式删除了即时模式和许多这些内置功能,因此您可以从头开始做很多事情,添加一些功能和语法更改.你必须使用 VBO 和着色器:
New, >= GL 3:
The new way of drawing removes immediate mode and a lot of these in-built features so you do a lot from scratch, adds a few features and syntax changes. You have to use VBOs and shaders:
glBufferData(...); //buffer mesh data
...
glVertexAttribPointer(...); //attach VBOs, but have to set your own position etc too
...
#version 150 //set GLSL version number
out vec3 myVarying; //replaces "varying"
gl_Position = myProjection * myModelview * myPosition;
...
in vec3 myVarying;
out vec4 fragColour; //have to define your own fragment shader output
...
fragColour = vec4(1, 0, 0, 1);
为了回答您的问题,这完全是我的观点,我将开始学习 GLES2.0(afaik 几乎是 GL3 的一个子集),因为它现在得到了很好的支持.GL2/即时模式作为一个学习步骤当然不会受到伤害,而且还有很多东西没有被弃用.如果你发现你需要它们,你总是可以只使用 GL 4 功能,但正如所说的那样,基础知识实际上只在上述版本之间发生了变化.即使您使用已弃用的功能您也必须不遗余力地获得不允许某些调用/功能的纯 GL3.2(例如)上下文.我不提倡这样做,但完全有可能将非常旧的和非常新的混合在一起,而且大多数司机似乎都允许这样做.
To answer your question, and this is completely my opinion, I'd start learning GLES2.0 (afaik pretty much a subset of GL3) because it's so well supported right now. GL2/immediate mode certainly doesn't hurt as a learning step, and there's still quite a lot that isn't deprecated. You can always just use GL 4 features if you find you need them, but as said the basics really only changed between the above versions. Even if you use deprecated features you have to go out of your way to get a pure GL3.2 (for example) context that disallows certain calls/features. I'm not advocating it but it's entirely possible to mix very old with very new and most drivers seem to allow it.
TLDR: 1. 使用 VBO,2. 使用着色器.只是为了学习,不要为明确的版本上下文而烦恼.
TLDR: 1. use VBOs, 2. use shaders. Just for learning, don't bother with an explicit version context.
另见:
- http://www.opengl.org/wiki/History_of_OpenGL
- http://www.opengl.org/wiki/Core_And_Compatibility_in_Contexts
- 已弃用的 OpenGL 功能列表
这篇关于开始的 OpenGL 版本(截至 2014 年底)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:开始的 OpenGL 版本(截至 2014 年底)
基础教程推荐
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01