nuclear@2: #include nuclear@2: #include nuclear@3: #include nuclear@1: #include "opengl.h" nuclear@0: #include "istereo.h" nuclear@2: #include "sanegl.h" nuclear@2: #include "sdr.h" nuclear@4: #include "respath.h" nuclear@14: #include "tex.h" nuclear@4: nuclear@4: static unsigned int get_shader_program(const char *vfile, const char *pfile); nuclear@2: nuclear@2: unsigned int prog; nuclear@14: unsigned int tex; nuclear@0: nuclear@0: int init(void) nuclear@0: { nuclear@4: add_resource_path("sdr"); nuclear@14: add_resource_path("data"); nuclear@3: nuclear@4: if(!(prog = get_shader_program("test.v.glsl", "test.p.glsl"))) { nuclear@2: fprintf(stderr, "failed to load shader program\n"); nuclear@2: return -1; nuclear@2: } nuclear@14: nuclear@14: if(!(tex = load_texture(find_resource("tiles.ppm", 0, 0)))) { nuclear@14: fprintf(stderr, "failed to load texture\n"); nuclear@14: return -1; nuclear@14: } nuclear@14: nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void cleanup(void) nuclear@0: { nuclear@2: free_program(prog); nuclear@0: } nuclear@0: nuclear@0: void redraw(void) nuclear@0: { nuclear@5: glClearColor(0.4, 0.6, 1.0, 1.0); nuclear@0: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); nuclear@2: nuclear@2: bind_program(prog); nuclear@2: nuclear@13: gl_matrix_mode(GL_MODELVIEW); nuclear@2: gl_load_identity(); nuclear@13: gl_translatef(0, 0, -8); nuclear@2: nuclear@14: glEnable(GL_TEXTURE_2D); nuclear@14: glBindTexture(GL_TEXTURE_2D, tex); nuclear@6: nuclear@13: gl_begin(GL_QUADS); nuclear@14: gl_texcoord2f(0, 0); nuclear@2: gl_color3f(1, 0, 0); nuclear@2: gl_vertex3f(-1, -1, 0); nuclear@14: gl_texcoord2f(1, 0); nuclear@2: gl_color3f(0, 1, 0); nuclear@2: gl_vertex3f(1, -1, 0); nuclear@14: gl_texcoord2f(1, 1); nuclear@2: gl_color3f(0, 0, 1); nuclear@2: gl_vertex3f(1, 1, 0); nuclear@14: gl_texcoord2f(0, 1); nuclear@2: gl_color3f(1, 1, 0); nuclear@2: gl_vertex3f(-1, 1, 0); nuclear@13: gl_end(); nuclear@2: nuclear@14: glDisable(GL_TEXTURE_2D); nuclear@14: nuclear@2: assert(glGetError() == GL_NO_ERROR); nuclear@0: } nuclear@2: nuclear@2: void reshape(int x, int y) nuclear@2: { nuclear@2: glViewport(0, 0, x, y); nuclear@2: nuclear@2: gl_matrix_mode(GL_PROJECTION); nuclear@2: gl_load_identity(); nuclear@2: glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0); nuclear@2: } nuclear@4: nuclear@4: static unsigned int get_shader_program(const char *vfile, const char *pfile) nuclear@4: { nuclear@4: unsigned int prog, vs, ps; nuclear@4: nuclear@4: if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) { nuclear@4: return -1; nuclear@4: } nuclear@4: if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) { nuclear@4: return -1; nuclear@4: } nuclear@4: nuclear@4: if(!(prog = create_program_link(vs, ps))) { nuclear@4: return -1; nuclear@4: } nuclear@4: return prog; nuclear@4: }