# HG changeset patch # User John Tsiombikas # Date 1355550733 -7200 # Node ID e4818a3300b93d9c6a83a5c62aefa9f6041c959f bloboland initial commit diff -r 000000000000 -r e4818a3300b9 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,29 @@ +src = $(wildcard src/*.cc) +obj = $(src:.cc=.o) +dep = $(obj:.o=.d) +bin = blobo + +CXXFLAGS = -ansi -pedantic -Wall -g +LDFLAGS = $(libgl) + +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) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + +.PHONY: cleandep +cleandep: + rm -f $(dep) diff -r 000000000000 -r e4818a3300b9 src/game.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/game.cc Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,19 @@ +#include "game.h" +#include "opengl.h" + +bool game_init() +{ + return true; +} + +void game_shutdown() +{ +} + +void game_iter(double dt) +{ +} + +void game_render() +{ +} diff -r 000000000000 -r e4818a3300b9 src/game.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/game.h Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,12 @@ +#ifndef GAME_H_ +#define GAME_H_ + +bool keystate[256]; + +bool game_init(); +void game_shutdown(); + +void game_iter(double dt); +void game_render(); + +#endif // GAME_H_ diff -r 000000000000 -r e4818a3300b9 src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cc Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,121 @@ +#include +#include +#include "opengl.h" +#include "game.h" +#include "opt.h" + +static void disp(); +static void reshape(int x, int y); +static void keydown(unsigned char key, int x, int y); +static void keyup(unsigned char key, int x, int y); +static void skeydown(int key, int x, int y); +static void skeyup(int key, int x, int y); +static void mouse(int bn, int state, int x, int y); +static void motion(int x, int y); +static void spacemove(int x, int y, int z); +static void spacerot(int x, int y, int z); +static void spacebut(int bn, int state); + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if(!parse_opt(argc, argv)) { + return 1; + } + + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); + glutInitWindowSize(800, 450); + glutCreateWindow("bloboland"); + + glutDisplayFunc(disp); + glutReshapeFunc(reshape); + glutKeyboardFunc(keydown); + glutKeyboardUpFunc(keyup); + glutSpecialFunc(skeydown); + glutSpecialUpFunc(skeyup); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutSpaceballMotionFunc(spacemove); + glutSpaceballRotateFunc(spacerot); + glutSpaceballButtonFunc(spacebut); + + glewInit(); + + if(!game_init()) { + return 1; + } + + glutMainLoop(); +} + +static void disp() +{ + unsigned int msec = glutGet(GLUT_ELAPSED_TIME); + game_iter((msec - prev_msec) / 1000.0); + + + glClear(GL_COLOR_BUFFER_BIT); + + game_render(); + + glutSwapBuffers(); +} + +static void 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); +} + +static void keydown(unsigned char key, int x, int y) +{ + skeydown(key, x, y); +} + +static void keyup(unsigned char key, int x, int y) +{ + skeyup(key, x, y); +} + +static void skeydown(int key, int x, int y) +{ + if(key == 27) { + exit(0); + } + + if(key < sizeof keystate / sizeof *keystate) { + keystate[key] = true; + } +} + +static void skeyup(int key, int x, int y) +{ + if(key < sizeof keystate / sizeof *keystate) { + keystate[key] = false; + } +} + +static void mouse(int bn, int state, int x, int y) +{ +} + +static void motion(int x, int y) +{ +} + +static void spacemove(int x, int y, int z) +{ +} + +static void spacerot(int x, int y, int z) +{ +} + +static void spacebut(int bn, int state) +{ +} + diff -r 000000000000 -r e4818a3300b9 src/opengl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opengl.h Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,12 @@ +#ifndef OPENGL_H_ +#define OPENGL_H_ + +#include + +#ifndef __APPLE__ +#include +#else +#include +#endif + +#endif /* OPENGL_H_ */ diff -r 000000000000 -r e4818a3300b9 src/opt.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opt.cc Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,6 @@ +#include "opt.h" + +bool parse_opt(int argc, char **argv) +{ + return true; +} diff -r 000000000000 -r e4818a3300b9 src/opt.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opt.h Sat Dec 15 07:52:13 2012 +0200 @@ -0,0 +1,11 @@ +#ifndef OPT_H_ +#define OPT_H_ + +struct Options { + int xsz, ysz; + bool stereo; +}; + +bool parse_opt(int argc, char **argv); + +#endif // OPT_H_