#include <windows.h> // digunakan oleh sistem
#include <gl/Gl.h>
#include <gl/glut.h>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // membuat latar belakang putih
glColor3f(0.0f, 0.0f, 0.0f); // membuat warna gambar hitam
glPointSize(6.0);// ukuran titik 4 x 4 pixel
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void myDisplay(void)
{
float xa = 50,ya = 70,
xb = 200,yb = 250,
xc = 250,yc = 50,
xd = 50,yd = 350,
x,y,m1,m2,c1,c2;
glClear(GL_COLOR_BUFFER_BIT); // hapus layar
glBegin(GL_LINES);
glVertex2f(xa, ya);
glVertex2f(xb, yb);
glEnd();
glBegin(GL_LINES);
glVertex2f(xc, yc);
glVertex2f(xd, yd);
glEnd();
m1 = (yb-ya)/(xb-xa);
m2 = (yd-yc)/(xd-xc);
c1 = ya - (m1*xa);
c2 = yc - (m2*xc);
x=(c2-c1)/(m1-m2);
y=(m1*x)+c1;
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
glVertex2f(x,y);
glEnd();
glFlush(); // mengirim semua output ke layar
}
int main(int argc, char** argv)
{
glutInit(&argc, argv); // inisialisasi toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set modus display
glutInitWindowSize(480,480); // set ukuran window
glutInitWindowPosition(100, 150); // set posisi window di layar
glutCreateWindow("Titik Potong 2 Garis"); // buka screen window
glutDisplayFunc(myDisplay); // registrasi fungsi menggambar
myInit();
glutMainLoop(); // berulang terus-menerus
}