istereo

view src/istereo.c @ 10:f72f96c93972

bah
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 07 Sep 2011 08:22:18 +0300
parents 22dc37e3ca05
children 698cbf1a1b97
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 void dbg_draw(void);
11 static unsigned int get_shader_program(const char *vfile, const char *pfile);
13 unsigned int prog;
15 int init(void)
16 {
17 add_resource_path("sdr");
19 if(!(prog = get_shader_program("test.v.glsl", "test.p.glsl"))) {
20 fprintf(stderr, "failed to load shader program\n");
21 return -1;
22 }
23 return 0;
24 }
26 void cleanup(void)
27 {
28 free_program(prog);
29 }
31 void redraw(void)
32 {
33 glClearColor(0.4, 0.6, 1.0, 1.0);
34 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
36 bind_program(prog);
38 gl_matrix_mode(GL_MODELVIEW);
39 gl_load_identity();
40 gl_translatef(0, 0, -8);
42 dbg_draw();
44 /*gl_begin(GL_QUADS);
45 gl_color3f(1, 0, 0);
46 gl_vertex3f(-1, -1, 0);
47 gl_color3f(0, 1, 0);
48 gl_vertex3f(1, -1, 0);
49 gl_color3f(0, 0, 1);
50 gl_vertex3f(1, 1, 0);
51 gl_color3f(1, 1, 0);
52 gl_vertex3f(-1, 1, 0);
53 gl_end();*/
55 assert(glGetError() == GL_NO_ERROR);
56 }
58 void reshape(int x, int y)
59 {
60 glViewport(0, 0, x, y);
62 gl_matrix_mode(GL_PROJECTION);
63 gl_load_identity();
64 glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0);
65 }
67 static unsigned int get_shader_program(const char *vfile, const char *pfile)
68 {
69 unsigned int prog, vs, ps;
71 if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) {
72 return -1;
73 }
74 if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) {
75 return -1;
76 }
78 if(!(prog = create_program_link(vs, ps))) {
79 return -1;
80 }
82 glBindAttribLocation(prog, 0, "attr_vertex");
83 glBindAttribLocation(prog, 1, "attr_color");
84 glLinkProgram(prog);
86 return prog;
87 }
89 void dbg_draw(void)
90 {
91 static const GLfloat squareVertices[] = {
92 -0.5f, -0.33f,
93 0.5f, -0.33f,
94 -0.5f, 0.33f,
95 0.5f, 0.33f,
96 };
98 static const GLubyte squareColors[] = {
99 255, 255, 0, 255,
100 0, 255, 255, 255,
101 0, 0, 0, 0,
102 255, 0, 255, 255,
103 };
105 int vloc, cloc;
107 glUseProgram(prog);
109 gl_apply_xform(prog);
111 vloc = 0;//glGetAttribLocation(prog, "attr_vertex");
112 cloc = 1;//glGetAttribLocation(prog, "attr_color");
113 assert(vloc >= 0 && cloc >= 0);
115 glVertexAttribPointer(vloc, 2, GL_FLOAT, 0, 0, squareVertices);
116 glEnableVertexAttribArray(vloc);
117 glVertexAttribPointer(cloc, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
118 glEnableVertexAttribArray(cloc);
120 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
122 glDisableVertexAttribArray(vloc);
123 glDisableVertexAttribArray(cloc);
124 }