# HG changeset patch # User John Tsiombikas # Date 1339623111 -10800 # Node ID b2a2a355b633dbb0c34b113042d136124f756f17 created a repo for stereoimg diff -r 000000000000 -r b2a2a355b633 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu Jun 14 00:31:51 2012 +0300 @@ -0,0 +1,34 @@ +PREFIX = /usr/local + +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = stereoimg + +CC = gcc +CFLAGS = -pedantic -Wall -g +LDFLAGS = $(libgl) -limago + +ifeq ($(shell uname -s), Darwin) + libgl = -framework OpenGL -framework GLUT +else + libgl = -lGL -lglut +endif + + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + + +.PHONY: install +install: + mkdir -p $(PREFIX)/bin + cp $(bin) $(PREFIX)/bin/$(bin) + +.PHONY: uninstall +uninstall: + rm -f $(PREFIX)/bin/$(bin) diff -r 000000000000 -r b2a2a355b633 src/stereoimg.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/stereoimg.c Thu Jun 14 00:31:51 2012 +0300 @@ -0,0 +1,203 @@ +/* +Stereoimg - an OpenGL stereoscopic image viewer. +Copyright (C) 2011 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include + +#ifndef __APPLE__ +#include +#else +#include +#endif + +#include + +struct imgnode { + char *name; + int width, height; + unsigned int tex; + int swap; + + struct imgnode *next; +}; + +void show_image(struct imgnode *node); +void disp(void); +void reshape(int x, int y); +void keyb(unsigned char key, int x, int y); +int parse_args(int argc, char **argv); + + +struct imgnode *imglist; +int swap_eyes; + + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);// | GLUT_STEREO); + glutInitWindowSize(128, 128); + glutCreateWindow("stereo image viewer"); + + if(parse_args(argc, argv) == -1) { + return 1; + } + + glutDisplayFunc(disp); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyb); + glutIdleFunc(glutPostRedisplay); + + glEnable(GL_TEXTURE_2D); + show_image(imglist); + + glutMainLoop(); + return 0; +} + + +void show_image(struct imgnode *node) +{ + glutReshapeWindow(node->width / 2, node->height); + glutSetWindowTitle(node->name); + + glBindTexture(GL_TEXTURE_2D, node->tex); + + swap_eyes = node->swap; +} + +void disp(void) +{ + glDrawBuffer(swap_eyes ? GL_BACK_RIGHT : GL_BACK_LEFT); + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex2f(-1, -1); + glTexCoord2f(0.5, 1); glVertex2f(1, -1); + glTexCoord2f(0.5, 0); glVertex2f(1, 1); + glTexCoord2f(0, 0); glVertex2f(-1, 1); + glEnd(); + + glDrawBuffer(swap_eyes ? GL_BACK_LEFT : GL_BACK_RIGHT); + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glTexCoord2f(0.5, 1); glVertex2f(-1, -1); + glTexCoord2f(1, 1); glVertex2f(1, -1); + glTexCoord2f(1, 0); glVertex2f(1, 1); + glTexCoord2f(0.5, 0); glVertex2f(-1, 1); + glEnd(); + + glutSwapBuffers(); + assert(glGetError() == GL_NO_ERROR); +} + +void reshape(int x, int y) +{ + glViewport(0, 0, x, y); +} + +void keyb(unsigned char key, int x, int y) +{ + switch(key) { + case 's': + swap_eyes = !swap_eyes; + glutPostRedisplay(); + break; + + case ' ': + imglist = imglist->next; + show_image(imglist); + glutPostRedisplay(); + break; + + case 27: + case 'q': + exit(0); + + default: + break; + } +} + +int parse_args(int argc, char **argv) +{ + int i, cur_swap = 0; + struct imgnode *node; + struct imgnode *head = 0, *tail = 0; + + for(i=1; iname = argv[i]; + node->width = xsz; + node->height = ysz; + node->tex = tex; + node->swap = cur_swap; + node->next = 0; + + if(head) { + tail->next = node; + tail = node; + } else { + head = tail = node; + } + } + } + + if(!head) { + fprintf(stderr, "you must specify one or more images to open\n"); + return -1; + } + tail->next = head; + imglist = head; + return 0; +}