如何改变 OpenGL glBegin(GL_POINTS) 中的点大小?

发布于 2024-10-10 00:46:08 字数 163 浏览 8 评论 0原文

绘制大量点时有什么方法可以改变点的大小吗?我知道有 glPointSize(float),但是有没有办法在“批量”或数组中做到这一点?

我希望这些点根据数据的属性具有不同的大小。比如每个点都有x、y、z和一个尺寸属性。我现在在java中使用帧缓冲区。

我可以为此使用顶点着色器吗?

Is there any way to vary the point size when drawing lots of points? I know there's the glPointSize(float), but is there a way to do it in a 'batch' or array?

I would like the points to have different sizes based on an attribute of the data. Such as each point having x, y, z, and a size attribute. I'm using frame buffers right now in java.

Could I possibly use vertex shaders for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蓝眸 2024-10-17 00:46:08

您可以使用点精灵:使用 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); 启用它,然后您可以在顶点程序中使用 gl_PointSize 属性。

顶点着色器示例取自 OpenGL 讨论线程

void main() {
    gl_FrontColor=gl_Color;
    gl_PointSize = gl_Normal.x;
    gl_Position = ftransform();
} 

You can use point sprite: enable it using glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); and then you can use gl_PointSize attribute in your vertex program.

Vertex shader example taken from an OpenGL discussion thread:

void main() {
    gl_FrontColor=gl_Color;
    gl_PointSize = gl_Normal.x;
    gl_Position = ftransform();
} 
寒尘 2024-10-17 00:46:08

这就是我曾经做过的事

 //reset 
 glLoadIdentity();                                   

 //set size to 1 for a group of points
 glPointSize(1);                                     

 //group #1 starts here     
 glBegin(GL_POINTS);                                 

    //color of group #1 is white 
    glColor3f(1,1,1);                                

    for(int a=0; a<x; a++)
        for(int b=0; b<y; b++)
                    glVertex3f(a/953.,-b/413.,0.);   //location of points
 glEnd();


 //set size to 5 for another group of points
 glPointSize(5);  

 //group #2 starts here     
 glBegin(GL_POINTS);

    //color of group #2 is red 
    glColor3f(1,0,0);
    for(unsigned long int a=0; a<jd; a++)
    {
           glVertex3f(data[a].i,data[a].j,0);
    }
 glEnd();

This was what I ever did,

 //reset 
 glLoadIdentity();                                   

 //set size to 1 for a group of points
 glPointSize(1);                                     

 //group #1 starts here     
 glBegin(GL_POINTS);                                 

    //color of group #1 is white 
    glColor3f(1,1,1);                                

    for(int a=0; a<x; a++)
        for(int b=0; b<y; b++)
                    glVertex3f(a/953.,-b/413.,0.);   //location of points
 glEnd();


 //set size to 5 for another group of points
 glPointSize(5);  

 //group #2 starts here     
 glBegin(GL_POINTS);

    //color of group #2 is red 
    glColor3f(1,0,0);
    for(unsigned long int a=0; a<jd; a++)
    {
           glVertex3f(data[a].i,data[a].j,0);
    }
 glEnd();
山川志 2024-10-17 00:46:08

我相信它与 glPointSize(GLfloat size)

来源:

http://www.talisman.org/opengl-1.1/Reference/ glPointSize.html

I believe it's with glPointSize(GLfloat size)

Source:

http://www.talisman.org/opengl-1.1/Reference/glPointSize.html

失与倦" 2024-10-17 00:46:08

使用 GL_POINT_DISTANCE_ATTENUATION (GL14?),您可以设置函数的系数(我认为它是二次函数),用于从 Z 距离计算点大小。

With GL_POINT_DISTANCE_ATTENUATION (GL14?) you can set the coefficients for a function (I think it's quadratic) for computing point size from Z distance.

谎言 2024-10-17 00:46:08

增加和减少点大小会影响多个像素,但着色器每个像素仅运行一次。它会失败,因为一旦对特定像素运行了着色器程序,更改是否只能影响后面的像素,而不影响前面的像素。

着色器程序同时在许多着色器单元上运行,并且对于许多像素并行运行,因此无法执行您想要执行的操作。限制是可以使用着色器程序设置像素大小,但它将保留着色器程序运行的所有像素的大小。

您可以尝试按大小对点数据进行排序,并将相同大小的点分组到一个数组中,并使用不同的点大小绘制每个数组。

或者,您可以尝试使用间接方式进行此操作,首先将不同的点大小渲染到纹理中,然后在第二遍中通过访问纹理数据并使用它来测试是否应该渲染像素来渲染像素。

Increasing and decreasing the point size affects more than one pixel, but shaders are meant to be run only once per pixel. It will fail, because once the shader program has been run for a particular pixel, can the change only affect the following pixels, but not the previous pixels.

Shader programs are run on many shader units simultaneously and for many pixels in parallel making it impossible to do what you are trying to do. The limitation will be that one can set the pixel size with a shader program, but it will keep its size for all pixels the shader program gets run.

You could try to sort your point data by size and group points of the same size into one array and draw each array with a different point size.

Or you could try doing it with an indirection where you first render the different point sizes into a texture and in a second pass render the pixels by accessing the texture data and using it to test if a pixel should be rendered (or not).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文