dbf-udg

changeset 1:1d5dc834d403

blockify
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 08 Jan 2013 14:19:06 +0200
parents 2d27bfd21fc5
children c45c7a1f7d9d
files src/udg.cc
diffstat 1 files changed, 17 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/src/udg.cc	Tue Jan 08 03:16:48 2013 +0200
     1.2 +++ b/src/udg.cc	Tue Jan 08 14:19:06 2013 +0200
     1.3 @@ -16,6 +16,14 @@
     1.4  #define DITHER_SZ		4
     1.5  #define DITHER_LEVELS	16
     1.6  
     1.7 +#if DITHER_SZ == 4
     1.8 +#define dither_matrix	dither_matrix4
     1.9 +#elif DITHER_SZ == 8
    1.10 +#define dither_matrix	dither_matrix8
    1.11 +#else
    1.12 +#error "invalid dither size"
    1.13 +#endif
    1.14 +
    1.15  struct render_target {
    1.16  	unsigned int fbo;
    1.17  	unsigned int color_tex, depth_buf;
    1.18 @@ -41,7 +49,7 @@
    1.19  int main(int argc, char **argv)
    1.20  {
    1.21  	glutInit(&argc, argv);
    1.22 -	glutInitWindowSize(800, 600);
    1.23 +	glutInitWindowSize(1024, 768);
    1.24  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.25  	glutCreateWindow("DBF UDG compo entry by Nuclear");
    1.26  
    1.27 @@ -72,7 +80,7 @@
    1.28  		for(int y=0; y<DITHER_SZ; y++) {
    1.29  			for(int x=0; x<DITHER_SZ; x++) {
    1.30  				/* (1 + M) / (1 + MxN) */
    1.31 -				float thres = (1.0 + dither_matrix4[x][y]) / (1.0 + DITHER_SZ * DITHER_SZ);
    1.32 +				float thres = (1.0 + dither_matrix[x][y]) / (1.0 + DITHER_SZ * DITHER_SZ);
    1.33  				*ptr++ = val >= thres ? 1.0 : 0.0;
    1.34  			}
    1.35  		}
    1.36 @@ -132,13 +140,14 @@
    1.37  	float ldir[] = {-1, 1, 2, 0};
    1.38  
    1.39  	if(!rtarg) {
    1.40 -		printf("(re)creating render target (%dx%d)\n", xsz, ysz);
    1.41 -		if(!(rtarg = create_rtarg(xsz, ysz))) {
    1.42 +		printf("(re)creating render target (%dx%d)\n", xsz / DITHER_SZ, ysz / DITHER_SZ);
    1.43 +		if(!(rtarg = create_rtarg(xsz / DITHER_SZ, ysz / DITHER_SZ))) {
    1.44  			exit(0);
    1.45  		}
    1.46  	}
    1.47  
    1.48  	glBindFramebufferEXT(GL_FRAMEBUFFER, rtarg->fbo);
    1.49 +	glViewport(0, 0, xsz / DITHER_SZ, ysz / DITHER_SZ);
    1.50  
    1.51  	glClearColor(1, 1, 1, 1);
    1.52  	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.53 @@ -163,6 +172,8 @@
    1.54  
    1.55  
    1.56  	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
    1.57 +	glViewport(0, 0, xsz, ysz);
    1.58 +
    1.59  	glClear(GL_COLOR_BUFFER_BIT);
    1.60  
    1.61  	glMatrixMode(GL_PROJECTION);
    1.62 @@ -292,8 +303,8 @@
    1.63  	glBindTexture(GL_TEXTURE_2D, rt->color_tex);
    1.64  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    1.65  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    1.66 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    1.67 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.68 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    1.69 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    1.70  	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
    1.71  
    1.72  	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color_tex, 0);