Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <stdio.h>
- #include <GL/gl.h>
- #include <math.h>
- void init(void)
- {
- glClearColor(0.0,0.0,0.0,0.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, 500.0, 0.0, 500.0, -1.0, 1.0);
- }
- void Draw()
- {
- int xs=21, ys=87, xe=387, ye=321;
- double xi, yi, m;
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f( 0,1, 0.5);
- m = (ye-ys)/(xe-xs);
- if(xe>xs){
- if(m<=1){
- xi = 1;
- yi = m;
- }
- else if(m>1){
- yi = 1;
- xi = 1/m;
- }
- }
- else if(xs>xe){
- if(m<=1){
- xi = -1;
- yi = -m;
- }
- else if(m>1){
- xi = (-1)/m;
- yi = -1;
- }
- }
- glBegin(GL_POINTS);
- glVertex2i(round(xs), round(ys));
- while(1){
- xs = xs+xi;
- ys = ys+yi;
- glVertex2i(round(xs), round(ys));
- if(xs==xe || ys==ye){
- break;
- }
- }
- glEnd();
- glutSwapBuffers();
- }
- int main(int argc,char **argv)
- {
- glutInit(&argc,argv);
- glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
- glutInitWindowPosition(0,0);
- glutInitWindowSize(500,500);
- glutCreateWindow("Sohag Raha - 182-15-2164");
- init();
- glutDisplayFunc(Draw);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement