istereo
view src/istereo.c @ 12:9890940948f7
fucking reshape wasn't getting called...
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Wed, 07 Sep 2011 08:30:24 +0300 |
parents | 698cbf1a1b97 |
children | fe1cb1c567cc |
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 assert(prog);
88 return prog;
89 }
91 void dbg_draw(void)
92 {
93 static const GLfloat squareVertices[] = {
94 -0.5f, -0.33f,
95 0.5f, -0.33f,
96 -0.5f, 0.33f,
97 0.5f, 0.33f,
98 };
100 static const GLubyte squareColors[] = {
101 255, 255, 0, 255,
102 0, 255, 255, 255,
103 0, 0, 0, 0,
104 255, 0, 255, 255,
105 };
107 int vloc, cloc;
109 glUseProgram(prog);
111 /*gl_apply_xform(prog);*/
114 vloc = 0;/*glGetAttribLocation(prog, "attr_vertex");*/
115 cloc = 1;/*glGetAttribLocation(prog, "attr_color");*/
116 assert(vloc >= 0 && cloc >= 0);
118 glVertexAttribPointer(vloc, 2, GL_FLOAT, 0, 0, squareVertices);
119 glEnableVertexAttribArray(vloc);
120 glVertexAttribPointer(cloc, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
121 glEnableVertexAttribArray(cloc);
123 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
125 glDisableVertexAttribArray(vloc);
126 glDisableVertexAttribArray(cloc);
127 }