istereo

diff src/istereo.c @ 14:b39d8607f4bb

added textures
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 07 Sep 2011 09:03:51 +0300
parents fe1cb1c567cc
children 20a9d3db38cb
line diff
     1.1 --- a/src/istereo.c	Wed Sep 07 08:33:55 2011 +0300
     1.2 +++ b/src/istereo.c	Wed Sep 07 09:03:51 2011 +0300
     1.3 @@ -6,20 +6,28 @@
     1.4  #include "sanegl.h"
     1.5  #include "sdr.h"
     1.6  #include "respath.h"
     1.7 +#include "tex.h"
     1.8  
     1.9 -void dbg_draw(void);
    1.10  static unsigned int get_shader_program(const char *vfile, const char *pfile);
    1.11  
    1.12  unsigned int prog;
    1.13 +unsigned int tex;
    1.14  
    1.15  int init(void)
    1.16  {
    1.17  	add_resource_path("sdr");
    1.18 +	add_resource_path("data");
    1.19  
    1.20  	if(!(prog = get_shader_program("test.v.glsl", "test.p.glsl"))) {
    1.21  		fprintf(stderr, "failed to load shader program\n");
    1.22  		return -1;
    1.23  	}
    1.24 +
    1.25 +	if(!(tex = load_texture(find_resource("tiles.ppm", 0, 0)))) {
    1.26 +		fprintf(stderr, "failed to load texture\n");
    1.27 +		return -1;
    1.28 +	}
    1.29 +
    1.30  	return 0;
    1.31  }
    1.32  
    1.33 @@ -39,19 +47,26 @@
    1.34  	gl_load_identity();
    1.35  	gl_translatef(0, 0, -8);
    1.36  
    1.37 -	//dbg_draw();
    1.38 +	glEnable(GL_TEXTURE_2D);
    1.39 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.40  
    1.41  	gl_begin(GL_QUADS);
    1.42 +	gl_texcoord2f(0, 0);
    1.43  	gl_color3f(1, 0, 0);
    1.44  	gl_vertex3f(-1, -1, 0);
    1.45 +	gl_texcoord2f(1, 0);
    1.46  	gl_color3f(0, 1, 0);
    1.47  	gl_vertex3f(1, -1, 0);
    1.48 +	gl_texcoord2f(1, 1);
    1.49  	gl_color3f(0, 0, 1);
    1.50  	gl_vertex3f(1, 1, 0);
    1.51 +	gl_texcoord2f(0, 1);
    1.52  	gl_color3f(1, 1, 0);
    1.53  	gl_vertex3f(-1, 1, 0);
    1.54  	gl_end();
    1.55  
    1.56 +	glDisable(GL_TEXTURE_2D);
    1.57 +
    1.58  	assert(glGetError() == GL_NO_ERROR);
    1.59  }
    1.60  
    1.61 @@ -80,41 +95,3 @@
    1.62  	}
    1.63  	return prog;
    1.64  }
    1.65 -
    1.66 -void dbg_draw(void)
    1.67 -{
    1.68 -	static const GLfloat squareVertices[] = {
    1.69 -        -0.5f, -0.33f,
    1.70 -         0.5f, -0.33f,
    1.71 -        -0.5f,  0.33f,
    1.72 -         0.5f,  0.33f,
    1.73 -    };
    1.74 -
    1.75 -    static const GLubyte squareColors[] = {
    1.76 -        255, 255,   0, 255,
    1.77 -        0,   255, 255, 255,
    1.78 -        0,     0,   0,   0,
    1.79 -        255,   0, 255, 255,
    1.80 -    };
    1.81 -
    1.82 -	int vloc, cloc;
    1.83 -
    1.84 -    glUseProgram(prog);
    1.85 -
    1.86 -	/*gl_apply_xform(prog);*/
    1.87 -
    1.88 -
    1.89 -	vloc = 0;/*glGetAttribLocation(prog, "attr_vertex");*/
    1.90 -	cloc = 1;/*glGetAttribLocation(prog, "attr_color");*/
    1.91 -	assert(vloc >= 0 && cloc >= 0);
    1.92 -
    1.93 -    glVertexAttribPointer(vloc, 2, GL_FLOAT, 0, 0, squareVertices);
    1.94 -    glEnableVertexAttribArray(vloc);
    1.95 -    glVertexAttribPointer(cloc, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
    1.96 -    glEnableVertexAttribArray(cloc);
    1.97 -
    1.98 -    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    1.99 -
   1.100 -	glDisableVertexAttribArray(vloc);
   1.101 -	glDisableVertexAttribArray(cloc);
   1.102 -}