vrchess

changeset 2:879194e4b1f0

fixed line-endings
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Apr 2014 05:44:09 +0300
parents cd7755e4663a
children a797e426e309
files src/game.cc src/game.h src/image.cc src/image.h src/main.cc src/texture.cc src/texture.h
diffstat 7 files changed, 538 insertions(+), 538 deletions(-) [+]
line diff
     1.1 --- a/src/game.cc	Fri Apr 25 05:43:26 2014 +0300
     1.2 +++ b/src/game.cc	Fri Apr 25 05:44:09 2014 +0300
     1.3 @@ -1,180 +1,180 @@
     1.4 -#include "game.h"
     1.5 -#include "opengl.h"
     1.6 -#include "camera.h"
     1.7 -#include "texture.h"
     1.8 -//#include "OVR_CAPI_GL.h"
     1.9 -
    1.10 -static void draw_scene();
    1.11 -
    1.12 -static const float move_speed = 10.0f;
    1.13 -
    1.14 -static int fb_width, fb_height;
    1.15 -static FlyCamera cam;
    1.16 -static Texture floor_tex;
    1.17 -static bool keystate[256];
    1.18 -
    1.19 -bool game_init()
    1.20 -{
    1.21 -	glEnable(GL_DEPTH_TEST);
    1.22 -	glEnable(GL_CULL_FACE);
    1.23 -	glEnable(GL_LIGHTING);
    1.24 -	glEnable(GL_LIGHT0);
    1.25 -
    1.26 -	glClearColor(0.1, 0.1, 0.1, 1);
    1.27 -
    1.28 -	if(!floor_tex.load("data/tiles.png")) {
    1.29 -		return false;
    1.30 -	}
    1.31 -
    1.32 -	cam.input_move(0, 0, 5);
    1.33 -	return true;
    1.34 -}
    1.35 -
    1.36 -void game_cleanup()
    1.37 -{
    1.38 -	floor_tex.destroy();
    1.39 -}
    1.40 -
    1.41 -
    1.42 -void game_update(unsigned int msec)
    1.43 -{
    1.44 -	static unsigned int prev_msec;
    1.45 -	float dt = (msec - prev_msec) / 1000.0f;
    1.46 -	float offs = dt * move_speed;
    1.47 -	prev_msec = msec;
    1.48 -
    1.49 -	Vector3 move;
    1.50 -	float roll = 0.0f;
    1.51 -
    1.52 -	if(keystate['d'] || keystate['D']) {
    1.53 -		move.x += offs;
    1.54 -	}
    1.55 -	if(keystate['a'] || keystate['A']) {
    1.56 -		move.x -= offs;
    1.57 -	}
    1.58 -	if(keystate['s'] || keystate['S']) {
    1.59 -		move.z += offs;
    1.60 -	}
    1.61 -	if(keystate['w'] || keystate['W']) {
    1.62 -		move.z -= offs;
    1.63 -	}
    1.64 -	if(keystate['e'] || keystate['E']) {
    1.65 -		roll += dt;
    1.66 -	}
    1.67 -	if(keystate['q'] || keystate['Q']) {
    1.68 -		roll -= dt;
    1.69 -	}
    1.70 -
    1.71 -	cam.input_move(move.x, move.y, move.z);
    1.72 -	cam.input_rotate(0, 0, roll);
    1.73 -}
    1.74 -
    1.75 -void game_render(int eye)
    1.76 -{
    1.77 -	Matrix4x4 view_matrix = cam.get_matrix().inverse();
    1.78 -
    1.79 -	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.80 -
    1.81 -	glMatrixMode(GL_PROJECTION);
    1.82 -	glLoadIdentity();
    1.83 -	gluPerspective(60.0, (float)fb_width / (float)fb_height, 0.5, 500.0);
    1.84 -
    1.85 -	glMatrixMode(GL_MODELVIEW);
    1.86 -	glLoadIdentity();
    1.87 -	glLoadTransposeMatrixf(view_matrix[0]);
    1.88 -
    1.89 -	draw_scene();
    1.90 -}
    1.91 -
    1.92 -void game_reshape(int x, int y)
    1.93 -{
    1.94 -	glViewport(0, 0, x, y);
    1.95 -	fb_width = x;
    1.96 -	fb_height = y;
    1.97 -}
    1.98 -
    1.99 -void game_keyboard(int key, bool pressed, int x, int y)
   1.100 -{
   1.101 -	if(pressed) {
   1.102 -		switch(key) {
   1.103 -		case 27:
   1.104 -			exit(0);
   1.105 -		}
   1.106 -	}
   1.107 -
   1.108 -	if(key < 256) {
   1.109 -		keystate[key] = pressed;
   1.110 -	}
   1.111 -}
   1.112 -
   1.113 -static int prev_x, prev_y;
   1.114 -static bool bnstate[32];
   1.115 -
   1.116 -void game_mouse(int bn, bool pressed, int x, int y)
   1.117 -{
   1.118 -	bnstate[bn] = pressed;
   1.119 -	prev_x = x;
   1.120 -	prev_y = y;
   1.121 -}
   1.122 -
   1.123 -void game_motion(int x, int y)
   1.124 -{
   1.125 -	int dx = x - prev_x;
   1.126 -	int dy = y - prev_y;
   1.127 -	prev_x = x;
   1.128 -	prev_y = y;
   1.129 -
   1.130 -	if(!dx && !dy) return;
   1.131 -
   1.132 -	if(bnstate[0]) {
   1.133 -		float xrot = dy * 0.5;
   1.134 -		float yrot = dx * 0.5;
   1.135 -		cam.input_rotate(DEG_TO_RAD(xrot), 0, 0);
   1.136 -		cam.input_rotate(0, DEG_TO_RAD(yrot), 0);
   1.137 -	}
   1.138 -}
   1.139 -
   1.140 -void game_6dof_move(float x, float y, float z)
   1.141 -{
   1.142 -	cam.input_move(x, y, z);
   1.143 -}
   1.144 -
   1.145 -void game_6dof_rotate(float x, float y, float z)
   1.146 -{
   1.147 -	cam.input_rotate(x, y, z);
   1.148 -}
   1.149 -
   1.150 -static void draw_scene()
   1.151 -{
   1.152 -	glMatrixMode(GL_MODELVIEW);
   1.153 -	glTranslatef(0, -1.5, 0);
   1.154 -
   1.155 -	float lpos[] = {-20, 30, 10, 1};
   1.156 -	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
   1.157 -
   1.158 -	glEnable(GL_TEXTURE_2D);
   1.159 -	floor_tex.bind();
   1.160 -
   1.161 -	glMatrixMode(GL_TEXTURE);
   1.162 -	glScalef(8, 8, 8);
   1.163 -
   1.164 -	glBegin(GL_QUADS);
   1.165 -	glNormal3f(0, 1, 0);
   1.166 -	glTexCoord2f(0, 0); glVertex3f(-25, 0, 25);
   1.167 -	glTexCoord2f(1, 0); glVertex3f(25, 0, 25);
   1.168 -	glTexCoord2f(1, 1); glVertex3f(25, 0, -25);
   1.169 -	glTexCoord2f(0, 1); glVertex3f(-25, 0, -25);
   1.170 -	glEnd();
   1.171 -	glDisable(GL_TEXTURE_2D);
   1.172 -	glLoadIdentity();
   1.173 -
   1.174 -	glMatrixMode(GL_MODELVIEW);
   1.175 -	glPushMatrix();
   1.176 -	glTranslatef(0, 0.75, 0);
   1.177 -
   1.178 -	glFrontFace(GL_CW);
   1.179 -	glutSolidTeapot(1.0);
   1.180 -	glFrontFace(GL_CCW);
   1.181 -
   1.182 -	glPopMatrix();
   1.183 -}
   1.184 +#include "game.h"
   1.185 +#include "opengl.h"
   1.186 +#include "camera.h"
   1.187 +#include "texture.h"
   1.188 +//#include "OVR_CAPI_GL.h"
   1.189 +
   1.190 +static void draw_scene();
   1.191 +
   1.192 +static const float move_speed = 10.0f;
   1.193 +
   1.194 +static int fb_width, fb_height;
   1.195 +static FlyCamera cam;
   1.196 +static Texture floor_tex;
   1.197 +static bool keystate[256];
   1.198 +
   1.199 +bool game_init()
   1.200 +{
   1.201 +	glEnable(GL_DEPTH_TEST);
   1.202 +	glEnable(GL_CULL_FACE);
   1.203 +	glEnable(GL_LIGHTING);
   1.204 +	glEnable(GL_LIGHT0);
   1.205 +
   1.206 +	glClearColor(0.1, 0.1, 0.1, 1);
   1.207 +
   1.208 +	if(!floor_tex.load("data/tiles.png")) {
   1.209 +		return false;
   1.210 +	}
   1.211 +
   1.212 +	cam.input_move(0, 0, 5);
   1.213 +	return true;
   1.214 +}
   1.215 +
   1.216 +void game_cleanup()
   1.217 +{
   1.218 +	floor_tex.destroy();
   1.219 +}
   1.220 +
   1.221 +
   1.222 +void game_update(unsigned int msec)
   1.223 +{
   1.224 +	static unsigned int prev_msec;
   1.225 +	float dt = (msec - prev_msec) / 1000.0f;
   1.226 +	float offs = dt * move_speed;
   1.227 +	prev_msec = msec;
   1.228 +
   1.229 +	Vector3 move;
   1.230 +	float roll = 0.0f;
   1.231 +
   1.232 +	if(keystate['d'] || keystate['D']) {
   1.233 +		move.x += offs;
   1.234 +	}
   1.235 +	if(keystate['a'] || keystate['A']) {
   1.236 +		move.x -= offs;
   1.237 +	}
   1.238 +	if(keystate['s'] || keystate['S']) {
   1.239 +		move.z += offs;
   1.240 +	}
   1.241 +	if(keystate['w'] || keystate['W']) {
   1.242 +		move.z -= offs;
   1.243 +	}
   1.244 +	if(keystate['e'] || keystate['E']) {
   1.245 +		roll += dt;
   1.246 +	}
   1.247 +	if(keystate['q'] || keystate['Q']) {
   1.248 +		roll -= dt;
   1.249 +	}
   1.250 +
   1.251 +	cam.input_move(move.x, move.y, move.z);
   1.252 +	cam.input_rotate(0, 0, roll);
   1.253 +}
   1.254 +
   1.255 +void game_render(int eye)
   1.256 +{
   1.257 +	Matrix4x4 view_matrix = cam.get_matrix().inverse();
   1.258 +
   1.259 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   1.260 +
   1.261 +	glMatrixMode(GL_PROJECTION);
   1.262 +	glLoadIdentity();
   1.263 +	gluPerspective(60.0, (float)fb_width / (float)fb_height, 0.5, 500.0);
   1.264 +
   1.265 +	glMatrixMode(GL_MODELVIEW);
   1.266 +	glLoadIdentity();
   1.267 +	glLoadTransposeMatrixf(view_matrix[0]);
   1.268 +
   1.269 +	draw_scene();
   1.270 +}
   1.271 +
   1.272 +void game_reshape(int x, int y)
   1.273 +{
   1.274 +	glViewport(0, 0, x, y);
   1.275 +	fb_width = x;
   1.276 +	fb_height = y;
   1.277 +}
   1.278 +
   1.279 +void game_keyboard(int key, bool pressed, int x, int y)
   1.280 +{
   1.281 +	if(pressed) {
   1.282 +		switch(key) {
   1.283 +		case 27:
   1.284 +			exit(0);
   1.285 +		}
   1.286 +	}
   1.287 +
   1.288 +	if(key < 256) {
   1.289 +		keystate[key] = pressed;
   1.290 +	}
   1.291 +}
   1.292 +
   1.293 +static int prev_x, prev_y;
   1.294 +static bool bnstate[32];
   1.295 +
   1.296 +void game_mouse(int bn, bool pressed, int x, int y)
   1.297 +{
   1.298 +	bnstate[bn] = pressed;
   1.299 +	prev_x = x;
   1.300 +	prev_y = y;
   1.301 +}
   1.302 +
   1.303 +void game_motion(int x, int y)
   1.304 +{
   1.305 +	int dx = x - prev_x;
   1.306 +	int dy = y - prev_y;
   1.307 +	prev_x = x;
   1.308 +	prev_y = y;
   1.309 +
   1.310 +	if(!dx && !dy) return;
   1.311 +
   1.312 +	if(bnstate[0]) {
   1.313 +		float xrot = dy * 0.5;
   1.314 +		float yrot = dx * 0.5;
   1.315 +		cam.input_rotate(DEG_TO_RAD(xrot), 0, 0);
   1.316 +		cam.input_rotate(0, DEG_TO_RAD(yrot), 0);
   1.317 +	}
   1.318 +}
   1.319 +
   1.320 +void game_6dof_move(float x, float y, float z)
   1.321 +{
   1.322 +	cam.input_move(x, y, z);
   1.323 +}
   1.324 +
   1.325 +void game_6dof_rotate(float x, float y, float z)
   1.326 +{
   1.327 +	cam.input_rotate(x, y, z);
   1.328 +}
   1.329 +
   1.330 +static void draw_scene()
   1.331 +{
   1.332 +	glMatrixMode(GL_MODELVIEW);
   1.333 +	glTranslatef(0, -1.5, 0);
   1.334 +
   1.335 +	float lpos[] = {-20, 30, 10, 1};
   1.336 +	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
   1.337 +
   1.338 +	glEnable(GL_TEXTURE_2D);
   1.339 +	floor_tex.bind();
   1.340 +
   1.341 +	glMatrixMode(GL_TEXTURE);
   1.342 +	glScalef(8, 8, 8);
   1.343 +
   1.344 +	glBegin(GL_QUADS);
   1.345 +	glNormal3f(0, 1, 0);
   1.346 +	glTexCoord2f(0, 0); glVertex3f(-25, 0, 25);
   1.347 +	glTexCoord2f(1, 0); glVertex3f(25, 0, 25);
   1.348 +	glTexCoord2f(1, 1); glVertex3f(25, 0, -25);
   1.349 +	glTexCoord2f(0, 1); glVertex3f(-25, 0, -25);
   1.350 +	glEnd();
   1.351 +	glDisable(GL_TEXTURE_2D);
   1.352 +	glLoadIdentity();
   1.353 +
   1.354 +	glMatrixMode(GL_MODELVIEW);
   1.355 +	glPushMatrix();
   1.356 +	glTranslatef(0, 0.75, 0);
   1.357 +
   1.358 +	glFrontFace(GL_CW);
   1.359 +	glutSolidTeapot(1.0);
   1.360 +	glFrontFace(GL_CCW);
   1.361 +
   1.362 +	glPopMatrix();
   1.363 +}
     2.1 --- a/src/game.h	Fri Apr 25 05:43:26 2014 +0300
     2.2 +++ b/src/game.h	Fri Apr 25 05:44:09 2014 +0300
     2.3 @@ -1,18 +1,18 @@
     2.4 -#ifndef GAME_H_
     2.5 -#define GAME_H_
     2.6 -
     2.7 -bool game_init();
     2.8 -void game_cleanup();
     2.9 -
    2.10 -void game_update(unsigned int msec);
    2.11 -void game_render(int eye);
    2.12 -
    2.13 -void game_reshape(int x, int y);
    2.14 -void game_keyboard(int key, bool pressed, int x, int y);
    2.15 -void game_mouse(int bn, bool pressed, int x, int y);
    2.16 -void game_motion(int x, int y);
    2.17 -
    2.18 -void game_6dof_move(float x, float y, float z);
    2.19 -void game_6dof_rotate(float x, float y, float z);
    2.20 -
    2.21 -#endif	// GAME_H_
    2.22 \ No newline at end of file
    2.23 +#ifndef GAME_H_
    2.24 +#define GAME_H_
    2.25 +
    2.26 +bool game_init();
    2.27 +void game_cleanup();
    2.28 +
    2.29 +void game_update(unsigned int msec);
    2.30 +void game_render(int eye);
    2.31 +
    2.32 +void game_reshape(int x, int y);
    2.33 +void game_keyboard(int key, bool pressed, int x, int y);
    2.34 +void game_mouse(int bn, bool pressed, int x, int y);
    2.35 +void game_motion(int x, int y);
    2.36 +
    2.37 +void game_6dof_move(float x, float y, float z);
    2.38 +void game_6dof_rotate(float x, float y, float z);
    2.39 +
    2.40 +#endif	// GAME_H_
     3.1 --- a/src/image.cc	Fri Apr 25 05:43:26 2014 +0300
     3.2 +++ b/src/image.cc	Fri Apr 25 05:44:09 2014 +0300
     3.3 @@ -1,94 +1,94 @@
     3.4 -#include <string.h>
     3.5 -#include "imago2.h"
     3.6 -#include "image.h"
     3.7 -
     3.8 -Image::Image()
     3.9 -{
    3.10 -	pixels = 0;
    3.11 -	own_pixels = true;
    3.12 -	width = height = 0;
    3.13 -}
    3.14 -
    3.15 -Image::~Image()
    3.16 -{
    3.17 -	destroy();
    3.18 -}
    3.19 -
    3.20 -Image::Image(const Image &img)
    3.21 -{
    3.22 -	pixels = 0;
    3.23 -	own_pixels = false;
    3.24 -
    3.25 -	create(img.width, img.height, img.pixels);
    3.26 -}
    3.27 -
    3.28 -Image &Image::operator =(const Image &img)
    3.29 -{
    3.30 -	if(this != &img) {
    3.31 -		destroy();
    3.32 -		create(img.width, img.height, img.pixels);
    3.33 -	}
    3.34 -	return *this;
    3.35 -}
    3.36 -
    3.37 -void Image::create(int xsz, int ysz, unsigned char *pixels)
    3.38 -{
    3.39 -	destroy();
    3.40 -
    3.41 -	this->pixels = new unsigned char[xsz * ysz * 4];
    3.42 -	if(pixels) {
    3.43 -		memcpy(this->pixels, pixels, xsz * ysz * 4);
    3.44 -	} else {
    3.45 -		memset(this->pixels, 0, xsz * ysz * 4);
    3.46 -	}
    3.47 -	width = xsz;
    3.48 -	height = ysz;
    3.49 -	own_pixels = true;
    3.50 -}
    3.51 -
    3.52 -void Image::destroy()
    3.53 -{
    3.54 -	if(own_pixels) {
    3.55 -		delete [] pixels;
    3.56 -	}
    3.57 -	pixels = 0;
    3.58 -	width = height = 0;
    3.59 -	own_pixels = true;
    3.60 -}
    3.61 -
    3.62 -int Image::get_width() const
    3.63 -{
    3.64 -	return width;
    3.65 -}
    3.66 -
    3.67 -int Image::get_height() const
    3.68 -{
    3.69 -	return height;
    3.70 -}
    3.71 -
    3.72 -void Image::set_pixels(int xsz, int ysz, unsigned char *pixels)
    3.73 -{
    3.74 -	destroy();
    3.75 -
    3.76 -	this->pixels = pixels;
    3.77 -	width = xsz;
    3.78 -	height = ysz;
    3.79 -	own_pixels = false;
    3.80 -}
    3.81 -
    3.82 -unsigned char *Image::get_pixels() const
    3.83 -{
    3.84 -	return pixels;
    3.85 -}
    3.86 -
    3.87 -bool Image::load(const char *fname)
    3.88 -{
    3.89 -	int xsz, ysz;
    3.90 -	unsigned char *pix = (unsigned char*)img_load_pixels(fname, &xsz, &ysz);
    3.91 -	if(!pix) {
    3.92 -		return false;
    3.93 -	}
    3.94 -
    3.95 -	create(xsz, ysz, pix);
    3.96 -	return true;
    3.97 -}
    3.98 \ No newline at end of file
    3.99 +#include <string.h>
   3.100 +#include "imago2.h"
   3.101 +#include "image.h"
   3.102 +
   3.103 +Image::Image()
   3.104 +{
   3.105 +	pixels = 0;
   3.106 +	own_pixels = true;
   3.107 +	width = height = 0;
   3.108 +}
   3.109 +
   3.110 +Image::~Image()
   3.111 +{
   3.112 +	destroy();
   3.113 +}
   3.114 +
   3.115 +Image::Image(const Image &img)
   3.116 +{
   3.117 +	pixels = 0;
   3.118 +	own_pixels = false;
   3.119 +
   3.120 +	create(img.width, img.height, img.pixels);
   3.121 +}
   3.122 +
   3.123 +Image &Image::operator =(const Image &img)
   3.124 +{
   3.125 +	if(this != &img) {
   3.126 +		destroy();
   3.127 +		create(img.width, img.height, img.pixels);
   3.128 +	}
   3.129 +	return *this;
   3.130 +}
   3.131 +
   3.132 +void Image::create(int xsz, int ysz, unsigned char *pixels)
   3.133 +{
   3.134 +	destroy();
   3.135 +
   3.136 +	this->pixels = new unsigned char[xsz * ysz * 4];
   3.137 +	if(pixels) {
   3.138 +		memcpy(this->pixels, pixels, xsz * ysz * 4);
   3.139 +	} else {
   3.140 +		memset(this->pixels, 0, xsz * ysz * 4);
   3.141 +	}
   3.142 +	width = xsz;
   3.143 +	height = ysz;
   3.144 +	own_pixels = true;
   3.145 +}
   3.146 +
   3.147 +void Image::destroy()
   3.148 +{
   3.149 +	if(own_pixels) {
   3.150 +		delete [] pixels;
   3.151 +	}
   3.152 +	pixels = 0;
   3.153 +	width = height = 0;
   3.154 +	own_pixels = true;
   3.155 +}
   3.156 +
   3.157 +int Image::get_width() const
   3.158 +{
   3.159 +	return width;
   3.160 +}
   3.161 +
   3.162 +int Image::get_height() const
   3.163 +{
   3.164 +	return height;
   3.165 +}
   3.166 +
   3.167 +void Image::set_pixels(int xsz, int ysz, unsigned char *pixels)
   3.168 +{
   3.169 +	destroy();
   3.170 +
   3.171 +	this->pixels = pixels;
   3.172 +	width = xsz;
   3.173 +	height = ysz;
   3.174 +	own_pixels = false;
   3.175 +}
   3.176 +
   3.177 +unsigned char *Image::get_pixels() const
   3.178 +{
   3.179 +	return pixels;
   3.180 +}
   3.181 +
   3.182 +bool Image::load(const char *fname)
   3.183 +{
   3.184 +	int xsz, ysz;
   3.185 +	unsigned char *pix = (unsigned char*)img_load_pixels(fname, &xsz, &ysz);
   3.186 +	if(!pix) {
   3.187 +		return false;
   3.188 +	}
   3.189 +
   3.190 +	create(xsz, ysz, pix);
   3.191 +	return true;
   3.192 +}
     4.1 --- a/src/image.h	Fri Apr 25 05:43:26 2014 +0300
     4.2 +++ b/src/image.h	Fri Apr 25 05:44:09 2014 +0300
     4.3 @@ -1,29 +1,29 @@
     4.4 -#ifndef IMAGE_H_
     4.5 -#define IMAGE_H_
     4.6 -
     4.7 -class Image {
     4.8 -private:
     4.9 -	int width, height;
    4.10 -	unsigned char *pixels;
    4.11 -	bool own_pixels;
    4.12 -
    4.13 -public:
    4.14 -	Image();
    4.15 -	~Image();
    4.16 -
    4.17 -	Image(const Image &img);
    4.18 -	Image &operator =(const Image &img);
    4.19 -
    4.20 -	void create(int xsz, int ysz, unsigned char *pix = 0);
    4.21 -	void destroy();
    4.22 -
    4.23 -	int get_width() const;
    4.24 -	int get_height() const;
    4.25 -
    4.26 -	void set_pixels(int xsz, int ysz, unsigned char *pix);
    4.27 -	unsigned char *get_pixels() const;
    4.28 -
    4.29 -	bool load(const char *fname);
    4.30 -};
    4.31 -
    4.32 -#endif	// IMAGE_H_
    4.33 \ No newline at end of file
    4.34 +#ifndef IMAGE_H_
    4.35 +#define IMAGE_H_
    4.36 +
    4.37 +class Image {
    4.38 +private:
    4.39 +	int width, height;
    4.40 +	unsigned char *pixels;
    4.41 +	bool own_pixels;
    4.42 +
    4.43 +public:
    4.44 +	Image();
    4.45 +	~Image();
    4.46 +
    4.47 +	Image(const Image &img);
    4.48 +	Image &operator =(const Image &img);
    4.49 +
    4.50 +	void create(int xsz, int ysz, unsigned char *pix = 0);
    4.51 +	void destroy();
    4.52 +
    4.53 +	int get_width() const;
    4.54 +	int get_height() const;
    4.55 +
    4.56 +	void set_pixels(int xsz, int ysz, unsigned char *pix);
    4.57 +	unsigned char *get_pixels() const;
    4.58 +
    4.59 +	bool load(const char *fname);
    4.60 +};
    4.61 +
    4.62 +#endif	// IMAGE_H_
     5.1 --- a/src/main.cc	Fri Apr 25 05:43:26 2014 +0300
     5.2 +++ b/src/main.cc	Fri Apr 25 05:44:09 2014 +0300
     5.3 @@ -1,111 +1,111 @@
     5.4 -#include <stdio.h>
     5.5 -#include <stdlib.h>
     5.6 -#include "opengl.h"
     5.7 -#include "game.h"
     5.8 -
     5.9 -static bool init();
    5.10 -static void cleanup();
    5.11 -
    5.12 -static void display();
    5.13 -static void idle();
    5.14 -static void reshape(int x, int y);
    5.15 -static void keyb(unsigned char key, int x, int y);
    5.16 -static void keyb_up(unsigned char key, int x, int y);
    5.17 -static void mouse(int bn, int st, int x, int y);
    5.18 -static void motion(int x, int y);
    5.19 -static void sball_motion(int x, int y, int z);
    5.20 -static void sball_rotate(int x, int y, int z);
    5.21 -
    5.22 -int main(int argc, char **argv)
    5.23 -{
    5.24 -	glutInitWindowSize(1024, 600);
    5.25 -	glutInit(&argc, argv);
    5.26 -	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    5.27 -	glutCreateWindow("VR Chess");
    5.28 -
    5.29 -	glutDisplayFunc(display);
    5.30 -	glutIdleFunc(idle);
    5.31 -	glutReshapeFunc(reshape);
    5.32 -	glutKeyboardFunc(keyb);
    5.33 -	glutKeyboardUpFunc(keyb_up);
    5.34 -	glutMouseFunc(mouse);
    5.35 -	glutMotionFunc(motion);
    5.36 -	glutSpaceballMotionFunc(sball_motion);
    5.37 -	glutSpaceballRotateFunc(sball_rotate);
    5.38 -
    5.39 -	if(!init()) {
    5.40 -		return 1;
    5.41 -	}
    5.42 -	atexit(cleanup);
    5.43 -
    5.44 -	glutMainLoop();
    5.45 -	return 0;
    5.46 -}
    5.47 -
    5.48 -static bool init()
    5.49 -{
    5.50 -	glewInit();
    5.51 -
    5.52 -	if(!game_init()) {
    5.53 -		return false;
    5.54 -	}
    5.55 -	return true;
    5.56 -}
    5.57 -
    5.58 -static void cleanup()
    5.59 -{
    5.60 -	game_cleanup();
    5.61 -}
    5.62 -
    5.63 -static void display()
    5.64 -{
    5.65 -	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    5.66 -
    5.67 -	game_update(msec);
    5.68 -	game_render(0);
    5.69 -
    5.70 -	glutSwapBuffers();
    5.71 -}
    5.72 -
    5.73 -static void idle()
    5.74 -{
    5.75 -	glutPostRedisplay();
    5.76 -}
    5.77 -
    5.78 -static void reshape(int x, int y)
    5.79 -{
    5.80 -	game_reshape(x, y);
    5.81 -}
    5.82 -
    5.83 -static void keyb(unsigned char key, int x, int y)
    5.84 -{
    5.85 -	game_keyboard(key, true, x, y);
    5.86 -}
    5.87 -
    5.88 -static void keyb_up(unsigned char key, int x, int y)
    5.89 -{
    5.90 -	game_keyboard(key, false, x, y);
    5.91 -}
    5.92 -
    5.93 -static void mouse(int bn, int st, int x, int y)
    5.94 -{
    5.95 -	game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
    5.96 -}
    5.97 -
    5.98 -static void motion(int x, int y)
    5.99 -{
   5.100 -	game_motion(x, y);
   5.101 -}
   5.102 -
   5.103 -#define SBALL_MOVE_SCALE	0.00025
   5.104 -#define SBALL_ROT_SCALE		0.01
   5.105 -
   5.106 -static void sball_motion(int x, int y, int z)
   5.107 -{
   5.108 -	game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
   5.109 -}
   5.110 -
   5.111 -static void sball_rotate(int x, int y, int z)
   5.112 -{
   5.113 -	game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
   5.114 -}
   5.115 \ No newline at end of file
   5.116 +#include <stdio.h>
   5.117 +#include <stdlib.h>
   5.118 +#include "opengl.h"
   5.119 +#include "game.h"
   5.120 +
   5.121 +static bool init();
   5.122 +static void cleanup();
   5.123 +
   5.124 +static void display();
   5.125 +static void idle();
   5.126 +static void reshape(int x, int y);
   5.127 +static void keyb(unsigned char key, int x, int y);
   5.128 +static void keyb_up(unsigned char key, int x, int y);
   5.129 +static void mouse(int bn, int st, int x, int y);
   5.130 +static void motion(int x, int y);
   5.131 +static void sball_motion(int x, int y, int z);
   5.132 +static void sball_rotate(int x, int y, int z);
   5.133 +
   5.134 +int main(int argc, char **argv)
   5.135 +{
   5.136 +	glutInitWindowSize(1024, 600);
   5.137 +	glutInit(&argc, argv);
   5.138 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
   5.139 +	glutCreateWindow("VR Chess");
   5.140 +
   5.141 +	glutDisplayFunc(display);
   5.142 +	glutIdleFunc(idle);
   5.143 +	glutReshapeFunc(reshape);
   5.144 +	glutKeyboardFunc(keyb);
   5.145 +	glutKeyboardUpFunc(keyb_up);
   5.146 +	glutMouseFunc(mouse);
   5.147 +	glutMotionFunc(motion);
   5.148 +	glutSpaceballMotionFunc(sball_motion);
   5.149 +	glutSpaceballRotateFunc(sball_rotate);
   5.150 +
   5.151 +	if(!init()) {
   5.152 +		return 1;
   5.153 +	}
   5.154 +	atexit(cleanup);
   5.155 +
   5.156 +	glutMainLoop();
   5.157 +	return 0;
   5.158 +}
   5.159 +
   5.160 +static bool init()
   5.161 +{
   5.162 +	glewInit();
   5.163 +
   5.164 +	if(!game_init()) {
   5.165 +		return false;
   5.166 +	}
   5.167 +	return true;
   5.168 +}
   5.169 +
   5.170 +static void cleanup()
   5.171 +{
   5.172 +	game_cleanup();
   5.173 +}
   5.174 +
   5.175 +static void display()
   5.176 +{
   5.177 +	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
   5.178 +
   5.179 +	game_update(msec);
   5.180 +	game_render(0);
   5.181 +
   5.182 +	glutSwapBuffers();
   5.183 +}
   5.184 +
   5.185 +static void idle()
   5.186 +{
   5.187 +	glutPostRedisplay();
   5.188 +}
   5.189 +
   5.190 +static void reshape(int x, int y)
   5.191 +{
   5.192 +	game_reshape(x, y);
   5.193 +}
   5.194 +
   5.195 +static void keyb(unsigned char key, int x, int y)
   5.196 +{
   5.197 +	game_keyboard(key, true, x, y);
   5.198 +}
   5.199 +
   5.200 +static void keyb_up(unsigned char key, int x, int y)
   5.201 +{
   5.202 +	game_keyboard(key, false, x, y);
   5.203 +}
   5.204 +
   5.205 +static void mouse(int bn, int st, int x, int y)
   5.206 +{
   5.207 +	game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
   5.208 +}
   5.209 +
   5.210 +static void motion(int x, int y)
   5.211 +{
   5.212 +	game_motion(x, y);
   5.213 +}
   5.214 +
   5.215 +#define SBALL_MOVE_SCALE	0.00025
   5.216 +#define SBALL_ROT_SCALE		0.01
   5.217 +
   5.218 +static void sball_motion(int x, int y, int z)
   5.219 +{
   5.220 +	game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
   5.221 +}
   5.222 +
   5.223 +static void sball_rotate(int x, int y, int z)
   5.224 +{
   5.225 +	game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
   5.226 +}
     6.1 --- a/src/texture.cc	Fri Apr 25 05:43:26 2014 +0300
     6.2 +++ b/src/texture.cc	Fri Apr 25 05:44:09 2014 +0300
     6.3 @@ -1,77 +1,77 @@
     6.4 -#include "texture.h"
     6.5 -#include "opengl.h"
     6.6 -
     6.7 -Texture::Texture()
     6.8 -{
     6.9 -	tex = 0;
    6.10 -	type = GL_TEXTURE_2D;
    6.11 -}
    6.12 -
    6.13 -Texture::~Texture()
    6.14 -{
    6.15 -	destroy();
    6.16 -}
    6.17 -
    6.18 -void Texture::create2d(int xsz, int ysz)
    6.19 -{
    6.20 -	destroy();
    6.21 -
    6.22 -	type = GL_TEXTURE_2D;
    6.23 -	img.create(xsz, ysz);
    6.24 -
    6.25 -	if(!tex) {
    6.26 -		glGenTextures(1, &tex);
    6.27 -	}
    6.28 -	glBindTexture(type, tex);
    6.29 -	glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    6.30 -	glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    6.31 -	glTexImage2D(type, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    6.32 -}
    6.33 -
    6.34 -void Texture::destroy()
    6.35 -{
    6.36 -	if(tex) {
    6.37 -		glDeleteTextures(1, &tex);
    6.38 -	}
    6.39 -}
    6.40 -
    6.41 -void Texture::set_image(const Image &img)
    6.42 -{
    6.43 -	this->img = img;
    6.44 -	create2d(img.get_width(), img.get_height());
    6.45 -
    6.46 -	glTexSubImage2D(type, 0, 0, 0, img.get_width(), img.get_height(),
    6.47 -			GL_RGBA, GL_UNSIGNED_BYTE, img.get_pixels());
    6.48 -}
    6.49 -
    6.50 -Image &Texture::get_image()
    6.51 -{
    6.52 -	return img;
    6.53 -}
    6.54 -
    6.55 -const Image &Texture::get_image() const
    6.56 -{
    6.57 -	return img;
    6.58 -}
    6.59 -
    6.60 -unsigned int Texture::get_texture_id() const
    6.61 -{
    6.62 -	return tex;
    6.63 -}
    6.64 -
    6.65 -void Texture::bind(int tunit) const
    6.66 -{
    6.67 -	glActiveTextureARB(GL_TEXTURE0_ARB + tunit);
    6.68 -	glBindTexture(type, tex);
    6.69 -	glActiveTextureARB(GL_TEXTURE0_ARB);
    6.70 -}
    6.71 -
    6.72 -bool Texture::load(const char *fname)
    6.73 -{
    6.74 -	Image image;
    6.75 -	if(!image.load(fname)) {
    6.76 -		return false;
    6.77 -	}
    6.78 -	set_image(image);
    6.79 -	return true;
    6.80 -}
    6.81 \ No newline at end of file
    6.82 +#include "texture.h"
    6.83 +#include "opengl.h"
    6.84 +
    6.85 +Texture::Texture()
    6.86 +{
    6.87 +	tex = 0;
    6.88 +	type = GL_TEXTURE_2D;
    6.89 +}
    6.90 +
    6.91 +Texture::~Texture()
    6.92 +{
    6.93 +	destroy();
    6.94 +}
    6.95 +
    6.96 +void Texture::create2d(int xsz, int ysz)
    6.97 +{
    6.98 +	destroy();
    6.99 +
   6.100 +	type = GL_TEXTURE_2D;
   6.101 +	img.create(xsz, ysz);
   6.102 +
   6.103 +	if(!tex) {
   6.104 +		glGenTextures(1, &tex);
   6.105 +	}
   6.106 +	glBindTexture(type, tex);
   6.107 +	glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   6.108 +	glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   6.109 +	glTexImage2D(type, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
   6.110 +}
   6.111 +
   6.112 +void Texture::destroy()
   6.113 +{
   6.114 +	if(tex) {
   6.115 +		glDeleteTextures(1, &tex);
   6.116 +	}
   6.117 +}
   6.118 +
   6.119 +void Texture::set_image(const Image &img)
   6.120 +{
   6.121 +	this->img = img;
   6.122 +	create2d(img.get_width(), img.get_height());
   6.123 +
   6.124 +	glTexSubImage2D(type, 0, 0, 0, img.get_width(), img.get_height(),
   6.125 +			GL_RGBA, GL_UNSIGNED_BYTE, img.get_pixels());
   6.126 +}
   6.127 +
   6.128 +Image &Texture::get_image()
   6.129 +{
   6.130 +	return img;
   6.131 +}
   6.132 +
   6.133 +const Image &Texture::get_image() const
   6.134 +{
   6.135 +	return img;
   6.136 +}
   6.137 +
   6.138 +unsigned int Texture::get_texture_id() const
   6.139 +{
   6.140 +	return tex;
   6.141 +}
   6.142 +
   6.143 +void Texture::bind(int tunit) const
   6.144 +{
   6.145 +	glActiveTextureARB(GL_TEXTURE0_ARB + tunit);
   6.146 +	glBindTexture(type, tex);
   6.147 +	glActiveTextureARB(GL_TEXTURE0_ARB);
   6.148 +}
   6.149 +
   6.150 +bool Texture::load(const char *fname)
   6.151 +{
   6.152 +	Image image;
   6.153 +	if(!image.load(fname)) {
   6.154 +		return false;
   6.155 +	}
   6.156 +	set_image(image);
   6.157 +	return true;
   6.158 +}
     7.1 --- a/src/texture.h	Fri Apr 25 05:43:26 2014 +0300
     7.2 +++ b/src/texture.h	Fri Apr 25 05:44:09 2014 +0300
     7.3 @@ -1,29 +1,29 @@
     7.4 -#ifndef TEXTURE_H_
     7.5 -#define TEXTURE_H_
     7.6 -
     7.7 -#include "image.h"
     7.8 -
     7.9 -class Texture {
    7.10 -private:
    7.11 -	Image img;
    7.12 -	unsigned int tex;
    7.13 -	unsigned int type;
    7.14 -
    7.15 -public:
    7.16 -	Texture();
    7.17 -	~Texture();
    7.18 -
    7.19 -	void create2d(int xsz, int ysz);
    7.20 -	void destroy();
    7.21 -
    7.22 -	void set_image(const Image &img);
    7.23 -	Image &get_image();
    7.24 -	const Image &get_image() const;
    7.25 -
    7.26 -	unsigned int get_texture_id() const;
    7.27 -	void bind(int tunit = 0) const;
    7.28 -
    7.29 -	bool load(const char *fname);
    7.30 -};
    7.31 -
    7.32 -#endif	// TEXTURE_H_
    7.33 \ No newline at end of file
    7.34 +#ifndef TEXTURE_H_
    7.35 +#define TEXTURE_H_
    7.36 +
    7.37 +#include "image.h"
    7.38 +
    7.39 +class Texture {
    7.40 +private:
    7.41 +	Image img;
    7.42 +	unsigned int tex;
    7.43 +	unsigned int type;
    7.44 +
    7.45 +public:
    7.46 +	Texture();
    7.47 +	~Texture();
    7.48 +
    7.49 +	void create2d(int xsz, int ysz);
    7.50 +	void destroy();
    7.51 +
    7.52 +	void set_image(const Image &img);
    7.53 +	Image &get_image();
    7.54 +	const Image &get_image() const;
    7.55 +
    7.56 +	unsigned int get_texture_id() const;
    7.57 +	void bind(int tunit = 0) const;
    7.58 +
    7.59 +	bool load(const char *fname);
    7.60 +};
    7.61 +
    7.62 +#endif	// TEXTURE_H_