# HG changeset patch # User John Tsiombikas # Date 1391132400 -7200 # Node ID 026cdd1737ff717eeac2ab13dff17cda43553c4d # Parent 469ce01809bc5f837fa97ee971cbe496cf813476 added spaceball controls to the example and needless GLEW dependency diff -r 469ce01809bc -r 026cdd1737ff examples/imgthumbs/Makefile --- a/examples/imgthumbs/Makefile Fri Jan 31 03:17:24 2014 +0200 +++ b/examples/imgthumbs/Makefile Fri Jan 31 03:40:00 2014 +0200 @@ -1,3 +1,6 @@ +# change PREFIX to install elsewhere (default: /usr/local) +PREFIX = /usr/local + src = $(wildcard src/*.c) obj = $(src:.c=.o) bin = imgthumbs @@ -6,9 +9,9 @@ LDFLAGS = $(libgl) -limago ifeq ($(shell uname -s), Darwin) - libgl = -framework OpenGL -framework GLUT + libgl = -framework OpenGL -framework GLUT -lGLEW else - libgl = -lGL -lGLU -lglut + libgl = -lGL -lGLU -lglut -lGLEW endif $(bin): $(obj) @@ -17,3 +20,12 @@ .PHONY: clean clean: rm -f $(obj) $(bin) + +.PHONY: install +install: + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp $(bin) $(DESTDIR)$(PREFIX)/bin/$(bin) + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/$(bin) diff -r 469ce01809bc -r 026cdd1737ff examples/imgthumbs/src/main.c --- a/examples/imgthumbs/src/main.c Fri Jan 31 03:17:24 2014 +0200 +++ b/examples/imgthumbs/src/main.c Fri Jan 31 03:40:00 2014 +0200 @@ -13,6 +13,7 @@ static void keyb(unsigned char key, int x, int y); static void mouse(int bn, int st, int x, int y); static void motion(int x, int y); +static void sball_motion(int x, int y, int z); static struct thumbnail *find_thumb(int x, int y); const char *path = "."; @@ -43,6 +44,7 @@ glutKeyboardFunc(keyb); glutMouseFunc(mouse); glutMotionFunc(motion); + glutSpaceballMotionFunc(sball_motion); if(init() == -1) { return 1; @@ -55,6 +57,8 @@ static int init(void) { + glewInit(); + thumbs = create_thumbs(path); return 0; } @@ -211,6 +215,26 @@ } } +static void sball_motion(int x, int y, int z) +{ + float fx = -x * 0.0004; + float fy = z * 0.0004; + float fz = -y * 0.0005; + + if(show_thumb) { + show_pan_x += fx / show_zoom; + show_pan_y += fy / show_zoom; + show_zoom += fz; + if(show_zoom <= 0) show_zoom = 0; + } else { + pan_x += fx; + pan_y += fy; + thumbs_size += fz; + if(thumbs_size <= 0.01) thumbs_size = 0.01; + } + glutPostRedisplay(); +} + static struct thumbnail *find_thumb(int x, int y) { float fx = (float)x / (float)win_width; diff -r 469ce01809bc -r 026cdd1737ff examples/imgthumbs/src/opengl.h --- a/examples/imgthumbs/src/opengl.h Fri Jan 31 03:17:24 2014 +0200 +++ b/examples/imgthumbs/src/opengl.h Fri Jan 31 03:40:00 2014 +0200 @@ -1,6 +1,8 @@ #ifndef OPENGL_H_ #define OPENGL_H_ +#include + #ifdef __APPLE__ #include #else diff -r 469ce01809bc -r 026cdd1737ff examples/imgthumbs/src/thumbs.c --- a/examples/imgthumbs/src/thumbs.c Fri Jan 31 03:17:24 2014 +0200 +++ b/examples/imgthumbs/src/thumbs.c Fri Jan 31 03:40:00 2014 +0200 @@ -13,6 +13,12 @@ struct dirent *dent; struct thumbnail *list = 0; + unsigned int intfmt = GL_COMPRESSED_RGB; + if(!GLEW_ARB_texture_compression) { + printf("warning, no texture compression available.\n"); + intfmt = GL_RGB; + } + if(!(dir = opendir(dirpath))) { fprintf(stderr, "failed to open directory: %s: %s\n", dirpath, strerror(errno)); return 0; @@ -50,7 +56,7 @@ glBindTexture(GL_TEXTURE_2D, node->tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, intfmt, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); img_free_pixels(pixels); node->aspect = (float)xsz / (float)ysz;