[英]How to draw point sprites of different sizes in OpenGL?
I'm making a small OpenGL Mac app that uses point sprites. 我正在制作一个使用点精灵的小型OpenGL Mac应用程序。 I'm using a vertex array to draw them, and I want to use a similar "array" function to give them all different sizes.
我正在使用顶点数组绘制它们,并且我想使用类似的“数组”函数为它们提供所有不同的大小。
In OpenGL ES, there is a client state called GL_POINT_SIZE_ARRAY_OES, and a corresponding function glPointSizePointerOES() which do exactly what I want, but I can't seem to find an equivalent in standard OpenGL. 在OpenGL ES中,有一个名为GL_POINT_SIZE_ARRAY_OES的客户端状态,以及一个对应的函数glPointSizePointerOES()可以完全满足我的要求,但是我似乎找不到标准OpenGL中的等效项。
Does OpenGL support this in any way? OpenGL是否以任何方式支持此功能?
OpenGL does not support this Apple extension, but you can do it other other way: OpenGL不支持此Apple扩展,但是您可以通过其他方式进行操作:
For fixed pipeline: (opengl 1.4 and above) 对于固定管道:(OpenGL 1.4及更高版本)
You need to setup point parameters: 您需要设置点参数:
float attenuation[3] = {0.0f, 1.0f, 0.0f};
glPointParameterfvEXT(GL_POINT_DISTANCE_ATTENUATION, attenuation);
glPointParameterfEXT(GL_POINT_SIZE_MIN, 1.0f);
glPointParameterfEXT(GL_POINT_SIZE_MAX, 128.0f);
glEnable(GL_POINT_SPRITE);
OpenGL will calculate point size for you that way OpenGL将以这种方式为您计算点大小
Shaders 着色器
Here is some info for rendering using shaders: http://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_01 以下是使用着色器进行渲染的一些信息: http : //en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_01
To expand a little on Fen's answer, the fixed function OpenGL pipeline can't do exactly what you want. 为了扩展芬的答案,固定功能的OpenGL管道无法完全满足您的要求。 It can do 'perspective' points which get smaller as the Z distance increases, but that's all.
它可以做随着Z距离增加而变小的“透视”点,仅此而已。
For arbitrary point size at each vertex you need a custom vertex shader to set the size for each. 对于每个顶点上的任意点大小,您需要一个自定义顶点着色器以设置每个顶点的大小。 Pass the point sizes either as an attribute array (re-use surface normals or tex coords, or use your own attribute index) or in a texture map, say a 1D texture with width equal to size of points array.
将点大小作为属性数组(重复使用曲面法线或tex坐标,或使用自己的属性索引)或在纹理贴图中传递,例如将一维纹理的宽度等于点数组的大小。 The shader code example referred to by Fen uses the texture map technique.
Fen引用的着色器代码示例使用纹理贴图技术。
If by "Does OpenGL support this", you mean "Can I do something like that in OpenGL", absolutely. 如果通过“ OpenGL是否支持此功能”,则表示“绝对可以在OpenGL中执行类似的操作”。
Use shaders. 使用着色器。 Pass a 1-dimensional generic vertex attribute that represents your point size.
传递一个表示您的点大小的一维通用顶点属性。 And in your vertex shader, set that point size as the
gl_PointSize
output from the vertex shader. 然后在您的顶点着色器中,将该点大小设置为顶点着色器的
gl_PointSize
输出。 It's really quite simple. 这真的很简单。
If you meant, "Does fixed-function OpenGL support this," no. 如果您的意思是“固定功能OpenGL是否支持此功能”,否。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.