intravenous
changeset 0:2b30f261f641
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 21 Apr 2012 06:56:33 +0300 |
parents | |
children | 3ea290d35984 |
files | .hgignore Makefile src/game.cc src/game.h src/main.cc src/opengl.h |
diffstat | 6 files changed, 194 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.hgignore Sat Apr 21 06:56:33 2012 +0300 1.3 @@ -0,0 +1,5 @@ 1.4 +\.o$ 1.5 +\.swp$ 1.6 +\.d$ 1.7 +^intrav$ 1.8 +^shots/
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/Makefile Sat Apr 21 06:56:33 2012 +0300 2.3 @@ -0,0 +1,32 @@ 2.4 +csrc = $(wildcard src/*.c) 2.5 +ccsrc = $(wildcard src/*.cc) 2.6 +obj = $(csrc:.c=.o) $(ccsrc:.cc=.o) 2.7 +dep = $(obj:.o=.d) 2.8 +bin = intrav 2.9 + 2.10 +CFLAGS = -pedantic -Wall -g -I/usr/local/include $(add_inc) 2.11 +CXXFLAGS = -std=c++0x $(CFLAGS) 2.12 +LDFLAGS = -L/usr/local/lib $(add_lib) $(libgl) $(libal) -lm -lvmath -limago 2.13 + 2.14 +ifeq ($(shell uname -s), Darwin) 2.15 + libgl = -framework OpenGL -framework GLUT -lGLEW 2.16 + add_inc += -I/opt/local/include 2.17 + add_lib += -L/opt/local/lib 2.18 +else 2.19 + libgl = -lGL -lGLU -lglut -lGLEW 2.20 +endif 2.21 + 2.22 +$(bin): $(obj) 2.23 + $(CXX) -o $@ $(obj) $(LDFLAGS) 2.24 + 2.25 +-include $(dep) 2.26 + 2.27 +%.d: %.c 2.28 + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ 2.29 + 2.30 +%.d: %.cc 2.31 + @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@ 2.32 + 2.33 +.PHONY: clean 2.34 +clean: 2.35 + rm -f $(obj) $(bin) $(dep)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/game.cc Sat Apr 21 06:56:33 2012 +0300 3.3 @@ -0,0 +1,56 @@ 3.4 +#include <stdlib.h> 3.5 +#include "opengl.h" 3.6 +#include "game.h" 3.7 + 3.8 +static unsigned long tmsec, start_time = -1; 3.9 + 3.10 +bool game_init() 3.11 +{ 3.12 + glEnable(GL_DEPTH_TEST); 3.13 + glEnable(GL_CULL_FACE); 3.14 + glEnable(GL_LIGHTING); 3.15 + glEnable(GL_LIGHT0); 3.16 + 3.17 + float lpos[] = {-1, 1, 1, 0}; 3.18 + glLightfv(GL_LIGHT0, GL_POSITION, lpos); 3.19 + 3.20 + return true; 3.21 +} 3.22 + 3.23 +void game_shutdown() 3.24 +{ 3.25 + exit(0); 3.26 +} 3.27 + 3.28 +void game_update(unsigned long msec) 3.29 +{ 3.30 + if(start_time == 0) { 3.31 + start_time = msec; 3.32 + } 3.33 + tmsec = msec - start_time; 3.34 +} 3.35 + 3.36 +void game_draw() 3.37 +{ 3.38 + glMatrixMode(GL_MODELVIEW); 3.39 + glLoadIdentity(); 3.40 + glTranslatef(0, 0, -8); 3.41 + glRotatef(20, 1, 0, 0); 3.42 + 3.43 + glFrontFace(GL_CW); 3.44 + glutSolidTeapot(1.0); 3.45 + glFrontFace(GL_CCW); 3.46 +} 3.47 + 3.48 +void game_input_keyb(int key, int state) 3.49 +{ 3.50 + if(state) { 3.51 + switch(key) { 3.52 + case 27: 3.53 + game_shutdown(); 3.54 + 3.55 + default: 3.56 + break; 3.57 + } 3.58 + } 3.59 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/game.h Sat Apr 21 06:56:33 2012 +0300 4.3 @@ -0,0 +1,12 @@ 4.4 +#ifndef GAME_H_ 4.5 +#define GAME_H_ 4.6 + 4.7 +bool game_init(); 4.8 +void game_shutdown(); 4.9 + 4.10 +void game_update(unsigned long msec); 4.11 +void game_draw(); 4.12 + 4.13 +void game_input_keyb(int key, int state); 4.14 + 4.15 +#endif // GAME_H_
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/main.cc Sat Apr 21 06:56:33 2012 +0300 5.3 @@ -0,0 +1,77 @@ 5.4 +#include <stdio.h> 5.5 +#include <assert.h> 5.6 +#include "opengl.h" 5.7 +#include "game.h" 5.8 + 5.9 +#define FOV_DEG 50.0 5.10 + 5.11 +void disp(); 5.12 +void idle(); 5.13 +void reshape(int x, int y); 5.14 +void key_press(unsigned char key, int x, int y); 5.15 +void key_release(unsigned char key, int x, int y); 5.16 + 5.17 +int win_xsz, win_ysz; 5.18 + 5.19 +int main(int argc, char **argv) 5.20 +{ 5.21 + glutInitWindowSize(800, 450); 5.22 + glutInit(&argc, argv); 5.23 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 5.24 + glutCreateWindow("intravenous interventor"); 5.25 + 5.26 + glutDisplayFunc(disp); 5.27 + glutIdleFunc(idle); 5.28 + glutReshapeFunc(reshape); 5.29 + glutKeyboardFunc(key_press); 5.30 + glutKeyboardUpFunc(key_release); 5.31 + 5.32 + if(!game_init()) { 5.33 + return 1; 5.34 + } 5.35 + 5.36 + glutMainLoop(); 5.37 + return 0; 5.38 +} 5.39 + 5.40 +void idle() 5.41 +{ 5.42 + glutPostRedisplay(); 5.43 +} 5.44 + 5.45 +void disp() 5.46 +{ 5.47 + unsigned long msec = glutGet(GLUT_ELAPSED_TIME); 5.48 + // update any game logic 5.49 + game_update(msec); 5.50 + 5.51 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 5.52 + 5.53 + // render stuff 5.54 + game_draw(); 5.55 + 5.56 + glutSwapBuffers(); 5.57 + assert(glGetError() == GL_NO_ERROR); 5.58 +} 5.59 + 5.60 +void reshape(int x, int y) 5.61 +{ 5.62 + glViewport(0, 0, x, y); 5.63 + 5.64 + glMatrixMode(GL_PROJECTION); 5.65 + glLoadIdentity(); 5.66 + gluPerspective(FOV_DEG, (float)x / (float)y, 1.0, 1000.0); 5.67 + 5.68 + win_xsz = x; 5.69 + win_ysz = y; 5.70 +} 5.71 + 5.72 +void key_press(unsigned char key, int x, int y) 5.73 +{ 5.74 + game_input_keyb(key, 1); 5.75 +} 5.76 + 5.77 +void key_release(unsigned char key, int x, int y) 5.78 +{ 5.79 + game_input_keyb(key, 0); 5.80 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/src/opengl.h Sat Apr 21 06:56:33 2012 +0300 6.3 @@ -0,0 +1,12 @@ 6.4 +#ifndef OPENGL_H_ 6.5 +#define OPENGL_H_ 6.6 + 6.7 +#include <GL/glew.h> 6.8 + 6.9 +#ifndef __APPLE__ 6.10 +#include <GL/glut.h> 6.11 +#else 6.12 +#include <GLUT/glut.h> 6.13 +#endif 6.14 + 6.15 +#endif /* OPENGL_H_ */