fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. return 0;
  7. }
Success #stdin #stdout 0.01s 5280KB
stdin
#include <windows.h>
#include <GL/glut.h>
#include <iostream>
using namespace std;
float x1, y1, x2, y2;
void display()
{
 glClear(GL_COLOR_BUFFER_BIT);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glOrtho(0, 640, 0, 480, -1, 1);
 glPointSize(8.0);
 glBegin(GL_POINTS);
 glColor3f(0.5, 0.0, 1.0);
 int dx = abs(x2 - x1);
 int dy = abs(y2 - y1);
 int x = x1;
 int y = y1;
 if (dx > dy)
 {
 int p=2*dy - dx;
 while (x <= x2)
 {
 glVertex2i(x,y);
 x++;
 if (p>=0)
 {
 y++;
 p +=(2*dy - 2*dx);
 }
 else
 {
 p += 2*dy;
 }
 }
 }
 else
 {
 int p=2*dx - dy;
 while (y<=y2)
 {
 glVertex2i(x,y);
 y++;
 if (p >= 0)
 {
 x++;
 p +=(2*dx - 2*dy);
 }
 else
 {
 p += 2*dx;
 }
 }
 }
 glEnd();
 glFlush();
}
int main(int argc, char **argv)
{
 cout << "Enter x_start and y_start: ";
 cin >> x1 >> y1;
 cout << "Enter x_end and y_end: ";
 cin >> x2 >> y2;
 if (x1 > x2)
 {
 swap(x1, x2);
 swap(y1, y2);
 }
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH);
 glutInitWindowSize(640, 480);
 glutInitWindowPosition(100, 100);
 glutCreateWindow("Bresenham's Algorithm");
 glutDisplayFunc(display);
 glutMainLoop();
 return 0;
stdout
Standard output is empty