vrfileman

changeset 0:dca518e371cf

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 Jan 2015 12:25:16 +0200
parents
children 9e3d77dad51b
files .hgignore Makefile src/app.cc src/app.h src/main.cc src/opengl.cc src/opengl.h
diffstat 7 files changed, 233 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Fri Jan 30 12:25:16 2015 +0200
     1.3 @@ -0,0 +1,7 @@
     1.4 +\.o$
     1.5 +\.swp$
     1.6 +\.d$
     1.7 +^vrfileman$
     1.8 +\.suo$
     1.9 +^Debug/
    1.10 +^Release/
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Fri Jan 30 12:25:16 2015 +0200
     2.3 @@ -0,0 +1,27 @@
     2.4 +src = $(wildcard src/*.cc)
     2.5 +obj = $(src:.cc=.o)
     2.6 +dep = $(obj:.o=.d)
     2.7 +bin = vrfileman
     2.8 +
     2.9 +warn = -pedantic -Wall
    2.10 +dbg = -g
    2.11 +
    2.12 +CXXFLAGS = $(warn) $(opt) $(dbg) $(inc)
    2.13 +LDFLAGS = $(libgl)
    2.14 +
    2.15 +
    2.16 +# system-specific stuff
    2.17 +ifeq ($(shell uname -s), Darwin)
    2.18 +	libgl = -framework OpenGL -framework GLUT -lGLEW
    2.19 +else
    2.20 +	libgl = -lGL -lGLU -lglut -lGLEW
    2.21 +endif
    2.22 +
    2.23 +
    2.24 +$(bin): $(obj)
    2.25 +	$(CXX) -o $@ $(obj) $(LDFLAGS)
    2.26 +
    2.27 +-include $(dep)
    2.28 +
    2.29 +%.d: %.cc
    2.30 +	@$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/app.cc	Fri Jan 30 12:25:16 2015 +0200
     3.3 @@ -0,0 +1,51 @@
     3.4 +#include <assert.h>
     3.5 +#include "opengl.h"
     3.6 +#include "app.h"
     3.7 +
     3.8 +bool app_init()
     3.9 +{
    3.10 +	if(!init_opengl()) {
    3.11 +		return false;
    3.12 +	}
    3.13 +	return true;
    3.14 +}
    3.15 +
    3.16 +void app_shutdown()
    3.17 +{
    3.18 +}
    3.19 +
    3.20 +void app_display()
    3.21 +{
    3.22 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    3.23 +
    3.24 +
    3.25 +	swap_buffers();
    3.26 +	assert(glGetError() == GL_NO_ERROR);
    3.27 +}
    3.28 +
    3.29 +void app_reshape(int x, int y)
    3.30 +{
    3.31 +	glViewport(0, 0, x, y);
    3.32 +
    3.33 +	glMatrixMode(GL_PROJECTION);
    3.34 +	glLoadIdentity();
    3.35 +	gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
    3.36 +}
    3.37 +
    3.38 +void app_keyboard(int key, bool pressed, int x, int y)
    3.39 +{
    3.40 +	if(pressed) {
    3.41 +		switch(key) {
    3.42 +		case 27:
    3.43 +			quit();
    3.44 +		}
    3.45 +	}
    3.46 +}
    3.47 +
    3.48 +void app_mouse_button(int bn, bool pressed, int x, int y)
    3.49 +{
    3.50 +}
    3.51 +
    3.52 +void app_mouse_motion(int x, int y)
    3.53 +{
    3.54 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/app.h	Fri Jan 30 12:25:16 2015 +0200
     4.3 @@ -0,0 +1,27 @@
     4.4 +#ifndef APP_H_
     4.5 +#define APP_H_
     4.6 +
     4.7 +bool app_init();
     4.8 +void app_shutdown();
     4.9 +
    4.10 +void app_display();
    4.11 +void app_reshape(int x, int y);
    4.12 +void app_keyboard(int key, bool pressed, int x, int y);
    4.13 +void app_mouse_button(int bn, bool pressed, int x, int y);
    4.14 +void app_mouse_motion(int x, int y);
    4.15 +
    4.16 +/* provided by the frontend */
    4.17 +enum {
    4.18 +	MOD_SHIFT	= 1,
    4.19 +	MOD_ALT		= 2,
    4.20 +	MOD_CTRL	= 4
    4.21 +};
    4.22 +
    4.23 +void swap_buffers();
    4.24 +void redisplay();
    4.25 +void quit();
    4.26 +void get_window_size(int *xsz, int *ysz);
    4.27 +
    4.28 +unsigned int get_modifiers();
    4.29 +
    4.30 +#endif	// APP_H_
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/main.cc	Fri Jan 30 12:25:16 2015 +0200
     5.3 @@ -0,0 +1,106 @@
     5.4 +#include <stdlib.h>
     5.5 +#include "opengl.h"
     5.6 +
     5.7 +#ifdef __APPLE__
     5.8 +#include <GLUT/glut.h>
     5.9 +#else
    5.10 +#include <GL/glut.h>
    5.11 +#endif
    5.12 +
    5.13 +#include "app.h"
    5.14 +
    5.15 +static void display();
    5.16 +static void reshape(int x, int y);
    5.17 +static void key_down(unsigned char key, int x, int y);
    5.18 +static void key_up(unsigned char key, int x, int y);
    5.19 +static void mouse(int bn, int state, int x, int y);
    5.20 +static void motion(int x, int y);
    5.21 +
    5.22 +static int win_width, win_height;
    5.23 +static unsigned int mod;
    5.24 +
    5.25 +int main(int argc, char **argv)
    5.26 +{
    5.27 +	glutInit(&argc, argv);
    5.28 +
    5.29 +	glutInitWindowSize(1280, 720);
    5.30 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    5.31 +	glutCreateWindow("VR file manager");
    5.32 +
    5.33 +	glutDisplayFunc(display);
    5.34 +	glutReshapeFunc(reshape);
    5.35 +	glutKeyboardFunc(key_down);
    5.36 +	glutKeyboardUpFunc(key_up);
    5.37 +	glutMouseFunc(mouse);
    5.38 +	glutMotionFunc(motion);
    5.39 +	glutPassiveMotionFunc(motion);
    5.40 +
    5.41 +	if(app_init() == -1) {
    5.42 +		return 1;
    5.43 +	}
    5.44 +
    5.45 +	glutMainLoop();
    5.46 +	return 0;
    5.47 +}
    5.48 +
    5.49 +void swap_buffers()
    5.50 +{
    5.51 +	glutSwapBuffers();
    5.52 +}
    5.53 +
    5.54 +void redisplay()
    5.55 +{
    5.56 +	glutPostRedisplay();
    5.57 +}
    5.58 +
    5.59 +void quit()
    5.60 +{
    5.61 +	app_shutdown();
    5.62 +	exit(0);
    5.63 +}
    5.64 +
    5.65 +void get_window_size(int *xsz, int *ysz)
    5.66 +{
    5.67 +	*xsz = win_width;
    5.68 +	*ysz = win_height;
    5.69 +}
    5.70 +
    5.71 +unsigned int get_modifiers()
    5.72 +{
    5.73 +	return mod;
    5.74 +}
    5.75 +
    5.76 +static void display()
    5.77 +{
    5.78 +	app_display();
    5.79 +}
    5.80 +
    5.81 +static void reshape(int x, int y)
    5.82 +{
    5.83 +	win_width = x;
    5.84 +	win_height = y;
    5.85 +	app_reshape(x, y);
    5.86 +}
    5.87 +
    5.88 +static void key_down(unsigned char key, int x, int y)
    5.89 +{
    5.90 +	mod = glutGetModifiers();
    5.91 +	app_keyboard(key, true, x, y);
    5.92 +}
    5.93 +
    5.94 +static void key_up(unsigned char key, int x, int y)
    5.95 +{
    5.96 +	mod = glutGetModifiers();
    5.97 +	app_keyboard(key, false, x, y);
    5.98 +}
    5.99 +
   5.100 +static void mouse(int bn, int state, int x, int y)
   5.101 +{
   5.102 +	mod = glutGetModifiers();
   5.103 +	app_mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
   5.104 +}
   5.105 +
   5.106 +static void motion(int x, int y)
   5.107 +{
   5.108 +	app_mouse_motion(x, y);
   5.109 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/opengl.cc	Fri Jan 30 12:25:16 2015 +0200
     6.3 @@ -0,0 +1,7 @@
     6.4 +#include "opengl.h"
     6.5 +
     6.6 +bool init_opengl()
     6.7 +{
     6.8 +	glewInit();
     6.9 +	return true;
    6.10 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/opengl.h	Fri Jan 30 12:25:16 2015 +0200
     7.3 @@ -0,0 +1,8 @@
     7.4 +#ifndef OPENGL_H_
     7.5 +#define OPENGL_H_
     7.6 +
     7.7 +#include <GL/glew.h>
     7.8 +
     7.9 +bool init_opengl();
    7.10 +
    7.11 +#endif	// OPENGL_H_