answersLogoWhite

0


Best Answer

Here is the C code for DDA line drawing...

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

{

int gd, gm;

float x, y, dx, dy, len;

int x1, y1, x2, y2, i;

detectgraph(&gd, &gm);

initgraph(&gd, &gm,"");

printf("\n Enter the coordinates of line : ");

scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

dx = abs(x2-x1);

dy = abs(y2-y1);

if (dx >= dy) len = dx;

else len = dy;

dx = (x2-x1)/len;

dy = (y2-y1)/len;

x = x1 + 0.5;

y = y1 + 0.5;

i = 1;

while (i <= len)

{

putpixel(x, y, 6);

x = x+dx;

y = y+dy;

i++;

}

getch();

}

-Suraj.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the code in c plus plus for line drawing algorithm using OpenGL?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Opengl programming source code for pool game?

writ an opengl program for pool game


The code 11110101101 was received Using Hamming encoding method 2 what is the original code sent?

the code 11110101101 was received using hamming encoding algorithm what was the original code sent


Matlab code for filters using LMS algorithm?

http://www.mathworks.com/matlabcentral/fileexchange/3649


Java source code for median filter algorithm?

research is going on to develop a source code for median filtering using java


What are the ways representing an algorithm?

You can represent an algorithm by three different ways: 1. Pseudo Code 2. Structured flow charts 3. Actual code


What is the difference between implementation and algorithm?

An algorithm is a instruction for solving a problem. It is typically illustrated using prose, pseudo code or flowcharts, but other methods exist. The algorithm is the "here's how it's going to work" part of the solution. An implementation (of an algorithm) is a specific expression of this algorithm, using a specific programming language or any other suitable means. The implementation is the "here's how I've done it" part of the solution.


Free car competition sample code on opengl animation?

coding for car animation in open gl


Can someone provide the C program for Prim's algorithm?

The C code for Prim's algorithm can be found in the following link. https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-find-minimal-spanning-tree-using--prims-algorithm


What is A algorithm in AI?

A algorithm in artificial intelligence is a line of code meant to simulate a human emotion.


What is the code of pegasis?

PEGASIS Cluster Algorithm Code for WSN Omnet++ ?


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


Are algorithms only meant for computers?

No. Indeed, algorithms are actually meant for humans, not computers. Computer programmers translate algorithms into working code such that a computer can process the algorithm. The code is actually the implementation of the algorithm, not the algorithm itself.