#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
#include <math.h>
void layar(void)
{
glClearColor (0.0 ,0.0, 0.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 300.0, 0.0, 300.0);
}
void titik (int x, int y)
{
glBegin(GL_POINTS);
glVertex2f (x, y);
glEnd();
glFlush();
}
void bresenham(int x1, int y1, int x2, int y2)
{
int dy = y2 - y1;
int dx = x2 - x1;
int stepx, stepy;
if(dy < 0) {
dy = -dy; stepy = -1;
}
else {
stepy = 1;
}
if(dx < 0) {
dx = -dx;
stepx = -1;
}
else {
stepx = 1;
}
dy <<= 1;
dx <<= 1;
titik(x1,y1);
if (dx > dy){
int fraction = dy - (dx >> 1);
while (x1 != x2){
if(fraction >= 0){
y1 += stepy;
fraction -= dx;
}
x1 += stepx;
fraction += dy;
titik(x1,y1);
}
}
else {
int fraction = dx - (dy >> 1);
while (y1 != y2){
if(fraction >= 0){
x1 += stepx;
fraction -= dy;
}
y1 += stepy;
fraction += dx;
titik(x1,y1);
}
}
}
void Garisku(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glPointSize (2.0);
//Garis Lurus
bresenham (10, 10, 165, 10);
//Garis Titik Sret Bawah
bresenham (10, 20, 20, 20);
bresenham (25, 20, 25, 20);
bresenham (30, 20, 40, 20);
bresenham (45, 20, 45, 20);
bresenham (50, 20, 60, 20);
bresenham (65, 20, 65, 20);
bresenham (70, 20, 80, 20);
bresenham (85, 20, 85, 20);
bresenham (90, 20, 100, 20);
bresenham (105, 20, 105, 20);
bresenham (110, 20, 120, 20);
bresenham (125, 20, 125, 20);
bresenham (130, 20, 140, 20);
bresenham (145, 20, 145, 20);
bresenham (150, 20, 160, 20);
//Garis Titik Sret Atas
bresenham (10, 100, 20, 95);
bresenham (25, 92, 25, 92);
bresenham (30, 90, 40, 85);
bresenham (45, 82, 45, 82);
bresenham (50, 80, 60, 75);
bresenham (65, 72, 65, 72);
bresenham (70, 70, 80, 65);
bresenham (85, 62, 85, 62);
bresenham (90, 60, 100, 55);
bresenham (105, 52, 105, 52);
bresenham (110, 50, 120, 45);
bresenham (125, 42, 125, 42);
bresenham (130, 40, 140, 35);
bresenham (145, 32, 145, 32);
bresenham (150, 30, 160, 25);
bresenham (165, 20, 165, 20);
}
int main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (640, 420);
glutInitWindowPosition (0, 0);
glutCreateWindow ("Tugas Algoritma Bresenham");
layar();
glutDisplayFunc (Garisku);
glutMainLoop();
return 0;
}
Nah seperti itulah project yang kami buat, dan sekiranya ada yang kurang sempurna ataupun salah kami harap dapat dimaklumi, karena kami sendiri juga masih dalam tahap pembelajaran , dan jika anda mau mendownload file source code project diatas sebagai bahan referensi pembelajaran, anda dapat mendownloadnya dengan link di bawah ini :
ini source codenya : download
0 komentar:
Posting Komentar