-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangular Mesh
51 lines (45 loc) · 976 Bytes
/
Rectangular Mesh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<GL/glut.h>
#include<stdlib.h>
#define maxx 20
#define maxy 25
#define dx 15
#define dy 10
GLfloat x[maxx]={0.0}, y[maxy]={0.0};
GLfloat x0=50.0, y0=50.0;
GLint i,j;
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glPointSize(5.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,500.0,0.0,500.0);
}
void dispaly(void)
{
glClear(GL_COLOR_BUFFER_BIT);
for(i=0;i<maxx;i++) x[i]=x0+i*dx;
for(j=0;j<maxy;j++) y[j]=y0+j*dy;
for(i=0;i<maxx-1;i++)
for(j=0;i<maxy-1;i++)
{
glBegin(GL_LINE_LOOP);
glVertex2f(x[i],y[j]);
glVertex2f(x[i],y[j+1]);
glVertex2f(x[i+1],y[j+1]);
glVertex2f(x[i+1],y[i]);
glEnd();
}
glFlush();
}
void main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("mesh");
glutDisplayFunc(dispaly);
myinit();
glutMainLoop();
}