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