Advertisement
Guest User

openglpru1

a guest
Sep 3rd, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <GL/gl.h>
  3. double X1, Y1, X2, Y2;
  4.  
  5. float round_value(float v)
  6. {
  7. return floor(v + 0.5);
  8. }
  9. void LineDDA(void)
  10. {
  11. double dx=(X2-X1);
  12. double dy=(Y2-Y1);
  13. double steps;
  14. float xInc,yInc,x=X1,y=Y1;
  15.  
  16. steps=(abs(dx)>abs(dy))?(abs(dx)):(abs(dy));
  17. xInc=dx/(float)steps;
  18. yInc=dy/(float)steps;
  19.  
  20.  
  21. glClear(GL_COLOR_BUFFER_BIT);
  22.  
  23.  
  24. glBegin(GL_POINTS);
  25.  
  26. glVertex2d(x,y);
  27. int k;
  28.  
  29. for(k=0;k<steps;k++)
  30. {
  31. x+=xInc;
  32. y+=yInc;
  33.  
  34. glVertex2d(round_value(x), round_value(y));
  35. }
  36. glEnd();
  37.  
  38. glFlush();
  39. }
  40. void Init()
  41. {
  42.  
  43. glClearColor(1.0,1.0,1.0,0);
  44.  
  45. glColor3f(0.0,0.0,0.0);
  46.  
  47. gluOrtho2D(0 , 640 , 0 , 480);
  48. }
  49. int main(int argc, char **argv)
  50. {
  51. printf("Enter two end points of the line to be drawn:\n");
  52.  
  53. printf("\nEnter Point1( X1 , Y1):\n");
  54. scanf("%lf%lf",&X1,&Y1);
  55.  
  56. printf("\nEnter Point1( X2 , Y2):\n");
  57. scanf("%lf%lf",&X2,&Y2);
  58.  
  59.  
  60. glutInit(&argc,argv);
  61.  
  62. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  63.  
  64. glutInitWindowPosition(0,0);
  65. glutInitWindowSize(640,480);
  66.  
  67. glutCreateWindow("DDA_Line");
  68.  
  69. Init();
  70.  
  71. glutDisplayFunc(LineDDA);
  72.  
  73. glutMainLoop();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement