Advertisement
raisul2010

2ndLab

Feb 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include<windows.h>
  2. #include<GL/glut.h>
  3.  
  4. void myInit(void)
  5. {
  6. glClearColor(1.0, 1.0, 1.0, 0.0); //background color is white
  7. glColor3f(0.0f, 0.0f, 0.0f); //drawing color is black
  8. glPointSize(4.0); //a dot is 2 by 2 pixels
  9.  
  10. //initialize view
  11. glMatrixMode(GL_PROJECTION);
  12. glLoadIdentity();
  13. glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
  14. gluOrtho2D(0.0,1024.0,0.0,768.0);
  15. }
  16. void myDisplay(void)
  17. {
  18. glClear(GL_COLOR_BUFFER_BIT); //clear the screen
  19. //draw a rectangle with background
  20.  
  21. //Line drawing algorithm
  22. glPointSize(2.0);
  23.  
  24. GLint x,y, x1=50, x2=100, y1=100, y2=200;
  25. GLint dx, dy, inc1, inc2, d;
  26.  
  27. x = x1;
  28. y = y1;
  29.  
  30. dx = x2-x1;
  31. dy = y2-y1;
  32.  
  33. inc1 = 2 * dy;
  34. inc2 = 2 * (dy-dx);
  35.  
  36. d = inc1 - dx;
  37. while(x <= x2)
  38. {
  39. glBegin(GL_POINTS);
  40. {
  41. glVertex2i(x, y);
  42. }
  43. glEnd();
  44. x++;
  45. if(d<0)
  46. d=d+inc2;
  47. else
  48. {
  49. d = d + inc2;
  50. y++;
  51. }
  52. }
  53. glFlush(); //send all output to display
  54. }
  55. int main (int argc, char** argv)
  56. {
  57. glutInit(&argc, argv); //initialize the toolkit
  58. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set the display
  59. glutInitWindowSize(1024,768);
  60. //set window position on screen
  61. glutInitWindowPosition(100,150);
  62. //open the screen window and set the name
  63. glutCreateWindow("My First Window");
  64.  
  65. glutDisplayFunc(myDisplay);
  66. myInit();
  67. glutMainLoop(); //go into a perpetual loop
  68.  
  69. //fprinitf(stderr, "Hello!\n");
  70. return 1;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement