bloboland

changeset 0:e4818a3300b9

bloboland initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Dec 2012 07:52:13 +0200
parents
children cfe68befb7cc
files Makefile src/game.cc src/game.h src/main.cc src/opengl.h src/opt.cc src/opt.h
diffstat 7 files changed, 210 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Sat Dec 15 07:52:13 2012 +0200
     1.3 @@ -0,0 +1,29 @@
     1.4 +src = $(wildcard src/*.cc)
     1.5 +obj = $(src:.cc=.o)
     1.6 +dep = $(obj:.o=.d)
     1.7 +bin = blobo
     1.8 +
     1.9 +CXXFLAGS = -ansi -pedantic -Wall -g
    1.10 +LDFLAGS = $(libgl)
    1.11 +
    1.12 +ifeq ($(shell uname -s), Darwin)
    1.13 +	libgl = -framework OpenGL -framework GLUT -lGLEW
    1.14 +else
    1.15 +	libgl = -lGL -lGLU -lglut -lGLEW
    1.16 +endif
    1.17 +
    1.18 +$(bin): $(obj)
    1.19 +	$(CXX) -o $@ $(obj) $(LDFLAGS)
    1.20 +
    1.21 +-include $(dep)
    1.22 +
    1.23 +%.d: %.cc
    1.24 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    1.25 +
    1.26 +.PHONY: clean
    1.27 +clean:
    1.28 +	rm -f $(obj) $(bin)
    1.29 +
    1.30 +.PHONY: cleandep
    1.31 +cleandep:
    1.32 +	rm -f $(dep)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/game.cc	Sat Dec 15 07:52:13 2012 +0200
     2.3 @@ -0,0 +1,19 @@
     2.4 +#include "game.h"
     2.5 +#include "opengl.h"
     2.6 +
     2.7 +bool game_init()
     2.8 +{
     2.9 +	return true;
    2.10 +}
    2.11 +
    2.12 +void game_shutdown()
    2.13 +{
    2.14 +}
    2.15 +
    2.16 +void game_iter(double dt)
    2.17 +{
    2.18 +}
    2.19 +
    2.20 +void game_render()
    2.21 +{
    2.22 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/game.h	Sat Dec 15 07:52:13 2012 +0200
     3.3 @@ -0,0 +1,12 @@
     3.4 +#ifndef GAME_H_
     3.5 +#define GAME_H_
     3.6 +
     3.7 +bool keystate[256];
     3.8 +
     3.9 +bool game_init();
    3.10 +void game_shutdown();
    3.11 +
    3.12 +void game_iter(double dt);
    3.13 +void game_render();
    3.14 +
    3.15 +#endif	// GAME_H_
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/main.cc	Sat Dec 15 07:52:13 2012 +0200
     4.3 @@ -0,0 +1,121 @@
     4.4 +#include <stdio.h>
     4.5 +#include <stdlib.h>
     4.6 +#include "opengl.h"
     4.7 +#include "game.h"
     4.8 +#include "opt.h"
     4.9 +
    4.10 +static void disp();
    4.11 +static void reshape(int x, int y);
    4.12 +static void keydown(unsigned char key, int x, int y);
    4.13 +static void keyup(unsigned char key, int x, int y);
    4.14 +static void skeydown(int key, int x, int y);
    4.15 +static void skeyup(int key, int x, int y);
    4.16 +static void mouse(int bn, int state, int x, int y);
    4.17 +static void motion(int x, int y);
    4.18 +static void spacemove(int x, int y, int z);
    4.19 +static void spacerot(int x, int y, int z);
    4.20 +static void spacebut(int bn, int state);
    4.21 +
    4.22 +int main(int argc, char **argv)
    4.23 +{
    4.24 +	glutInit(&argc, argv);
    4.25 +
    4.26 +	if(!parse_opt(argc, argv)) {
    4.27 +		return 1;
    4.28 +	}
    4.29 +
    4.30 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0));
    4.31 +	glutInitWindowSize(800, 450);
    4.32 +	glutCreateWindow("bloboland");
    4.33 +
    4.34 +	glutDisplayFunc(disp);
    4.35 +	glutReshapeFunc(reshape);
    4.36 +	glutKeyboardFunc(keydown);
    4.37 +	glutKeyboardUpFunc(keyup);
    4.38 +	glutSpecialFunc(skeydown);
    4.39 +	glutSpecialUpFunc(skeyup);
    4.40 +	glutMouseFunc(mouse);
    4.41 +	glutMotionFunc(motion);
    4.42 +	glutSpaceballMotionFunc(spacemove);
    4.43 +	glutSpaceballRotateFunc(spacerot);
    4.44 +	glutSpaceballButtonFunc(spacebut);
    4.45 +
    4.46 +	glewInit();
    4.47 +
    4.48 +	if(!game_init()) {
    4.49 +		return 1;
    4.50 +	}
    4.51 +
    4.52 +	glutMainLoop();
    4.53 +}
    4.54 +
    4.55 +static void disp()
    4.56 +{
    4.57 +	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    4.58 +	game_iter((msec - prev_msec) / 1000.0);
    4.59 +
    4.60 +
    4.61 +	glClear(GL_COLOR_BUFFER_BIT);
    4.62 +
    4.63 +	game_render();
    4.64 +
    4.65 +	glutSwapBuffers();
    4.66 +}
    4.67 +
    4.68 +static void reshape(int x, int y)
    4.69 +{
    4.70 +	glViewport(0, 0, x, y);
    4.71 +
    4.72 +	glMatrixMode(GL_PROJECTION);
    4.73 +	glLoadIdentity();
    4.74 +	gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
    4.75 +}
    4.76 +
    4.77 +static void keydown(unsigned char key, int x, int y)
    4.78 +{
    4.79 +	skeydown(key, x, y);
    4.80 +}
    4.81 +
    4.82 +static void keyup(unsigned char key, int x, int y)
    4.83 +{
    4.84 +	skeyup(key, x, y);
    4.85 +}
    4.86 +
    4.87 +static void skeydown(int key, int x, int y)
    4.88 +{
    4.89 +	if(key == 27) {
    4.90 +		exit(0);
    4.91 +	}
    4.92 +
    4.93 +	if(key < sizeof keystate / sizeof *keystate) {
    4.94 +		keystate[key] = true;
    4.95 +	}
    4.96 +}
    4.97 +
    4.98 +static void skeyup(int key, int x, int y)
    4.99 +{
   4.100 +	if(key < sizeof keystate / sizeof *keystate) {
   4.101 +		keystate[key] = false;
   4.102 +	}
   4.103 +}
   4.104 +
   4.105 +static void mouse(int bn, int state, int x, int y)
   4.106 +{
   4.107 +}
   4.108 +
   4.109 +static void motion(int x, int y)
   4.110 +{
   4.111 +}
   4.112 +
   4.113 +static void spacemove(int x, int y, int z)
   4.114 +{
   4.115 +}
   4.116 +
   4.117 +static void spacerot(int x, int y, int z)
   4.118 +{
   4.119 +}
   4.120 +
   4.121 +static void spacebut(int bn, int state)
   4.122 +{
   4.123 +}
   4.124 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/opengl.h	Sat Dec 15 07:52:13 2012 +0200
     5.3 @@ -0,0 +1,12 @@
     5.4 +#ifndef OPENGL_H_
     5.5 +#define OPENGL_H_
     5.6 +
     5.7 +#include <GL/glew.h>
     5.8 +
     5.9 +#ifndef __APPLE__
    5.10 +#include <GL/glut.h>
    5.11 +#else
    5.12 +#include <GLUT/glut.h>
    5.13 +#endif
    5.14 +
    5.15 +#endif	/* OPENGL_H_ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/opt.cc	Sat Dec 15 07:52:13 2012 +0200
     6.3 @@ -0,0 +1,6 @@
     6.4 +#include "opt.h"
     6.5 +
     6.6 +bool parse_opt(int argc, char **argv)
     6.7 +{
     6.8 +	return true;
     6.9 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/opt.h	Sat Dec 15 07:52:13 2012 +0200
     7.3 @@ -0,0 +1,11 @@
     7.4 +#ifndef OPT_H_
     7.5 +#define OPT_H_
     7.6 +
     7.7 +struct Options {
     7.8 +	int xsz, ysz;
     7.9 +	bool stereo;
    7.10 +};
    7.11 +
    7.12 +bool parse_opt(int argc, char **argv);
    7.13 +
    7.14 +#endif	// OPT_H_