stratgame

changeset 3:8d95187cb3ee

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 23 May 2012 17:10:46 +0300
parents 369b51c9e4a8
children cd12944a8ea8
files Makefile gfx/Makefile gfx/src/opengl.cc gfx/src/opengl.h gfx/src/sdr.c gfx/src/sdr.h level/Makefile level/src/level.cc level/src/level.h src/game_part.cc src/game_part.h src/main.cc src/opengl.h src/part.cc src/part.h
diffstat 15 files changed, 536 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Wed May 23 07:25:43 2012 +0300
     1.2 +++ b/Makefile	Wed May 23 17:10:46 2012 +0300
     1.3 @@ -4,11 +4,12 @@
     1.4  dep = $(obj:.o=.d)
     1.5  bin = strat
     1.6  
     1.7 -incdir = -Isrc -Ilevel/src -Icommon/src
     1.8 +incdir = -Isrc -Igfx/src -Ilevel/src -Icommon/src
     1.9  
    1.10 +libgfx = gfx/libgfx.a
    1.11  liblevel = level/liblevel.a
    1.12  libcommon = common/libcommon.a
    1.13 -slibs = $(liblevel) $(libcommon)
    1.14 +slibs = $(libgfx) $(liblevel) $(libcommon)
    1.15  
    1.16  CFLAGS = -pedantic -Wall -g $(incdir)
    1.17  CXXFLAGS = -std=c++0x $(CFLAGS)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gfx/Makefile	Wed May 23 17:10:46 2012 +0300
     2.3 @@ -0,0 +1,28 @@
     2.4 +csrc = $(wildcard src/*.c)
     2.5 +ccsrc = $(wildcard src/*.cc)
     2.6 +obj = $(ccsrc:.cc=.o) $(csrc:.c=.o)
     2.7 +dep = $(obj:.o=.d)
     2.8 +lib_a = libgfx.a
     2.9 +
    2.10 +CFLAGS = -pedantic -Wall -g -I../common/src
    2.11 +CXXFLAGS = -std=c++0x $(CFLAGS)
    2.12 +
    2.13 +ifeq ($(shell uname -s), Darwin)
    2.14 +	CC = clang
    2.15 +	CXX = clang++
    2.16 +endif
    2.17 +
    2.18 +$(lib_a): $(obj)
    2.19 +	$(AR) rcs $@ $(obj)
    2.20 +
    2.21 +-include $(dep)
    2.22 +
    2.23 +%.d: %.c
    2.24 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    2.25 +
    2.26 +%.d: %.cc
    2.27 +	@$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
    2.28 +
    2.29 +.PHONY: clean
    2.30 +clean:
    2.31 +	rm -f $(obj) $(bin) $(dep)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gfx/src/opengl.cc	Wed May 23 17:10:46 2012 +0300
     3.3 @@ -0,0 +1,39 @@
     3.4 +#include "opengl.h"
     3.5 +
     3.6 +void load_gl_matrix(const Matrix4x4 &mat)
     3.7 +{
     3.8 +#ifdef SINGLE_PRECISION_MATH
     3.9 +	if(glLoadTransposeMatrixfARB) {
    3.10 +		glLoadTransposeMatrixfARB((float*)&mat);
    3.11 +	} else {
    3.12 +		Matrix4x4 tmat = mat.transposed();
    3.13 +		glLoadMatrixf((float*)&tmat);
    3.14 +	}
    3.15 +#else
    3.16 +	if(glLoadTransposeMatrixdARB) {
    3.17 +		glLoadTransposeMatrixdARB((double*)&mat);
    3.18 +	} else {
    3.19 +		Matrix4x4 tmat = mat.transposed();
    3.20 +		glLoadMatrixd((double*)&tmat);
    3.21 +	}
    3.22 +#endif
    3.23 +}
    3.24 +
    3.25 +void mult_gl_matrix(const Matrix4x4 &mat)
    3.26 +{
    3.27 +#ifdef SINGLE_PRECISION_MATH
    3.28 +	if(glMultTransposeMatrixfARB) {
    3.29 +		glMultTransposeMatrixfARB((float*)&mat);
    3.30 +	} else {
    3.31 +		Matrix4x4 tmat = mat.transposed();
    3.32 +		glMultMatrixf((float*)&tmat);
    3.33 +	}
    3.34 +#else
    3.35 +	if(glMultTransposeMatrixdARB) {
    3.36 +		glMultTransposeMatrixdARB((double*)&mat);
    3.37 +	} else {
    3.38 +		Matrix4x4 tmat = mat.transposed();
    3.39 +		glMultMatrixd((double*)&tmat);
    3.40 +	}
    3.41 +#endif
    3.42 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/gfx/src/opengl.h	Wed May 23 17:10:46 2012 +0300
     4.3 @@ -0,0 +1,19 @@
     4.4 +#ifndef OPENGL_H_
     4.5 +#define OPENGL_H_
     4.6 +
     4.7 +#include <GL/glew.h>
     4.8 +
     4.9 +#ifndef __APPLE__
    4.10 +#include <GL/glut.h>
    4.11 +#else
    4.12 +#include <GLUT/glut.h>
    4.13 +#endif
    4.14 +
    4.15 +#ifdef __cplusplus
    4.16 +#include <vmath/vmath.h>
    4.17 +
    4.18 +void load_gl_matrix(const Matrix4x4 &mat);
    4.19 +void mult_gl_matrix(const Matrix4x4 &mat);
    4.20 +#endif	/* __cplusplus */
    4.21 +
    4.22 +#endif	/* OPENGL_H_ */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/gfx/src/sdr.c	Wed May 23 17:10:46 2012 +0300
     5.3 @@ -0,0 +1,328 @@
     5.4 +#include <stdio.h>
     5.5 +#include <stdlib.h>
     5.6 +#include <string.h>
     5.7 +#include <errno.h>
     5.8 +#include <assert.h>
     5.9 +#include <GL/glew.h>
    5.10 +
    5.11 +#if defined(unix) || defined(__unix__)
    5.12 +#include <unistd.h>
    5.13 +#include <sys/stat.h>
    5.14 +#endif	/* unix */
    5.15 +
    5.16 +#include "sdr.h"
    5.17 +
    5.18 +unsigned int create_vertex_shader(const char *src)
    5.19 +{
    5.20 +	return create_shader(src, GL_VERTEX_SHADER);
    5.21 +}
    5.22 +
    5.23 +unsigned int create_pixel_shader(const char *src)
    5.24 +{
    5.25 +	return create_shader(src, GL_FRAGMENT_SHADER);
    5.26 +}
    5.27 +
    5.28 +unsigned int create_shader(const char *src, unsigned int sdr_type)
    5.29 +{
    5.30 +	unsigned int sdr;
    5.31 +	int success, info_len;
    5.32 +	char *info_str = 0;
    5.33 +	GLenum err;
    5.34 +
    5.35 +	sdr = glCreateShader(sdr_type);
    5.36 +	assert(glGetError() == GL_NO_ERROR);
    5.37 +	glShaderSource(sdr, 1, &src, 0);
    5.38 +	err = glGetError();
    5.39 +	assert(err == GL_NO_ERROR);
    5.40 +	glCompileShader(sdr);
    5.41 +	assert(glGetError() == GL_NO_ERROR);
    5.42 +
    5.43 +	glGetShaderiv(sdr, GL_COMPILE_STATUS, &success);
    5.44 +	assert(glGetError() == GL_NO_ERROR);
    5.45 +	glGetShaderiv(sdr, GL_INFO_LOG_LENGTH, &info_len);
    5.46 +	assert(glGetError() == GL_NO_ERROR);
    5.47 +
    5.48 +	if(info_len) {
    5.49 +		if((info_str = malloc(info_len + 1))) {
    5.50 +			glGetShaderInfoLog(sdr, info_len, 0, info_str);
    5.51 +			assert(glGetError() == GL_NO_ERROR);
    5.52 +		}
    5.53 +	}
    5.54 +
    5.55 +	if(success) {
    5.56 +		fprintf(stderr, info_str ? "done: %s\n" : "done\n", info_str);
    5.57 +	} else {
    5.58 +		fprintf(stderr, info_str ? "failed: %s\n" : "failed\n", info_str);
    5.59 +		glDeleteShader(sdr);
    5.60 +		sdr = 0;
    5.61 +	}
    5.62 +
    5.63 +	free(info_str);
    5.64 +	return sdr;
    5.65 +}
    5.66 +
    5.67 +void free_shader(unsigned int sdr)
    5.68 +{
    5.69 +	glDeleteShader(sdr);
    5.70 +}
    5.71 +
    5.72 +unsigned int load_vertex_shader(const char *fname)
    5.73 +{
    5.74 +	return load_shader(fname, GL_VERTEX_SHADER);
    5.75 +}
    5.76 +
    5.77 +unsigned int load_pixel_shader(const char *fname)
    5.78 +{
    5.79 +	return load_shader(fname, GL_FRAGMENT_SHADER);
    5.80 +}
    5.81 +
    5.82 +unsigned int load_shader(const char *fname, unsigned int sdr_type)
    5.83 +{
    5.84 +#if defined(unix) || defined(__unix__)
    5.85 +	struct stat st;
    5.86 +#endif
    5.87 +	unsigned int sdr;
    5.88 +	size_t filesize;
    5.89 +	FILE *fp;
    5.90 +	char *src;
    5.91 +
    5.92 +	if(!(fp = fopen(fname, "r"))) {
    5.93 +		fprintf(stderr, "failed to open shader %s: %s\n", fname, strerror(errno));
    5.94 +		return 0;
    5.95 +	}
    5.96 +
    5.97 +#if defined(unix) || defined(__unix__)
    5.98 +	fstat(fileno(fp), &st);
    5.99 +	filesize = st.st_size;
   5.100 +#else
   5.101 +	fseek(fp, 0, SEEK_END);
   5.102 +	filesize = ftell(fp);
   5.103 +	fseek(fp, 0, SEEK_SET);
   5.104 +#endif	/* unix */
   5.105 +
   5.106 +	if(!(src = malloc(filesize + 1))) {
   5.107 +		fclose(fp);
   5.108 +		return 0;
   5.109 +	}
   5.110 +	fread(src, 1, filesize, fp);
   5.111 +	src[filesize] = 0;
   5.112 +	fclose(fp);
   5.113 +
   5.114 +	fprintf(stderr, "compiling %s shader: %s... ", (sdr_type == GL_VERTEX_SHADER ? "vertex" : "pixel"), fname);
   5.115 +	sdr = create_shader(src, sdr_type);
   5.116 +
   5.117 +	free(src);
   5.118 +	return sdr;
   5.119 +}
   5.120 +
   5.121 +
   5.122 +unsigned int get_vertex_shader(const char *fname)
   5.123 +{
   5.124 +	return get_shader(fname, GL_VERTEX_SHADER);
   5.125 +}
   5.126 +
   5.127 +unsigned int get_pixel_shader(const char *fname)
   5.128 +{
   5.129 +	return get_shader(fname, GL_FRAGMENT_SHADER);
   5.130 +}
   5.131 +
   5.132 +unsigned int get_shader(const char *fname, unsigned int sdr_type)
   5.133 +{
   5.134 +	unsigned int sdr;
   5.135 +	if(!(sdr = load_shader(fname, sdr_type))) {
   5.136 +		return 0;
   5.137 +	}
   5.138 +	return sdr;
   5.139 +}
   5.140 +
   5.141 +
   5.142 +/* ---- gpu programs ---- */
   5.143 +
   5.144 +unsigned int create_program(void)
   5.145 +{
   5.146 +	unsigned int prog = glCreateProgram();
   5.147 +	assert(glGetError() == GL_NO_ERROR);
   5.148 +	return prog;
   5.149 +}
   5.150 +
   5.151 +unsigned int create_program_link(unsigned int vs, unsigned int ps)
   5.152 +{
   5.153 +	unsigned int prog;
   5.154 +
   5.155 +	if(!(prog = create_program())) {
   5.156 +		return 0;
   5.157 +	}
   5.158 +
   5.159 +	if(vs) {
   5.160 +		attach_shader(prog, vs);
   5.161 +		assert(glGetError() == GL_NO_ERROR);
   5.162 +	}
   5.163 +	if(ps) {
   5.164 +		attach_shader(prog, ps);
   5.165 +		assert(glGetError() == GL_NO_ERROR);
   5.166 +	}
   5.167 +
   5.168 +	if(link_program(prog) == -1) {
   5.169 +		free_program(prog);
   5.170 +		return 0;
   5.171 +	}
   5.172 +	return prog;
   5.173 +}
   5.174 +
   5.175 +unsigned int create_program_load(const char *vfile, const char *pfile)
   5.176 +{
   5.177 +	unsigned int vs = 0, ps = 0;
   5.178 +
   5.179 +	if(vfile && !(vs = get_vertex_shader(vfile))) {
   5.180 +		return 0;
   5.181 +	}
   5.182 +	if(pfile && !(ps = get_pixel_shader(pfile))) {
   5.183 +		return 0;
   5.184 +	}
   5.185 +	return create_program_link(vs, ps);
   5.186 +}
   5.187 +
   5.188 +void free_program(unsigned int sdr)
   5.189 +{
   5.190 +	glDeleteProgram(sdr);
   5.191 +}
   5.192 +
   5.193 +void attach_shader(unsigned int prog, unsigned int sdr)
   5.194 +{
   5.195 +	glAttachShader(prog, sdr);
   5.196 +	assert(glGetError() == GL_NO_ERROR);
   5.197 +}
   5.198 +
   5.199 +int link_program(unsigned int prog)
   5.200 +{
   5.201 +	int linked, info_len, retval = 0;
   5.202 +	char *info_str = 0;
   5.203 +
   5.204 +	glLinkProgram(prog);
   5.205 +	assert(glGetError() == GL_NO_ERROR);
   5.206 +	glGetProgramiv(prog, GL_LINK_STATUS, &linked);
   5.207 +	assert(glGetError() == GL_NO_ERROR);
   5.208 +	glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &info_len);
   5.209 +	assert(glGetError() == GL_NO_ERROR);
   5.210 +
   5.211 +	if(info_len) {
   5.212 +		if((info_str = malloc(info_len + 1))) {
   5.213 +			glGetProgramInfoLog(prog, info_len, 0, info_str);
   5.214 +			assert(glGetError() == GL_NO_ERROR);
   5.215 +		}
   5.216 +	}
   5.217 +
   5.218 +	if(linked) {
   5.219 +		fprintf(stderr, info_str ? "linking done: %s\n" : "linking done\n", info_str);
   5.220 +	} else {
   5.221 +		fprintf(stderr, info_str ? "linking failed: %s\n" : "linking failed\n", info_str);
   5.222 +		retval = -1;
   5.223 +	}
   5.224 +
   5.225 +	free(info_str);
   5.226 +	return retval;
   5.227 +}
   5.228 +
   5.229 +int bind_program(unsigned int prog)
   5.230 +{
   5.231 +	GLenum err;
   5.232 +
   5.233 +	glUseProgram(prog);
   5.234 +	if(prog && (err = glGetError()) != GL_NO_ERROR) {
   5.235 +		/* maybe the program is not linked, try linking first */
   5.236 +		if(err == GL_INVALID_OPERATION) {
   5.237 +			if(link_program(prog) == -1) {
   5.238 +				return -1;
   5.239 +			}
   5.240 +			glUseProgram(prog);
   5.241 +			return glGetError() == GL_NO_ERROR ? 0 : -1;
   5.242 +		}
   5.243 +		return -1;
   5.244 +	}
   5.245 +	return 0;
   5.246 +}
   5.247 +
   5.248 +/* ugly but I'm not going to write the same bloody code over and over */
   5.249 +#define BEGIN_UNIFORM_CODE \
   5.250 +	int loc, curr_prog; \
   5.251 +	glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog); \
   5.252 +	if((unsigned int)curr_prog != prog && bind_program(prog) == -1) { \
   5.253 +		return -1; \
   5.254 +	} \
   5.255 +	if((loc = glGetUniformLocation(prog, name)) != -1)
   5.256 +
   5.257 +#define END_UNIFORM_CODE \
   5.258 +	if((unsigned int)curr_prog != prog) { \
   5.259 +		bind_program(curr_prog); \
   5.260 +	} \
   5.261 +	return loc == -1 ? -1 : 0
   5.262 +
   5.263 +int set_uniform_int(unsigned int prog, const char *name, int val)
   5.264 +{
   5.265 +	BEGIN_UNIFORM_CODE {
   5.266 +		glUniform1i(loc, val);
   5.267 +	}
   5.268 +	END_UNIFORM_CODE;
   5.269 +}
   5.270 +
   5.271 +int set_uniform_float(unsigned int prog, const char *name, float val)
   5.272 +{
   5.273 +	BEGIN_UNIFORM_CODE {
   5.274 +		glUniform1f(loc, val);
   5.275 +	}
   5.276 +	END_UNIFORM_CODE;
   5.277 +}
   5.278 +
   5.279 +int set_uniform_float3(unsigned int prog, const char *name, float x, float y, float z)
   5.280 +{
   5.281 +	BEGIN_UNIFORM_CODE {
   5.282 +		glUniform3f(loc, x, y, z);
   5.283 +	}
   5.284 +	END_UNIFORM_CODE;
   5.285 +}
   5.286 +
   5.287 +int set_uniform_float4(unsigned int prog, const char *name, float x, float y, float z, float w)
   5.288 +{
   5.289 +	BEGIN_UNIFORM_CODE {
   5.290 +		glUniform4f(loc, x, y, z, w);
   5.291 +	}
   5.292 +	END_UNIFORM_CODE;
   5.293 +}
   5.294 +
   5.295 +int set_uniform_matrix4(unsigned int prog, const char *name, float *mat)
   5.296 +{
   5.297 +	BEGIN_UNIFORM_CODE {
   5.298 +		glUniformMatrix4fv(loc, 1, GL_FALSE, mat);
   5.299 +	}
   5.300 +	END_UNIFORM_CODE;
   5.301 +}
   5.302 +
   5.303 +int set_uniform_matrix4_transposed(unsigned int prog, const char *name, float *mat)
   5.304 +{
   5.305 +	BEGIN_UNIFORM_CODE {
   5.306 +		glUniformMatrix4fv(loc, 1, GL_TRUE, mat);
   5.307 +	}
   5.308 +	END_UNIFORM_CODE;
   5.309 +}
   5.310 +
   5.311 +int get_attrib_loc(unsigned int prog, const char *name)
   5.312 +{
   5.313 +	int loc, curr_prog;
   5.314 +
   5.315 +	glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog);
   5.316 +	if((unsigned int)curr_prog != prog && bind_program(prog) == -1) {
   5.317 +		return -1;
   5.318 +	}
   5.319 +
   5.320 +	loc = glGetAttribLocation(prog, (char*)name);
   5.321 +
   5.322 +	if((unsigned int)curr_prog != prog) {
   5.323 +		bind_program(curr_prog);
   5.324 +	}
   5.325 +	return loc;
   5.326 +}
   5.327 +
   5.328 +void set_attrib_float3(int attr_loc, float x, float y, float z)
   5.329 +{
   5.330 +	glVertexAttrib3f(attr_loc, x, y, z);
   5.331 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/gfx/src/sdr.h	Wed May 23 17:10:46 2012 +0300
     6.3 @@ -0,0 +1,49 @@
     6.4 +#ifndef SDR_H_
     6.5 +#define SDR_H_
     6.6 +
     6.7 +#ifdef __cplusplus
     6.8 +extern "C" {
     6.9 +#endif	/* __cplusplus */
    6.10 +
    6.11 +/* ---- shaders ---- */
    6.12 +unsigned int create_vertex_shader(const char *src);
    6.13 +unsigned int create_pixel_shader(const char *src);
    6.14 +unsigned int create_shader(const char *src, unsigned int sdr_type);
    6.15 +void free_shader(unsigned int sdr);
    6.16 +
    6.17 +unsigned int load_vertex_shader(const char *fname);
    6.18 +unsigned int load_pixel_shader(const char *fname);
    6.19 +unsigned int load_shader(const char *src, unsigned int sdr_type);
    6.20 +
    6.21 +unsigned int get_vertex_shader(const char *fname);
    6.22 +unsigned int get_pixel_shader(const char *fname);
    6.23 +unsigned int get_shader(const char *fname, unsigned int sdr_type);
    6.24 +
    6.25 +int add_shader(const char *fname, unsigned int sdr);
    6.26 +int remove_shader(const char *fname);
    6.27 +
    6.28 +/* ---- gpu programs ---- */
    6.29 +unsigned int create_program(void);
    6.30 +unsigned int create_program_link(unsigned int vs, unsigned int ps);
    6.31 +unsigned int create_program_load(const char *vfile, const char *pfile);
    6.32 +void free_program(unsigned int sdr);
    6.33 +
    6.34 +void attach_shader(unsigned int prog, unsigned int sdr);
    6.35 +int link_program(unsigned int prog);
    6.36 +int bind_program(unsigned int prog);
    6.37 +
    6.38 +int set_uniform_int(unsigned int prog, const char *name, int val);
    6.39 +int set_uniform_float(unsigned int prog, const char *name, float val);
    6.40 +int set_uniform_float3(unsigned int prog, const char *name, float x, float y, float z);
    6.41 +int set_uniform_float4(unsigned int prog, const char *name, float x, float y, float z, float w);
    6.42 +int set_uniform_matrix4(unsigned int prog, const char *name, float *mat);
    6.43 +int set_uniform_matrix4_transposed(unsigned int prog, const char *name, float *mat);
    6.44 +
    6.45 +int get_attrib_loc(unsigned int prog, const char *name);
    6.46 +void set_attrib_float3(int attr_loc, float x, float y, float z);
    6.47 +
    6.48 +#ifdef __cplusplus
    6.49 +}
    6.50 +#endif	/* __cplusplus */
    6.51 +
    6.52 +#endif	/* SDR_H_ */
     7.1 --- a/level/Makefile	Wed May 23 07:25:43 2012 +0300
     7.2 +++ b/level/Makefile	Wed May 23 17:10:46 2012 +0300
     7.3 @@ -3,7 +3,7 @@
     7.4  dep = $(obj:.o=.d)
     7.5  lib_a = liblevel.a
     7.6  
     7.7 -CXXFLAGS = -std=c++0x -pedantic -Wall -g -I../common/src
     7.8 +CXXFLAGS = -std=c++0x -pedantic -Wall -g -I../gfx/src -I../common/src
     7.9  
    7.10  ifeq ($(shell uname -s), Darwin)
    7.11  	CC = clang
     8.1 --- a/level/src/level.cc	Wed May 23 07:25:43 2012 +0300
     8.2 +++ b/level/src/level.cc	Wed May 23 17:10:46 2012 +0300
     8.3 @@ -2,6 +2,7 @@
     8.4  #include <string.h>
     8.5  #include "level.h"
     8.6  #include "datapath.h"
     8.7 +#include "opengl.h"
     8.8  
     8.9  using namespace tinyxml2;
    8.10  
    8.11 @@ -53,6 +54,32 @@
    8.12  	return true;
    8.13  }
    8.14  
    8.15 +void Level::draw() const
    8.16 +{
    8.17 +	auto iter = levelmaps.find("height");
    8.18 +	if(iter == levelmaps.end()) {
    8.19 +		return;
    8.20 +	}
    8.21 +
    8.22 +	img_pixmap *hmap = (img_pixmap*)iter->second.get_pixmap();
    8.23 +
    8.24 +	glBegin(GL_POINTS);
    8.25 +	for(int i=0; i<hmap->height; i++) {
    8.26 +		for(int j=0; j<hmap->width; j++) {
    8.27 +			int height;
    8.28 +			img_getpixel1i(hmap, j, i, &height);
    8.29 +
    8.30 +			float x = (float)j / (float)hmap->width - 0.5;
    8.31 +			float y = height / 255.0;
    8.32 +			float z = (float)i / (float)hmap->height - 0.5;
    8.33 +
    8.34 +			glColor3f(y, 0.0, 1.0 - y);
    8.35 +			glVertex3f(x, y, z);
    8.36 +		}
    8.37 +	}
    8.38 +	glEnd();
    8.39 +}
    8.40 +
    8.41  
    8.42  LevelMap::LevelMap()
    8.43  {
     9.1 --- a/level/src/level.h	Wed May 23 07:25:43 2012 +0300
     9.2 +++ b/level/src/level.h	Wed May 23 17:10:46 2012 +0300
     9.3 @@ -18,6 +18,8 @@
     9.4  	~Level();
     9.5  
     9.6  	bool load(const char *fname);
     9.7 +
     9.8 +	void draw() const;
     9.9  };
    9.10  
    9.11  class LevelMap {
    10.1 --- a/src/game_part.cc	Wed May 23 07:25:43 2012 +0300
    10.2 +++ b/src/game_part.cc	Wed May 23 17:10:46 2012 +0300
    10.3 @@ -1,3 +1,4 @@
    10.4 +#include <stdlib.h>
    10.5  #include "opengl.h"
    10.6  #include "game_part.h"
    10.7  #include "level.h"
    10.8 @@ -12,32 +13,39 @@
    10.9  	return true;
   10.10  }
   10.11  
   10.12 +void Game::start()
   10.13 +{
   10.14 +	Part::start();
   10.15 +
   10.16 +	glEnable(GL_DEPTH_TEST);
   10.17 +}
   10.18 +
   10.19  void Game::draw() const
   10.20  {
   10.21 -	glClear(GL_COLOR_BUFFER_BIT);
   10.22 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   10.23  
   10.24  	glMatrixMode(GL_MODELVIEW);
   10.25  	glLoadIdentity();
   10.26 -	glRotatef(current_time / 100.0, 0, 0, 1);
   10.27 -	glScalef(0.5, 0.5, 1);
   10.28 +	glTranslatef(0, 0, -4);
   10.29 +	glRotatef(50, 1, 0, 0);
   10.30 +	glRotatef(current_time / 100.0, 0, 1, 0);
   10.31  
   10.32 -	glBegin(GL_QUADS);
   10.33 -	glColor3f(1, 0, 0);
   10.34 -	glVertex2f(-1, -1);
   10.35 -	glColor3f(0, 1, 0);
   10.36 -	glVertex2f(1, -1);
   10.37 -	glColor3f(0, 0, 1);
   10.38 -	glVertex2f(1, 1);
   10.39 -	glColor3f(1, 0, 1);
   10.40 -	glVertex2f(-1, 1);
   10.41 -	glEnd();
   10.42 +	level.draw();
   10.43 +}
   10.44 +
   10.45 +void Game::reshape(int x, int y)
   10.46 +{
   10.47 +	glMatrixMode(GL_PROJECTION);
   10.48 +	glLoadIdentity();
   10.49 +	gluPerspective(45.0, (float)x / (float)y, 0.5, 500);
   10.50  }
   10.51  
   10.52  void Game::key(int key, bool pressed)
   10.53  {
   10.54  	switch(key) {
   10.55  	case 27:
   10.56 -		cur_part = menu_part;
   10.57 +		exit(0);
   10.58 +		//cur_part = menu_part;
   10.59  		break;
   10.60  
   10.61  	default:
    11.1 --- a/src/game_part.h	Wed May 23 07:25:43 2012 +0300
    11.2 +++ b/src/game_part.h	Wed May 23 17:10:46 2012 +0300
    11.3 @@ -12,7 +12,10 @@
    11.4  
    11.5  	bool init();
    11.6  
    11.7 +	void start();
    11.8 +
    11.9  	void draw() const;
   11.10 +	void reshape(int x, int y);
   11.11  	void key(int key, bool pressed);
   11.12  };
   11.13  
    12.1 --- a/src/main.cc	Wed May 23 07:25:43 2012 +0300
    12.2 +++ b/src/main.cc	Wed May 23 17:10:46 2012 +0300
    12.3 @@ -62,7 +62,8 @@
    12.4  		return false;
    12.5  	}
    12.6  
    12.7 -	cur_part = menu_part;
    12.8 +	//menu_part->start();
    12.9 +	game_part->start();
   12.10  	return true;
   12.11  }
   12.12  
    13.1 --- a/src/opengl.h	Wed May 23 07:25:43 2012 +0300
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,12 +0,0 @@
    13.4 -#ifndef OPENGL_H_
    13.5 -#define OPENGL_H_
    13.6 -
    13.7 -#include <GL/glew.h>
    13.8 -
    13.9 -#ifdef __APPLE__
   13.10 -#include <GLUT/glut.h>
   13.11 -#else
   13.12 -#include <GL/glut.h>
   13.13 -#endif
   13.14 -
   13.15 -#endif	/* OPENGL_H_ */
    14.1 --- a/src/part.cc	Wed May 23 07:25:43 2012 +0300
    14.2 +++ b/src/part.cc	Wed May 23 17:10:46 2012 +0300
    14.3 @@ -13,6 +13,16 @@
    14.4  	return true;
    14.5  }
    14.6  
    14.7 +void Part::start()
    14.8 +{
    14.9 +	if(cur_part) {
   14.10 +		cur_part->stop();
   14.11 +	}
   14.12 +	cur_part = this;
   14.13 +}
   14.14 +
   14.15 +void Part::stop() {}
   14.16 +
   14.17  void Part::update(unsigned long msec)
   14.18  {
   14.19  	current_time = msec;
    15.1 --- a/src/part.h	Wed May 23 07:25:43 2012 +0300
    15.2 +++ b/src/part.h	Wed May 23 17:10:46 2012 +0300
    15.3 @@ -15,6 +15,9 @@
    15.4  
    15.5  	virtual bool init();
    15.6  
    15.7 +	virtual void start();
    15.8 +	virtual void stop();
    15.9 +
   15.10  	virtual void update(unsigned long msec);
   15.11  	virtual void draw() const = 0;
   15.12