fractorb
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.c Sat Nov 18 20:04:16 2017 +0200 1.3 @@ -0,0 +1,95 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <GL/glew.h> 1.7 +#include <GL/glut.h> 1.8 +#include "sdr.h" 1.9 + 1.10 +int init(void); 1.11 +void cleanup(void); 1.12 +void disp(void); 1.13 +void reshape(int x, int y); 1.14 +void keyb(unsigned char key, int x, int y); 1.15 +void mouse(int bn, int st, int x, int y); 1.16 +void motion(int x, int y); 1.17 + 1.18 +static float aspect; 1.19 +static int mouse_x, mouse_y; 1.20 +static unsigned int prog_mbrot; 1.21 + 1.22 +int main(int argc, char **argv) 1.23 +{ 1.24 + glutInit(&argc, argv); 1.25 + glutInitWindowSize(1280, 800); 1.26 + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 1.27 + glutCreateWindow("fractorb"); 1.28 + 1.29 + glutDisplayFunc(disp); 1.30 + glutReshapeFunc(reshape); 1.31 + glutKeyboardFunc(keyb); 1.32 + glutMouseFunc(mouse); 1.33 + glutMotionFunc(motion); 1.34 + 1.35 + if(init() == -1) { 1.36 + return 1; 1.37 + } 1.38 + atexit(cleanup); 1.39 + 1.40 + glutMainLoop(); 1.41 + return 0; 1.42 +} 1.43 + 1.44 + 1.45 +int init(void) 1.46 +{ 1.47 + glewInit(); 1.48 + 1.49 + if(!(prog_mbrot = create_program_load("vertex.glsl", "mbrot.glsl"))) { 1.50 + return -1; 1.51 + } 1.52 + set_uniform_float(prog_mbrot, "view_scale", 1.1); 1.53 + set_uniform_float2(prog_mbrot, "view_center", 0.7, 0); 1.54 + return 0; 1.55 +} 1.56 + 1.57 +void cleanup(void) 1.58 +{ 1.59 + free_program(prog_mbrot); 1.60 +} 1.61 + 1.62 +void disp(void) 1.63 +{ 1.64 + glUseProgram(prog_mbrot); 1.65 + 1.66 + glBegin(GL_QUADS); 1.67 + glTexCoord2f(-aspect, 1); glVertex2f(-1, -1); 1.68 + glTexCoord2f(aspect, 1); glVertex2f(1, -1); 1.69 + glTexCoord2f(aspect, -1); glVertex2f(1, 1); 1.70 + glTexCoord2f(-aspect, -1); glVertex2f(-1, 1); 1.71 + glEnd(); 1.72 + 1.73 + glutSwapBuffers(); 1.74 +} 1.75 + 1.76 +void reshape(int x, int y) 1.77 +{ 1.78 + glViewport(0, 0, x, y); 1.79 + 1.80 + aspect = (float)x / (float)y; 1.81 +} 1.82 + 1.83 +void keyb(unsigned char key, int x, int y) 1.84 +{ 1.85 + if(key == 27) { 1.86 + exit(0); 1.87 + } 1.88 +} 1.89 + 1.90 +void mouse(int bn, int st, int x, int y) 1.91 +{ 1.92 +} 1.93 + 1.94 +void motion(int x, int y) 1.95 +{ 1.96 + mouse_x = x; 1.97 + mouse_y = y; 1.98 +}