pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C pastebin - collaborative debugging tool View Help


Posted by fourth on Wed 8 Oct 03:33
report abuse | View followups from Vector XX | download | new post

  1. /*
  2. ** File:        drawLine.c
  3. ** Author:      Nicholas Forysinski
  4. */
  5.  
  6. #include <GL/glut.h>
  7. #include <drawLine.h>
  8.  
  9. /*
  10. ** drawLine
  11. **
  12. ** Draw a line from vertex (x0,y0) to vertex (x1,y1) using
  13. ** the midpoint line algorithm (as discussed in class).
  14. */
  15.  
  16. void drawLine( GLint x0, GLint y0, GLint x1, GLint y1 ) {
  17.  
  18.   GLint x, y;
  19.  
  20.   //check the orientation of the line
  21.   if( x0 > x1 ) {
  22.     drawLine( x1, y1, x0, y0 );
  23.     return;
  24.   }
  25.  
  26.   GLint d, dE, dNE;
  27.  
  28.   int dy = y1 - y0;
  29.   int dx = x1 - x0;
  30.   int stepx = 1;
  31.   int stepy = 1;
  32.  
  33.   if( dy < 0 ) {
  34.     dy = dy * -1;
  35.     stepy = -1;
  36.   }
  37.  
  38.   if( dx > dy ) {
  39.    
  40.     dE = 2 * dy;
  41.     dNE = 2 * (dy - dx);
  42.     d = dE - dx;
  43.     y = y0;
  44.    
  45.     for ( x = x0; x != x1; x += stepx ) {
  46.      
  47.       //draw a pixel
  48.       glBegin( GL_POINTS );
  49.         glVertex2i( x, y );
  50.       glEnd();
  51.      
  52.       if( d <= 0 ) {
  53.         d += dE;
  54.       } else {
  55.         y += stepy;
  56.         d += dNE;
  57.       }
  58.      
  59.     }
  60.    
  61.   } else {
  62.    
  63.     dNE = 2 * (dx - dy);
  64.     dE = 2 * dx;
  65.     d = dE - dy;
  66.     x = x0;
  67.  
  68.     for( y = y0; y != y1; y += stepy ) {
  69.      
  70.       //draw a pixel
  71.       glBegin( GL_POINTS );
  72.         glVertex2i( x, y );
  73.       glEnd();
  74.      
  75.       if( d <= 0 ) {
  76.         d += dE;
  77.       } else {
  78.         x += stepx;
  79.         d += dNE;
  80.       }
  81.      
  82.     }
  83.    
  84.   }
  85.  
  86. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post