CompuForm Assigment 1: grid · posted by vaibhav bhawsar Sep 14, 06:40

void drawGrid ( void )
{
	//the color of the line
	glColor3f(.8,.8,.8);	
	//draw lines
	glBegin(GL_LINES);
	//horizontal line
	for(int h = 0 ; h < windowH/10 ; h++ ){
		glVertex2f ( 0 , h*10 );
		glVertex2f ( windowW , h*10 );
		//vertical lines
		for(int v = 0 ; v < windowW/10 ; v++ ){
			glVertex2f(v*10 , windowH );
			glVertex2f(v*10 , 0);
		}
	}
        glEnd();
	//draw points
	glColor3f(.4,.4,.4);
	glPointSize(3);		
	glBegin(GL_POINTS);
	int numberOfDivisions = 10;
	for(int h = 0 ; h <= windowH/numberOfDivisions ; h++){
		for(int v = 0 ; v <= windowW/numberOfDivisions ; v++){
			glVertex2f(v*numberOfDivisions, h*numberOfDivisions);
		}
	}
	glEnd();
}

Commenting is closed for this article.