istereo

view src/istereo.c @ 4:14bbdfcb9030

resource path find code
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 07 Sep 2011 06:25:05 +0300
parents 2c5620f0670c
children 76ad575d72d0
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 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
35 bind_program(prog);
37 gl_matrix_mode(GL_MODELVIEW);
38 gl_load_identity();
39 gl_translatef(0, 0, -8);
41 gl_begin(GL_QUADS);
42 gl_color3f(1, 0, 0);
43 gl_vertex3f(-1, -1, 0);
44 gl_color3f(0, 1, 0);
45 gl_vertex3f(1, -1, 0);
46 gl_color3f(0, 0, 1);
47 gl_vertex3f(1, 1, 0);
48 gl_color3f(1, 1, 0);
49 gl_vertex3f(-1, 1, 0);
50 gl_end();
52 assert(glGetError() == GL_NO_ERROR);
53 }
55 void reshape(int x, int y)
56 {
57 glViewport(0, 0, x, y);
59 gl_matrix_mode(GL_PROJECTION);
60 gl_load_identity();
61 glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0);
62 }
64 static unsigned int get_shader_program(const char *vfile, const char *pfile)
65 {
66 unsigned int prog, vs, ps;
68 if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) {
69 return -1;
70 }
71 if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) {
72 return -1;
73 }
75 if(!(prog = create_program_link(vs, ps))) {
76 return -1;
77 }
78 return prog;
79 }