I am using QOpenGLFunctions with modern OpenGL. I want to draw some GL_POINTS on my window but the point size seems to be really small. 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.
Drawing GL_TRIANGLES works perfectly fine for me.
I want to draw points to display a point cloud of real-world objects.
If you use QOpenGLFunctions
, there is really no glPointSize()
available. Why?
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
Cross-checking it on 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.
There are two possible options:
Option 1: gl_PointSize
In OpenGL ES, you may use the GLSL shader variable gl_PointSize
instead.
(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)
.
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.
Option 2: Use an alternative 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).
The best overview in Qt doc. I could find: QAbstractOpenGLFunctions
.
As suggested derhass, first enable the point size with this line in your C++ code (not the shader):
glEnable(GL_PROGRAM_POINT_SIZE);
Then as suggested Scheff, in your vertex shader code, add the gl_PointSize
builtin function. So for example if you wanted a size of 12 for a point, use it like that.
// main from your vertex.glsl shader (not from your main.cpp!)
void main() {
...
gl_PointSize = 12;
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.