Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by hellyeah ( 16 years ago )
#define BLACK 0
#include <GL/glut.h>
#include <stdio.h>
void draw_pixel(int ix, int iy, int value)
{
glBegin(GL_POINTS);
glVertex2i( ix, iy);
glEnd();
}
void bres(int x1,int y1,int x2,int y2)
{
int dx, dy, i, e;
int incx, incy, inc1, inc2;
int x,y;
dx = x2 - x1;
dy = y2 - y1;
if(dx < 0) dx = -dx;
if(dy < 0) dy = -dy;
incx = 1;
if(x2 < x1) incx = -1;
incy = 1;
if(y2 < y1) incy = -1;
x=x1;
y=y1;
if(dx > dy)
{
draw_pixel(x,y, BLACK);
e = 2*dy - dx;
inc1 = 2*( dy -dx);
inc2 = 2*dy;
for(i = 0; i < dx; i++)
{
if(e >= 0)
{
y += incy;
e += inc1;
}
else e += inc2;
x += incx;
draw_pixel(x,y, BLACK);
}
}
else
{
draw_pixel(x,y, BLACK);
e = 2*dx - dy;
inc1 = 2*( dx - dy);
inc2 = 2*dx;
for(i = 0; i < dy; i++)
{
if(e >= 0)
{
x += incx;
e += inc1;
}
else e += inc2;
y += incy;
draw_pixel(x,y, BLACK);
}
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
bres(200, 200, 100, 50);
glFlush();
}
void myinit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 499.0, 0.0, 499.0);
}
int main(int argc, char** argv)
{
/* standard GLUT initialization */
glutInit(&argc;,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
glutInitWindowSize(500,500); /* 500x500 pixel window */
glutInitWindowPosition(0,0); /* place window top left on display */
glutCreateWindow("Bresenham's Algorithm"); /* window title */
glutDisplayFunc(display); /* display callback invoked when window opened */
myinit(); /* set attributes */
glutMainLoop(); /* enter event loop */
}
xyz@xyz:~/comp304/304$ c++ -lGLU bresenham.c
/tmp/ccxFNM48.o: In function `main':
bresenham.c:(.text+0x2b5): undefined reference to `glutInit'
bresenham.c:(.text+0x2c1): undefined reference to `glutInitDisplayMode'
bresenham.c:(.text+0x2d5): undefined reference to `glutInitWindowSize'
bresenham.c:(.text+0x2e9): undefined reference to `glutInitWindowPosition'
bresenham.c:(.text+0x2f5): undefined reference to `glutCreateWindow'
bresenham.c:(.text+0x301): undefined reference to `glutDisplayFunc'
bresenham.c:(.text+0x30b): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
Revise this Paste
Parent: 18734