dbf-udg

changeset 3:403ec1be3a1a

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 11 Jan 2013 22:52:56 +0200
parents c45c7a1f7d9d
children 5fb21401b7c8
files data/foo.png data/hieroglyph.png data/hieroglyph2.png sdr/dither.p.glsl src/dither_matrix.h src/opengl.h src/scroller.cc src/scroller.h src/texture.c src/texture.h src/udg.cc
diffstat 11 files changed, 152 insertions(+), 14 deletions(-) [+]
line diff
     1.1 Binary file data/foo.png has changed
     2.1 Binary file data/hieroglyph.png has changed
     3.1 Binary file data/hieroglyph2.png has changed
     4.1 --- a/sdr/dither.p.glsl	Wed Jan 09 02:37:05 2013 +0200
     4.2 +++ b/sdr/dither.p.glsl	Fri Jan 11 22:52:56 2013 +0200
     4.3 @@ -7,8 +7,6 @@
     4.4  
     4.5  	vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy);
     4.6  	float lum = dot(pixel.xyz, vec3(0.2126, 0.7152, 0.0722));
     4.7 -	// gamma correct luminance?
     4.8 -	//lum = pow(lum, 1.0 / 2.2);
     4.9  	float coord_shift = floor(lum * levels) / levels;
    4.10  
    4.11  	vec2 dsz2 = vec2(float(dither_size), float(dither_size));
     5.1 --- a/src/dither_matrix.h	Wed Jan 09 02:37:05 2013 +0200
     5.2 +++ b/src/dither_matrix.h	Fri Jan 11 22:52:56 2013 +0200
     5.3 @@ -23,4 +23,15 @@
     5.4  	{42, 26, 38, 22, 41, 25, 37, 21}
     5.5  };
     5.6  
     5.7 +static const float halftone_matrix8[8][8] = {
     5.8 +	{24, 10, 12, 26, 35, 47, 49, 37},
     5.9 +	{8, 0, 2, 14, 45, 59, 61, 51},
    5.10 +	{22, 6, 4, 16, 43, 57, 63, 53},
    5.11 +	{30, 20, 18, 28, 33, 41, 55, 39},
    5.12 +	{34, 46, 48, 36, 25, 11, 13, 27},
    5.13 +	{44, 58, 60, 50, 9, 1, 3, 15},
    5.14 +	{42, 56, 62, 52, 23, 7, 5, 17},
    5.15 +	{32, 40, 54, 38, 31, 21, 19, 29}
    5.16 +};
    5.17 +
    5.18  #endif	/* DITHER_MATRIX_H_ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/opengl.h	Fri Jan 11 22:52:56 2013 +0200
     6.3 @@ -0,0 +1,12 @@
     6.4 +#ifndef OPENGL_H_
     6.5 +#define OPENGL_H_
     6.6 +
     6.7 +#include <GL/glew.h>
     6.8 +
     6.9 +#ifndef __APPLE__
    6.10 +#include <GL/glut.h>
    6.11 +#else
    6.12 +#include <GLUT/glut.h>
    6.13 +#endif
    6.14 +
    6.15 +#endif	/* OPENGL_H_ */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/scroller.cc	Fri Jan 11 22:52:56 2013 +0200
     7.3 @@ -0,0 +1,62 @@
     7.4 +#include <math.h>
     7.5 +#include "opengl.h"
     7.6 +#include "texture.h"
     7.7 +
     7.8 +unsigned int hiero_tex;
     7.9 +
    7.10 +bool init_scroller()
    7.11 +{
    7.12 +	if(!(hiero_tex = load_texture("data/hieroglyph2.png"))) {
    7.13 +		return false;
    7.14 +	}
    7.15 +
    7.16 +	glBindTexture(GL_TEXTURE_2D, hiero_tex);
    7.17 +	/*glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    7.18 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);*/
    7.19 +
    7.20 +	return true;
    7.21 +}
    7.22 +
    7.23 +void destroy_scroller()
    7.24 +{
    7.25 +	free_texture(hiero_tex);
    7.26 +	hiero_tex = 0;
    7.27 +}
    7.28 +
    7.29 +void draw_scroller(float sec)
    7.30 +{
    7.31 +	glPushAttrib(GL_ENABLE_BIT);
    7.32 +
    7.33 +	glDisable(GL_DEPTH_TEST);
    7.34 +	glDisable(GL_LIGHTING);
    7.35 +	glEnable(GL_TEXTURE_2D);
    7.36 +	glBindTexture(GL_TEXTURE_2D, hiero_tex);
    7.37 +
    7.38 +	glMatrixMode(GL_MODELVIEW);
    7.39 +	glPushMatrix();
    7.40 +	glLoadIdentity();
    7.41 +	glScalef(1.4, 0.4, 1.4);
    7.42 +	glMatrixMode(GL_PROJECTION);
    7.43 +	glPushMatrix();
    7.44 +	glLoadIdentity();
    7.45 +	glMatrixMode(GL_TEXTURE);
    7.46 +	glPushMatrix();
    7.47 +	glLoadIdentity();
    7.48 +
    7.49 +	glTranslatef(sec * 0.25, 0, 0);
    7.50 +
    7.51 +	glBegin(GL_QUADS);
    7.52 +	glColor3f(1, 1, 1);
    7.53 +	glTexCoord2f(0, 1); glVertex2f(-1, -1);
    7.54 +	glTexCoord2f(1, 1); glVertex2f(1, -1);
    7.55 +	glTexCoord2f(1, 0); glVertex2f(1, 1);
    7.56 +	glTexCoord2f(0, 0); glVertex2f(-1, 1);
    7.57 +	glEnd();
    7.58 +
    7.59 +	glPopMatrix();
    7.60 +	glMatrixMode(GL_PROJECTION);
    7.61 +	glPopMatrix();
    7.62 +	glMatrixMode(GL_MODELVIEW);
    7.63 +	glPopMatrix();
    7.64 +	glPopAttrib();
    7.65 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/scroller.h	Fri Jan 11 22:52:56 2013 +0200
     8.3 @@ -0,0 +1,9 @@
     8.4 +#ifndef SCROLLER_H_
     8.5 +#define SCROLLER_H_
     8.6 +
     8.7 +bool init_scroller();
     8.8 +void destroy_scroller();
     8.9 +
    8.10 +void draw_scroller(float sec);
    8.11 +
    8.12 +#endif	// SCROLLER_H_
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/texture.c	Fri Jan 11 22:52:56 2013 +0200
     9.3 @@ -0,0 +1,31 @@
     9.4 +#include <stdio.h>
     9.5 +#include "opengl.h"
     9.6 +#include <imago2.h>
     9.7 +#include "texture.h"
     9.8 +
     9.9 +unsigned int load_texture(const char *fname)
    9.10 +{
    9.11 +	int xsz, ysz;
    9.12 +	void *pixels;
    9.13 +	unsigned int tex;
    9.14 +
    9.15 +	if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) {
    9.16 +		fprintf(stderr, "failed to load texture: %s\n", fname);
    9.17 +		return 0;
    9.18 +	}
    9.19 +
    9.20 +	glGenTextures(1, &tex);
    9.21 +	glBindTexture(GL_TEXTURE_2D, tex);
    9.22 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    9.23 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    9.24 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    9.25 +
    9.26 +	img_free_pixels(pixels);
    9.27 +
    9.28 +	return tex;
    9.29 +}
    9.30 +
    9.31 +void free_texture(unsigned int tex)
    9.32 +{
    9.33 +	glDeleteTextures(1, &tex);
    9.34 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/texture.h	Fri Jan 11 22:52:56 2013 +0200
    10.3 @@ -0,0 +1,15 @@
    10.4 +#ifndef TEXTURE_H_
    10.5 +#define TEXTURE_H_
    10.6 +
    10.7 +#ifdef __cplusplus
    10.8 +extern "C" {
    10.9 +#endif
   10.10 +
   10.11 +unsigned int load_texture(const char *fname);
   10.12 +void free_texture(unsigned int tex);
   10.13 +
   10.14 +#ifdef __cplusplus
   10.15 +}
   10.16 +#endif
   10.17 +
   10.18 +#endif	/* TEXTURE_H_ */
    11.1 --- a/src/udg.cc	Wed Jan 09 02:37:05 2013 +0200
    11.2 +++ b/src/udg.cc	Fri Jan 11 22:52:56 2013 +0200
    11.3 @@ -2,16 +2,10 @@
    11.4  #include <stdlib.h>
    11.5  #include <math.h>
    11.6  #include <assert.h>
    11.7 -#include <GL/glew.h>
    11.8 -
    11.9 -#ifndef __APPLE__
   11.10 -#include <GL/glut.h>
   11.11 -#else
   11.12 -#include <GLUT/glut.h>
   11.13 -#endif
   11.14 -
   11.15 +#include "opengl.h"
   11.16  #include "sdr.h"
   11.17  #include "dither_matrix.h"
   11.18 +#include "scroller.h"
   11.19  
   11.20  #define DITHER_SZ		8
   11.21  #define DITHER_LEVELS	16
   11.22 @@ -19,7 +13,7 @@
   11.23  #if DITHER_SZ == 4
   11.24  #define dither_matrix	dither_matrix4
   11.25  #elif DITHER_SZ == 8
   11.26 -#define dither_matrix	dither_matrix8
   11.27 +#define dither_matrix	halftone_matrix8
   11.28  #else
   11.29  #error "invalid dither size"
   11.30  #endif
   11.31 @@ -98,6 +92,10 @@
   11.32  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   11.33  	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, DITHER_SZ, DITHER_SZ * DITHER_LEVELS, 0, GL_LUMINANCE, GL_FLOAT, img);
   11.34  
   11.35 +	if(!init_scroller()) {
   11.36 +		return false;
   11.37 +	}
   11.38 +
   11.39  	glEnable(GL_CULL_FACE);
   11.40  	glEnable(GL_DEPTH_TEST);
   11.41  	glEnable(GL_LIGHTING);
   11.42 @@ -108,6 +106,7 @@
   11.43  
   11.44  void draw_backdrop()
   11.45  {
   11.46 +	/*
   11.47  	glPushAttrib(GL_ENABLE_BIT);
   11.48  	glDisable(GL_DEPTH_TEST);
   11.49  	glDisable(GL_LIGHTING);
   11.50 @@ -133,6 +132,8 @@
   11.51  	glPopMatrix();
   11.52  
   11.53  	glPopAttrib();
   11.54 +	*/
   11.55 +	draw_scroller(glutGet(GLUT_ELAPSED_TIME) / 1000.0);
   11.56  }
   11.57  
   11.58  void disp()
   11.59 @@ -154,8 +155,6 @@
   11.60  
   11.61  	draw_backdrop();
   11.62  
   11.63 -	glEnable(GL_DEPTH_TEST);
   11.64 -
   11.65  	glMatrixMode(GL_MODELVIEW);
   11.66  	glLoadIdentity();
   11.67  
   11.68 @@ -176,7 +175,6 @@
   11.69  	glFrontFace(GL_CCW);
   11.70  
   11.71  
   11.72 -
   11.73  	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
   11.74  	glViewport(0, 0, xsz, ysz);
   11.75  
   11.76 @@ -200,8 +198,10 @@
   11.77  
   11.78  	glActiveTextureARB(GL_TEXTURE0);
   11.79  	glBindTexture(GL_TEXTURE_2D, rtarg->color_tex);
   11.80 +	glEnable(GL_TEXTURE_2D);
   11.81  	glActiveTextureARB(GL_TEXTURE1);
   11.82  	glBindTexture(GL_TEXTURE_2D, dither_tex);
   11.83 +	glEnable(GL_TEXTURE_2D);
   11.84  
   11.85  	glBegin(GL_QUADS);
   11.86  	glColor3f(0, 1, 0);