<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>how to &#187; OpenGL</title>
	<atom:link href="http://www.neteyaz.com/category/opengl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.neteyaz.com</link>
	<description>linux and open source tips</description>
	<lastBuildDate>Mon, 23 May 2011 08:47:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Drawing Line With DDA Algorithm using OpenGL in C++</title>
		<link>http://www.neteyaz.com/drawing-line-with-dda-algorithm-using-opengl-in-c</link>
		<comments>http://www.neteyaz.com/drawing-line-with-dda-algorithm-using-opengl-in-c#comments</comments>
		<pubDate>Sun, 06 Dec 2009 19:38:01 +0000</pubDate>
		<dc:creator>TaZ</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[DDA]]></category>
		<category><![CDATA[glutMouseFunc]]></category>
		<category><![CDATA[Line Drawing]]></category>

		<guid isPermaLink="false">http://www.neteyaz.com/?p=152</guid>
		<description><![CDATA[The code is based on the popularly used dda line drawing algorithm.It picks up two point from the window and change the color of pixels which are closest to vectorial line between them.



#include &#60;GL/glut.h&#62;
#include &#60;math.h&#62;
#include &#60;time.h&#62;
#define W 512
#define H 512
int points[2][2];
int point_count=0;
void initialize(){
	glClearColor( 0.0, 0.0, 0.0, 0.0);//set background color to black
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, W,0,H);
}

void setPixel(int x, int [...]]]></description>
			<content:encoded><![CDATA[<p>The code is based on the popularly used dda line drawing algorithm.It picks up two point from the window and change the color of pixels which are closest to vectorial line between them.<br />
<span id="more-152"></span><br />
<img src="http://www.neteyaz.com/files/2009/12/adsız-300x163.jpg" alt="changing color of closest pixels to vectorial line " title="changing color of closest pixels to vectorial line " width="300" height="163" class="alignnone size-medium wp-image-154" /></p>
<pre>
#include &lt;GL/glut.h&gt;
#include &lt;math.h&gt;
#include &lt;time.h&gt;
#define W 512
#define H 512
int points[2][2];
int point_count=0;
void initialize(){
	glClearColor( 0.0, 0.0, 0.0, 0.0);//set background color to black
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, W,0,H);
}

void setPixel(int x, int y){	//change color of a pixel
	glColor3f(1, 1, 1);
	y=H-y;
	glBegin(GL_POINTS);
	glVertex2f(x,y);
	glEnd();
}

void LineWithDDA(int x0, int y0, int x1, int y1) {//DDa line algorithm
    int dy = y1 - y0;
    int dx = x1 - x0;
    int steps,i;
    float xinc,yinc,x=x0,y=y0;
    if( fabs(dx) &gt; fabs(dy)){
        steps=fabs(dx);
    }else{
          steps=fabs(dy);
    }
    xinc=(float) dx/ (float) steps;
    yinc=(float) dy/ (float) steps;
    setPixel(round(x), round(y));
    for(i=0;i&lt;steps;i++){
         x+=xinc;
         y+=yinc;
         setPixel(round(x), round(y));
    }
    glutSwapBuffers();
}
void lineSegment(){
    glClear(GL_COLOR_BUFFER_BIT);
    glutSwapBuffers();
    LineWithDDA(W/2,0,W/2,H);
    LineWithDDA(0,H/2,W,H/2);
}
void Control(int button, int state, int x, int y){

  // Respond to mouse button presses.
  // If button1 pressed, mark this state so we know in motion function.

  if (button == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN)
    {
  			setPixel(x,y);
  			if(point_count&lt;1){
					points[0][0]=x;
					points[0][1]=y;
					point_count++;
			}else{
					points[1][0]=x;
	 			    points[1][1]=y;
			        use_dda(points[0][0],points[0][1],points[1][0],points[1][1]);
			        point_count=0;
			}
	      glutSwapBuffers();
    }
}
int main(int argc, char** argv) {
	glutInit(&amp;argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
	glutInitWindowPosition(0,0);
	glutInitWindowSize(W,H);
	glutCreateWindow("OpenGL Mouse Function");
	initialize();
	glutMouseFunc(Control);
	glutDisplayFunc(lineSegment);
	glutMainLoop();
	return 0;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.neteyaz.com/drawing-line-with-dda-algorithm-using-opengl-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

