Chinaunix首页 | 论坛 | 博客
  • 博客访问: 740995
  • 博文数量: 251
  • 博客积分: 10367
  • 博客等级: 上将
  • 技术积分: 2750
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-10 14:43
文章分类

全部博文(251)

文章存档

2009年(2)

2008年(86)

2007年(163)

分类: C/C++

2008-04-16 13:17:13

/* -*- C -*-
 *
 * point.c - 中点画线算法
 *
 *
 * Created On : Wed Apr 16 12:37:37 2008
 * Last Modified On: Wed Apr 16 13:03:43 2008
 *
 */

#include <GL/glut.h> /* glut.h includes gl.h and glu.h*/
#include <stdio.h>

void midLine( int x0,int y0,int x1,int y1 ){
     int dx,dy,incrE,incrNE,d,d_pre,x,y;

     dx = x1 - x0;
     dy = y1 - y0;
     d = dy * 2 - dx;
     incrE = dy * 2;
     incrNE = ( dy - dx ) * 2;
     x = x0;
     y = y0;

     while( x < x1 ){
          if( d <= 0 ){
               d_pre = d;
               d+= incrE;
               x ++;
          }
          else {
               d_pre = d;
               d += incrNE;
               x ++;
               y ++;
          }
        
    glBegin(GL_POINTS);

    //Note the convetion.
                glVertex2f((float)x/300,(float)y/300);
    glEnd();
     }
}

void display(void)

{
/* clear window */

    glClear(GL_COLOR_BUFFER_BIT);


        glPointSize( 2.0 );
        
        midLine( -200,-200,200,200 );

/* flush GL buffers */

   glFlush();

}


int main(int argc, char** argv)
{

/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */

     glutInit(&argc,argv);
    /* glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(0,0); */

    glutCreateWindow("MiddleLine");
    glutDisplayFunc(display);
    glutMainLoop();

}


阅读(1059) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~