Bresenham
bresenham画线——非并行
#include<glut.h> #include<math.h> #include<stdlib.h> void init (void) { glClearColor (1.0,1.0,1.0,0.0);//白色背景 glPointSize (1.0);//点大小 glColor3f (1.0,0.0,0.0);//线颜色 glMatrixMode (GL_PROJECTION);//投影 gluOrtho2D (0.0,200.0,0.0,150.0); } void draw_pixel (int x,int y) { //opengl画点 glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); } void Bresenham(int x0,int y0,int xend,int yend){ int dx = fabs (xend - x0),dy = fabs (yend - y0); int p = 2*dy - dy; int twoDy = 2*dy,twodyminuxdx = 2*(dy-dx); int x,y; if(x0>xend){ //画线方向 x = xend; y = yend; xend = x0; } else { x = x0; y = y0; } draw_pixel (x, y); while (x < xend) { x++; if (p < 0) p += twoDy; else { y++; p += twodyminuxdx; } draw_pixel (x, y); } } void display (void){ //画线 glClear (GL_COLOR_BUFFER_BIT);//清缓存 Bresenham(200,200,100,50); //线的初始点 glFlush (); //刷新画面 } void main (int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition (50, 100); glutInitWindowSize (400, 300); glutCreateWindow ("Parallel Bresenham Exp."); init(); glutDisplayFunc (display); glutMainLoop (); }有空得研究一下并行画线