rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <stdlib.h>
|
nuclear@0
|
3 #include <GL/glew.h>
|
nuclear@0
|
4 #include <GL/glut.h>
|
nuclear@0
|
5 #include "sdr.h"
|
nuclear@0
|
6
|
nuclear@0
|
7 int init(void);
|
nuclear@0
|
8 void cleanup(void);
|
nuclear@0
|
9 void disp(void);
|
nuclear@0
|
10 void reshape(int x, int y);
|
nuclear@0
|
11 void keyb(unsigned char key, int x, int y);
|
nuclear@0
|
12 void mouse(int bn, int st, int x, int y);
|
nuclear@0
|
13 void motion(int x, int y);
|
nuclear@0
|
14
|
nuclear@0
|
15 static float aspect;
|
nuclear@0
|
16 static int mouse_x, mouse_y;
|
nuclear@0
|
17 static unsigned int prog_mbrot;
|
nuclear@0
|
18
|
nuclear@0
|
19 int main(int argc, char **argv)
|
nuclear@0
|
20 {
|
nuclear@0
|
21 glutInit(&argc, argv);
|
nuclear@0
|
22 glutInitWindowSize(1280, 800);
|
nuclear@0
|
23 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
|
nuclear@0
|
24 glutCreateWindow("fractorb");
|
nuclear@0
|
25
|
nuclear@0
|
26 glutDisplayFunc(disp);
|
nuclear@0
|
27 glutReshapeFunc(reshape);
|
nuclear@0
|
28 glutKeyboardFunc(keyb);
|
nuclear@0
|
29 glutMouseFunc(mouse);
|
nuclear@0
|
30 glutMotionFunc(motion);
|
nuclear@0
|
31
|
nuclear@0
|
32 if(init() == -1) {
|
nuclear@0
|
33 return 1;
|
nuclear@0
|
34 }
|
nuclear@0
|
35 atexit(cleanup);
|
nuclear@0
|
36
|
nuclear@0
|
37 glutMainLoop();
|
nuclear@0
|
38 return 0;
|
nuclear@0
|
39 }
|
nuclear@0
|
40
|
nuclear@0
|
41
|
nuclear@0
|
42 int init(void)
|
nuclear@0
|
43 {
|
nuclear@0
|
44 glewInit();
|
nuclear@0
|
45
|
nuclear@0
|
46 if(!(prog_mbrot = create_program_load("vertex.glsl", "mbrot.glsl"))) {
|
nuclear@0
|
47 return -1;
|
nuclear@0
|
48 }
|
nuclear@0
|
49 set_uniform_float(prog_mbrot, "view_scale", 1.1);
|
nuclear@0
|
50 set_uniform_float2(prog_mbrot, "view_center", 0.7, 0);
|
nuclear@0
|
51 return 0;
|
nuclear@0
|
52 }
|
nuclear@0
|
53
|
nuclear@0
|
54 void cleanup(void)
|
nuclear@0
|
55 {
|
nuclear@0
|
56 free_program(prog_mbrot);
|
nuclear@0
|
57 }
|
nuclear@0
|
58
|
nuclear@0
|
59 void disp(void)
|
nuclear@0
|
60 {
|
nuclear@0
|
61 glUseProgram(prog_mbrot);
|
nuclear@0
|
62
|
nuclear@0
|
63 glBegin(GL_QUADS);
|
nuclear@0
|
64 glTexCoord2f(-aspect, 1); glVertex2f(-1, -1);
|
nuclear@0
|
65 glTexCoord2f(aspect, 1); glVertex2f(1, -1);
|
nuclear@0
|
66 glTexCoord2f(aspect, -1); glVertex2f(1, 1);
|
nuclear@0
|
67 glTexCoord2f(-aspect, -1); glVertex2f(-1, 1);
|
nuclear@0
|
68 glEnd();
|
nuclear@0
|
69
|
nuclear@0
|
70 glutSwapBuffers();
|
nuclear@0
|
71 }
|
nuclear@0
|
72
|
nuclear@0
|
73 void reshape(int x, int y)
|
nuclear@0
|
74 {
|
nuclear@0
|
75 glViewport(0, 0, x, y);
|
nuclear@0
|
76
|
nuclear@0
|
77 aspect = (float)x / (float)y;
|
nuclear@0
|
78 }
|
nuclear@0
|
79
|
nuclear@0
|
80 void keyb(unsigned char key, int x, int y)
|
nuclear@0
|
81 {
|
nuclear@0
|
82 if(key == 27) {
|
nuclear@0
|
83 exit(0);
|
nuclear@0
|
84 }
|
nuclear@0
|
85 }
|
nuclear@0
|
86
|
nuclear@0
|
87 void mouse(int bn, int st, int x, int y)
|
nuclear@0
|
88 {
|
nuclear@0
|
89 }
|
nuclear@0
|
90
|
nuclear@0
|
91 void motion(int x, int y)
|
nuclear@0
|
92 {
|
nuclear@0
|
93 mouse_x = x;
|
nuclear@0
|
94 mouse_y = y;
|
nuclear@0
|
95 }
|