10. Program to display a set of values
{fij} as a rectangular mesh.
static GLdouble viewer[]={0,0,5};
int m, n;
void rectmesh( int m, int n)
{
int i, j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
glBegin(GL_LINE_LOOP);
glVertex2i( i, j);
glVertex2i( i+1, j);
glVertex2i( i+1, j+1);
glVertex2i( i, j+1);
glEnd();
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(viewer[0],viewer[1],viewer[2],0,0,0,0,1,0);
glTranslated(0,0,-5);
glColor3f(0,0,0);
rectmesh( m, n);
glFlush();
}
void myReshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,20,-2,20,-10,20);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char **argv)
{
printf(“enter m & n:”);
scanf(“%d%d”,&m,&n);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(“Rectangular Mesh”);
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
glClearColor(1.0,1.0,1.0,1.0);
glutMainLoop();
return 0;
}
#include<GL/glut.h>
#include<stdio.h>static GLdouble viewer[]={0,0,5};
int m, n;
void rectmesh( int m, int n)
{
int i, j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
glBegin(GL_LINE_LOOP);
glVertex2i( i, j);
glVertex2i( i+1, j);
glVertex2i( i+1, j+1);
glVertex2i( i, j+1);
glEnd();
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(viewer[0],viewer[1],viewer[2],0,0,0,0,1,0);
glTranslated(0,0,-5);
glColor3f(0,0,0);
rectmesh( m, n);
glFlush();
}
void myReshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,20,-2,20,-10,20);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char **argv)
{
printf(“enter m & n:”);
scanf(“%d%d”,&m,&n);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(“Rectangular Mesh”);
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
glClearColor(1.0,1.0,1.0,1.0);
glutMainLoop();
return 0;
}