istereo

annotate 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
rev   line source
nuclear@2 1 #include <stdio.h>
nuclear@2 2 #include <assert.h>
nuclear@3 3 #include <unistd.h>
nuclear@1 4 #include "opengl.h"
nuclear@0 5 #include "istereo.h"
nuclear@2 6 #include "sanegl.h"
nuclear@2 7 #include "sdr.h"
nuclear@4 8 #include "respath.h"
nuclear@14 9 #include "tex.h"
nuclear@4 10
nuclear@4 11 static unsigned int get_shader_program(const char *vfile, const char *pfile);
nuclear@2 12
nuclear@2 13 unsigned int prog;
nuclear@14 14 unsigned int tex;
nuclear@0 15
nuclear@0 16 int init(void)
nuclear@0 17 {
nuclear@4 18 add_resource_path("sdr");
nuclear@14 19 add_resource_path("data");
nuclear@3 20
nuclear@4 21 if(!(prog = get_shader_program("test.v.glsl", "test.p.glsl"))) {
nuclear@2 22 fprintf(stderr, "failed to load shader program\n");
nuclear@2 23 return -1;
nuclear@2 24 }
nuclear@14 25
nuclear@14 26 if(!(tex = load_texture(find_resource("tiles.ppm", 0, 0)))) {
nuclear@14 27 fprintf(stderr, "failed to load texture\n");
nuclear@14 28 return -1;
nuclear@14 29 }
nuclear@14 30
nuclear@0 31 return 0;
nuclear@0 32 }
nuclear@0 33
nuclear@0 34 void cleanup(void)
nuclear@0 35 {
nuclear@2 36 free_program(prog);
nuclear@0 37 }
nuclear@0 38
nuclear@0 39 void redraw(void)
nuclear@0 40 {
nuclear@5 41 glClearColor(0.4, 0.6, 1.0, 1.0);
nuclear@0 42 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@2 43
nuclear@2 44 bind_program(prog);
nuclear@2 45
nuclear@13 46 gl_matrix_mode(GL_MODELVIEW);
nuclear@2 47 gl_load_identity();
nuclear@13 48 gl_translatef(0, 0, -8);
nuclear@2 49
nuclear@16 50 bind_texture(tex, 0);
nuclear@6 51
nuclear@13 52 gl_begin(GL_QUADS);
nuclear@14 53 gl_texcoord2f(0, 0);
nuclear@2 54 gl_color3f(1, 0, 0);
nuclear@2 55 gl_vertex3f(-1, -1, 0);
nuclear@14 56 gl_texcoord2f(1, 0);
nuclear@2 57 gl_color3f(0, 1, 0);
nuclear@2 58 gl_vertex3f(1, -1, 0);
nuclear@14 59 gl_texcoord2f(1, 1);
nuclear@2 60 gl_color3f(0, 0, 1);
nuclear@2 61 gl_vertex3f(1, 1, 0);
nuclear@14 62 gl_texcoord2f(0, 1);
nuclear@2 63 gl_color3f(1, 1, 0);
nuclear@2 64 gl_vertex3f(-1, 1, 0);
nuclear@13 65 gl_end();
nuclear@2 66
nuclear@16 67 bind_texture(0, 0);
nuclear@14 68
nuclear@2 69 assert(glGetError() == GL_NO_ERROR);
nuclear@0 70 }
nuclear@2 71
nuclear@2 72 void reshape(int x, int y)
nuclear@2 73 {
nuclear@2 74 glViewport(0, 0, x, y);
nuclear@2 75
nuclear@2 76 gl_matrix_mode(GL_PROJECTION);
nuclear@2 77 gl_load_identity();
nuclear@2 78 glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0);
nuclear@2 79 }
nuclear@4 80
nuclear@4 81 static unsigned int get_shader_program(const char *vfile, const char *pfile)
nuclear@4 82 {
nuclear@4 83 unsigned int prog, vs, ps;
nuclear@4 84
nuclear@4 85 if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) {
nuclear@4 86 return -1;
nuclear@4 87 }
nuclear@4 88 if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) {
nuclear@4 89 return -1;
nuclear@4 90 }
nuclear@4 91
nuclear@4 92 if(!(prog = create_program_link(vs, ps))) {
nuclear@4 93 return -1;
nuclear@4 94 }
nuclear@4 95 return prog;
nuclear@4 96 }