-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
executable file
·75 lines (62 loc) · 1.65 KB
/
main.m
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <GLUT/glut.h>
// Screen Size
#define width 1024
#define height 768
#define size width*height
// This function is implemented an a seperate file: fast.nasm
void update(GLubyte *,GLubyte *,GLubyte *) __attribute__ ((regparm (3)));
// Frame Buffer
static GLubyte bitmap[size];
// Temp Frame Buffer
static GLubyte vbitmap[size];
// Final Frame Buffer
static GLubyte drawbitmap[size];
// Used for mouse tracking
static int ox,oy;
void display(void) {
glDrawPixels(width,height,GL_GREEN,GL_UNSIGNED_BYTE,(GLvoid*)drawbitmap);
glutSwapBuffers();
}
void tick() {
update(bitmap,vbitmap,drawbitmap);
glutPostRedisplay();
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0,(float)w,0,(float)h);
glMatrixMode (GL_MODELVIEW);
}
void mouse(int button, int state, int x, int y) {
int i;
int j;
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
ox = x;
oy = y;
} else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
oy = height - oy;
y = height - y;
for (i = y ; i <= oy ; i++) {
for (j = ox ; j <= x ; j++) {
bitmap[j+(i<<10)] = 1;
}
}
}
}
int main (int argc, char **argv) {
int i;
// Used for pseudo-random initial spread of cells.
for (i = 0 ; i < size ; i++) bitmap[i] = vbitmap[i] = 1*(i > 10000);
glutInit (&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize (width, height);
glutInitWindowPosition (0, 0);
glutCreateWindow ("Life");
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutIdleFunc(tick);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}