Qt OpenGL 磅值
Qt OpenGL point size
我正在将 QOpenGLFunctions 与现代 OpenGL 一起使用。我想在我的 window 上画一些 GL_POINTS 但点数似乎很小。通常,您可以使用
更改点的大小
glPointSize(4);
但是,此代码片段在 QOpenGLFunctions 包装器中不存在,因此我不确定如何更改它们。
绘图 GL_TRIANGLES 对我来说非常好。
我想绘制点来显示真实世界对象的点云。
如果用QOpenGLFunctions
,就真的没有glPointSize()
了。为什么?
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
在 khronos.org 上进行交叉检查:
+--------------+-----------------------------------------------------------------------+
| Function / | OpenGL Version |
| Feature Name | 2.0 | 2.1 | 3.0 | 3.1 | 3.2 | 3.3 | 4.0 | 4.1 | 4.2 | 4.3 | 4.4 | 4.5 |
+--------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| glPointSize | v | v | v | v | v | v | v | v | v | v | v | v |
+--------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
因此,它支持 OpenGL 但不支持 OpenGL ES。
有两种可能的选择:
选项 1:gl_PointSize
在 OpenGL ES 中,您可以改用 GLSL 着色器变量 gl_PointSize
。
(我在搜索适当的文档链接时发现了这个 "accidentally" – 以前不知道也从未使用过它。)
derhass provided the additional hint that this might be used with OpenGL (non-ES) as well if enabled by glEnable(GL_PROGRAM_POINT_SIZE)
.
GL_PROGRAM_POINT_SIZE
If enabled and a vertex or geometry shader is active, then the derived point size is taken from the (potentially clipped) shader builtin gl_PointSize
and clamped to the implementation-dependent point size range.
选项 2:使用替代方案 QOpenGLFunctions_???
class
而不是 QOpenGLFunctions
,您可以明确使用非便携式替代方案(假设您不需要支持手机、嵌入式设备或类似设备)。
Qt 文档中最好的概述。我可以找到:QAbstractOpenGLFunctions
.
按照 derhass 的建议,首先在 C++ 代码(不是着色器)中使用此行启用点大小:
glEnable(GL_PROGRAM_POINT_SIZE);
然后按照 Scheff 的建议,在您的 vertex 着色器代码中,添加 gl_PointSize
内置函数。
因此,例如,如果你想要一个点的大小为 12,就这样使用它。
// main from your vertex.glsl shader (not from your main.cpp!)
void main() {
...
gl_PointSize = 12;
...
}
我正在将 QOpenGLFunctions 与现代 OpenGL 一起使用。我想在我的 window 上画一些 GL_POINTS 但点数似乎很小。通常,您可以使用
更改点的大小glPointSize(4);
但是,此代码片段在 QOpenGLFunctions 包装器中不存在,因此我不确定如何更改它们。
绘图 GL_TRIANGLES 对我来说非常好。
我想绘制点来显示真实世界对象的点云。
如果用QOpenGLFunctions
,就真的没有glPointSize()
了。为什么?
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
在 khronos.org 上进行交叉检查:
+--------------+-----------------------------------------------------------------------+ | Function / | OpenGL Version | | Feature Name | 2.0 | 2.1 | 3.0 | 3.1 | 3.2 | 3.3 | 4.0 | 4.1 | 4.2 | 4.3 | 4.4 | 4.5 | +--------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ | glPointSize | v | v | v | v | v | v | v | v | v | v | v | v | +--------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
因此,它支持 OpenGL 但不支持 OpenGL ES。
有两种可能的选择:
选项 1:gl_PointSize
在 OpenGL ES 中,您可以改用 GLSL 着色器变量 gl_PointSize
。
(我在搜索适当的文档链接时发现了这个 "accidentally" – 以前不知道也从未使用过它。)
derhass provided the additional hint that this might be used with OpenGL (non-ES) as well if enabled by glEnable(GL_PROGRAM_POINT_SIZE)
.
GL_PROGRAM_POINT_SIZE
If enabled and a vertex or geometry shader is active, then the derived point size is taken from the (potentially clipped) shader builtin
gl_PointSize
and clamped to the implementation-dependent point size range.
选项 2:使用替代方案 QOpenGLFunctions_???
class
而不是 QOpenGLFunctions
,您可以明确使用非便携式替代方案(假设您不需要支持手机、嵌入式设备或类似设备)。
Qt 文档中最好的概述。我可以找到:QAbstractOpenGLFunctions
.
按照 derhass 的建议,首先在 C++ 代码(不是着色器)中使用此行启用点大小:
glEnable(GL_PROGRAM_POINT_SIZE);
然后按照 Scheff 的建议,在您的 vertex 着色器代码中,添加 gl_PointSize
内置函数。
因此,例如,如果你想要一个点的大小为 12,就这样使用它。
// main from your vertex.glsl shader (not from your main.cpp!)
void main() {
...
gl_PointSize = 12;
...
}