Text Share Online

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <cmath>

void display()
{
glClear(GL_COLOR_BUFFER_BIT);

int x1 = -200, y1 = -100;
int x2 = 200, y2 = 150;

float dx = x2 – x1;
float dy = y2 – y1;

int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);

float xInc = dx / steps;
float yInc = dy / steps;

float x = x1;
float y = y1;

glPointSize(4);
glColor3f(0,0,1);

glBegin(GL_POINTS);

for(int i = 0; i <= steps; i++)
{
// Dotted Line
if(i % 3 == 0)
glVertex2i(round(x), round(y));

x += xInc;
y += yInc;
}

glEnd();

glFlush();
}

void init()
{
glClearColor(1,1,1,1);
gluOrtho2D(-300,300,-300,300);
}

int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600,600);
glutCreateWindow(“DDA Dotted Line”);

init();

glutDisplayFunc(display);

glutMainLoop();

return 0;
}

  • none/plain text
  • 1h
Share This: