libresman

changeset 2:026cdd1737ff

added spaceball controls to the example and needless GLEW dependency
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 31 Jan 2014 03:40:00 +0200
parents 469ce01809bc
children a396d43a62f9
files examples/imgthumbs/Makefile examples/imgthumbs/src/main.c examples/imgthumbs/src/opengl.h examples/imgthumbs/src/thumbs.c
diffstat 4 files changed, 47 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/examples/imgthumbs/Makefile	Fri Jan 31 03:17:24 2014 +0200
     1.2 +++ b/examples/imgthumbs/Makefile	Fri Jan 31 03:40:00 2014 +0200
     1.3 @@ -1,3 +1,6 @@
     1.4 +# change PREFIX to install elsewhere (default: /usr/local)
     1.5 +PREFIX = /usr/local
     1.6 +
     1.7  src = $(wildcard src/*.c)
     1.8  obj = $(src:.c=.o)
     1.9  bin = imgthumbs
    1.10 @@ -6,9 +9,9 @@
    1.11  LDFLAGS = $(libgl) -limago
    1.12  
    1.13  ifeq ($(shell uname -s), Darwin)
    1.14 -	libgl = -framework OpenGL -framework GLUT
    1.15 +	libgl = -framework OpenGL -framework GLUT -lGLEW
    1.16  else
    1.17 -	libgl = -lGL -lGLU -lglut
    1.18 +	libgl = -lGL -lGLU -lglut -lGLEW
    1.19  endif
    1.20  
    1.21  $(bin): $(obj)
    1.22 @@ -17,3 +20,12 @@
    1.23  .PHONY: clean
    1.24  clean:
    1.25  	rm -f $(obj) $(bin)
    1.26 +
    1.27 +.PHONY: install
    1.28 +install:
    1.29 +	mkdir -p $(DESTDIR)$(PREFIX)/bin
    1.30 +	cp $(bin) $(DESTDIR)$(PREFIX)/bin/$(bin)
    1.31 +
    1.32 +.PHONY: uninstall
    1.33 +uninstall:
    1.34 +	rm -f $(DESTDIR)$(PREFIX)/bin/$(bin)
     2.1 --- a/examples/imgthumbs/src/main.c	Fri Jan 31 03:17:24 2014 +0200
     2.2 +++ b/examples/imgthumbs/src/main.c	Fri Jan 31 03:40:00 2014 +0200
     2.3 @@ -13,6 +13,7 @@
     2.4  static void keyb(unsigned char key, int x, int y);
     2.5  static void mouse(int bn, int st, int x, int y);
     2.6  static void motion(int x, int y);
     2.7 +static void sball_motion(int x, int y, int z);
     2.8  static struct thumbnail *find_thumb(int x, int y);
     2.9  
    2.10  const char *path = ".";
    2.11 @@ -43,6 +44,7 @@
    2.12  	glutKeyboardFunc(keyb);
    2.13  	glutMouseFunc(mouse);
    2.14  	glutMotionFunc(motion);
    2.15 +	glutSpaceballMotionFunc(sball_motion);
    2.16  
    2.17  	if(init() == -1) {
    2.18  		return 1;
    2.19 @@ -55,6 +57,8 @@
    2.20  
    2.21  static int init(void)
    2.22  {
    2.23 +	glewInit();
    2.24 +
    2.25  	thumbs = create_thumbs(path);
    2.26  	return 0;
    2.27  }
    2.28 @@ -211,6 +215,26 @@
    2.29  	}
    2.30  }
    2.31  
    2.32 +static void sball_motion(int x, int y, int z)
    2.33 +{
    2.34 +	float fx = -x * 0.0004;
    2.35 +	float fy = z * 0.0004;
    2.36 +	float fz = -y * 0.0005;
    2.37 +
    2.38 +	if(show_thumb) {
    2.39 +		show_pan_x += fx / show_zoom;
    2.40 +		show_pan_y += fy / show_zoom;
    2.41 +		show_zoom += fz;
    2.42 +		if(show_zoom <= 0) show_zoom = 0;
    2.43 +	} else {
    2.44 +		pan_x += fx;
    2.45 +		pan_y += fy;
    2.46 +		thumbs_size += fz;
    2.47 +		if(thumbs_size <= 0.01) thumbs_size = 0.01;
    2.48 +	}
    2.49 +	glutPostRedisplay();
    2.50 +}
    2.51 +
    2.52  static struct thumbnail *find_thumb(int x, int y)
    2.53  {
    2.54  	float fx = (float)x / (float)win_width;
     3.1 --- a/examples/imgthumbs/src/opengl.h	Fri Jan 31 03:17:24 2014 +0200
     3.2 +++ b/examples/imgthumbs/src/opengl.h	Fri Jan 31 03:40:00 2014 +0200
     3.3 @@ -1,6 +1,8 @@
     3.4  #ifndef OPENGL_H_
     3.5  #define OPENGL_H_
     3.6  
     3.7 +#include <GL/glew.h>
     3.8 +
     3.9  #ifdef __APPLE__
    3.10  #include <GLUT/glut.h>
    3.11  #else
     4.1 --- a/examples/imgthumbs/src/thumbs.c	Fri Jan 31 03:17:24 2014 +0200
     4.2 +++ b/examples/imgthumbs/src/thumbs.c	Fri Jan 31 03:40:00 2014 +0200
     4.3 @@ -13,6 +13,12 @@
     4.4  	struct dirent *dent;
     4.5  	struct thumbnail *list = 0;
     4.6  
     4.7 +	unsigned int intfmt = GL_COMPRESSED_RGB;
     4.8 +	if(!GLEW_ARB_texture_compression) {
     4.9 +		printf("warning, no texture compression available.\n");
    4.10 +		intfmt = GL_RGB;
    4.11 +	}
    4.12 +
    4.13  	if(!(dir = opendir(dirpath))) {
    4.14  		fprintf(stderr, "failed to open directory: %s: %s\n", dirpath, strerror(errno));
    4.15  		return 0;
    4.16 @@ -50,7 +56,7 @@
    4.17  		glBindTexture(GL_TEXTURE_2D, node->tex);
    4.18  		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    4.19  		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    4.20 -		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    4.21 +		glTexImage2D(GL_TEXTURE_2D, 0, intfmt, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    4.22  		img_free_pixels(pixels);
    4.23  
    4.24  		node->aspect = (float)xsz / (float)ysz;