istereo

view src/istereo.c @ 16:20a9d3db38cb

forgot to actually use bind_texture
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 07 Sep 2011 09:19:47 +0300
parents b39d8607f4bb
children 4c20f10a7183
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"
9 #include "tex.h"
11 static unsigned int get_shader_program(const char *vfile, const char *pfile);
13 unsigned int prog;
14 unsigned int tex;
16 int init(void)
17 {
18 add_resource_path("sdr");
19 add_resource_path("data");
21 if(!(prog = get_shader_program("test.v.glsl", "test.p.glsl"))) {
22 fprintf(stderr, "failed to load shader program\n");
23 return -1;
24 }
26 if(!(tex = load_texture(find_resource("tiles.ppm", 0, 0)))) {
27 fprintf(stderr, "failed to load texture\n");
28 return -1;
29 }
31 return 0;
32 }
34 void cleanup(void)
35 {
36 free_program(prog);
37 }
39 void redraw(void)
40 {
41 glClearColor(0.4, 0.6, 1.0, 1.0);
42 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
44 bind_program(prog);
46 gl_matrix_mode(GL_MODELVIEW);
47 gl_load_identity();
48 gl_translatef(0, 0, -8);
50 bind_texture(tex, 0);
52 gl_begin(GL_QUADS);
53 gl_texcoord2f(0, 0);
54 gl_color3f(1, 0, 0);
55 gl_vertex3f(-1, -1, 0);
56 gl_texcoord2f(1, 0);
57 gl_color3f(0, 1, 0);
58 gl_vertex3f(1, -1, 0);
59 gl_texcoord2f(1, 1);
60 gl_color3f(0, 0, 1);
61 gl_vertex3f(1, 1, 0);
62 gl_texcoord2f(0, 1);
63 gl_color3f(1, 1, 0);
64 gl_vertex3f(-1, 1, 0);
65 gl_end();
67 bind_texture(0, 0);
69 assert(glGetError() == GL_NO_ERROR);
70 }
72 void reshape(int x, int y)
73 {
74 glViewport(0, 0, x, y);
76 gl_matrix_mode(GL_PROJECTION);
77 gl_load_identity();
78 glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0);
79 }
81 static unsigned int get_shader_program(const char *vfile, const char *pfile)
82 {
83 unsigned int prog, vs, ps;
85 if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) {
86 return -1;
87 }
88 if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) {
89 return -1;
90 }
92 if(!(prog = create_program_link(vs, ps))) {
93 return -1;
94 }
95 return prog;
96 }