erebus

diff src/main.cc @ 34:d15ee526daa6

- changed the UI font, made it a bit smaller - fixed the text positioning in the status bar - added ThreadPool::clear to remove all pending jobs - fixed the TargetCamera matrix calculation to avoid singularities when the camera looks straight up or down. - fixed ommited normalization in TargetCamera's matrix calculation - added paths/sec display in the status bar
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 08 Jun 2014 08:12:05 +0300
parents b1fc96c71bcc
children db8a90307386
line diff
     1.1 --- a/src/main.cc	Sat Jun 07 14:21:56 2014 +0300
     1.2 +++ b/src/main.cc	Sun Jun 08 08:12:05 2014 +0300
     1.3 @@ -1,5 +1,6 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6 +#include <string.h>
     1.7  #include <assert.h>
     1.8  #include <signal.h>
     1.9  #include <vector>
    1.10 @@ -88,10 +89,10 @@
    1.11  	width = glutGet(GLUT_WINDOW_WIDTH) / opt_imgscale;
    1.12  	height = glutGet(GLUT_WINDOW_HEIGHT) / opt_imgscale;
    1.13  
    1.14 +	//if(!(font = dtx_open_font("/usr/share/fonts/opentype/linux-libertine/LinLibertine_R.otf", 22))) {
    1.15  	if(!(font = dtx_open_font_glyphmap("data/serif.glyphmap"))) {
    1.16  		fprintf(stderr, "warning: failed to load font!\n");
    1.17  	}
    1.18 -	dtx_use_font(font, 24);
    1.19  
    1.20  	if(!(erb = erb_init())) {
    1.21  		return false;
    1.22 @@ -244,6 +245,9 @@
    1.23  	float maxu = (float)width / (float)rtex_width;
    1.24  	float maxv = (float)height / (float)rtex_height;
    1.25  
    1.26 +	glEnable(GL_TEXTURE_2D);
    1.27 +	glBindTexture(GL_TEXTURE_2D, rtex);
    1.28 +
    1.29  	glBegin(GL_QUADS);
    1.30  	glColor4f(1, 1, 1, 1);
    1.31  	glTexCoord2f(0, maxv); glVertex2f(-1, -1);
    1.32 @@ -267,7 +271,6 @@
    1.33  
    1.34  	bool show_progress = opt_samples > 0;
    1.35  
    1.36 -	glPushAttrib(GL_ENABLE_BIT);
    1.37  	glDisable(GL_TEXTURE_2D);
    1.38  
    1.39  	glMatrixMode(GL_PROJECTION);
    1.40 @@ -279,40 +282,68 @@
    1.41  	glPushMatrix();
    1.42  	glLoadIdentity();
    1.43  
    1.44 -	int font_height = dtx_glyph_height('Q');
    1.45 +	dtx_box bbox;
    1.46 +	dtx_glyph_box('Q', &bbox);
    1.47 +
    1.48 +	// draw progress/status bar
    1.49 +	int bar_height = bbox.height + 4;
    1.50  	int prog_width = show_progress ? status.progress_percent * win_width / 100 : 0;
    1.51  
    1.52  	glBegin(GL_QUADS);
    1.53  	glColor4f(0, 0, 0, 1);
    1.54  	glVertex2f(prog_width, 0);
    1.55  	glVertex2f(win_width, 0);
    1.56 -	glVertex2f(win_width, font_height);
    1.57 -	glVertex2f(prog_width, font_height);
    1.58 +	glVertex2f(win_width, bar_height);
    1.59 +	glVertex2f(prog_width, bar_height);
    1.60  
    1.61  	glColor4f(0.25, 0, 0, 1);
    1.62  	glVertex2f(0, 0);
    1.63  	glVertex2f(prog_width, 0);
    1.64 -	glVertex2f(prog_width, font_height);
    1.65 -	glVertex2f(0, font_height);
    1.66 +	glVertex2f(prog_width, bar_height);
    1.67 +	glVertex2f(0, bar_height);
    1.68  	glEnd();
    1.69  
    1.70 -	glTranslatef(5, 5, 0);
    1.71 +	// draw the text
    1.72 +	glTranslatef(bbox.x + 2, bbox.y + 2, 0);
    1.73  
    1.74  	glColor4f(1, 1, 1, 1);
    1.75  
    1.76  	if(opt_samples > 0) {
    1.77 -		dtx_printf("samples: %d / %d\n", status.samples, status.max_samples);
    1.78 +		dtx_printf("samples: %ld / %ld", status.samples, status.max_samples);
    1.79  
    1.80 -		glTranslatef(win_width - dtx_string_width("progress: 100%") - 5, 0, 0);
    1.81 -		dtx_printf("progress: %d%%\n", status.progress_percent);
    1.82 +		glLoadIdentity();
    1.83 +		glTranslatef(win_width - dtx_string_width("progress: 100%") - 2, bbox.y + 2, 0);
    1.84 +		dtx_printf("progress: %ld%%", status.progress_percent);
    1.85  	} else {
    1.86 -		dtx_printf("samples: %d\n", status.samples);
    1.87 +		dtx_printf("samples: %ld", status.samples);
    1.88  	}
    1.89 +
    1.90 +	// samples/sec display
    1.91 +	static long paths_per_sec, prev_msec, prev_paths;
    1.92 +
    1.93 +	long msec = duration_cast<milliseconds>(steady_clock::now() - start_time).count();
    1.94 +	long dt = msec - prev_msec;
    1.95 +
    1.96 +	if(dt >= 1500) {	// average over 1.5 seconds
    1.97 +		long paths = status.samples * width * height;
    1.98 +		if(prev_msec > 0 && prev_paths <= paths) {	// check valid interval (not a restart or whatever)
    1.99 +			paths_per_sec = 1000 * (paths - prev_paths) / dt;
   1.100 +		}
   1.101 +		prev_msec = msec;
   1.102 +		prev_paths = paths;
   1.103 +	}
   1.104 +
   1.105 +	glLoadIdentity();
   1.106 +	glTranslatef((win_width - dtx_string_width("paths/s: 999999")) / 2, bbox.y + 2, 0);
   1.107 +	if(paths_per_sec) {
   1.108 +		dtx_printf("paths/s: %ld", paths_per_sec);
   1.109 +	} else {
   1.110 +		dtx_printf("paths/s: ???");
   1.111 +	}
   1.112 +
   1.113  	glPopMatrix();
   1.114  	glMatrixMode(GL_PROJECTION);
   1.115  	glPopMatrix();
   1.116 -
   1.117 -	glPopAttrib();
   1.118  }
   1.119  
   1.120  static void save_image(const char *fname)
   1.121 @@ -344,12 +375,12 @@
   1.122  		begin_frame(0);
   1.123  		break;
   1.124  
   1.125 -	case '`':
   1.126 +	case '\b':
   1.127  		printf("saving image.\n");
   1.128  		save_image();
   1.129  		break;
   1.130  
   1.131 -	case 'p':
   1.132 +	case '`':
   1.133  		show_status = !show_status;
   1.134  		glutPostRedisplay();
   1.135  		break;
   1.136 @@ -451,4 +482,4 @@
   1.137  	}
   1.138  
   1.139  	return true;
   1.140 -}
   1.141 \ No newline at end of file
   1.142 +}