istereo

changeset 9:22dc37e3ca05

what the fucking fuck
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 07 Sep 2011 08:16:06 +0300
parents aa70df4bb0e5
children f72f96c93972
files src/istereo.c
diffstat 1 files changed, 24 insertions(+), 38 deletions(-) [+]
line diff
     1.1 --- a/src/istereo.c	Wed Sep 07 07:58:53 2011 +0300
     1.2 +++ b/src/istereo.c	Wed Sep 07 08:16:06 2011 +0300
     1.3 @@ -7,25 +7,11 @@
     1.4  #include "sdr.h"
     1.5  #include "respath.h"
     1.6  
     1.7 -float varr[] = {
     1.8 -	-2, 1.5, 0,
     1.9 -	2, 1.5, 0,
    1.10 -	0, 4, 0
    1.11 -};
    1.12 -
    1.13 -float carr[] = {
    1.14 -	1, 0, 0,
    1.15 -	0, 1, 0,
    1.16 -	0, 0, 1
    1.17 -};
    1.18 -
    1.19  void dbg_draw(void);
    1.20  static unsigned int get_shader_program(const char *vfile, const char *pfile);
    1.21  
    1.22  unsigned int prog;
    1.23  
    1.24 -unsigned int vbo, cbo;
    1.25 -
    1.26  int init(void)
    1.27  {
    1.28  	add_resource_path("sdr");
    1.29 @@ -34,17 +20,6 @@
    1.30  		fprintf(stderr, "failed to load shader program\n");
    1.31  		return -1;
    1.32  	}
    1.33 -
    1.34 -	glGenBuffers(1, &vbo);
    1.35 -	glBindBuffer(GL_ARRAY_BUFFER, vbo);
    1.36 -	glBufferData(GL_ARRAY_BUFFER, sizeof varr, varr, GL_STATIC_DRAW);
    1.37 -
    1.38 -	glGenBuffers(1, &cbo);
    1.39 -	glBindBuffer(GL_ARRAY_BUFFER, cbo);
    1.40 -	glBufferData(GL_ARRAY_BUFFER, sizeof carr, carr, GL_STATIC_DRAW);
    1.41 -
    1.42 -	glBindBuffer(GL_ARRAY_BUFFER, 0);
    1.43 -
    1.44  	return 0;
    1.45  }
    1.46  
    1.47 @@ -66,7 +41,7 @@
    1.48  
    1.49  	dbg_draw();
    1.50  
    1.51 -	gl_begin(GL_QUADS);
    1.52 +	/*gl_begin(GL_QUADS);
    1.53  	gl_color3f(1, 0, 0);
    1.54  	gl_vertex3f(-1, -1, 0);
    1.55  	gl_color3f(0, 1, 0);
    1.56 @@ -75,7 +50,7 @@
    1.57  	gl_vertex3f(1, 1, 0);
    1.58  	gl_color3f(1, 1, 0);
    1.59  	gl_vertex3f(-1, 1, 0);
    1.60 -	gl_end();
    1.61 +	gl_end();*/
    1.62  
    1.63  	assert(glGetError() == GL_NO_ERROR);
    1.64  }
    1.65 @@ -108,25 +83,36 @@
    1.66  
    1.67  void dbg_draw(void)
    1.68  {
    1.69 +	static const GLfloat squareVertices[] = {
    1.70 +        -0.5f, -0.33f,
    1.71 +         0.5f, -0.33f,
    1.72 +        -0.5f,  0.33f,
    1.73 +         0.5f,  0.33f,
    1.74 +    };
    1.75 +
    1.76 +    static const GLubyte squareColors[] = {
    1.77 +        255, 255,   0, 255,
    1.78 +        0,   255, 255, 255,
    1.79 +        0,     0,   0,   0,
    1.80 +        255,   0, 255, 255,
    1.81 +    };
    1.82 +
    1.83  	int vloc, cloc;
    1.84  
    1.85 +    glUseProgram(prog);
    1.86 +
    1.87  	gl_apply_xform(prog);
    1.88  
    1.89  	vloc = glGetAttribLocation(prog, "attr_vertex");
    1.90  	cloc = glGetAttribLocation(prog, "attr_color");
    1.91 -	assert(vloc != -1 && cloc != -1);
    1.92 +	assert(vloc >= 0 && cloc >= 0);
    1.93  
    1.94 -	glBindBuffer(GL_ARRAY_BUFFER, vbo);
    1.95 -	glVertexAttribPointer(vloc, 3, GL_FLOAT, 0, 0, 0);
    1.96 -	glEnableVertexAttribArray(vloc);
    1.97 +    glVertexAttribPointer(vloc, 2, GL_FLOAT, 0, 0, squareVertices);
    1.98 +    glEnableVertexAttribArray(vloc);
    1.99 +    glVertexAttribPointer(cloc, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
   1.100 +    glEnableVertexAttribArray(cloc);
   1.101  
   1.102 -	glBindBuffer(GL_ARRAY_BUFFER, cbo);
   1.103 -	glVertexAttribPointer(cloc, 3, GL_FLOAT, 0, 0, 0);
   1.104 -	glEnableVertexAttribArray(cloc);
   1.105 -
   1.106 -	glBindBuffer(GL_ARRAY_BUFFER, 0);
   1.107 -
   1.108 -	glDrawArrays(GL_TRIANGLES, 0, 3);
   1.109 +    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.110  
   1.111  	glDisableVertexAttribArray(vloc);
   1.112  	glDisableVertexAttribArray(cloc);