Skip to content

Instantly share code, notes, and snippets.

@abrarShariar
Created June 25, 2018 04:22
Show Gist options
  • Save abrarShariar/373f5f098eb053efd7d1527227753ecc to your computer and use it in GitHub Desktop.
Save abrarShariar/373f5f098eb053efd7d1527227753ecc to your computer and use it in GitHub Desktop.
line with points using dd algo
#include<iostream>
#include <GL/gl.h>
#include <GL/glut.h>
using namespace std;
double x1 = 0;
double y1 = 0;
double x2 = 0;
double y2 = 0;
void display(void)
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);//(R,G,B)
double startX = x1;
double startY = y1;
double m = (y2 - y1) / (x2 - x1);
while(startX <= x2 || startY <= y2){
cout<<"x : "<<startX<<endl;
cout<<"y: "<<startY<<endl;
glBegin(GL_POINTS);
glVertex3f(startX, startY, 0.0);
glEnd();
startX++;
startY = startY + m;
}
glFlush();
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 400.0, 0, 400.0);
}
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with “hello”
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
cout<<"X1: ";
cin>>x1;
cout<<"Y1: ";
cin>>y1;
cout<<"X2: ";
cin>>x2;
cout<<"Y2: ";
cin>>y2;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 400);
//glutInitWindowPosition(400, 400);
glutCreateWindow("hello");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment