nuclear@2: #include nuclear@18: #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@18: #include "config.h" nuclear@4: nuclear@4: static unsigned int get_shader_program(const char *vfile, const char *pfile); nuclear@18: static float get_sec(void); nuclear@2: nuclear@2: unsigned int prog; nuclear@14: unsigned int tex; nuclear@0: nuclear@18: int stereo; nuclear@18: nuclear@18: /* construction parameters */ nuclear@18: int sides = 24; nuclear@18: int segm = 20; nuclear@18: float ring_height = 0.5; nuclear@18: nuclear@18: 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@18: float t = get_sec(); nuclear@18: 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@18: gl_rotatef(t * 100.0, 0, 0, 1); nuclear@2: nuclear@16: bind_texture(tex, 0); nuclear@17: set_uniform_int(prog, "tex", 0); 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@16: bind_texture(0, 0); 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: } nuclear@18: nuclear@18: nuclear@18: #ifdef IPHONE nuclear@18: #include nuclear@18: nuclear@18: static float get_sec(void) nuclear@18: { nuclear@18: static float first; nuclear@18: static int init; nuclear@18: nuclear@18: if(!init) { nuclear@18: init = 1; nuclear@18: first = CACurrentMediaTime(); nuclear@18: return 0.0f; nuclear@18: } nuclear@18: return CACurrentMediaTime() - first; nuclear@18: } nuclear@18: nuclear@18: #else nuclear@18: nuclear@18: static float get_sec(void) nuclear@18: { nuclear@18: return (float)glutGet(GLUT_ELAPSED_TIME) / 1000.0f; nuclear@18: } nuclear@18: #endif