Python+OpenGL DDA直线段的扫描转换算法
算法还是比较容易理解的,glVertex2f()没摸明白。
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import math
def draw():
x0=0
y0=0
x1=500
y1=200
a=y0-y1
b=x1-x0
d=2*a+b
d1=2*a
d2=2*(a+b)
x=x0
y=y0
# glBegin(GL_POINTS)
# glVertex2f(x, y)
# glEnd()
glBegin(GL_POINTS)
while x<x1:
print(x,y,d)
glVertex2f(x, y)
if(d<0):
x=x+1
y=y+1
d=d+d2
else:
x=x+1
d=d+d1
glEnd()
glFlush()
glutInit()
glutCreateWindow('Middle drawLine')
glutDisplayFunc(draw)
glutMainLoop()