简体   繁体   English

试图了解OpenGL中的像素和GL_POINTS

[英]Trying to understand pixels and GL_POINTS in OpenGL

So basically i am trying to get my head around pixels and how OpenGL deals with them when rendering them using GL_POINTS (and if it applies to texture buffers also): 所以基本上我使用GL_POINTS渲染时,他们试图让我周围的像素头,以及如何的OpenGL与他们交易(如果它适用于质地缓冲区也):

Here is the uploaded image of the result after rendering to screen( i tried to put more smaller ones but i was only allowed two links) 下面是渲染到屏幕后的结果上传的图片(我试图把更多的小的,但我只被允许两个链接)

http://i.imgur.com/hcdloMD.png

http://i.imgur.com/9GBtK9m.png

To begin here is a program i wrote and its outcome when i change the values noted below: 从这里开始是我编写的程序及其更改以下所述值时的结果:

and here is the code that deals with uploading the pixels and updating them , with the main attention towards value variable that when i change it, i change the size of the picture 这是处理像素上传和更新的代码,主要注意值变量,当我更改它时,我更改图片的大小

   glDisable(GL_POINT_SMOOTH);
   int i = 0, j=0, k=0;

   GLuint vao;

   glGenVertexArrays(1, &vao);
   glBindVertexArray(vao);

   GLfloat point[3] = {-1.0f, -1.0f, 0.0f};
   GLfloat color[3];

   float value = 3.0f;

   float incrementX = value/640.0f;
   float incrementY = value/480.0f;


   while(j<256){
      //initialize starting position for x for each line 
      point[0] = -1.0f; 

      //run the width
      while(k<256){         
         //upload vertex position to GL server 
         glVertexAttrib3fv(0,point);      

         //deals with updating colour
         color[2] = data[i+0]/255.0f;            //B
         color[1] = data[i+1]/255.0f;            //G
         color[0] = data[i+2]/255.0f;            //R
         //upload texture data to GL server
         glVertexAttrib3fv(1, color);

         //draws array
         glDrawArrays(GL_POINTS, 0, 1);
         //deals with updating incrementors
         point[0]+=incrementX;   //moving forward in appropriate units for the size of width
         k++;
         i+=3;
      }
      //restart width
      k=0;;
      j++; 
      //update height
      point[1]+=incrementY;    

   }

   glXSwapBuffers ( dpy, glxWin );
   sleep(6);

my question is about the actual pixels 我的问题是关于实际像素

i understand that point actually has no area, all that opengl sees is the point as a location in the 2d plane, and it makes sense of what happens when it gets scaled up 我明白这一点实际上已经没有任何区域,所有的OpenGL看到的是点在2D平面的位置,它使得当它被扩大会发生什么意义

however when i make the image smaller and smaller i am confused about what happens on the pixel level when it get smaller and smaller , lets say as it tends towards 0 ie 0.000001 然而,当我使图像小我感到困惑的像素级别时,它变得越来越小,会发生什么,让我们说,因为它向0即0.000001趋向

surely the pixels on the screen have a limitation? 确定屏幕上的像素有限制吗?

does that mean that opengl actually divides the pixels to make the image fit when it is say 1/100th of the normal size of a given pixel? 这是否意味着当说是给定像素正常大小的1/100时,opengl实际上将像素划分为合适的图像?

because the image can be made smaller and smaller to the point that is a dot 因为可以将图像缩小到一个点

surely opengl isn't still drawing the individual colours to portions of one pixel on screen? 当然,opengl仍不将单个颜色绘制到屏幕上一个像素的一部分吗? or is the colour that it iterates through being repeatedly drawn to one pixels since the point location is always only within one pixel? 还是因为点位置始终仅在一个像素内,所以通过反复绘制到一个像素来迭代产生的颜色?

or does the one pixel further get divided into even smaller pixel sizes? 还是将一个像素进一步划分为更小的像素大小?

EDIT: 编辑:

My assumption about point having no size was not an assumption but what i read from the "red book" 我对没有大小点的假设是不是一个假设,但我从“红书”读

"Points are represented by a single vertex. The vertex represents a point in four-dimensional homogeneous coordinates. As such, a point really has no area, and so in OpenGL it is really an analogue for a square region of the display (or draw buffer). When rendering points, OpenGL determines which pixels are covered by the point using a set of rules called rasterization rules. The rules for rasterizing a point in OpenGL are quite straightforward---a sample is considered covered by a point if it falls within a square centered on the point's location in window coordinates." “点由单个顶点表示。顶点表示在四维齐次坐标的点。 这样,一个点确实没有区域,因此在OpenGL它是真正用于显示的正方形区域中的类似物(或绘制缓冲液)。当渲染分,OpenGL的确定哪些像素由点使用一组被称为光栅化规则的规则覆盖。用于在OpenGL光栅化的点的规则是非常简单---样品被认为是由点所覆盖,如果它落在在以窗口坐标中的点位置为中心的正方形内。”

So i guess what i am trying to understand is the rasterization process here 所以我想我要了解的是这里的栅格化过程

Your assumption that point primitives have zero area is incorrect. 您认为点图元的面积为零是不正确的。

Points have sizes. 点有大小。 They default to 1px, but their screen-space size lengths can be altered via the glPointSize function or the gl_PointSize shader variable. 它们默认为1px,但是可以通过glPointSize函数或gl_PointSize着色器变量来更改其屏幕空间大小长度。

From the OpenGL wiki : OpenGL Wiki

Points are rasterized as screen-aligned squares of a given window-space size. 将点栅格化为给定窗口空间大小的屏幕对齐的正方形。 The size can be given in two methods: by the last active vertex processing shader stage or by the context's state. 大小可以通过两种方法给出:通过上一个活动顶点处理着色器阶段或上下文状态。 To set the point size from a shader, enable the glEnable with argument ( GL_PROGRAM_POINT_SIZE ) to set the point size from the program. 要从着色器设置点大小,请启用带参数glEnableGL_PROGRAM_POINT_SIZE ),以从程序中设置点大小。 If GL_PROGRAM_POINT_SIZE is enabled, then the point size comes from the output variable float gl_PointSize ​. 如果启用了GL_PROGRAM_POINT_SIZE ,则点大小来自输出变量float gl_PointSize If it is disabled, the point size is constant for all points in a primitive, and is set by the glPointSize​ function. 如果它被禁用,点的大小是在原始的所有点不变,并通过设置glPointSize​功能。

The size defines the number of window pixels that each side of the point's square takes up. 大小定义点正方形的每一侧占用的窗口像素数。 The point's position defines the center of that square. 该点的位置定义了该正方形的中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM