0% found this document useful (0 votes)
11 views3 pages

Grafika Komputer

The document contains a C program that implements the Digital Differential Analyzer (DDA) algorithm to draw a line using OpenGL. It sets up a window and defines functions to configure the display, set pixel colors, and draw the line based on given coordinates. The main function initializes the OpenGL context and starts the rendering loop.

Uploaded by

Muh Ilham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Grafika Komputer

The document contains a C program that implements the Digital Differential Analyzer (DDA) algorithm to draw a line using OpenGL. It sets up a window and defines functions to configure the display, set pixel colors, and draw the line based on given coordinates. The main function initializes the OpenGL context and starts the rendering loop.

Uploaded by

Muh Ilham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NAMA: MUH.

ILHAM

NIM: D0222315

Sourcode:

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <stdarg.h>

#include <GL/glut.h>

void tampilan(void) {

glClearColor(0.0, 0.0, 0.0, 1.0);

glMatrixMode(GL_PROJECTION);

gluOrtho2D(0.0, 160.0, 0.0, 120.0);

void aturPixel(GLint xCoordinate, GLint yCoordinate) {

glBegin(GL_POINTS);

glVertex2i(xCoordinate, yCoordinate);

glEnd();

glFlush();

void garisDDA(GLint x0, GLint y0, GLint xEnd, GLint yEnd) {

GLint dx = xEnd - x0;

GLint dy = yEnd - y0;

GLint steps, k;

GLfloat xIncrement, yIncrement, x = x0, y = y0;

if (fabs(dx) > fabs(dy)) {


steps = fabs(dx);

} else {

steps = fabs(dy);

xIncrement = dx / (GLfloat)steps;

yIncrement = dy / (GLfloat)steps;

aturPixel(round(x), round(y));

for (k = 0; k < steps; k++) {

x += xIncrement;

y += yIncrement;

aturPixel(round(x), round(y));

void gambarGaris(void) {

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 0.0, 1.0);

glPointSize(4.0);

GLint x0 = 10;

GLint y0 = 5;

GLint xEnd = 80;

GLint yEnd = 75;

garisDDA(x0, y0, xEnd, yEnd);

int main(int argc, char** argv) {

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(400, 400);

glutInitWindowPosition(0, 0);

glutCreateWindow("Membuat Garis Algoritma DDA");

tampilan();

glutDisplayFunc(gambarGaris);

glutMainLoop();

return 0;

Output:

You might also like