1. <legend id='NggiZ'><style id='NggiZ'><dir id='NggiZ'><q id='NggiZ'></q></dir></style></legend>

      <small id='NggiZ'></small><noframes id='NggiZ'>

          <bdo id='NggiZ'></bdo><ul id='NggiZ'></ul>
      1. <tfoot id='NggiZ'></tfoot>
        <i id='NggiZ'><tr id='NggiZ'><dt id='NggiZ'><q id='NggiZ'><span id='NggiZ'><b id='NggiZ'><form id='NggiZ'><ins id='NggiZ'></ins><ul id='NggiZ'></ul><sub id='NggiZ'></sub></form><legend id='NggiZ'></legend><bdo id='NggiZ'><pre id='NggiZ'><center id='NggiZ'></center></pre></bdo></b><th id='NggiZ'></th></span></q></dt></tr></i><div id='NggiZ'><tfoot id='NggiZ'></tfoot><dl id='NggiZ'><fieldset id='NggiZ'></fieldset></dl></div>

      2. C++中的扫描线填充OpenGL/GLUT算法

        时间:2023-09-17

          <bdo id='IIv6q'></bdo><ul id='IIv6q'></ul>

          <i id='IIv6q'><tr id='IIv6q'><dt id='IIv6q'><q id='IIv6q'><span id='IIv6q'><b id='IIv6q'><form id='IIv6q'><ins id='IIv6q'></ins><ul id='IIv6q'></ul><sub id='IIv6q'></sub></form><legend id='IIv6q'></legend><bdo id='IIv6q'><pre id='IIv6q'><center id='IIv6q'></center></pre></bdo></b><th id='IIv6q'></th></span></q></dt></tr></i><div id='IIv6q'><tfoot id='IIv6q'></tfoot><dl id='IIv6q'><fieldset id='IIv6q'></fieldset></dl></div>

          <small id='IIv6q'></small><noframes id='IIv6q'>

            1. <legend id='IIv6q'><style id='IIv6q'><dir id='IIv6q'><q id='IIv6q'></q></dir></style></legend>

              1. <tfoot id='IIv6q'></tfoot>
                  <tbody id='IIv6q'></tbody>
                • 本文介绍了C++中的扫描线填充OpenGL/GLUT算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试学习在 OpenGL/GLUT 中实现的扫描线填充算法.我无法围绕这个概念进行思考.有人能用一种相当简单的方式向我解释算法吗?算法如下:

                  I am trying to learn the scan-line fill algorithm implemented in OpenGL/GLUT. I cannot wrap my mind around the concept. Could anybody explain to me the algorithm in a reasonably simple fashion? The algo is below:

                  #include<GL/glut.h>
                  
                  float x1,x2,x3,x4,y1,y2,y3,y4;
                  
                  void draw_pixel(int x,int y)
                  {
                      glColor3f(0.0,1.0,1.0);
                      glPointSize(1.0);
                      glBegin(GL_POINTS);
                      glVertex2i(x,y);
                      glEnd();
                  }
                  
                  void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)
                  {
                      float temp,x,mx;
                      int i;
                  
                      if(y1>y2)
                      {
                          temp=x1,x1=x2,x2=temp;
                          temp=y1,y1=y2,y2=temp;
                      }
                  
                      if(y1==y2)
                          mx=x2-x1;
                      else
                          mx=(x2-x1)/(y2-y1);
                  
                      x=x1;
                  
                      for(i=int(y1);i<=(int)y2;i++)
                      {
                          if(x<(float)le[i]) le[i]=(int)x;
                          if(x>(float)re[i]) re[i]=(int)x;
                          x+=mx;
                      }
                  }
                  
                  void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)
                  {
                      int le[500],re[500],i,j;
                  
                      for(i=0;i<500;i++)
                          le[i]=500,re[i]=0;
                  
                      edgedetect(x1,y1,x2,y2,le,re);
                      edgedetect(x2,y2,x3,y3,le,re);
                      edgedetect(x3,y3,x4,y4,le,re);
                      edgedetect(x4,y4,x1,y1,le,re);
                  
                      for(j=0;j<500;j++)
                      {
                          if(le[j]<=re[j])
                              for(i=le[j];i<re[j];i++)
                                  draw_pixel(i,j);
                      }
                  }
                  
                  
                  void display()
                  {
                      x1=250.0;y1=200.0;x2=150.0;y2=300.0;x3=250.0;
                      y3=400.0;x4=350.0;y4=300.0;
                      glClear(GL_COLOR_BUFFER_BIT);
                      glColor3f(0.0,0.0,1.0);
                      glBegin(GL_LINE_LOOP);
                      glVertex2f(x1,y1);
                      glVertex2f(x2,y2);
                      glVertex2f(x3,y3);
                      glVertex2f(x4,y4);
                      glEnd();
                  
                      scanfill(x1,y1,x2,y2,x3,y3,x4,y4);
                  
                      glFlush();
                  }
                  
                  
                  void init()
                  {
                      glClearColor(1.0,1.0,1.0,1.0);
                      glMatrixMode(GL_PROJECTION);
                      glLoadIdentity();
                      gluOrtho2D(0.0,499.0,0.0,499.0);
                  }
                  
                  void main(int argc,char **argv)
                  {
                      glutInit(&argc,argv);
                      glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                      glutInitWindowSize(500,500);
                  
                      glutCreateWindow("scanline");
                      glutDisplayFunc(display);
                  
                      init();
                      glutMainLoop();
                  }
                  

                  推荐答案

                  scanfill 函数正在填充由四个 x-y 坐标描述的 4 边多边形覆盖的像素.为此,它使用了 edgedetect 函数,该函数模拟绘制多边形的边缘并记住每个 y 坐标的最小和最大 x 坐标.然后 scanfill 函数遍历每个 y 坐标并在记住的范围内绘制一条水平像素线.

                  The scanfill function is filling the the pixels coverted by the 4-sided polygon described by the four x-y coordinates. To do this, it uses the edgedetect function, which simulates drawing the edges of the polygon and remembers the minimum and maximum x coordinate for each y coordinate. The scanfill function then goes through each y coordinate and draws a horizontal line of pixels across the remembered range.

                  这篇关于C++中的扫描线填充OpenGL/GLUT算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何让 VBO 工作 下一篇:最小无窗口 OpenGL 上下文初始化

                  相关文章

                  最新文章

                • <small id='8N8J7'></small><noframes id='8N8J7'>

                • <tfoot id='8N8J7'></tfoot>
                  • <bdo id='8N8J7'></bdo><ul id='8N8J7'></ul>

                  1. <i id='8N8J7'><tr id='8N8J7'><dt id='8N8J7'><q id='8N8J7'><span id='8N8J7'><b id='8N8J7'><form id='8N8J7'><ins id='8N8J7'></ins><ul id='8N8J7'></ul><sub id='8N8J7'></sub></form><legend id='8N8J7'></legend><bdo id='8N8J7'><pre id='8N8J7'><center id='8N8J7'></center></pre></bdo></b><th id='8N8J7'></th></span></q></dt></tr></i><div id='8N8J7'><tfoot id='8N8J7'></tfoot><dl id='8N8J7'><fieldset id='8N8J7'></fieldset></dl></div>
                    <legend id='8N8J7'><style id='8N8J7'><dir id='8N8J7'><q id='8N8J7'></q></dir></style></legend>