[英]Qt OpenGL point size
I am using QOpenGLFunctions with modern OpenGL.我在现代 OpenGL 中使用 QOpenGLFunctions。 I want to draw some GL_POINTS on my window but the point size seems to be really small.我想在我的窗口上画一些 GL_POINTS 但点的大小似乎真的很小。 Usually, you can change the size of points with通常,您可以更改点的大小
glPointSize(4);
However, this code snippet does not exist in the QOpenGLFunctions wrapper, so I am not sure how to change them.但是,此代码片段在 QOpenGLFunctions 包装器中不存在,因此我不确定如何更改它们。
Drawing GL_TRIANGLES works perfectly fine for me.绘制 GL_TRIANGLES 对我来说非常好。
I want to draw points to display a point cloud of real-world objects.我想绘制点以显示真实世界对象的点云。
If you use QOpenGLFunctions
, there is really no glPointSize()
available.如果您使用QOpenGLFunctions
,则实际上没有可用的glPointSize()
。 Why?为什么?
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API. QOpenGLFunctions 类提供对 OpenGL ES 2.0 API 的跨平台访问。
Cross-checking it on khronos.org :在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 | +--------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
So, it is supported for OpenGL but not for OpenGL ES.因此,它支持 OpenGL,但不支持 OpenGL ES。
There are two possible options:有两种可能的选择:
Option 1: gl_PointSize
选项 1: gl_PointSize
In OpenGL ES, you may use the GLSL shader variable gl_PointSize
instead.在 OpenGL ES 中,您可以改用 GLSL 着色器变量gl_PointSize
。
(I found this "accidentally" while searching for appropriate doc. links – haven't known this before nor ever used it.) (我在寻找合适的文档链接时“偶然”发现了这个 - 以前不知道也从未使用过它。)
derhass provided the additional hint that this might be used with OpenGL (non-ES) as well if enabled by glEnable(GL_PROGRAM_POINT_SIZE)
. derhass提供了额外的提示,如果通过glEnable(GL_PROGRAM_POINT_SIZE)
启用,这也可能与 OpenGL(非 ES)一起使用。
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.如果启用并且顶点或几何着色器处于活动状态,则派生点大小取自(可能被剪裁的)着色器内置gl_PointSize
并固定到与实现相关的点大小范围。
Option 2: Use an alternative QOpenGLFunctions_???
选项 2:使用替代QOpenGLFunctions_???
class班级
Instead of QOpenGLFunctions
, you may explicitly use a non-portable alternative (assuming you don't need to support phones, embeddeds or something like this).代替QOpenGLFunctions
,您可以明确使用非便携式替代方案(假设您不需要支持电话、嵌入式或类似的东西)。
The best overview in Qt doc. Qt 文档中最好的概述。 I could find: QAbstractOpenGLFunctions
.我可以找到: QAbstractOpenGLFunctions
。
As suggested derhass, first enable the point size with this line in your C++ code (not the shader):按照建议的 derhass,首先在C++ 代码(不是着色器)中使用这一行启用点大小:
glEnable(GL_PROGRAM_POINT_SIZE);
Then as suggested Scheff, in your vertex shader code, add the gl_PointSize
builtin function.然后按照 Scheff 的建议,在您的顶点着色器代码中,添加gl_PointSize
内置函数。 So for example if you wanted a size of 12 for a point, use it like that.因此,例如,如果您想要一个点的大小为 12,请像这样使用它。
// main from your vertex.glsl shader (not from your main.cpp!)
void main() {
...
gl_PointSize = 12;
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.