Sunteți pe pagina 1din 9

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

CSE ENGINEERS
Al Hizbul Bahar

Home
PHP

AboutMe
cake php JAVA Python WordPress OpenGL Linux/Ubuntu

Home OpenGL Bresenham Line Algorithm Using OpenGL andC++

Bresenham Line Algorithm Using OpenGL andC++


Posted on May 21, 2013 by Al Hizbul Bahar

Leave a comment

Bresenham Line Algorithm Using OpenGL and C++.

// bresenham_line_algorithm.cpp : Defnes the entry point for the console application. //


#include "stdafx.h" #include "GL/glut.h";
foat x1,x2,y1,y2,b=0; void setPixel(int x, int y)
{

Follow

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

lBegin(GL_POINTS); g glVertex2i(x,y);
glEnd();
glFlush();
}
void horizontal() {
if(x1>x2)
{
foat temp;
temp = x1;
x1 = x2;
x2 = temp;
}
for(foat x=x1; x<=x2; x++)
{
setPixel(x,y1);
}
}
void vertical() {
if(y1>y2)
{
foat temp;
temp = y1;
y1 = y2;
y2 = temp;
}
for(foat y=y1; y<=y2; y++)
{
setPixel(x1,y);
}
}
void bresenham1() {
if(x1>x2)
{
foat temp;
temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;

Follow CSE ENGINEERS


Get every new post delivered to your Inbox.
Enter your email address
Sign me up

Powered by WordPress.com

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

y 2 = temp; }
int x = x1, y = y1;
int dx = x2-x1;
int dy = y2-y1;
int dT = 2*(dy-dx);
int dS = 2*dy;
int d = 2*dy-dx;
setPixel(x,y); while(x<x2)
{
x++;
if(d<0)
{
d = d+dS;
}
else
{
d = d+dT;
y++;
}
setPixel(x,y);
}
setPixel(x2,y2);
}
void bresenham2() {
if(x1>x2)
{
foat temp;
temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
}
int x = x1, y = y1;
int dx = x2-x1;
int dy = y2-y1;
int dT = 2*(dy+dx);
int dS = 2*dy;
int d = -(2*dx+dy);

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

setPixel(x,y); while(x<x2)
{
x++;
if(d<0)
{
d = d-dS;
}
else
{
y;
d = d-dT;
}
setPixel(x,y);
}
setPixel(x2,y2);
}
void bresenham3() {
if(y1>y2)
{
foat temp;
temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
}
int x = x1, y = y1;
int dx = x2-x1;
int dy = y2-y1;
int dT = 2*(dx-dy);
int dS = 2*dx;
int d = 2*dx-dy;
setPixel(x,y); while(y<y2)
{
y++;
if(d<0)
{
d = d+dS;
}
else

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

{ x++;
d = d+dT;
}
setPixel(x,y);
}
setPixel(x2,y2);
}
void bresenham4() {
if(y1>y2)
{
foat temp;
temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
}
int x = x1, y = y1;
int dx = x2-x1;
int dy = y2-y1;
int dT = 2*(dy+dx);
int dS = 2*dx;
int d = -(2*dy+dx);
setPixel(x,y); while(y<y2)
{
y++;
if(d<0)
{
d = d-dS;
}
else
{
x;
d = d-dT;
}
setPixel(x,y);
}
setPixel(x2,y2);
}

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

void myMouse(int button, int state, int x, int y) {


if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
if(b==0)
{
x1 = x;
y1 = 480-y;
b = 1;
}
else if(b==1)
{
x2 = x;
y2 = 480-y;
b = 0;
if(y1==y2) horizontal(); else if(x1==x2) vertical();
foat m = (y2-y1)/(x2-x1); if(0<m && m<1) bresenham1(); else if(0>m && m>-1) bresenham2();
else if(1<m) bresenham3();
else if(-1>m) bresenham4();
}
}
}
void myDisplay(void) {
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
gluOrtho2D(0.0,640.0,0.0,480.0);
glClear(GL_COLOR_BUFFER_BIT);
glutMouseFunc(myMouse);
glFlush();
}
int _tmain(int argc, char** argv) {
glutInitWindowSize(640,480);
glutInitWindowPosition(100, 100);
glutCreateWindow ("A simple Line");
glutDisplayFunc(myDisplay);
glutMainLoop ( );

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

r eturn 0; }
To get complete code and project contact with me through email , mobile. You may commented below as your requirement.

Share this:

Twitter

Facebook

Related

DDA Line Drawing Algorithm Using OpenGL and C++ In "OpenGL"

Bresenham Circle Algorithm Using OpenGL and C++ In "OpenGL"

Lexical Analysis in Compiler Design Using Java In "JAVA"

About Al Hizbul Bahar Junior Software Engineer at Nascenia IT , Dhaka , Bangladesh

Bresenham Circle Algorithm Using OpenGL andC++ Car Workshop(Multi Server Queuing) Simulation UsingJava

Tagged with: Bresenham algorithm, OpenGL Posted in OpenGL

Leave a Reply

search here

Go

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

Archives
January 2014 December 2013 November 2013 September 2013 July 2013 June 2013 May 2013 April 2013

My Cloud
Algorithm
array
banker's algorithm
Binary Search
Bresenham

algorithm
c++
cakephp
Compiler
country array
cpu scheduling

data insert
Factorial
Fibonacci
First
Follow
framework
GCD
image to binary
ip address

comm
linux command
MANET
Multi

Server
nam
ns2
OpenGL
OS
paypal

java

php

Javascript
lamp
Lexical Analysis
linux

php framework
prime
Prime

number

Pyramid

python
shortest path
simulation
single server
sql
ubuntu12.04
user login
user registration
validation

wirelessnetwork
wordpress
youtube

Popular Posts & Pages


CPU Scheduling Algorithm using Java Bresenham Line Algorithm Using OpenGL and C++ Install ns2 in Ubuntu 12.04 LTS Image to binary and binary to image conversion in php Simple registration in CakePHP Banker's Algorithm Using Java DDA Line Drawing Algorithm Using OpenGL and C++ Simulation of Single Server Queuing System User Login in CakePHP Bresenham Circle Algorithm Using OpenGL and C++

CSE Engineers
CSE Engineers

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

Bresenham Line Algorithm Using OpenGL and C++ | CSE ENGINEERS

Like

102 people like CSE Engineers.

Facebook social plugin

2014 CSE ENGINEERS

Blog at WordPress.com.
| The Responsive Theme.

http://engineersview.wordpress.com/2013/05/21/bresenham-line-algorithm-using-opengl-and-c/[11/02/2014 19:59:53]

S-ar putea să vă placă și