};
void disp(void);
+void draw_scene(int eye);
void draw_field(int xcells, int ycells);
void draw_tile(int col, int row, int xcells, int ycells);
void set_view_matrix(int eye, float ipd);
void keyb(unsigned char key, int x, int y);
void save_tiles(void);
int save_tile(const char *fname, unsigned char *pixptr, int xsz, int ysz, int pitch);
+void draw_grid(void);
-static int win_width = 320;
-static int win_height = 640;
+void draw_shaft(void);
+
+static int win_width = 1280;
+static int win_height = 960;
static int grid_cols = 10;
static int grid_rows = 20;
static float aspect;
static int view = 0;
-static float eye_dist = 1.3;
+static float eye_dist_well = 0.5;
+static float eye_dist_tiles = 1.3;
+
+static int show_blocks = 0;
+static int show_stereo = 0;
+static int show_grid = 1;
int main(int argc, char **argv)
{
+ printf("press 't' to toggle block tiles\n");
+ printf("press 's' to toggle stereo\n");
+ printf("press 'g' to toggle guide grid\n");
+ printf("press space to resize to 8x8 tiles\n");
+
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(win_width, win_height);
void disp(void)
{
- glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColorMask(1, 0, 0, 0);
+ if(show_stereo) {
+ glColorMask(1, 0, 0, 0);
+ draw_scene(-1);
- set_proj_matrix(-1, eye_dist);
- set_view_matrix(-1, eye_dist);
- glTranslatef(0, 0, -1);
+ glColorMask(0, 1, 1, 0);
+ draw_scene(1);
- draw_field(grid_cols, grid_rows);
+ glColorMask(1, 1, 1, 1);
+ } else {
+ draw_scene(0);
+ }
- glColorMask(0, 1, 1, 0);
+ if(show_grid) {
+ draw_grid();
+ }
+
+ glutSwapBuffers();
+ assert(glGetError() == GL_NO_ERROR);
+}
- set_proj_matrix(1, eye_dist);
- set_view_matrix(1, eye_dist);
+void draw_scene(int eye)
+{
+ set_proj_matrix(eye, eye_dist_well);
+ set_view_matrix(eye, eye_dist_well);
glTranslatef(0, 0, -1);
+ draw_shaft();
+ set_proj_matrix(eye, eye_dist_tiles);
+ set_view_matrix(eye, eye_dist_tiles);
+ glTranslatef(0, 0, -1);
draw_field(grid_cols, grid_rows);
-
- glColorMask(1, 1, 1, 1);
-
- glutSwapBuffers();
- assert(glGetError() == GL_NO_ERROR);
}
void draw_field(int xcells, int ycells)
{
int i, j;
- for(i=0; i<ycells; i++) {
- for(j=0; j<xcells; j++) {
- draw_tile(j, i, xcells, ycells);
+ if(show_blocks) {
+ for(i=0; i<ycells; i++) {
+ for(j=0; j<xcells; j++) {
+ draw_tile(j, i, xcells, ycells);
+ }
}
}
}
-#define DX 0.4
-#define DZ 0.35
+#define DX 0.75
+#define DZ 0.45
static struct vec3 tileverts[] = {
{-1, -1, 0}, {1, -1, 0}, {1, 1, 0}, {-1, 1, 0},
void set_proj_matrix(int eye, float ipd)
{
const float offs[] = {1.0, 0.0, -1.0};
- float vpsz = 0.5;
+ float vpsz = 0.5 / (2.0 / 3.0);
float right = aspect * vpsz;
float top = vpsz;
break;
case 's':
- save_tiles();
+ show_stereo = !show_stereo;
+ glutPostRedisplay();
break;
case ' ':
}
glutPostRedisplay();
break;
+
+ case 't':
+ show_blocks = !show_blocks;
+ glutPostRedisplay();
+ break;
+
+ case 'g':
+ show_grid = !show_grid;
+ glutPostRedisplay();
+ break;
}
}
fclose(fp);
return 0;
}
+
+void draw_grid(void)
+{
+ int x, y;
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(0, win_width, 0, win_height, -1, 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glBegin(GL_LINES);
+ glColor3f(0.5, 0.2, 0.1);
+ for(y=0; y<win_height; y += 32) {
+ glVertex2f(0, y);
+ glVertex2f(win_width, y);
+ }
+ for(x=0; x<win_width; x += 32) {
+ glVertex2f(x, 0);
+ glVertex2f(x, win_height);
+ }
+ glEnd();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+}