Home » Source Code » LINE PROGRAM USING OPENGL

LINE PROGRAM USING OPENGL

wde
2013-10-12 01:49:35
The author
View(s):
Download(s): 0
Point (s): 1 
Category Category:
OpenGLOpenGL CPlusPlus, C-C++C++

Description

#include
#include
#include
#include
#include
#define INCR 1
#define DECR -1
#define PREDX 1
#define PREDY 0
int dx,dy,e,e_inc,e_noinc;
int main(void)
{
   int xa,ya,xb,yb,i;
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   void lineBres(int,int,int,int);
   /* initialize graphics mode */
    clrscr();
    initgraph(&gdriver, &gmode, "t:\\turboc\\bgi");
    /*neBres(200,400,220,400);//m=0,lowerhorizontal line
    lineBres(200,300,200,400);//m=infinity,vertical line
    lineBres(220,300,220,400);//rightverticalline
    lineBres(200,300,220,300);//upperhoriline
    xa=200;ya=350;xb=150;yb=300;
    for(i=0;i<=4;i++)
    {
    lineBres(xa,ya,xb,yb);
    ya=ya-10;
    xb=xb+10;
    }*/
    printf("LINE DRAWING ALGORITHM:");
 //   xa=200;ya=150;xb=300;yb=250;
    /*for(i=0;i<=8;i++)
    {
lineBres(xa,ya,xb,yb);
ya+=10;
xb-=10;
    } */
   lineBres(200,150,100,250);
   lineBres(200,150,300,250);
  lineBres(100,250,300,250);
 lineBres(100,250,100,400);
  lineBres(300,250,300,400);
  lineBres(100,400,300,400);
  //lineBres(250,280,300,180);
//ineBres(500,0,200,200);
  // lineBres(200,150,150,200);
  // lineBres(150,200,200,250);












    getch();
    closegraph();
   return 0;
}
void lineBres(int x1,int y1,int x2,int y2)
{
 int incdec,t,i;
 if(x1>x2)
 {
t=x1;
x1=x2;
x2=t;


t=y1;
y1=y2;
y2=t;
 }
 dx=x2-x1;
 //printf("\ndx:\t%d",dx);
 dy=y2-y1;
 //printf("\ndy:\t%d",dy);
 if(dx==0)//vertical line
 {
if(y1>y2)
{
t=y1;
y1=y2;
y2=t;
}
for(i=y1;i<=y2;i++)
putpixel(x1,i,2);
return;
 }
 if(dy==0)//horizontal line
 {
for(i=x1;i<=x2;i++)
putpixel(i,y1,2);
return;
 }
 //0<m<1
 if(dy0)
 {
e_noinc=2*dy;
e=2*dy-dx;
e_inc=2*(dy-dx);
drawline(x1,y1,x2,y2,PREDX,INCR);
 }
 //m=1
 if(dy==dx && dy>0)
 {
e_noinc=2*dy;
e=2*dy-dx;
e_inc=2*(dy-dx);
drawline(x1,y1,x2,y2,PREDX,INCR);
 }
 //1<m<infinity
 if(dy>dx && dy>0)
 {
e_noinc=2*dx;
e=2*dx-dy;
e_inc=2*(dx-dy);
drawline(x1,y1,x2,y2,PREDY,INCR);
 }
 //0>m>-1
 if(-dy<dx && dy<0)
 {
dy=-dy;
e_noinc=2*dy;
e=2*dy-dx;
e_inc=2*(dy-dx);
drawline(x1,y1,x2,y2,PREDX,DECR);
 }
 //m=-1
 if(dy==-dx && dy<0)
 {
      //rintf("\nhai\nx2:%d\ty2:%d\tx1:%d\ty1:%d\n",x2,y2,x1,y1);
dy=-dy;
e_noinc=(2*dy);
e=2*dy-dx;
e_inc=2*(dy-dx);
drawline(x1,y1,x2,y2,PREDX,DECR);
 }
 //-1>m>0
 if(-dy>dx && dy<0)
 {
dx=-dx;
e_noinc=-(2*dx);
e=2*dx-dy;
e_inc=-2*(dx-dy);
drawline(x1,y1,x2,y2,PREDX,DECR);
 }
}
drawline(int x1,int y1,int x2,int y2,int pred,int incdec)
{
 int i,start,end,var;
 if(pred==PREDX)
 {
start=x1;
end=x2;
var=y1;
 }
 else
 {
start=y1;
end=y2;
var=x1;
 }
 for(i=start;i<=end;i++)
 {
if(pred==PREDY)
putpixel(var,i,GREEN);
else
putpixel(i,var,GREEN);
if(e<0)
e+=e_noinc;
else
{
var+=incdec;
e+=e_inc;
}
 }
 return ;
}

Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
LINE.CPP2.94 kB2013-07-31 13:21
...
Sponsored links

Comments

(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

LINE PROGRAM USING OPENGL (1.14 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D