예제 #1
0
파일: intro.c 프로젝트: jaeh/may_first
void draw_overlay( program_state_t* PS )
{
	int w = PS->window_width;
	int h = PS->window_height;
	microtime_t T = PS->current_time_us;

	GLfloat R, G, B;

	glViewport( 0, 0, w, h );		// Using screen coordinates

	glMatrixMode( GL_PROJECTION );		// Setup 2D mode
	glLoadIdentity();
	gluOrtho2D( 0, w, 0, h );

	glMatrixMode( GL_MODELVIEW );
	glDisable( GL_DEPTH_TEST );
	glLoadIdentity();

	color_from_hue( (T % 6000000) / 6000000.0, &R, &G, &B );
	glColor3f( R, G, B );

	glLineWidth( 2 );
	glBegin( GL_LINES );
		glVertex2i( 0, 2*h/3 );
		glVertex2i( w, 2*h/3 );
	glEnd();
	glLineWidth( 1 );

	hud_printf( PS,
		w/2,
		2*h/3 + PS->line_height/2,
		ALIGN_CENTER,
		0xFFFFFF,
		PROGRAM_NAME
	);

	hud_printf( PS,
		w/2,
		2*h/3 - 3*PS->line_height/2,
		ALIGN_CENTER,
		0x888888,
		PROGRAM_VERSION
	);
}
예제 #2
0
void draw_hud_resource( program_state_t* PS, game_state_t* GS )
{
	int	i, j;
	real_t	x, y;
	GLfloat	R, G, B;

	real_t	bar_width, step_size;
	real_t	resource;
	int	resource_color;
	int	hit_points = calculate_hit_points( GS->current_resource );

	microtime_t Tc = PS->current_time_us;

	int w = PS->window_width;
	int h = PS->window_height;

	// In cheat mode, after the numbers are output as digits, ..
	// ..we use an adjusted Resource value to get a nice bar size
	resource
		= GS->current_resource
#if CHEAT_MODE
		/ CHEAT_RESOURCE_FACTOR
#endif
	;


	/* CALCULATE BASE COLOR indicating level of resource */

	color_from_hue(
		// The following ratio is manually tweaked to give nice..
		// ..results up to 10K. Perhaps using log2 would be better?
		fmin( 1.0, sqrt(GS->current_resource) / 100.0 ),
		&R, &G, &B
	);

	resource_color                          // Pack the float values into..
		= ((int)(R * 255) << 16)        // ..a handy int.
		+ ((int)(G * 255) << 8)
		+ ((int)(B * 255) << 0)
	;


	/* RENDER RESOURCE as TEXT (ALIGN_TOP Panel) */

	hud_printf(
		PS,
		PS->window_width/2,
		h - 3*PS->line_height/2,
		ALIGN_CENTER,
		resource_color,
		"ENERGY: %d (%d)",
		GS->current_resource,
		GS->best_resource
	);

	/* CALCULATE BLINK COLOR */

	// From here on, everything rendered might be blinking

	if (resource >= 200) {
		/* Reuse R, G and B from above, no change needed */
	} else {
		if      (resource < 50)   i = 150000;
		else if (resource < 100)  i = 225000;
		else if (resource < 150)  i = 350000;
		else {                    i = 500000;
		}

		GLfloat f = fabs((int)(Tc % i) - i/2) / ((GLfloat)i/2);
		R = R * f;
		G = G * f;
		B = B * f;

		// Additionally blink white, when Resource critically low
		if ((resource < 50) && (Tc % 150000 < 50000)) {
			R = G = B = 1.0;
		}
	}
	resource_color                          // Pack the float values into..
		= ((int)(R * 255) << 16)        // ..a handy int.
		+ ((int)(G * 255) << 8)
		+ ((int)(B * 255) << 0)
	;


	/* RESOURCE BAR */

	// Calculate size of the bar
	bar_width = sqrt(resource) * 10.0;   //... Perhaps we should use log2 ?
	step_size = round( bar_width / hit_points );

	glBegin( GL_LINES );
	glColor3f( R, G, B );

	for( i = 0 ; i < 5 ; i++ ) {
		for( j = 0 ; j < hit_points ; j++ ) {

			x = (w - bar_width)/2 + (real_t)j * step_size;
			y = h - 3*PS->line_height + i*2;

			glVertex2i( x + 1.0,             y );
			glVertex2i( x - 1.0 + step_size, y );
		}
	}
	glEnd();

	hud_printf(
		PS,
		PS->window_width/2,
		h - 9*PS->line_height/2,
		ALIGN_CENTER,
		resource_color,
		"%d",
		hit_points
	);
}