简体   繁体   中英

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):

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

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

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?

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? 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."

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.

From the 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. If GL_PROGRAM_POINT_SIZE is enabled, then the point size comes from the output variable 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.

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.

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.

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