istereo

view src/istereo.c @ 5:76ad575d72d0

trying to make it fucking work
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 07 Sep 2011 07:29:51 +0300
parents 14bbdfcb9030
children f72c585aec26
line source
1 #include <stdio.h>
2 #include <assert.h>
3 #include <unistd.h>
4 #include "opengl.h"
5 #include "istereo.h"
6 #include "sanegl.h"
7 #include "sdr.h"
8 #include "respath.h"
10 static unsigned int get_shader_program(const char *vfile, const char *pfile);
12 unsigned int prog;
14 int init(void)
15 {
16 add_resource_path("sdr");
18 if(!(prog = get_shader_program("test.v.glsl", "test.p.glsl"))) {
19 fprintf(stderr, "failed to load shader program\n");
20 return -1;
21 }
23 return 0;
24 }
26 void cleanup(void)
27 {
28 free_program(prog);
29 }
31 void redraw(void)
32 {
33 glClearColor(0.4, 0.6, 1.0, 1.0);
34 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
36 bind_program(prog);
38 gl_matrix_mode(GL_MODELVIEW);
39 gl_load_identity();
40 gl_translatef(0, 0, -8);
42 gl_begin(GL_QUADS);
43 gl_color3f(1, 0, 0);
44 gl_vertex3f(-1, -1, 0);
45 gl_color3f(0, 1, 0);
46 gl_vertex3f(1, -1, 0);
47 gl_color3f(0, 0, 1);
48 gl_vertex3f(1, 1, 0);
49 gl_color3f(1, 1, 0);
50 gl_vertex3f(-1, 1, 0);
51 gl_end();
53 assert(glGetError() == GL_NO_ERROR);
54 }
56 void reshape(int x, int y)
57 {
58 glViewport(0, 0, x, y);
60 gl_matrix_mode(GL_PROJECTION);
61 gl_load_identity();
62 glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0);
63 }
65 static unsigned int get_shader_program(const char *vfile, const char *pfile)
66 {
67 unsigned int prog, vs, ps;
69 if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) {
70 return -1;
71 }
72 if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) {
73 return -1;
74 }
76 if(!(prog = create_program_link(vs, ps))) {
77 return -1;
78 }
79 return prog;
80 }