|
Post by hady1606 on May 27, 2013 0:58:13 GMT -5
hy masters ,, i want your help , cause i want to create line with bresenham algorythm , not with "line method" ... please help me .. what i mean , is create a line from "dot"
submit your answer in reply message or you can send me message , in hady.java16@yahoo.com
thanks for your attention ..
|
|
|
Post by matthew on May 27, 2013 11:58:35 GMT -5
I've never heard of Bresenham's Line Algorithm before (I had to look it up on Wikipedia) however if you're interested in drawing lines with dots then you should take a look at this example written by Tom; it's a 3D Function Graphics Calculator. 
|
|
|
Post by DJLinux on May 27, 2013 13:54:03 GMT -5
Here are one solution for the 2D mode. By the way in the case of homework you should try it first self and we can help if somethings goes wrong. How ever Wikipedia can be your friend ;-) DJ ' ####################### ' # 2D mode(True/False) # ' ####################### sub Mode2D(onoff) if (onoff<>FALSE) then ' save current 3D mode and enable 2D mode glDisable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0,WindowWidth(),WindowHeight(),0,-1,1) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() else ' disable 2D and restore 3D mode glPopMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST) end if end sub
' ################################### ' # Draw a line from x1,y1 to x2,y2 # ' ################################### sub BresenhamLine(x1,y1,x2,y2) dim dx = x2-x1 dim dy = y2-y1 ' only one pixel if dx=0 land dy=0 then glBegin(GL_POINTS) glVertex2f(x1,y1) glEnd() return end if
dim adx = ABS(dx), ady = ABS(dy) dim sdx = SGN(dx), sdy = SGN(dy) dim pdx,pdy,ddx,ddy,es,el IF adx > ady THEN ' loop in x direction pdx = sdx: pdy = 0 ddx = sdx: ddy = sdy es = ady: el = adx ELSE ' loop in y direction pdx = 0 : pdy = sdy ddx = sdx: ddy = sdy es = adx: el = ady END IF dim i,error = el/2 glBegin(GL_POINTS) glVertex2f(x1,y1) FOR i=1 TO el ' new error therm error = error - es IF error < 0 THEN error = error + el x1 = x1 + ddx: y1 = y1 + ddy ELSE x1 = x1 + pdx: y1 = y1 + pdy END IF glVertex2f(x1,y1) NEXT glEnd() end sub ' ################################ ' # create a random float number # ' ################################ function RND#() return rnd()*(1.0/RND_MAX) end function
dim w = WindowWidth() dim h = WindowHeight() dim frames Mode2d(true)
while inkey$()="" frames=frames+1 if frames % 50=0 then SwapBuffers() glClear(GL_COLOR_BUFFER_BIT) sleep(10) end if glColor3ub(rnd#()*255,rnd#()*255,rnd#()*255) BresenhamLine(rnd#()*w,rnd#()*h,rnd#()*w,rnd#()*h)
wend Mode2d(false)
|
|