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 bking ( 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 lineDDA(int x1, int y1, int xn, int yn)
{
int dx, dy, m, i;
m = (yn-y1)/(xn-x1);
for (i=x1; i<=xn; i++)
{
if (m <= 1)
{
dx = 1;
dy = m * dx;
}
else
{
dy = 1;
dx = dy / m;
}
x1 = x1 + dx;
y1 = y1 + dy;
draw_pixel(x1, y1, BLACK);
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
lineDDA(0, 100, 100, 200);
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 */
}
Revise this Paste
Parent: 18828
Children: 18833