# HG changeset patch # User John Tsiombikas # Date 1422613516 -7200 # Node ID dca518e371cf8f3d8504147cbe30bc18f3f256fa initial commit diff -r 000000000000 -r dca518e371cf .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,7 @@ +\.o$ +\.swp$ +\.d$ +^vrfileman$ +\.suo$ +^Debug/ +^Release/ diff -r 000000000000 -r dca518e371cf Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,27 @@ +src = $(wildcard src/*.cc) +obj = $(src:.cc=.o) +dep = $(obj:.o=.d) +bin = vrfileman + +warn = -pedantic -Wall +dbg = -g + +CXXFLAGS = $(warn) $(opt) $(dbg) $(inc) +LDFLAGS = $(libgl) + + +# system-specific stuff +ifeq ($(shell uname -s), Darwin) + libgl = -framework OpenGL -framework GLUT -lGLEW +else + libgl = -lGL -lGLU -lglut -lGLEW +endif + + +$(bin): $(obj) + $(CXX) -o $@ $(obj) $(LDFLAGS) + +-include $(dep) + +%.d: %.cc + @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@ diff -r 000000000000 -r dca518e371cf src/app.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app.cc Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,51 @@ +#include +#include "opengl.h" +#include "app.h" + +bool app_init() +{ + if(!init_opengl()) { + return false; + } + return true; +} + +void app_shutdown() +{ +} + +void app_display() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + + swap_buffers(); + assert(glGetError() == GL_NO_ERROR); +} + +void app_reshape(int x, int y) +{ + glViewport(0, 0, x, y); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0); +} + +void app_keyboard(int key, bool pressed, int x, int y) +{ + if(pressed) { + switch(key) { + case 27: + quit(); + } + } +} + +void app_mouse_button(int bn, bool pressed, int x, int y) +{ +} + +void app_mouse_motion(int x, int y) +{ +} diff -r 000000000000 -r dca518e371cf src/app.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app.h Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,27 @@ +#ifndef APP_H_ +#define APP_H_ + +bool app_init(); +void app_shutdown(); + +void app_display(); +void app_reshape(int x, int y); +void app_keyboard(int key, bool pressed, int x, int y); +void app_mouse_button(int bn, bool pressed, int x, int y); +void app_mouse_motion(int x, int y); + +/* provided by the frontend */ +enum { + MOD_SHIFT = 1, + MOD_ALT = 2, + MOD_CTRL = 4 +}; + +void swap_buffers(); +void redisplay(); +void quit(); +void get_window_size(int *xsz, int *ysz); + +unsigned int get_modifiers(); + +#endif // APP_H_ diff -r 000000000000 -r dca518e371cf src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cc Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,106 @@ +#include +#include "opengl.h" + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#include "app.h" + +static void display(); +static void reshape(int x, int y); +static void key_down(unsigned char key, int x, int y); +static void key_up(unsigned char key, int x, int y); +static void mouse(int bn, int state, int x, int y); +static void motion(int x, int y); + +static int win_width, win_height; +static unsigned int mod; + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + glutInitWindowSize(1280, 720); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + glutCreateWindow("VR file manager"); + + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(key_down); + glutKeyboardUpFunc(key_up); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutPassiveMotionFunc(motion); + + if(app_init() == -1) { + return 1; + } + + glutMainLoop(); + return 0; +} + +void swap_buffers() +{ + glutSwapBuffers(); +} + +void redisplay() +{ + glutPostRedisplay(); +} + +void quit() +{ + app_shutdown(); + exit(0); +} + +void get_window_size(int *xsz, int *ysz) +{ + *xsz = win_width; + *ysz = win_height; +} + +unsigned int get_modifiers() +{ + return mod; +} + +static void display() +{ + app_display(); +} + +static void reshape(int x, int y) +{ + win_width = x; + win_height = y; + app_reshape(x, y); +} + +static void key_down(unsigned char key, int x, int y) +{ + mod = glutGetModifiers(); + app_keyboard(key, true, x, y); +} + +static void key_up(unsigned char key, int x, int y) +{ + mod = glutGetModifiers(); + app_keyboard(key, false, x, y); +} + +static void mouse(int bn, int state, int x, int y) +{ + mod = glutGetModifiers(); + app_mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y); +} + +static void motion(int x, int y) +{ + app_mouse_motion(x, y); +} diff -r 000000000000 -r dca518e371cf src/opengl.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opengl.cc Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,7 @@ +#include "opengl.h" + +bool init_opengl() +{ + glewInit(); + return true; +} diff -r 000000000000 -r dca518e371cf src/opengl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opengl.h Fri Jan 30 12:25:16 2015 +0200 @@ -0,0 +1,8 @@ +#ifndef OPENGL_H_ +#define OPENGL_H_ + +#include + +bool init_opengl(); + +#endif // OPENGL_H_